Increase or Decrease the Size of Static Partition in Linux
Hello everyone, today I would like to share with you all the steps on how to increase or decrease the size of the static partition in Linux.
First, we will add a new hard disk in the RedHat Linux OS running in the VirtualBox as shown.
Now we will login to the OS and and run the following command in CLI which will show you the attached hard disk as shown in the image
fdisk -l
Creating, Formatting and Mounting the Partition
As you can see in the above picture that a hard disk named “/dev/sdb” has been attached, so now we will create a new partition of 4 GiB by running the following command and entering the options as shown in the below image
fdisk /dev/sdb
We can see that the partition has been created by running the following command
fdisk -l /dev/sdb
Now we will format the partition with ext4 file system by running the following command
mkfs.ext4 /dev/sdb1
After that we will create a mounting point directory i.e a folder which we will mount on the created partition and then mount the directory to the created partition using the following command.
mkdir /task7 (Creating the directory)
mount /dev/sdb1 /task7 (Mounting the partition)
After running the above commands we can see if the partition has been mounted or not by running the following command
df -h
It can be clearly seen in the picture that the folder has been mounted to “/task7” folder
Now we will save some data inside this partition by creating a file on the “/task7” folder as shown in the picture below
Increasing the Partition Size
For increasing the partition size, first we will unmount the partition by running the following command
umount /dev/sdb1
You can see that the partition has been unmounted by running the “df -h” command as shown in the picture
Now we will delete the partition by running the following command and entering the options as shown in the image
fdisk /dev/sdb
We can see that the partition has been deleted. We can also confirm by writing the “ fdisk -l /dev/sdb” command as shown in the image
Now we will again create the partition of greater size, lets say 6 GiB by running the following command and entering the options as shown in the image
fdisk /dev/sdb
You can also see if the new 6 GiB partition has been created or not by writing the following command.
fdisk -l /dev/sdb
Now we will run the following command for scanning and cleaning any corrupted or bad sectors as shown in the image
e2fsck -f /dev/sdb1
Now we will run the following commands for resizing and mounting the created partition to the “/task7” folder as shown in the image
resize2fs /dev/sdb1
mount /dev/sdb1 /task7
Now we can check if the folder has been mounted or not by running “df -h” command as shown below
Now we can clearly see that the partition size is 6 GiB and we can also check our created file and its data inside our “/task7” folder as shown in the below image
Similarly, we can also decrease the size of the static partition.
Thanks for reading!!:)
Do connect me on LinkedIn: https://www.linkedin.com/in/shivam-prasad-upadhyay/