increase root fs lvs
I came across the issue of having to increase the size of the a hard disk partition containing all logical volumes comprising the root file system on a VM.
In this example, our block devices will be similar to the following:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 250M 0 part /boot/efi
└─sda3 8:3 0 99.3G 0 part
├─vg_root-lv_root 253:0 0 4G 0 lvm /
├─vg_root-lv_swap 253:1 0 4G 0 lvm [SWAP]
├─vg_root-lv_usr 253:2 0 8G 0 lvm /usr
├─vg_root-lv_opt 253:3 0 8G 0 lvm /opt
├─vg_root-lv_tmp 253:4 0 8G 0 lvm /tmp
├─vg_root-lv_home 253:5 0 20G 0 lvm /home
└─vg_root-lv_var 253:6 0 20G 0 lvm /var
sr0 11:0 1 1024M 0 rom
If you hypervisor allows, expand the size of the VMs disk. In my example, I am using vSphere 6.7 and will be expanding /dev/sda
from 100G to 101G.
Next, you’ll need to rescan the SCSI device. Before proceeding, find the SCSI address of your target disk:
ls -d /sys/block/sda/device/scsi_device/*
/sys/block/sda/device/scsi_device/0:0:0:0
Now that we’re certain the SCSI address is 0:0:0:0
, rescan the SCSI device:
echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
After noting down where the cylinder starts, proceed with caution and delete the partition containing your LVM structure. After deleting the target partition, create a new one using the same partition number, default start sector (double check that it matches the above), default end sector, and change the partition type to ‘Linux LVM’ with hexcode 8e
fdisk -l /dev/sda
Disk /dev/sda: 108.4 GB, 108447924224 bytes, 211812352 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
Disk label type: dos
Disk identifier: 0x000bf25d
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 1538047 256000 6 FAT16
/dev/sda3 1538048 209715199 104088576 8e Linux LVM
fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (1538048-211812351, default 1538048):
Using default value 1538048
Last sector, +sectors or +size{K,M,G} (1538048-211812351, default 211812351):
Using default value 211812351
Partition 3 of type Linux and of size 100.3 GiB is set
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Use partprobe to supply the kernel with the new partition table:
partprobe
We can now see that /dev/sda
has grown to the size we specified before:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 101G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 250M 0 part /boot/efi
└─sda3 8:3 0 100.3G 0 part
├─vg_root-lv_root 253:0 0 4G 0 lvm /
├─vg_root-lv_swap 253:1 0 4G 0 lvm [SWAP]
├─vg_root-lv_usr 253:2 0 8G 0 lvm /usr
├─vg_root-lv_opt 253:3 0 8G 0 lvm /opt
├─vg_root-lv_tmp 253:4 0 8G 0 lvm /tmp
├─vg_root-lv_home 253:5 0 20G 0 lvm /home
└─vg_root-lv_var 253:6 0 20G 0 lvm /var
sr0 11:0 1 1024M 0 rom
To supply the additional 1GB to our root volume group, vg_root
:
vgs
VG #PV #LV #SN Attr VSize VFree
vg_root 1 7 0 wz--n- <99.27g <27.27g
pvresize /dev/sda3
vgs
VG #PV #LV #SN Attr VSize VFree
vg_root 1 7 0 wz--n- <100.27g <28.27g