Linux VM online disk expansion

     Occasionally, there is a need to expand disk assigned to some Linux virtual machine, depending on infrastructure or service provided inside datacenter. Personally, I liked feature inside Windows OS where, after you resize HDD through virtual machine settings, using Disk management tool you have easy option just to do an online expansion, without rebooting or something similar.

    For most of the time similar action, at least from my side on Linux based VMs, was performed using reboot operation and then disk expansion process. Particular commands needed to expand disk inside Linux VMs are very well explained on following links:

    I would like to introduce couple of new options for these kind of scenarios, which will give you an option to do an online enlargement on disk and partition of Linux virtual machine. Steps which I followed are given below:
  • please have a functional backup before any actions on Linux disk change;
  • remove any snapshot on Linux VM that you maybe created;
  • expand disk on Linux VM through regular procedure using Edit Settings VM window;
  • after expansion we need to make Linux kernel aware on new size - which can be accomplished using following cmd - in my case sdb is disk that is changed, so please use your disk name in following command:
echo 1 > /sys/class/block/sdb/device/rescan 
  • for partition to take change and expand we need to use very useful cmd growpart which is included inside cloud-utils package, easily installed on various distributions using:
yum install cloud-utils - Red Hat/CentOS
sudo apt-get install -y cloud-utils - Ubuntu/Debian
  • using growpart we can change partition easily using:
growpart /dev/sdb 1 - sdb is disk to grow / 1 is partition on that disk - change according your needs
  • last action is file system awareness, which is easily accomplished using included tools in Linux distro:
resize2fs /dev/sdb1 - again take care for your needs on exact disk
  • if working with LVM based disks and partitions inside Linux distribution, couple of useful and changed instructions:
lvdisplay - get information about logical volumes
vgdisplay - get information about volume groups
pvresize /dev/sdb1resizes required physical volume - change volume inputs (sdb1 in my example) according your environment
lvextend -r /dev/centos/root /dev/sdb1 - resizes logical volume - change volume inputs (/dev/centos/root and sdb1 in my example) according your environment

    Hope this overview on different options will help you in managing your Linux disk environment, providing increased productivity with fact that all mentioned operations could be done online inside operating system.

Comments

Popular posts from this blog

NSX ALB LetsEncrypt with DNS-01 challenge - BIND example

NSX ALB routing - multiple floating IP and BGP setup

VMware SD WAN - multiple locations - LAN IP address space overlapping with NAT