Increase or Decrease the Size of Static Partition in Linux.

There are two Memory Management Techniques: Contiguous, and Non-Contiguous. In Contiguous Technique, executing process must be loaded entirely in main-memory.

Prasantmahato
5 min readNov 11, 2020

Contiguous Technique can be divided into:

1. Fixed (or static) partitioning

2. Variable (or dynamic) partitioning

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.

Fixed Partitioning .

Is it possible to Increase or Decrease any Static partition without losing any data ??

The answer is YES we can do it but for doing this we have to go through long process.

Lets start with step by step process.

STEP 1

We need attach a external storage device to our VM or Bare-metal anything what you prefer .

Attaching external device.

Checking the device is attached or not and looking for the device name .

Looking for Device name .

STEP 2

Creating a Partition of 5 gb .

Commands used :-

fdisk <device_name > :-for the device Command line to be opened .

n :-For creating a new partition.

p :-For creating a primary partition.

1 :- For creating one partition.

5G :-For creating a partition of 5 GB .

w :-For writing or save all the changes made .

Finally we are done with the partition ,Now we only need to format and mount the partition to a mount point .

Creating a Partition .

To check Partition is created

I runned lsblk command .

Running lsblk command

STEP 3

Formatting the Partition .

Command used :-

mkfs.ext4 <device_name>

And then mounting the partition.

Command used :-

mount <device_name> <mount_point>

Formatting and mounting the partition

To check partition is successfully formatted and mounted I used

df-h

Looking for partitions which are mounted

Now the actual practical starts from here

What should we do now to increase the static storage ?

As the storage is static we can’t increase or decrease the storage when the partition is mounted .But one thing I can do, If I unmount the partition and delete the existing partition and in place of that partition . Add one more partition by Increasing or Decreasing the storage and then repairing the inode table and after that formatting only the increased storage in the partition .

It looks like a long process but it is simple to do .

STEP 4

To prove that data can be reterived even after if we increase or decrease the storage .

I added three folders named

static1 static2 static3

Command used : -

mkdir <folder_name> <folder_name> <folder_name>

Making directories.

STEP 5

Unmounting the mount point .As we unmount the partition is now free to do anything .

Command used :-

umount <mount point or folder name >

Unmounting the partition

STEP 6

I deleted the partition of 5GB and in place of first partition I created a new partition of 10 GB.

Commands used :-

fdisk <device_name > :-for the device Command line to be opened .

d :-For deleting the unmounted partition

Deleting a partition

Now I am creating a new partition with the extended size I want .

Commands used :-

fdisk <device_name > :-for the device Command line to be opened .

n :-For creating a new partition.

p :-For creating a primary partition.

1 :- For creating one partition.

Y :- Is for removing the signature also known as format .

Why they are asking to remove signature ???

As because ,We have already created a partition on partition number 1 and we have also formatted it with the format ext4 ..,So actually they mean to say you have already created a partition on partition number 1 and then you deleted it but the data in that storage is still present in ext4 format ,So would like to have your data in ext4 format or remove the signature to be formatted later .

10G :-For creating a partition of 10GB ,this time I am increasing the size by 5GB.

w :-For writing or save all the changes made .

Creating a new partition on top of the deleted partition number .

STEP 7

Now the challenging part comes What should we do now ,How to reterive data ?

To reterive data I repaired the partition table as it was before ,by the use of command

e2fsck -f <device_name>

Repairing the partition.

STEP 8

As I have repaired the partition table and I know 5GB is formatted but rest of 5GB is not formatted of partition of 10 GB .

So for formatting the remaining storage which has not been formatted we use ,

resize2fs <device_name >

Resizing the partition.

STEP 9

Now every thing is done we just need to mount the partition to the mount point to have our data .

Command used :-

mount <device_name> <mount_point>

We are done with everything .

To prove you all that without losing any data I have successfully increased the static partition .

ls

Data reterived

Thankyou so much for reading my blog .Hope It would benefit you in some way.

For any queries or suggestions dm me .

Thankyou.

--

--

No responses yet