Increase OR decrease the size of the static partition in linux>-

Gulsha Chawla
6 min readAug 24, 2021

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.

Static V/S Dynamic

For all the concepts of LVM do refer to my previous blog also: https://gulshachawla.medium.com/integration-of-lvm-with-hadoop-cluster-using-aws-cloud-66edc98992cd

Letā€™s move towards the practical partšŸ‘‡šŸ»

Firstly we will add a new external hard disk of letā€™s say 20GB

To add an external H.D go to

Settings=>Storage=>Add hard disk

Then click here

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.

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.

Now itā€™s time to go inside o.s & do this taskšŸ™Œ

Step 1: Check & verify new H.D attached or not

We will check & verify by using : #fdisk -l

Step 2: To create a partition, format & mount.

For partition, we will go inside this H.D so we will use: #fdisk /dev/sdd here to create a new partition press n then as we are first time creating partition i.e primary partition press p hit enter size letā€™s say of 10GB and to save it press w thatā€™s it our partition of 10GB /dev/sdd1 is created.

Partition done

Now as we are using RHEL8 O.S we need to load a driver so that user can interact with this H.D storage by using: #udevadm settle

Then we need to format this partition using: #mkfs.ext4 /dev/sdd1

Format done

After this, we will mount this partition

Firstly we will create a directory or folder using: #mkdir /folder-name

So to mount we will use: #mount /partition-name /folder-name

Then using: #df -h or #lsblk command we can verify it is successfully mounted.

Mount done

Step 3: Increase OR Decrease the size of the static partition in Linux

Here before I do partition I will make text files to prove that after I increase or decrease my partition storage it wonā€™t lose my data.

Now we will do unmount of folder we created earlier to increase its storage i.e static storage using command #umount /gc_LVM

Then we will delete the partition by pressing d using the command

: #fdisk /hard-disk-name

For creating a partition of 15GB, I am increasing storage by 5GB more here n is for the new partition and to save it press w.

Have you noticed??šŸ‘€ Before increasing static partition it asked me Yes Or No? & it is telling partition #1 contains an 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 in 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 signaling 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 is used by an 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 retrieve them back?šŸ¤Ø

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

Clean & Scan

As we had earlier formatted 10GB now letā€™s re-format this 5GB more data by using command #resize2fs /dev/sdd1 here we didnā€™t use mkfs.ext4 to re-format it will lose my data and so I used resize2fs as it is part of ext4 format-type also it wonā€™t lose my data. In ext4 format type, we can extend & reduce the size of the partition.

Partition re-formated

Sometimes we have big commands we need to again & again manually run them but here I have some small trick or wayšŸ’” without manually typing within a go we can run that big command so go to history=>check command line-number=>!command-number run it! thatā€™s it we again ran the same big command without more typingā€¦here I did re-mount using #mount /partition-name /folder-name.

Static Partition successfully increased!!

As we can see in the above snapshot our static partition is successfully increased from 10GB to nearly 15GB using command #df -h

Now letā€™s check do I got or have my data still or not?šŸ§

Oh! Yes itā€™s still there hence proved though we resized my partition our data wonā€™t be lost by using the command: #ls

Finally, our task 7.1.B Increase OR Decrease the size of the static partition in Linux is accomplished!

Thank you for reading my articlešŸ¤—

Keep LearningšŸ’«Keep SharingšŸ¤šŸ»

Good Day!

--

--