How to Increase or Decrease the Size of Static Partition in Linux Operating System

GAURAV Jangid
8 min readMar 14, 2021

Hello Everyone,

Before starting this practice we need to know what static partition. So I want to discuss some vocabulary that is related to today’s practical.

What is a static partition?

Static(Fixed) Partitioning:

->According to geek for geeks

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

As illustrated in the above figure, the first process is only consuming 1MB out of 4MB in the main memory.

Hence, Internal Fragmentation in the first block is (4–1) = 3MB.

Sum of Internal Fragmentation in every block = (4–1)+(8–7)+(8–7)+(16–14)= 3+1+1+2 = 7MB.

Suppose process P5 of size 7MB comes. But this process cannot be accommodated in spite of available free space because of contiguous allocation (as spanning is not allowed). Hence, 7MB becomes part of External Fragmentation.

Static V/S Dynamic Partitioning

💁🏻‍♀️In most cases, we can use dynamic partitioning. It provides us a lot of flexibility. The following table will help you understand the difference between Static and dynamic partitioning.

There are some advantages and disadvantages of fixed partitioning.

Advantages of Fixed Partitioning –

  1. Easy to implement:
  2. Algorithms needed to implement Fixed Partitioning are easy to implement. It simply requires putting a process into certain partitions without focussing on the emergence of Internal and External Fragmentation.
  3. Little OS overhead:
  4. Processing of Fixed Partitioning requires lesser excess and indirect computational power.

Disadvantages of Fixed Partitioning –

  1. Internal Fragmentation:
  2. Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This can cause internal fragmentation.
  3. External Fragmentation:
  4. The total unused space (as stated above) of various partitions cannot be used to load the processes even though there is space available but not in the contiguous form (as spanning is not allowed).
  5. Limit process size:
  6. Process of size greater than the size of the partition in Main Memory cannot be accommodated. The partition size cannot be varied according to the size of the incoming process size. Hence, the process size of 32MB in the above-stated example is invalid.
  7. Limitation on Degree of Multiprogramming:
  8. Partitions in Main Memory are made before execution or during system configure. Main Memory is divided into a fixed number of the partition. Suppose if there are
  9. partitions in RAM and
  10. are the number of processes, then
  11. the condition must be fulfilled. The number of processes greater than the number of partitions in RAM is invalid in Fixed Partitioning.

Let’s move towards practical part👇🏻

First of all, we focus on the agenda:

  1. Attach a disk with OS
  2. Create partition
  3. Increased that parttion

To perform the whole particle we need to follow the steps given below:

Step 1: Add a Hard disk of any size

We will start by adding a hard disk to an existing virtual machine. In the settings of the VM go to storage and add a hard disk of the desired size. I added a Hard Disk of 15 GB. Following are the images of the steps to follow while adding the disk.

  • Add a Hard Disk
  • Click on create
  • Then tap next
  • Again tap next
  • Now give a name to your new H.D & specify a size you wish for it.
  • Here our H.D is created but still, it is not attached to our VM or RHEL8 O.S.
  • Attach the not attached harddisk.

To attach just click on choose that’s it our H.D name & size you specified will pop-up there tap ok! as you can see in above snapshot.

To Check & verify new H.D attached or not use the below command

fdisk -l

Output:

Step 2- Creating partition, Formatting, and Mounting it

We can see that a hard disk of 20 GB is attached to the virtual machine. Now we have to create a partition, format it and then mount it.

2.a: Create a partition

For the partition, we have to go in the /dev/sdb. Follow the below commands to create partitions.

After you reach inside the disk then follow the steps given below

  1. Type ’n’ to create a new partition.
  2. Specify where you would like the partition to end and start. You can set the number of MB of the partition instead of the end cylinder. For example +1000M(in my case it is +4G)
  3. After here you think why one extra option ‘Y” comes up so don’t worry if you do partition the first time then this option will not have come.
  4. Type ‘p’ to view the partition, and type ‘w’ to save the partition
fdisk /dev/sdb

2.b: Format the partition

Now that we have created a partition we have to format the partition that we have created. For that we can use the below command:

mkfs.ext4 /dev/sdb1

2.c: Creating the mount point

After we successfully format the partition now we have to mount it to a directory. So first we need to create a directory. To create a directory using the below command:

mkdir (directory_name)

2.d: Mount the disk

Now after creating the directory we have to mount the created partition to the directory by using the below command and in order to check, we can use lsblk command as follows:

mount /(partition)/(dir name)lsblk

Now we are done with mounting. Let’s keep some test files in the directory created so that we can prove that the data isn’t affected by the increase or decrease of partition.

Step 3- Unmount the Created Partition

Now we will unmount the created partition for that we will use the below command

umount (mount_point_dir name)

In order to check whether the unmount is successful we will use the df -hT command:

df -hT

Output:

Step 4 — Delete the partition and create a new partition with increased/decreased size

Delete the earlier partition and create a new onw using the same commands as we used earlier.The output looks as below:

4.a:Delete the partition

we will delete the partition by pressing d using command

fdisk /hard-disk-namePress d- To delete partition

4.b:Create the new partition

Now create a new partition with same size we have created earlier.The output is as follows:

Have you noticed??👀 Before increasing static partition it asked me Yes Or No? & it is telling partition #1 contains a ext4 signature what does it mean??🧐

📍So,the signature of partition is basically a mark/beacon there is something there, and it is not empty. It may also identify a partition.

📍It is useful on the context of several utilities/OS to tell the partition has already data there.

📍Moving a partition size/recreating a partition is usually a non-destructive operation up to the point before formatting it.

📍So a signature warning is signalling you “There is already data here!…are you sure you want to go ahead?”

📍Each disk and partition has some sort of signature and metadata/magic strings on it. The metadata used by operating system to configure disks or attach drivers and mount disks on your system.

📍As for removing it or not, it depends on whether you are for instance resizing a partition or creating a new partition . If you are creating a new partition, obviously you may want to remove the signature, if you are resizing a partition you surely want to keep it so i pressed here w to keep this signature as it contains my data i.e text files we created earlier.

But here a challenge comes in scenario🤔 i know i have somewhere my data files but how to retreive them back?🤨

So for that i repaired my partition table or inode table i.e Clean & Scan if any bad corrupted files, data…etc it will remove using command :#e2fsck -f /dev/sdb1 here full form of this command is extend to(2) file system clean check & -f means forcefully clean it.

4.c: Repair the old inode table

Now we have to clean the partition to avoid unwanted values hence we can use the below command

e2fsck -f /dev/sdb1

Now we will resize and format the partition.We will use the below command to resize

resize2fs /dev/sdc1

Step 5- Mount the partition

Mount the new partition again using the previously used commands and now we can see that the data we had created for testing remains safe and there is no data loss even if we delete the partition.The size of the partition also gets increased or decreased.The final results will be like as follows:

Finally,our task 7.1.B Increase OR Decrease the size of static partition in linux is successfully accomplised !

Thank you for reading my article🤗

--

--