Expand LVM / Non-LVM partition

While working on Virtual Machines on VMware / Hyper-V / VirtualBox, we might often end-up with a requirement to expand the disk and partition size. This guide will summarize all commands that are required. As part of my Linux Sys-Admin work, these are the common steps I follow to expand the virtual drives in Linux.

NOTE: Always make sure backups exists before trying to make changes on a partition, otherwise there is a chance of data loss and it is your responsibility .

Expand Non-LVM Partition

This is probably the most easy to handle, firstly increase the space of virtual disk allocated to VM on the Hypervisor.

Install cloud utils and rescan the scsi device so that operating system will know the change in storage. Later use growpart and growfs to resize the disk

$ sudo yum install cloud-utils
$ sudo echo 1> /sys/class/scsi_device/0\:0\:0\:0/device/rescan
$ sudo growpart /dev/sda 1
$ sudo xfs_growfs / 
$ df -h 
$ sudo reboot

Reboot is not necessary, required only when “df” command doesn’t show the resized storage.

Expand LVM Partition

Increase the space allocated to the virtual disk via Hypervisor client.

Run the following cmds on the linux VM

$ sudo echo 1> /sys/class/scsi_device/0\:0\:1\:0/device/rescan
$ sudo growpart /dev/sdb 1
$ sudo lvextend -l +100%FREE /dev/tux-vg/data
$ sudo xfs_growfs /dev/tux-vg/data
$ df -h

Conclusion

These two patterns are the most common type of disk resize I handle as part of my sys admin work. For LVM, you could also add a new Disk, and allocate to the same volume group. However thats not the scope of this tutorial.

Please share and comment if you find any issue

0 Comments on Expand LVM / Non-LVM partition

Leave a Comment

Your email address will not be published. Required fields are marked *

You Might Be Interested In