# Logical Volume Manager command usage (lvm) ###### tags: `linux` `lvm` ``` # term PV - physical volume VG - volume group PE - physical extent LV - logical volume ``` ### list current lvm ``` root@develop:/home/ycheng# lvmdiskscan /dev/vda2 [ <20.00 GiB] /dev/vdb [ 20.00 GiB] /dev/vdc [ 20.00 GiB] 2 disks 1 partition 0 LVM physical volume whole disks 0 LVM physical volumes ``` ### create / remove PV ``` root@develop:/home/ycheng# pvcreate /dev/vdb Physical volume "/dev/vdb" successfully created. root@develop:/home/ycheng# pvcreate /dev/vdc Physical volume "/dev/vdc" successfully created. root@develop:/home/ycheng# lvmdiskscan /dev/vda2 [ <20.00 GiB] /dev/vdb [ 20.00 GiB] LVM physical volume /dev/vdc [ 20.00 GiB] LVM physical volume 0 disks 1 partition 2 LVM physical volume whole disks 0 LVM physical volumes root@develop:/home/ycheng# pvdisplay "/dev/vdc" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/vdc VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID LraVsw-U2HV-e2nA-z7rc-qKtx-QVmr-YNk0dF "/dev/vdb" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/vdb VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID o4dT1U-SkDI-lunc-2Q7n-60OJ-40TL-72zoFB !!! remove PV pvremove < PV Name > ``` ### create / remove VG ``` root@develop:/home/ycheng# vgcreate vg1 /dev/vdb /dev/vdc Volume group "vg1" successfully created root@develop:/home/ycheng# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VG UUID OwIsAL-iQSB-FJb0-dGUG-O4ro-1iNK-sw7Baf !!! create VG with PE size to 128MiB vgcreate -s 128 vg1 /dev/vdb /dev/vdc !!! remove VG vgremove vg1 !!! maximum 65534 PEs. ``` ### create /remove LV ``` root@develop:/home/ycheng# lvcreate -L 8G -n lv1 vg1 Logical volume "lv1" created. root@develop:/home/ycheng# lvcreate -l 100%FREE -n lv2 vg1 Logical volume "lv2" created. root@develop:/home/ycheng# lvdisplay --- Logical volume --- LV Path /dev/vg1/lv1 LV Name lv1 VG Name vg1 LV UUID 03jsBD-3XKC-88oZ-XHwJ-uJHw-J92j-MtTGdL LV Write Access read/write LV Creation host, time develop, 2020-11-15 05:46:58 +0000 LV Status available # open 0 LV Size 8.00 GiB Current LE 2048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg1/lv2 LV Name lv2 VG Name vg1 LV UUID zMhcOs-Xpib-SSyA-fmeI-6puj-k3v8-NXAsb6 LV Write Access read/write LV Creation host, time develop, 2020-11-15 05:47:59 +0000 LV Status available # open 0 LV Size 31.99 GiB Current LE 8190 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 !!! create "striped" allocation type LV 8GB root@develop:/home/ycheng# lvcreate --type striped -i 2 -L 8G -n striped_lv1 vg1 Using default stripesize 64.00 KiB. Logical volume "striped_lv1" created. !!! allocate 100% free extends to create new LV. "-l < extends number >" root@develop:/home/ycheng# lvcreate --type striped -i 2 -l 100%FREE -n striped_lv2 vg1 Using default stripesize 64.00 KiB. Logical volume "striped_lv2" created. !!! remove LV lvremove /dev/vg1/striped_lv2 ``` ### create / remove snapshot and merge (recovery) ``` root@develop:/home/ycheng# lvcreate -s -L 8G -n snap_striped_lv1 vg1/striped_lv1 Using default stripesize 64.00 KiB. Logical volume "snap_striped_lv1" created. root@develop:/home/ycheng# lvconvert --merge vg1/snap_striped_lv1 Merging of volume vg1/snap_striped_lv1 started. vg1/striped_lv1: Merged: 100.00% !!! remove snapshot lvremove ``` ### resize LV ``` root@develop:/home/ycheng# lvscan ACTIVE '/dev/vg1/striped_lv1' [8.00 GiB] inherit root@develop:/home/ycheng# lvresize -L +4G vg1/striped_lv1 Using stripesize of last segment 64.00 KiB Size of logical volume vg1/striped_lv1 changed from 8.00 GiB (2048 extents) to 12.00 GiB (3072 extents). Logical volume vg1/striped_lv1 successfully resized. ``` ### remove PV from VG ``` pvmove /dev/vdc vgreduce vg1 /dev/vdc pvremove /dev/vdc ``` ### rename VG ``` root@develop:/home/ycheng# vgscan Reading volume groups from cache. Found volume group "vg1" using metadata type lvm2 root@develop:/home/ycheng# vgrename vg1 new_vg1 Volume group "vg1" successfully renamed to "new_vg1" root@develop:/home/ycheng# vgscan Reading volume groups from cache. Found volume group "new_vg1" using metadata type lvm2 ``` ### other commands ``` vgextend - add new PV to VG vgchange - change VG attributes lvextend - increase LV size lvreduce - reduce LV size ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up