The Lazy Admin Blog

Home  /  CentOS  /  CentOS 7: Resize xfs Partition

CentOS 7: Resize xfs Partition

September 03, 2017 CentOS Leave a Comment

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 🙂

fdisk /dev/xvda

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:

http://www.unitconversion.org/data-storage/blocks-to-gigabytes-conversion.html

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 –

vi /etc/fstab

Save & reboot.

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.

vi /etc/fstab

That’s it!

Previous Article
Next Article

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Linux
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup bash CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh ssmtp systemd threads VMFS WHM Wordpress xenserver

Popular Posts

  • Convert JetBackup to cPanel structure October 6, 2022
  • How To Install & Configure a Galera Cluster with MariaDB on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • rsync without prompting for password October 10, 2022

Recent Posts

  • Understanding Why More Threads Can Sometimes Slow Down Performance October 9, 2024
  • Set up a new systemd service May 18, 2024
  • Bash Arrays November 7, 2023
  • rsync without prompting for password October 10, 2022

Recent Comments

  • Sven on rsync without prompting for password
  • TheLazyAdmin on rsync without prompting for password
  • Sven on rsync without prompting for password
  • TheLazyAdmin on Convert JetBackup to cPanel structure
  • Chris on Convert JetBackup to cPanel structure
Privacy Policy • Contact