Increase or Decrease the Size of Static Partition in Linux

Nikhilgp
5 min readMar 16, 2021

Fixed Partitioning

This is the oldest and simplest technique used to put more than one processes in the main memory. In this partitioning, number of partitions (non-overlapping) in RAM are fixed but size of each partition may or may not be same. As it is contiguous allocation, hence no spanning is allowed. Here partition are made before execution or during system configure.

This article shows steps for increasing or decreasing the size of static partition using fdisk command.

OBJECTIVE

  1. Have a 15GB fresh hard disk attached to the OS.
  2. Create a partition of 10GB from the 15GB hdd.
  3. Format and mount to the first folder “myfiles” and store a sample text file inside it.
  4. Increase the size of static partition from 10GB to 14GB using fdisk.
  5. Check for its condition and previously stored file.
  6. Resize and decrease the static partition from 14GB to 7GB using fdisk command.
  7. Check for its condition and previously stored file.

Lets start the practical….

1.CREATE A 10GB PARTITION

Step 1: Attach a 15GB hard disk drive to your OS, to list the disks use the following command.

#fdisk -l <disk_name>

Step 2: Create a new partition of size 10GB, using the fdisk command, use “n” to create new partition, select primary partition and enter the size.

#fdisk <disk_name>

Check for partition created using fdisk -l command.

Step 3: Format the partition using the type mkfs.ext4 and create a folder named “myfiles” and mount to it, then store a sample text file in it.

Use command “df -h” list all the partitions and its details.

2. WE NEED TO INCREASE THE SIZE OF PARTITION TO 14GB

To increase the size of a static partition it is not possible on the go without unmounting, so first we need to unmount then delete the partition and create a new partition of more size.

Step 1: Unmount the previously created partition and delete the partition using fdisk command.

Step 2: Create a partition with new size that is of 14GB again using fdisk command.

Step 3: Check the condition of partition using e2fsck command then resize the partition using resize2fs command.

Step 4: Create a new folder “myfiles2” and mount to it, then check for the previously stored sample text file.

As we can see the previously stored files remains there and do not get deleted, therefore the size of the partition is increased successfully.

Check the size of the new sized partition using “df -h” command

2. DECREASE THE SIZE OF PARTITION TO 7GB

Before deleting or creating new partition to decrease the size of static partition first unmount the partition then resize it to the required size then proceed.

Step 1: Unmount the partition using the following command then resize using “resize2fs” command also mention the size as 7G that is 7GB.

#umount /dev/xvdf1

Step 2: Delete the older partition using fdisk.

Step 3: Create new partition with size as 7GB and keep the format type of the partition.

Step 4: Check the condition of the partition using “e2fsck” command then create a new 3rd folder named “myfiles3” and mount to it.

Step 5: Go to the folder /myfiles3 and look for the previously stored sample text file is present or not.

As we can see the previously stored old sample text file is present and is not deleted therefore we have successfully decreased the size of static partition.

Check the details of the new decreased partition using “df -h” command.

CONCLUSION

To increase or to decrease the size of a static/fixed partition we need to unmount delete and create a new sized partition on same disk then mount back, this seems a longer process and we cannot use the files from the partition at the time of increasing or decreasing. This problem can be overcome using dynamic partition using LVM where we can increase or decrease the size of partition very quickly and also at the time of use.

Thanks for reading

--

--