Increasing and Decreasing the size of Static Partition: Linux (the right way)

Prithviraj Singh
5 min readNov 21, 2020

Traditionally it’s been thought that a static partition is a fixed size partition and hence changing it’s size is impossible. For example this in year 2006, this was stated over the internet by a computer enthusiast: “In short, static volume can’t be changed dynamically, meaning you can’t resize them. To make a new partition you need to blow them away and start over. A logical partition can be resized by adding new disks, taking over space from an existing disk, etc.” which is not completely wrong, logical volumes are a much smarter way to manage partitions. However it is very much possible to change the size of a static partition without loosing data… Let’s see some ways to change the size of a static partition by first increasing the size of a partition and then let’s try to reduce the size of another partition.

All the steps done ahead are done over RHEL 8 while signed in as root account.

Let’s first plug a new volume to our system to work upon, once plugged let’s check upon it using the command fdisk -l

Here you can see a new volume appear name /dev/sdb which is 8 GiB in size. Next let’s create a static partition over it

Here we created a new partition of size 5 GiB and it must be visible as /dev/sdb1

Yeah as expected we can see the partition as /dev/sdb1 ,now let’s format the partition with ext4

Now that we’ve successfully formatted our partition, let’s mount the newly formatted partition so that we can write some data upon it

Here we mounted the partition with a new directory named /prithvi , now let’s put some data upon it

Now that we have the partition all ready we can proceed with changing the size of it…

First you’d like to unmount the partition, use the command:

umount <directory name>

Next we are going to delete the partition so that we can replace it with a new partition with increased size

Next create a new partition to replace the last partition with

Here we created a new partition of size 7 GiB, again this partition will be available to us as /dev/sdb1

Here you can see the new partition has been made successfully, also it has replaced the last partition. Now let’s check for bad sectors and fix them by using the command: e2fsck -f /dev/sdb1

Result of the mentioned command

Here some command fixed some journals for us, this may or may not happen. Now since we changed the size of our partition, next we must change the size of sectors that are journaled by the Inode table, also while we are at it let’s mount the new partition

Now that we have our partition fixed and ready, let’s try to read the data we stored and check if it is good or not

The data still persists, hence we were able to increase the size of our partition successfully…

Now let’s try to reduce the size of a partition of a the same volume… here we again created a new partition /dev/sdb1 of size 5 Gib, formatted and mounted it to /prithvi and as last time we gave it the same data to hold and protect…

Now onwards to reduce the size, we’ll again have to unmount the directory from the partition using the command: umount /prithvi

Next since we are trying to reduce the size of the partition we’ll have to resize the Inode table’s journal, so that we don’t create bad sectors and ruin our volume

Here as you can see we used the command e2fsck to fix any prior bad sectors and next we used the command resize2fs with some options to resize to 1GiB, but next you can also see that the fdisk -l /dev/sdb command still shows the disk size to be 5GiB, to fix this we’ll need to replace the existing partition with a new partition of size 1GiB, hence like before let’s start with deleting this partition and then create a new partition to replace the last one

Now all that remains is to mount the partition and read the data that it was suppose to hold and protect, so…

Also I gave it a last check to show that the size has really been reduced to 1Gib and as you can see that it really has, and yet the data still persists hence we have completed the task successfully…

So that’s it… Task completed successfully!!!✔🎉

Thankyou for reading. See you later!!! 😊👋

--

--