In the last blog, we've discussed how can we increase the size of the partition using Logical Volume Management, but what if we have data stored in a static partition which is not from a Volume group, then we cannot take space from the volume group.
So, here we goona increase the size of a static partition and for this, we're going to use AWS instance with 5GB EBS (Elastic Block Storage) connected:-
To check all the Partitions and connected devices we use the command:-
fdisk -l
Here you can see 5GB storage is connected to the instance.
For now, we'll make a partition of 2GB and store some data on it, to create partition use command:-
fdisk <device name>
This will take you fdisk prompt just add +2G in option of last sector.
Now format the partition by using:-
mkfs.ext4 <device name>
Now after formatting the partition, it's time to mount the partition on some folder, so I've created a folder name folder1 inside root directory and mount the partition to it.
To mount the folder:-
mount <partition name> <location>
This will mount the partition to the folder, to confirm the mount you can use the command:-
df -hT
Here you can see in the last /dev/xvdf1 is mounted to folder1 and consists of 2GB in size.
Now we add some data in the folder1 :-
Now we assume that our 2GB partition storage is full and we want to increase it so at first, we unmount the storage from folder1 by using command:-
umount /dev/xvdf1
We can confirm it again by using:-
df -hT
Now we delete the partition again by accessing the fdisk prompt.
After the partition is deleted we again create a partition using fdisk with the same device name. But this time in the option of last section instead of +2GB we will give +4GB.
In the end, it will also ask you that partition contains an ext4 signature do you want to remove it. If you enter [y] it will remove all the data in the partition that we don't want to do, so enter [n].
Now check for any errors by using the command:-
e2fsck -f /dev/xvdf1
The size of the partiton is increased to 4GB but it is not formatted into ext4 format, so we use command:-
resize2fs /dev/xvdf1
This will format the new sectors into ext4 format, and now we can mount it back to the folder1 .
Now here you can see the size of the our Partition is increased from 2GB to 4GB and also our data inside the old partition is safe.
Thank You