Software Developer, Linux Enthusiast, Musician, Weeb
4 October 2016
vgs
to check the volume group's capacity:
# vgs VG #PV #LV #SN Attr VSize VFree volgroup00 2 1 0 wz--n- 19.99g 9.99g
PV VG Fmt Attr PSize PFree /dev/xvdb1 volgroup00 lvm2 a-- 10.00g 10.00g /dev/xvdb2 volgroup00 lvm2 a-- 10.00g 10.00g /dev/xvdc volgroup01 lvm2 a-- 25.00g 25.00gThis is a device with partitions:
# parted /dev/xvdb unit gib print Model: Xen Virtual Block Device (xvd) Disk /dev/xvdb: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 0.00GiB 10.0GiB 10.0GiB primary lvm 2 10.0GiB 20.0GiB 10.0GiB primary lvmThis is a device without partitions:
# parted /dev/xvdc unit gib print Error: /dev/xvdc: unrecognised disk label Model: Xen Virtual Block Device (xvd) Disk /dev/xvdc: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags:
# pvs PV VG Fmt Attr PSize PFree /dev/xvdc volgroup01 lvm2 a-- 25.00g 25.00g # parted /dev/xvdc unit gib print Error: /dev/xvdc: unrecognised disk label Model: Xen Virtual Block Device (xvd) Disk /dev/xvdc: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags:
# echo 1 > /sys/block/xvdc/device/rescan # vgs VG #PV #LV #SN Attr VSize VFree volgroup01 1 0 0 wz--n- 25.00g 25.00g # pvs PV VG Fmt Attr PSize PFree /dev/xvdc volgroup01 lvm2 a-- 25.00g 25.00g
# pvresize /dev/xvdc Physical volume "/dev/xvdc" changed 1 physical volume(s) resized / 0 physical volume(s) not resized # pvs PV VG Fmt Attr PSize PFree /dev/xvdc volgroup01 lvm2 a-- 50.00g 50.00g # vgs VG #PV #LV #SN Attr VSize VFree volgroup01 1 0 0 wz--n- 50.00g 50.00g
# echo "- - -" > /sys/class/scsi_host/host0/scan
# parted /dev/xvdc mklabel gpt # parted /dev/xvdc mkpart primary 0% 100%
# parted /dev/xvdb unit gib print free Model: Xen Virtual Block Device (xvd) Disk /dev/xvdb: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 0.00GiB 0.00GiB 0.00GiB Free Space 1 0.00GiB 10.0GiB 10.0GiB primary lvm 2 10.0GiB 20.0GiB 10.0GiB primary lvm 20.0GiB 50.0GiB 30.0GiB Free Space
parted
to create a new lvm partition.# parted /dev/xvdb unit gib print Model: Xen Virtual Block Device (xvd) Disk /dev/xvdb: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 0.00GiB 10.0GiB 10.0GiB primary lvm 2 10.0GiB 20.0GiB 10.0GiB primary lvm # parted /dev/xvdb mkpart primary 20GiB 30GiB # parted /dev/xvdb set 3 lvm on # parted /dev/xvdb unit gib print Model: Xen Virtual Block Device (xvd) Disk /dev/xvdb: 50.0GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 0.00GiB 10.0GiB 10.0GiB primary lvm 2 10.0GiB 20.0GiB 10.0GiB primary lvm 3 20.0GiB 30.0GiB 10.0GiB primary lvm
pvcreate
to build a new physical volume on the partition.# pvs PV VG Fmt Attr PSize PFree /dev/xvdb1 lvm2 --- 10.00g 10.00g /dev/xvdb2 lvm2 --- 10.00g 10.00g # pvcreate /dev/xvdb3 # pvs PV VG Fmt Attr PSize PFree /dev/xvdb1 lvm2 --- 10.00g 10.00g /dev/xvdb2 lvm2 --- 10.00g 10.00g /dev/xvdb3 lvm2 --- 10.00g 10.00g
vgextend
to extend the volume group with the new physical volume.# vgs VG #PV #LV #SN Attr VSize VFree volgroup00 2 1 0 wz--n- 19.99g 9.99g # vgextend volgroup00 /dev/xvdb3 Volume group "volgroup00" successfully extended # vgs VG #PV #LV #SN Attr VSize VFree volgroup00 2 1 0 wz--n- 29.99g 19.99g
lvextend
to increase the size of the logical partition.# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvol0 volgroup00 -wi-a----- 10.00gWe can extend with a specific size:
# lvextend -L +5GiB /dev/mapper/volgroup00-lvol0 Size of logical volume volgroup00/lvol0 changed from 10.00 GiB (2560 extents) to 15.00 GiB (3840 extents). Logical volume lvol0 successfully resized. # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvol0 volgroup00 -wi-a----- 15.00gWe can fill the entire device:
# lvextend -l +100%FREE /dev/mapper/volgroup00-lvol0 Size of logical volume volgroup00/lvol0 changed from 15.00 GiB (3840 extents) to 29.99 GiB (7677 extents). Logical volume lvol0 successfully resized. # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvol0 volgroup00 -wi-a----- 29.99g
resize2fs
to resize the filesystem.# df -h /dev/volgroup00/lvol0 Filesystem Size Used Avail Use% Mounted on /dev/mapper/volgroup00-lvol0 20G 45M 19G 1% /mnt/volgroup00/lvol0 # resize2fs /dev/volgroup00/lvol0 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/volgroup00/lvol0 is mounted on /mnt/volgroup00/lvol0; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The filesystem on /dev/volgroup00/lvol0 is now 7859200 blocks long. # df -h /dev/volgroup00/lvol0 Filesystem Size Used Avail Use% Mounted on /dev/mapper/volgroup00-lvol0 30G 44M 28G 1% /mnt/volgroup00/lvol0
xfs_growfs
to resize the filesystem.# df -h /dev/volgroup00/lvol0 Filesystem Size Used Avail Use% Mounted on /dev/mapper/volgroup00-lvol0 20G 45M 19G 1% /mnt/volgroup00/lvol0 # resize2fs /dev/volgroup00/lvol0 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/volgroup00/lvol0 is mounted on /mnt/volgroup00/lvol0; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The filesystem on /dev/volgroup00/lvol0 is now 7859200 blocks long. # df -h /dev/volgroup00/lvol0 Filesystem Size Used Avail Use% Mounted on /dev/mapper/volgroup00-lvol0 30G 44M 28G 1% /mnt/volgroup00/lvol0