Increase or Decrease the Size of Static Partition in Linux

In this blog, I am going to discuss how to resize the static partition in Linux with the help of the resize2fs command. The basic prerequisite for this task is Linux partition.

Linux 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:

Step 1: Add one Hard Disk to the VM

fdisk -l

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

Step 2: Create one Primary partition of 30GiB

fdisk /dev/sdb

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

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

Step 3: Format the partition and mount it with some directory

mkfs.ext4 /dev/sdb1

mount /dev/sdb1 /data

We can verify that the partition is mounted with /data folder or not with df command.

df -h

Step 4: Put some data in the directory

Step 5: Unmount the partition from the /data folder.

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.

Step 6: Create the existing partition

Step 7: Create that partition again with the changed size

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 create or not by listing the partition command.

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

Step 8: Verify partition consistency with 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.

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

Thank You !!

I'm passionate learner diving into the concepts of computing 💻