Increase or Decrease the Size of Static Partition in Linux

Task Objective : Find a way to increase or decrease the size of a static partition in Linux without loosing the data.

Lets start on increasing size of static partition in Linux.

Steps :

  1. unmount the storage before decreasing or increasing the storage.
  2. ‘ fdisk -l ‘ -This command will give the storage names of the devices connected.
  3. fdisk ‘device name’ -This command can be used to create/delete an partition .
  • p -to get the partitions
  • d -Delete the Partitions
  • n -To create a new partition
  • w -To write the changes in partition tables

4. e2fsck -f ‘device name’ -To check the filesystem is it ok or some errors

5. resize2fs ‘device name’ -To resize our file system so new blocks will sync with the older one

6. Mount the storage after increasing or decreasing the storage.

Lets consider a folder is mounted with a harddisk which is of 4GB in size but we need storage of 8GB So we increase the storage of same Harddisk to 8GB without loosing the data.

Now we will be increasing the storage without loosing the data.

First we need to unmount the storage .

Next we need to delete the partition using the fdisk command

Now we can create the desired storage of 8GB

Now we need to run e2fsck -f “name” for any errors in the filesystem.

now we have to resize our file system so new blocks will sync with the older one .

To do this we have the following command resize2fs “device name”

after mounting we see that the data is still available in the storage.