So, we got a CentOS 7 Machine with 20GB (XFS Filesystem), We want to increase the disk to 120GB. The machine is actually a VM inside XenServer (HVM).
Fdisk output before the upgrade –
As you can see there is on HD (/dev/xvda) with two partitions on it –
The main “/” root partition with 18 GB
Another swap partition with 1 GB
So far, so good :), let’s continue with the resize –
Increasing the disk size from XenServer:
*Increasing disk has the potential to cause a lot of damage. It’s very important to make a backup of your server, if you are using a virtual machine, make sure to take a snapshot before starting the process.
So, we turned off the server, resized the disk. Now, let’s take a look at fdisk outpt
The /dev/xvda is now 120 GB as we want to, but we still need to resize the partition. Since our swap partition (/xvda2) comes right after xvda1, we can’t resize xvda1 unless we remove / move xvda2. In that case, since it’s only a swap partition we choose to remove it, resize and then re-create it.
Let’s start the process 🙂
Delete the 2 partitions (xvda1 + xvda2) we have by typing “d”:
After we deleted them, we need to create them again with the increased size.
Since, we want the swap partition with 2GB size, so we have to limit the block size of our primary root partition.
You can calculate block to GB in this site:
120 GB is 251658240 blocks.
2 GB (to our swap partition) is 4194304 blocks.
We will give 118 GB to our primary root partition and 2GB to swap partition
We will calculate:
251658240 – 4194304 = 247463936
The last sector of our primary too partition will be 247463936 (118GB)
Now create another partition to swap with the rest of the blocks:
Change the partition system id of our swap:
We’ve finished with fdisk for now, type “w” in the fdisk prompt to save changes & exit. You should receive an error saying “Re-reading the partition table failed with error 16” –
The error is normal – you need to reboot the server for the system to follow all the changes. Before we reboot the server, as we don’t have (yet) a swap partition, let’s first remark it in fstat as the system might fail to boot.
Edit fstab and remark the swap partiton –
After server goes back from reboot, your swap partition won’t mount because of UUID changes. We will fix this below. First, increase the disk size with the following command:
xfs_growfs -d /
Our primary root partition now reflects the right size:
We have to create our swap now, run the following command:
Copy the uuid that the mksawp command has generated. Edit the /etc/fstab file – remove our previous remark and paste the new uuid.