Extending size of Boot Disk on Rocky8 with LVM

OK so the scenario is that we are using boot disks on vsphere/vmware and use LVM. We have allocated all available space as predicted usage has grown beyond what we anticipated. This is how we do it.

So by example.

On Rocky Linux we haveĀ  a boot disk sda.

This provides two partitions: sda1 (/boot) and sda2 (LVM)

sda2 is used for LVM (to make /, /var, /home and so on)

The sda2 LVM volume group is “rootvg”

This is all pretty normal.

The plan:

  1. Increase the disk size in Vsphere.
  2. Reboot
  3. The disk size sda should be observed to be bigger.
  4. Now delete partition sda2 and recreate it taking default for the full size of the disk
  5. pvresize /dev/sda2  to extend the size of the system volume group (rootvg in this case)

This is a test machine so I am going to increase the disk just 2GB, so this is the situation before.

fdisk -l /dev/sda
Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectors
...
Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   3907583   3905536  1.9G 83 Linux
/dev/sda2       3907584 125829119 121921536 58.1G 8e Linux LVM

pvs
  PV         VG     Fmt  Attr PSize  PFree 
  /dev/sda2  rootvg lvm2 a--  58.13g 39.95g

After I increase the disk volume size in vsphere and reboot, this is how the partition looks:

 fdisk -l /dev/sda
Disk /dev/sda: 62 GiB, 66571993088 bytes, 130023424 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7c703867

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   3907583   3905536  1.9G 83 Linux
/dev/sda2       3907584 125829119 121921536 58.1G 8e Linux LVM

So we are going to delete sda2 to grow it. We are going to preserve the LVM signature by the way.

 fdisk /dev/sda
p * print current
d * delete
2
n * create
   p (default) * primary partition
   2 (default) * partition number
  (default) first/last cylinders
Partition #2 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: N

t * change partition id
  2 (default)
  8e (hex code)
b * print the current again to verify its expanded
w * write changes

So after doing this, inspect with fdisk to check the LVM disk is now expanded.

fdisk /dev/sda

Disk /dev/sda: 62 GiB, 66571993088 bytes, 130023424 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7c703867

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   3907583   3905536  1.9G 83 Linux
/dev/sda2       3907584 130023423 126115840 60.1G 8e Linux LVM

And resize the volume group on sda2. An extra 2GB in the example shows up in the PFree column.

pvresize /dev/sda2
  Physical volume "/dev/sda2" changed

pvs
  PV         VG     Fmt  Attr PSize  PFree 
  /dev/sda2  rootvg lvm2 a--  60.13g 41.95g

So with the disk bigger, you can extend LVM paritions in the volume group eg

lvextend -L+2G /dev/mapper/rootvg-var
xfs_growfs /var

My notes for doing this previously on CentOS7 included doing the partition changes by booting off CDROM.