×

Are you trying to resize your disk size and extend the file system resizing a disk volume?

This guide is for you.

Resizing a root partition is tricky. In Linux, there isn't a way to actually resize an existing partition. One should delete the partition and re-create a new partition again with the required size in the same position.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Linux related tasks.
In this context, we shall look into how to extend a Linux File System after resizing a volume.

How to extend file system after resize disk volume in Linux ?

1. Getting More information about the Disk volume?
First you need to find more information about the disks. As soon as Linux detects disk size change, you will see a message in your log as follows using the dmesg command:

sudo dmesg
sudo dmesg | more

You will see an output such as this;

[   12.834446] bpfilter: Loaded bpfilter_umh pid 1037
[   12.917195] new mount options do not match the existing superblock, will be ignored
[262733.527584] sd 0:0:2:0: [abc] 838860800 512-byte logical blocks: (429 GB/400 GiB)
[262733.527587] sd 0:0:2:0: [abc] 4096-byte physical blocks
[262733.528263] abc: detected capacity change from 214748364800 to 429496729600

Note: Take note of the name of the disk (abc).
Also, make a backup of all your data. It is crucial to create a snapshot of the disk and backup data somewhere else safely.

2. How to Verify the new Disk Space in Linux?
To verify the new disk space, simply execute the fdisk command shown below;

sudo fdisk -l /dev/sdb

Then you will get an output such as this;

Disk /dev/abc: 400 GiB, 429496729600 bytes, 838860800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xd3a4f1f7
Device     Boot Start       End   Sectors  Size Id Type
/dev/abc1        2048 419430399 419428352  200G 83 Linux

3.  How to list block devices in Linux?
To show information about the block devices attached to your cloud VM, simply execute the following lsblk command;

sudo lsblk

4. How to find the current disk size and partition type ?
To know the the current disk size and partition type, simply execute the command below;

df -HT
df -HT | grep /backup1
df -HT | grep /dev/abc1
sudo file -s /dev/abc*

You will get an output such as this;

/dev/abc:  DOS/MBR boot sector; partition 1 : ID=0x83, ...
/dev/abc1: SGI XFS filesystem data 

From the output, you will know that xfs is the file system for /dev/abc1 partition.

5. How to Unmount the partition if mounted ?
To Unmount a partition, simply run the command:

sudo umount /dev/abc1

The process of extending a Linux partition

Since the resized volume has a partition and the partition does not reflect the new size of the disk volume, we use the growpart command on Linux to extend the partition size.

How to use growpart to resize the image partition in Linux ?

To do this, execute the command:

growpart /dev/DEVICE_NAME    PARTITION_NUMBER

Please note that there is a space between the DEVICE_NAME and the PARTITION_NUMBER. For example:

sudo growpart --dry-run /dev/abc 1

You will see an output such as this;

CHANGE: partition=1 start=2048 old: size=419428352 end=419430400 new: size=838858719,end=838860767
# === old sfdisk -d ===
label: dos
label-id: 0xd3a4f1f7
device: /dev/abc
unit: sectors

/dev/abc1 : start=        2048, size=   419428352, type=83
# === new sfdisk -d ===
label: dos
label-id: 0xd3a4f1f7
device: /dev/abc
unit: sectors

/dev/abc1 : start=        2048, size=   838858719, type=83


Note that the --dry-run option only reports what would be done.
To resize it, execute:

sudo growpart /dev/abc 1

To verify that the partition size increased , you can use the lsblk command as shown below:

sudo lsblk

How to Mount the file system again ?

To do this, run the following command;

sudo mount /dev/abc1 /backup1/

Then verify the disk size with the command below;

df -H

You will get an output such as this;

Filesystem      Size  Used Avail Use% Mounted on
udev            501M     0  501M   0% /dev
tmpfs           103M  938k  102M   1% /run
/dev/abc1        11G  3.1G  7.2G  30% /
tmpfs           515M     0  515M   0% /dev/shm
tmpfs           5.3M     0  5.3M   0% /run/lock
tmpfs           515M     0  515M   0% /sys/fs/cgroup
/dev/abc15      110M  3.8M  106M   4% /boot/efi
tmpfs           103M     0  103M   0% /run/user/1001
/dev/abc1       215G   36G  180G  17% /backup1

The process extending the file system in Linux.

As you can size mounted file system still shows 200GB total size for the /dev/abc1 partition.

How to extend the XFS file system on Linux ?

To extend the XFS file system on Linux, simply execute the command as shown below:

sudo xfs_growfs /mount_point
sudo xfs_growfs /backup1/

How to extend the ext4 file system on Linux ?

To extend the ext4 file, execute:

sudo resize2fs /dev/DEVICE_NAME_PARTITION_NUMBER
## note /dev/sdb1 must be unmouted ##
sudo resize2fs /dev/abc1

How to verify that extending the file system after resizing a disk volume in Linux is working ?

Finally, to verify that your disk sized increased from old size to new size, execute:

df -HT


[Need urgent support to resize the disk volume of an instance in Linux? We are available to help you today. ]


Conclusion