Increase or Decrease the size of static partition in Linux
Here are the steps to increase or decrease the size of partition in Linux....
Increasing the Size
- I have added an extra hard disk of size 10GiB "/dev/sdb", and I have created 2 primary partitions, one extended and two logical partitions inside the extended partition..
To list all the partitions inside /dev/sdb device, command ---> fdisk -l /dev/sdb
2. I will use the logical partition /dev/sdb6 of size 3GiB to show how to increase or decrease size of the partition. So, I am formatting it with the fs ext4, command ---> mkfs.ext4 /dev/sdb6
3. Now, I will mount the device with /fold, command ---> mount /dev/sdb6
now, create a file inside the it, so that we can check our process in future
we can see that current mounted file size of the fs is appx. 3GiB..
4. Now, we will delete the the partition /dev/sdb6...
Type "w" to save the changes made..
5. Now, we will again create a same logical partition, but this time of size 4GiB
As it will contain the previous fs "ext4", and we don't want to lose the file we stored in the device earlier named "increase.txt", so we have to write n, when it asks to remove the signature..
we can see that size of /dev/sdb6 device has been increased, but we still have to do some extra things also to prevent it from bad blocks, from getting corrupt..
6. Run the command ---> e2fsck -f /dev/sdb6, to have a check on the fs(ext4 in this case)
7. Now, use the command ---> resize2fs /dev/sdb6, to make it into a suitable previously configured fs(ext4)
8. Now, we will confirm that the partition size has been increased or not..
we can also see that the file we stored still exists, bczz we haven't removed the signature.
Decreasing the Size
- Similarly, we will do to decrease the partition size..
we will create a file decrease.txt
2. Now, again run the command ---> e2fsck -f /dev/sdb6, to have a check on the fs(ext4 in this case)
3. Now, use the command ---> resize2fs /dev/sdb6 3G, to make it into a suitable previously configured fs(ext4)
we can see that, size of fs has been changed from 4GiB to 3GiB
but, we can observe that total partition size still of the partition /dev/sdb6 is same as previous 4GiB
Note: resize2fs doesn't make any changes to total size of the partition, it only make changes to the fs
4. To decrease the size, some more steps has to be done. Run the following commands... as we did in increasing the size
5. Now, again mount dev/sdb6 /fold and use df -h..., it's working fine as previous
run the command --> fdisk -l /dev/sdb6, now it's coming what we want that is the size has been reduced to 3GiB
6. We can also check for the file we have stored previously name decrease.txt
!!! Task Completed !!!