Increase or Decrease the Size of Static Partition in Linux
Harshita Kumari
DevOps Engineer | Terraform/RHCSA/AWS/Azure Certified | AWS,Docker, Ansible, Kubernetes ,Terraform ,Python ,Jenkins,
?? Task Description
?? 7.1: Elasticity Task
??Increase or Decrease the Size of Static Partition in Linux.
Linux partition:
Partitioning allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive. Partitioning is particularly useful if you run multiple operating systems. There are lots of powerful tools for creating, removing, and otherwise manipulating disk partitions in Linux.
Step 1: Add one Hard Disk to the VM
In the first step add one hard disk to the VM, we can see the hard disk with the fdisk command.
Command: fdisk -l
Here we can see that one new hard disk with the name /dev/xvdf of 3GiB is added.
Step 2: Create one Primary partition of 1GiB
In this step, we will create one primary partition of 1GiB with the help of fdisk command.
Command: fdisk /dev/xvdf
Now we can check the partition is a created or not.
Here we can see that one partition /dev/xvdf1 with the size of 1GiB.
Step 3: Format the partition and mount it with some directory
In this step, we will format the partition with the ext4 file system, and then we will mount with /newfile directory.
Command: "mkfs.ext4 /dev/xvdf1" Command: "mount /dev/xvdg1 /newfile"
We can verify that the partition is mounted with /file folder or not with df -h command.
Command: df -h
Step 4: Put some data in the directory
In this step, we will put some data in the directory so that we can check if the data get lost or not after resizing the partition.
Step 5: Unmount the partition from the /newfile folder.
In this step, we will unmount the partition because we have to resize the partition size and the static partition doesn’t allow us to resize the partition on-line.
To unmount the partition we can use the umount command.
Command: umount /dev/xvdg1
Here the partition /dev/xvdg1 has been unmounted from the /file directory.
We can check that there is no data in the /newfile directory.
Step 6: Delete the existing partition
We will first delete the partition having size 1 GIB
Step 7: Create that partition again with the changed size
As we have to resize the partition so in this step we will create the partition again but the starting sector will be the same as the previous partition.
In my case the previous partition was started from the 2048 sector so again I will create the partition from that sector only and this time I am going to increase the size from 1GiB to 2GiB.
We can check the partition is created or not by listing the partition.
We can clearly see that one partition /dev/xvdf1 of size 2GiB is created.
Step 8: Verify partition consistency with the e2fsck command
In this step, we will verify the partition consistency by running the e2fsck command.
Command: "e2fsck -f /dev/xvdg1"
Here it is showing that there is some mismatch in the file system configuration and current partition size. To fix this issue we have to use the resize2fs command.
Command: "resize2fs /dev/xvdg1"
Now the file system block size is the same as for partition configuration. Let’s mount the resized volume and check if our data is still there or not.
Step 9: Mount the resized volume and check the data
Here we have mounted the volume with the /newfile directory.
We can clearly see that our data is still there in the directory.
Thank You for Reading..!!