Increasing or decreasing the size of Static partition in linux
--
In this article, I am going to explain about resizing the static linux partiton without using an LVM.
What is Linux?
Just like Windows, iOS, and Mac OS, Linux is an operating system. In fact, one of the most popular platforms on the planet, Android, is powered by the Linux operating system.
An operating system is software that manages all of the hardware resources associated with your desktop or laptop.
What partition? and why we need it?
Disk partitioning is the creation of one or more regions on secondary storage , so that each region can be managed separately. These regions are called partitions. It is typically the first step of preparing a newly installed disk, before any file system is created.
Before using the storage we need to create partition. Without the partition we cannot use the storage.
How to create a partition?
In this article we’ll learn creating the partition using step by step approach with practical implementation.
Prerequisites:
- Linux OS( In this practical I have used Redhat)
- External Hard disk
Procedure:
For increasing or decreasing the static partition of linux we need a static partition first.
For creating the static partition we have to attach the Hard disk to the system.
In this practical, we have implemented using the virtual box. You can also use bare metal for the same.
For attaching the hard disk to the virtual box instance we can attach like this
Then click on the + icon on the right side for adding the hard disk.
Click on ‘Create’ button and create the new hard disk.
We can also check whether it is attached or not by clicking on storage.
Now boot into to the O.S
We can also check the attached drives to the OS by using the command
fdisk -l
We can see the disk with name ‘/dev/sdb’ with 5GiB size.
we need to create the partition first.
For creating the partition we can use command
fdisk ‘<disk_name>’
On clicking m we get the help and get list of commands/
For creating new we need to use :n
To save use : w
That’s it we have created the new partition . For checking the partition we need to use command ‘lsblk’. We can see that under sdb 1 partition created with 4GB size.
For mounting it to the folder.
We need to create a folder
mkdir /folder
mount </dev/sdb> </folder>
Here /dev/sdb is the disk and /folder is the folder path.
Here we can check using command ‘df -hT’.
We have successfully created the static partition. Now we can store the data
For resizing the linux partition we need to unmount it first.
for unmounting command is ‘umount /dev/sdk’
‘/dev/sdb’ is the disk name
Now delete the partition for deleting we need to do same as before
fdisk /dev/sdb
Use ‘d’ for deleting and ‘w’ for saving it.
Now , we need to again create the partition same as above.
Do create the partition again same as above with change in size that we want to resize
If we want to create 4GB then use +4G likewise.
After creating the partition we need to check the file system using command
e2fsck -f /dev/sdb
Then after changing the size of the partition we need to format the the un formatted size for that we need to use command
resize2fs /dev/sdb
Then again mount with the same folder like above
Then go to the folder and check for the contents. It is there …..
That’s it we have successfully completed the resizing of the linux partition without losing any data from it.
Thank you guys for reading my article.
I hope it helped you