Increase or Decrease the Size of Static Partition Without Losing Any Data
Yash Dwivedi
RHCA | Quantum Computing | OpenShift | DevSecOps | DevOps | MLOps | Big Data | Hybrid Multi Cloud | AWS | GCP | Python | Terraform | Ansible | Kubernetes | MongoDB | GIT & GitHub
This Article explain how to increase/decrease the size of the static partition without losing data in Linux.
WHAT IS PARTITIONING OF HARD DISK?
It is the concept in which a given hard disk is divided into segments of secondary storage, so that each segment is managed separately. This is also done with a view that if damage is caused to one segment, like in cases of complete deletion of data, the damage is not transferred to the entire disk. It rather remains confined to that particular segment.
MAJOR STEPS INVOLVED IN CREATING A PARTITION
Three major steps are involved are:
- Create
- Format
- Mount
CREATING
You need to have a harddisk attached.
fdisk -l
This command shows you the list of all attached disks.
fdisk <drive_name> , In my case fdisk /dev/sdc
This command creates the partition for you. The ‘n’ in the line 'Command (m for help):n' indicates that we are creating a new partition.
The hard disk is of size 10GB in total, But I want to make use of 3GB so I will input +3G.
w: to save the changes made to the partition.
FORMATTING
mkfs.ext4 <drive_name>, In my case mkfs.ext4 /dev/sdc1
Above command is used to format the partition.
MOUNTING
Create a new directory , I created /st1.
mount /dev/sdc1 /st1
In order to mount the partition to /st1.
df -hT
To check the successful mounting of the partition.
Within the directory create a file , I created dwi.txt.
Now comes our main task which is to increase or decrease the size of the static partition.
For accomplishing this task, we need to first unmount it , using command:
umount /st1
Now delete the partition:
And create partition again:
Now:
e2fsck -f /dev/sdc1
This command will check errors and will mark file system as clean.
Now format the remaining partition i.e. resized partition:
resize2fs /dev/sdc1
and mount to directory
mount /dev/sdc1 /st1
Here, we can see the previous file exist. so through this method we can increase the size of static partition.
Thank You!