Increase or Decrease the Size of Static Partition in Linux
We can increase the size of fixed partition without losing any data but it is to create a dynamic partition using LVM if in future if we wish to increase or decrease the size of hard-disk.
There are two Memory Management Techniques: Contiguous, and Non-Contiguous. In Contiguous Technique, executing process must be loaded entirely in main-memory.
Contiguous Technique can be divided into:
- Fixed (or static) partitioning
- Variable (or dynamic) partitioning
Fixed (or static) partitioning is the oldest and simplest technique used to put more than one processes in the main memory. In this partitioning, number of partitions (non-overlapping) in RAM are fixed but size of each partition may or may not be same. As it is contiguous allocation, hence no spanning is allowed. Here partition are made before execution or during system configure.
We can increase the size by the following steps:
STEP 1: We need attach a external storage device to our system or virtual machine. Checking the device is attached or not and looking for the device name using fsdick -l command.
Step 2: Creating a partiton of 5GB.
fdisk <device_name > to open the device Command line
n : For creating a new partition.
p : For creating a primary partition.
1 : For creating one partition.
5G : For creating a partition of 5 GB .
w : For writing or save all the changes made .
We are done with the partition. Now we only need to format and mount the partition to a mount point.
To check if the partition is created run the command lsblk.
Step 3 : Formatting the Partition:
mkfs.ext4 <device_name>
Then mounting the partition.
mount <device_name> <mount_point>
Run the command df -h to check if the partition is formatted and mounted successfully.
What should we do now to increase the static storage ?
As the storage is static we can’t increase or decrease the storage when the partition is mounted. But one thing I can do, If I unmount the partition and delete the existing partition and in place of that partition . Add one more partition by Increasing or Decreasing the storage and then repairing the inode table and after that formatting only the increased storage in the partition .
Step 4 : To prove that data can be retrieved even after if we increase or decrease the storage, we will add three folders.
mkdir <folder_name> <folder_name> <folder_name>
Step 5 : Unmounting the mount point. As we unmount the partition is now free to do anything.
umount <mount_point or folder_name>
Step 6: We deleted the partition of 5GB and in place of first partition we created a new partition of 10 GB.
fdisk <device_name > : for the device Command line to be opened .
d : For deleting the unmounted partition
Now we will be creating a new partition with the extended size we want .
fdisk <device_name > : for the device Command line to be opened .
n :-For creating a new partition.
p :-For creating a primary partition.
1 :- For creating one partition.
Y :- Is for removing the signature also known as format .
Why is the system asking to remove signature ?
As we have already created a partition on partition number 1 and we have also formatted it with the format ext4. So the system is saying that we have already created a partition on partition number 1 and then we deleted it but the data in that storage is still present in ext4 format. So, would we like to have our data in ext4 format or remove the signature to be formatted later .
10G :- For creating a partition of 10GB. This time we are increasing the size by 5GB.
w :- For writing or save all the changes made .
Step 7: Now the challenging part comes What should we do now ,How to retrieve data ?
To retrieve data we repaired the partition table as it was before, using the command,
e2fsck -f <device_name>
Step 8: As we have repaired the partition table and we know 5GB is formatted but rest of 5GB is not formatted of partition of 10 GB .
So for formatting the remaining storage which has not been formatted we use,
resize2fs <device_name >
Resizing the partition.
Step 9: Now we just need to mount the partition to the mount point to have our data .
mount <device_name> <mount_point>
Finally,
We check that all the data can accessed using the command.
ls