Jackson Argo

Me

Software Developer, Linux Enthusiast, Musician, Weeb

Add Space to a Filesystem with LVM

4 October 2016

Is there space in the volume group? Use 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
Are the physical volumes in the volume group on partitions?
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.00g
This 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  lvm
This 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:
Is the device entire used?
# 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:
Can you increase the size of the device?
Increase the size of the device.
Scan the device so the kernel recognizes the new size.
# 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
Increase the size of the physical volume.
# 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
Add a new device.
Scan the scsi host for the new device.
# echo "- - -" > /sys/class/scsi_host/host0/scan
Create a partition on the new device.
# parted /dev/xvdc mklabel gpt
# parted /dev/xvdc mkpart primary 0% 100%
Is there space available to add a new partition?
# 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
Use 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
Use 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
Use 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
Use 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.00g
We 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.00g
We 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
Is the filesystem ext4 or xfs?
Use 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
Use 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
You are done!
tags: filesystems - lvm