Extending disks in CentOS
Recently a customer wanted to add more diskspace to a Domino server as they expected an sharp increase in usage (due to the Corona crisis) and asked me how to do it. Of course there are more than enough manuals on the internet on how to extend diskspace, but it’s usually a matter of having to combine the information from multiple sources to get what you want. I therefore decided to write down the procedure for a quite standard Domino installation on CentOS.
The disks on this server were split into an LVM, with both the root and swap file system on a logical volume, and several “physical” volumes for things like the transactional logs, full text indexes etc. In this case, both the root volume and one of the physical disks needed to be extended. Their servers were virtualised and disks could be easily extended when the virtual machine is down through a web interface. If you would use somthing like KVM, it’s a comparable situation. So here are the steps to take. All steps are done with the root user, but you can put sudo in front of every command to use another administration user.
To extend the disks, we first needed to shutdown the operating system:
Next the disks are extended. For the customer this was done through a web interface, but if this was performed on a KVM the command to extend the disk with 10GB would be:
qemu-img resize <path-to-image>/<image name>.qcow2 +10G
After this, the server can be started again. When logged in use
to check if the OS is aware of the added space. If not, something went wrong in the previous step. If you see the new sizes, you can continue.To understand the next step, look at this overview of the result for the lsblk command on one of my VMs which I just enlarged by 10GB:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 60G 0 disk ├─vda1 252:1 0 500M 0 part /boot └─vda2 252:2 0 49.5G 0 part ├─centos-swap 253:0 0 2G 0 lvm [SWAP] └─centos-root 253:1 0 47.5G 0 lvm /
As you can see the disk vda is 60GB. The partitions, however, are 49,5GB and 0,5GB, so 50GB in total. The new 10GB needs to be assigned to one of these partitions. If you search around, you will find that many advice to use a live version of GParted for this. Load the iso of the GParted live cd in your virtual DVD drive and boot from it. Then graphically assign the extra space to the correct image and apply. There’s however another way where you you can do everything from inside the operating system. This needs a small utility which is not installed by default.
yum -y install cloud-utils-growpart
installs it. This utility allows you to extend a partition in a partition table to fill available space, which is what we need to do to extend the root volume. In above example, the LVM was on device vda and the root volume was on the 2nd partition, so the command was:
growpart /dev/vda 2
Now the size is assigned to the LVM as you can see when you run lsblk again:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 60G 0 disk ├─vda1 252:1 0 500M 0 part /boot └─vda2 252:2 0 59.5G 0 part ├─centos-swap 253:0 0 2G 0 lvm [SWAP] └─centos-root 253:1 0 47.5G 0 lvm /
To assign it to the root volume you need the resize the physical volume of the LVM:
pvresize /dev/vda2Physical volume "/dev/vda2" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Now you can assign the created space to the root partition:
lvextend -l +100%FREE /dev/centos/root
# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 60G 0 disk ├─vda1 252:1 0 500M 0 part /boot └─vda2 252:2 0 59.5G 0 part ├─centos-swap 253:0 0 2G 0 lvm [SWAP] └─centos-root 253:1 0 57.5G 0 lvm /
Now your partition has the new size, but your filesystem doesn’t as you can see when check your filesystem.
# df -h /dev/mapper/centos-root Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 48G 41G 7.2G 85% /
What you need to do is resize your filesystem to the partition. How you do that depends on the type of filesystem you use. ext2/3/4 or xfs. You can check this in your filesystem table:
If you use ext2/3/4 then the command is:
If you use xfs (default on CentOS) the command is:
Compared to the above procedure it’s surprisingly simple to resize a physical volume in CentOS. After you have enlarged the disk outside the VM, you can skip straight to the very last step and use
resize2fs /dev/vdb in case of an ext4 formatted disk)
It’s advisable to finish with a reboot, though not strictly necessary.
One thought on “Extending disks in CentOS”
Nice ! 🙂