LVMの使い方をすぐ忘れてしまうので、覚え書き。 LVM用のパーティションを用意しておいてください。ここでは/dev/sda7とします。
基本編
物理ボリューム作成する
# pvcreate /dev/sda7
確認する
# pvdisplay --- Physical volume --- PV Name /dev/sda7 VG Name vol1 PV Size 672.28 GiB / not usable 3.13 MiB Allocatable yes PE Size 4.00 MiB Total PE 172102 Free PE 171846 Allocated PE 256 PV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx
ボリュームグループを、vg1という名前で作成する。
# vgcreate vg1 /dev/sda7 Volume group "vg1" successfully created
確認する
# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 672.27 GiB PE Size 4.00 MiB Total PE 172102 Alloc PE / Size 256 / 1.00 GiB Free PE / Size 171846 / 671.27 GiB VG UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-zzzzzz
1GBのロジカルボリュームを、lvol1という名前で vol1 から切り出す
# lvcreate -L 1G -n lv1 vg1 Logical volume "lv1" created
確認する
# lvdisplay --- Logical volume --- LV Name /dev/vg1/lv1 VG Name vg1 LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwwww LV Write Access read/write LV Status available # open 0 LV Size 1.00 GiB Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
以上で、/dev/vg1/lv1 を普通のパーティションのように使用できます。
ちなみに、削除は、lvremove, vgremove といったコマンドを使いますし、名前を変更したいならば、vgrenameやlvrenameを使いますが、ここでは省略します。
次ページの応用編に備えて、とりあえずファイルシステム作成しておきます。
mke2fs -j /dev/vg1/lv1
次は応用編
応用編
ファイルシステムの拡張(ext3の場合)
ロジカルボリュームを1GB増やす
# lvextend -L +1G /dev/vg1/lv1 Extending logical volume lv1 to 2.00 GiB Logical volume lv1 successfully resized
確認
# lvdisplay
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwwww
LV Write Access read/write
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
ファイルシステムチェック
# e2fsck -f /dev/vg1/lv1 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg1/lv1: 11/65536 files (0.0% non-contiguous), 12644/262144 blocks
ファイルシステム拡張
# resize2fs /dev/vg1/lv1 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg1/lv1 to 524288 (4k) blocks. The filesystem on /dev/vg1/lv1 is now 524288 blocks long.
スナップショットの作成
lv1のスナップショットをlv1-snapという名前で取得。cow (copy-on-write)領域は100MBとする。つまり、100MB分の書き換えまで大丈夫なスナップショット領域となる。
# lvcreate -L 100M -n lv1-snap --snapshot /dev/vg1/lv1
確認
# lvdisplay
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwwww
LV Write Access read/write
LV snapshot status source of
/dev/vg1/lv1-snap [active]
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/vg1/lv1-snap
VG Name vg1
LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwww1
LV Write Access read/write
LV snapshot status active destination for /dev/vg1/lv1
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
COW-table size 100.00 MiB
COW-table LE 25
Allocated to snapshot 0.01%
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
COW領域が少なくなってきた場合、100M増やす。
# lvextend -L +100M -n /dev/vg1/lv1-snap Extending logical volume lv1-snap to 200.00 MiB Logical volume lv1-snap successfully resized
確認
# lvdisplay
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwwww
LV Write Access read/write
LV snapshot status source of
/dev/vg1/lv1-snap [active]
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/vg1/lv1-snap
VG Name vg1
LV UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-wwwww1
LV Write Access read/write
LV snapshot status active destination for /dev/vg1/lv1
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
COW-table size 200.00 MiB
COW-table LE 50
Allocated to snapshot 0.00%
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1