LVM でストレージに拡張性を持たせる
LVMは論理的にボリュームを管理できる機能です。
物理ディスクの場合、容量は固定ですが LVM で論理的に管理する事でボリュームの増設・縮小が可能になります。また、 Kubernetes 向けストレージプロバイダーの製品に LVM の機能を内包しているものがいくつかあるので、利用して慣れる点でもメリットがあると考えています。
LVM の考え方は以下の通りです。
- Physical Volume(PV) -> 物理的なディスクまたはパーティション
- Volume Group(VG) -> 1つ以上のPVをグルーピング
- Logical Volume(LV) -> VGを論理的なボリュームとして確保
上記の概念をコマンドで設定していきます。
コマンドの概要についても記載します。
論理ボリューム
| コマンド | 概要 |
| --------- | -------------------- |
| pvcreate | 物理ボリュームの作成 |
| pvdisplay | 物理ボリュームの表示 |
| pvremove | 物理ボリュームの削除 |
ボリュームグループの管理コマンド
| コマンド | 概要 |
| --------- | ------------------------ |
| vgcreate | ボリュームグループの作成 |
| vgdisplay | ボリュームグループの表示 |
| vgremove | ボリュームグループの削除 |
| vgextend | ボリュームグループの拡張 |
| vgreduce | ボリュームグループの縮小 |
論理ボリュームの管理コマンド
| コマンド | 概要 |
| --------- | -------------------- |
| lvcreate | 論理ボリュームの作成 |
| lvdisplay | 論理ボリュームの表示 |
| lvremove | 論理ボリュームの削除 |
| lvextend | 論理ボリュームの拡張 |
| lvreduce | 論理ボリュームの縮小 |
論理ボリュームの容量指定方法
数値%VG = diskの総量から何%か指定して作成する
数値%FREE = diskの空き容量から何%か指定して作成する
VG全体のサイズに対する割合を指定してLVを作成
lvcreate -l 数値%VG -n 論理ボリューム名 ボリュームグループ名
VGの空き容量に対する割合を指定して、LVを作成
lvcreate -l 数値%FREE -n 論理ボリューム名 ボリュームグループ名
ここからは設定方法について紹介します。
目次
- 物理ボリューム作成(PV)
- ボリュームグループ作成(VG)
- 論理ボリューム作成(LV)
- 論理ボリュームをファイルシステムにフォーマット
- ファイルシステム状態確認
- 自動マウント設定
まずは、 fdisk コマンドでディスクまたはパーティションを確認します。
fdisk -l
Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Generic
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
fdisk で確認したディスクに対して物理ボリューム(PV)を設定します。
pvcreate /dev/sda
ボリュームグループ作成します。
vgcreate
vgcreate vg01 /dev/sda
論理ボリューム作成を作成します。
VG から確保する容量を -l で指定し、 -n で論理ボリューム名を付けます。
今回は複数の用途に分けて LV を作成します。
RAWデバイス用のLV
lvcreate -l 20%VG -n lv-raw vg01
docker volume用のLV
lvcreate -l 30%VG -n lv-fs-docker vg01
GlusterFS用のLV
lvcreate -l 100%FREE -n lv-fs vg01
フォーマットする際に必要なパスを確認(LV Path)します。
root@node1:/home# lvdisplay
--- Logical volume ---
LV Path /dev/vg01/lv-fs-docker
LV Name lv-fs-docker
VG Name vg01
LV UUID J6PGbx-cPqW-QozB-PK6p-aZdJ-P5LW-2hsHT5
LV Write Access read/write
LV Creation host, time node1, 2021-01-28 14:05:03 +0000
LV Status available
# open 1
LV Size 279.45 GiB
Current LE 71540
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg01/lv-raw
LV Name lv-raw
VG Name vg01
LV UUID x73sDZ-Uhwd-HDSZ-wT7V-6nA7-Ses7-ZEUVfR
LV Write Access read/write
LV Creation host, time node1, 2021-01-28 14:05:12 +0000
LV Status available
# open 0
LV Size 186.30 GiB
Current LE 47693
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/vg01/lv-fs
LV Name lv-fs
VG Name vg01
LV UUID JijAhZ-93Rx-B0V0-n5MQ-vVUu-064S-ozhVfQ
LV Write Access read/write
LV Creation host, time node1, 2021-01-28 14:05:20 +0000
LV Status available
# open 1
LV Size <465.76 GiB
Current LE 119234
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
論理ボリュームをフォーマットします。
※フォーマット完了まで少し間があるので、プロンプトの応答があるまで待機
mkfs.<フォーマット形式>
mkfs.xfs /dev/vg01/lv-fs
mkfs.ext4 /dev/vg01/lv-fs-docker
フォーマットの状態を確認します。
root@node1:/home# lsblk -fi
sda LVM2_member QeHaKf-TNdL-z1vp-4QP4-DitI-6wYN-mfKqeK
|-vg01-lv--fs--docker ext4 05a55309-ea7a-4ee8-b435-7be149171c66 258.9G 0% /var/lib/docker/volumes
|-vg01-lv--raw
`-vg01-lv--fs xfs fd1f53fc-5d35-4310-b908-388d05b2f3aa 451.3G 3% /data
自動マウント設定のため、UUIDを確認します。
root@node1:/home# blkid
/dev/mmcblk0p1: LABEL_FATBOOT="system-boot" LABEL="system-boot" UUID="B726-57E2" TYPE="vfat" PARTUUID="ab86aefd-01"
/dev/mmcblk0p2: LABEL="writable" UUID="483efb12-d682-4daf-9b34-6e2f774b56f7" TYPE="ext4" PARTUUID="ab86aefd-02"
/dev/sda: UUID="QeHaKf-TNdL-z1vp-4QP4-DitI-6wYN-mfKqeK" TYPE="LVM2_member"
/dev/mapper/vg01-lv--fs--docker: UUID="05a55309-ea7a-4ee8-b435-7be149171c66" TYPE="ext4"
/dev/mapper/vg01-lv--fs: UUID="fd1f53fc-5d35-4310-b908-388d05b2f3aa" TYPE="xfs"
自動マウント設定に必要なパスを確認します。
lvdisplay で確認した場合ファイルパスは “-” を用いているのですが
fdisk コマンドで確認すると “/” が “-” に変っているので注意してください。
/etc/fstab にマウント設定を記載する際は fdisk で表示されている Disk名を記載します。
root@node1:/home# fdisk -l
Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Generic
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/vg01-lv--fs--docker: 279.46 GiB, 300060508160 bytes, 586055680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/vg01-lv--raw: 186.31 GiB, 200038940672 bytes, 390701056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/vg01-lv--fs: 465.78 GiB, 500103643136 bytes, 976764928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
起動時に自動でマウントする設定を行います。
vi /etc/fstab
LABEL=writable / ext4 defaults 0 0
LABEL=system-boot /boot/firmware vfat defaults 0 1
/dev/mapper/vg01-lv--fs--docker /var/lib/dcoker ext4 defaults 1 2
/dev/mapper/vg01-lv--fs /glsuterfs xfs defaults 1 2
以下コマンドで設定を反映して完了です。
mount -a