How to Increase or Decrease the Size of Static Partition in Linux?

Ananya Sharma
4 min readMar 14, 2021

A hard disk can be divided into several partitions. There may be several reasons for creating the partitions. Some of them are as follows:-

  • Multiple operating systems on the same disk.
  • Different file systems on different partitions.
  • More efficient disk space management.
  • Different security settings on different partitions.
  • Easier backup procedure.

So let’s get started…

Step 1:- First, we need to attach a external storage device to our VM or Bare-metal.

Step 2:- We can see the hard disk is attached or not by using the following command:-

fdisk -l

Here, we can see that one new hard disk with the name /dev/sdb of 50GiB is added.

Step 3:- Next, create a primary partition of 30GiB with the help of following command:-

fdisk /dev/sdb

We can also check the partition is a created or not by using fdisk -l command.

Here, we can see that one partition is created named /dev/sdb1 with the size of 30GiB.

Step 4:- Next, we have to format the partition with the ext4 file system, and then we will mount with / data directory. Use the following command for the same:-

mkfs.ext4 /dev/sdb1mount /dev/sdb1 /data

We can verify that the partition is mounted or not by using the following command:-

df -h 

Step 5:- Next, put some data in the directory so that we can check if the data get lost or not after resizing the partition.

Step 6:- Now, we have to unmount the partition because we have to resize the partition and the static partition doesn’t allow us to resize the partition on-line. To unmount the partition, we can use the following command:-

umount /dev/sdb1

We can check that there is no data in the /data directory.

Step 7:- Next, we have to create a partition /dev/sdb1 so that we can change the size of the partition.

Step 8:- Now, create that partition again with the changed size. As we have to resize the partition so, we will create the partition again but the starting sector will be the same as the previous partition. In my case, the previous partition was started from the 2048 sector so, again I will create the partition from that sector only and this time I am going to increase the size from 30GiB to 40GiB.

We can clearly see that one partition /dev/sdb1 of size 40GiB is created.

Step 9:- Next, we have to verify the partition consistency. Use the following command for the same:-

e2fsck -f /dev/sdb1

Here, it is showing that there is some mismatch in the file system configuration and current partition size. To fix this issue, use the following command:-

resize2fs /dev/sdb1

Now, you can see that the file system block size is the same as for partition configuration.

Step 10:- Now, mount the resized volume and check the data is still there or not.

Now, check the data is there or not.

We can clearly see that the data is still there in the directory.

Thank you :)

--

--