Increase or Decrease the Size of Static Partition in Linux
What is a Partition?
Large storage devices are divided into separate sections called partitions. Partitioning also allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive.
What is a static partition?
A static partition is created when the use case is such that the partition need not be resized in the future. Basically a static partition does not by default have the capability to resize itself dynamically according to the need of the event.
What to do if we want to increase or decrease the size of static partition?
Here we will look at how we can resize the static partition to overcome its difficulties. In my case I will be using a Virtual Machine deployed in Virtual Box softaware.Follow the steps below.
Step 1: Create a hard disk and allocate the amount of storage you want. In my case i will allocate 8GB.
Step 2: Now boot up the VM. Open the terminal and write fdisk -l command in the terminal. You can see the hard disk you have attached. We will create partitions now. So use fdisk <hard disk name> which will launch the tool to create partition. I will create a partition of 8GB.
We can again use fdisk -l command to check the partition has been created or not.
Step 3: Now that we have created the partition we need to install the drivers for the partition. We use udevadm settle command for this. Next thing to do is to format the partition. We will use ext4 format type. To do this use mkfs.etx4 <partition> . Now we will mount this to a directory using mount <partition name> <mount point>.
Step 4: We have successfully created and mounted a static partition. Now we want to resize it. For this we will first need to unmount it using umount <partition name>. Now we will run the e2fsck command to check for any garbage values in the Inode table. Now we will resize the partition to 4GB. To do this we will use resize2fs <partition name> <size>.
Step 5: The end part is to mount the partition again and check using df -h command to see if it has been resized or not.
Conclusion: Hence we have resized a static partition. However it is advisable to use dynamic partitions as they provide better flexibility.
😇