Increase or Decrease the Size of Static Partition in Linux

Sheikh Aafaq Rashid
5 min readMar 15, 2021

--

Today we are going to discuss how to resize the static partition in Linux with the help of the resize2fs command.

Linux Partition:

A hard disk can be divided into several partitions. Each partition functions as if it were a separate hard disk. There are several reasons why we create the partition:

  • 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.

Task Description:

In this task, we have to increase or decrease the size of static partition Linux. In Linux, the primary partition that we create don’t allow to increase or decrease the partition size. By default for increasing or decreasing the size we must have to format the partition that causes data loss. Now we have to find some way through which we can increase or decrease the size of static partition without losing data.

Procedure:

1. Add one Hard Disk to the VM

Add one new hard disk to the VM, use ‘ # fdisk -l ’ command to see that hard disk is perfectly attached or not

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

2. Create one Primary partition of 30GiB

Create one primary partition of 30GiB with the help of ‘ #fdisk /dev/sdb

Now we can check the partition is a created or not.

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

3. Format the partition and mount it with some directory

Format the partition with the ext4 file system, and mount on/data directory.

#mkfs.ext4 /dev/sdb1

#mount /dev/sdb1 /data

Verify that the partition is mounted perfectly on /data folder or not using:

#df -h

or

#df -T

3. Store some data in the directory

Store some data in the directory so that we can check if the data get lost or not after resizing the partition.

5. Unmount the partition from the /data folder.

In this step, we will unmount the partition because we have to resize the partition size and the static partition doesn’t allow us to resize the partition on-line.

To unmount the partition we can use the umount command.

#umount /dev/sdb1

Here the partition /dev/sdb1 has been mounted from the /data directory.

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

6. Create the existing partition

Create the partition /dev/sdb1 so that we can change the size of the partition.

7. Create that partition again with the changed size

As we have to resize the partition so in this step 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 check the partition is created or not by listing the partition command.

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

8. Verify partition consistency with the e2fsck command.

Verify the partition consistency by running the e2fsck command.

#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 we have to use the resize2fs command.

#resize2fs /dev/sdb1

Now the file system block size is the same as for partition configuration. Let’s mount the resized volume and check if our data is still there or not.

9. Mount the resize volume and check the data

Here we have mounted the volume with the /data directory.

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

📃Thanks for Reading !!

🔰 Keep Learning !! Keep Sharing !! 🔰

Author: Sheikh Aafaq Rashid

--

--