Extend Size Of Static Partition In Linux

Pawan Kumar
3 min readMar 12, 2021

Namaste guys I’m back with another article. This article illustrating about Extending the static partition in linux without making partition offline( unmount ) and without loosing any previous data. So let’s start

1. Select Partition

First have to select the partition of which you wanna extend the size:

Use lsblk or fdisk -l command to list all the disk table and thier partition.

In my case I’m using lsblk because it display output in tree format as you can see from below image I’m selecting sdb1 partition( currently of size 2GiB ) of sdb disk( total size 10GiB ) to extend .

Now you can see that this partition is currently mounted to /test directory.

Use df -hT command to see the mounted device and type.

Now choose the disk( not the partition ) to extend the size.

With command fdisk disk_name you can select the disk.

  1. Delete the above selected partition (/dev/sdb1) with d option. It will ask for partion number if you have more than one partition of that disk. In my case I’had only one so it deleted the partition 1 automatically.

2. Create new partition with n option

▪️Then give p as option to tell the partition is of primary type.

▪️Give partition number same as that of previous on( In my case it was 1).

▪️Give First sector or starting point. If you won’t give anything it by default select.

▪️Give last sector or end point or can give the size in KiB, MiB, GiB, TiB and PiB use K, M, G, T and P respectively.( I’m giving +5G which will channge the size from 2GiB to 5GiB).

▪️Then use w option to save the previous change

3. Now time to format the partition. If we use mkfs command here to format then it will delete the inode table, all data and create new inode table which is definitely not good.

So use the resize2fs coammand to avoid the above case.

use resize2fs partition_name (In my case /dev/sdb1)

In case if resize2fs command give some error then use:

e2fsck -f partition_name first

then again use resize2fs partition_name (In my case /dev/sdb1)

Now chcek the disk information again with lsblk or fdisk -l command will show the extended size.

Also check the mounted device with df -hT command will show that the partition is still mounted to the same. And also check the data inside the directory will be there.

That’s all guys all done here..

Thank You 😊

Connect me on linkedIn for more update…

--

--