Increase or Decrease the size of Static Partition in Linux
Suman Sourav
CKA | Azure Cloud Solution Architect | Containerization Expert (Kubernetes & Docker) | CI/CD & Azure DevOps | Infrastructure as Code (IaC) Specialist
Hey, Everyone today we will change the size of the static partition in Linux. So, this will be a step to step guide how can you change the size of the partition and in your Linux system.
Here I will create a partition of a smaller size and then mount it to a folder and then extend it to a larger partition.
Pre-requisite:
- A system with Linux installed in your system.
- Space in your drive to which you want to extend the partition.
STEP 1: First we have to check the disk partition of the system
# fdisk -l
As I have a drive of 3 GiB attached to my system I will use it to create a partition of smaller space 1GiB which I will extend further.
STEP 2: Now to create a partition of 1GiB I will use fdisk command to create the partition
# fdisk /dev/<name_of_the_drive>
Then " n " to create a new partition
Then we have to enter the partition number, here the default is 1 so I will go with the default.
Now we have to select the size of the partition and from what sector it should start and at what sector it should end I will choose the default 2048 for the starting of the partition and +1G to create a partition size of 1 GiB.
Lastly, we have to press " w " and hit Enter key to write the changes.
STEP 3: Formatting the partition which will make the inode table for the size of 1GiB
# mkfs.ext4 /dev/<name_of_the_drive>
STEP 4: Create a directory where we will mount the partition
# mkdir <name_of_the_folder>
I have created a folder by name mount_here there I will mount the partition of 1GiB
STEP 5: Mounting the partition to the directory
First, we will run the command
# df -hT
to check all the mounting directories of the drives
We can see that the newly created partition is not mounted anywhere
Now we will mount the partition to the directory
# mount /dev/<drive_name> /<directory_location>
STEP 6: Creating data inside the directory.
STEP 7: Creating a partition of 2GiB
STEP 8: Formatting the newly created partition
# mkfs.ext4 /dev/<drive_name>
STEP 9: Mounting the newly created partition
First, we have to unmount the previous partition
# umount /dev/<partition_name>
# mount /dev/<partition name> /<mounting folder>
#