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:
- extending a logical volume (LVM) in a Linux virtual machine - Red Hat/CentOS example, or
- increasing the size of a Linux ext3 virtual machine disk.
- useful KB if you need to create new disk on existing Linux VM, for test/lab purpose, before trying below process - LINK
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:
- 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:
sudo apt-get install -y cloud-utils - Ubuntu/Debian
- using growpart we can change partition easily using:
- last action is file system awareness, which is easily accomplished using included tools in Linux distro:
- 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/sdb1 - resizes 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
Post a Comment