We are tasked with increasing the root LVM partition of a VM client without taking the system down. The disk size has been increased for the VM Client on the ESXi Host.
Note: You should always back up your data before making any changes to the filesystem to avoid data loss. The commands are ran on Oracle Linux 7. It should also work on other versions of Oracle Linux (OL) and Redhat Linux(RHEL) with little or no changes. All the commands should be executed as root user.
Step 1. Checking the current sizes of the root LVM and the disk.
[root@linux101 ~]# df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/rootvg-rootlv 50G 22G 25G 47% / [root@linux101 ~]# parted /dev/sda print Model: VMware Virtual disk (scsi) Disk /dev/sda: 215GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 1075MB 1074MB primary ext4 boot 2 1075MB 161GB 160GB primary lvm 3 161GB 215GB 53.7GB primary lvm [root@linux101 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rootvg lvm2 a-- <149.00g 0 /dev/sda3 rootvg lvm2 a-- <50.00g <15.00g
Step 2. Rescan the disk to update it with the new size.
Get the SCSI Disk ID
[root@linux101 ~]# dmesg|grep sda|grep "logical" [ 1.045452] sd 0:0:0:0: [sda] 419430400 512-byte logical blocks: (214 GB/200 GiB)
Then rescan it. Use the SCSI Disk ID from the dmesg output above.
[root@linux101 ~]# echo 1 > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan
Verify the new disk size. In this example, it went from 215GB to 236GB.
[root@linux101 ~]# parted /dev/sda print Model: VMware Virtual disk (scsi) Disk /dev/sda: 236GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 1075MB 1074MB primary ext4 boot 2 1075MB 161GB 160GB primary lvm 3 161GB 215GB 53.7GB primary lvm
We will expand the partition 3, which is already part of the LVM used for the root partition, to use up all the free space on the disk (i.e. 100%). There are different ways to do this. This is just one way. For example, we could have chosen to create a new partition rather than expanding the last partition.
[root@linux101 ~]# parted /dev/sda resizepart 3 100% Information: You may need to update /etc/fstab. [root@linux101 ~]# parted /dev/sda print Model: VMware Virtual disk (scsi) Disk /dev/sda: 236GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 1075MB 1074MB primary ext4 boot 2 1075MB 161GB 160GB primary lvm 3 161GB 236GB 75.2GB primary lvm
Step 3. Resize the Physical Volume.
[root@linux101 ~]# pvresize /dev/sda3 Physical volume "/dev/sda3" changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@linux101 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rootvg lvm2 a-- <149.00g 0 /dev/sda3 rootvg lvm2 a-- <70.00g <35.00g
Note that PFree above went up by 20G, from 15G to 35G.
Step 4. To extend the root LVM partition by 10G.
[root@linux101 ~]# lvextend -L +10G /dev/rootvg/rootlv Size of logical volume rootvg/rootlv changed from 50.00 GiB (12800 extents) to 60.00 GiB (15360 extents). Logical volume rootvg/rootlv successfully resized. [root@linux101 ~]# lvdisplay /dev/rootvg/rootlv --- Logical volume --- LV Path /dev/rootvg/rootlv LV Name rootlv VG Name rootvg LV UUID aMoKKt-uY0C-W12j-118f-53lI-cMaB-6AnBBz LV Write Access read/write LV Creation host, time esxihost1, 2020-01-15 09:42:40 -0800 LV Status available # open 2 LV Size 60.00 GiB Current LE 15360 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 249:0 [root@linux101 ~]# vgs VG #PV #LV #SN Attr VSize VFree rootvg 2 5 0 wz--n- 218.99g <25.00g
***This section below is for your information only. Skip to Step 5 to continue.***
Here are other ways to specify the sizes to extend with lvextend.
To use all available free space in the Volume Group.
lvextend -l +100%FREE /dev/rootvg/rootlv
To specify physical extents (PEs), determine where the Free PEs are located.
[root@linux101 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rootvg PV Size <149.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 38143 Free PE 0 Allocated PE 38143 PV UUID wxKNjo-Mc8E-k9Jn-RAn9-KVOu-OQmC-iMFwD4 --- Physical volume --- PV Name /dev/sda3 VG Name rootvg PV Size <70.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 17919 Free PE 6399 Allocated PE 11520 PV UUID eKOl1g-ojPa-O4jl-9lHX-4Hfd-dAfs-Dj0dOG
Then specify how much of the Free PE you want to extend the root partition. Example below specify 6399 which would be the entire Free PE for /dev/sda3.
lvextend -l lvextend -l +6399 /dev/rootvg/rootlv /dev/sda3
Step 5. Finally, resize the root LVM partition. As we can see from the df -h output, the /(root partition) has increased by 10G (from 25G to 35G).
[root@linux101 ~]# resize2fs /dev/rootvg/rootlv resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/rootvg/rootlv is mounted on /; on-line resizing required old_desc_blocks = 7, new_desc_blocks = 8 The filesystem on /dev/rootvg/rootlv is now 15728640 blocks long. [root@linux101 ~]# df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/rootvg-rootlv 59G 22G 35G 39% /
Notes: Use ext2online instead for OL or RHEL 4. resize2fs cannot be used for mounted filesystem on OL/RH 4. It will only work OL/RHEL 5 or newer. And for xfs filesystem, use xfs_growfs.