How to resize the static partition in Linux without losing your data?
Some Prerequisites we need to check…
- The only way to change a static partition size using fdisk is by deleting and recreating it so ensure that the information on the file system is backed up.
- Make sure the partition you are resizing is the last partition on a particular disk.
1. Creating a partition and store some data:
- Use fdisk -l to check disk and partiton details…
- To create a new partition…
- I am allocated 2G size. Now format and mount it to some directory.
And I also created one file with some data.
2. Unmount the partition:
# umount /dev/xvdf1
3. Run fdisk disk_name…
- Check the partition number you wish to delete with the p. The partitions are listed under the heading “Device”.
- Now use the option d to delete a partition. If there is more than one, fdisk prompts for which one to delete.
- Use option n to create a new partition. Follow the prompts and if it asks to remove the signature, type N. And use option w to save the partition.
Don’t format the partition after it is created.
4. Run fsck on the partition:
The system utility fsck (file system consistency check) is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux.
5. Use resize2fs tool for grow/shrink the partiton:
The resize2fs is a command-line utility that allows you to resize ext2, ext3, or ext4 file systems.
6. Finally, mount it again and check the size this time…
We can see that size of disk is increased to 4GiB and data of disk is also still remained the same.
Do Clap if you find this useful :)
Thanks for Reading…😊