Increase-Decrease Size of Static Partitions

Prince Prashant Saini
4 min readMar 7, 2021

--

ARTH Task-7.1[B]

Increase or Decrease the size of Static Partition in linux

  • Step 1- Add a Hard disk of any size

We will start by adding a hard disk to a existing virtual machine.In the settings of the VM go to storage and add a hard disk of desired size.I added a Hard Disk of 15 GB. Following are the images of the steps to follow while adding the disk.

  • Add a Hard Disk
  • Click on create
  • Create a Disk of 15GB and add it to the VM

Now that we have successfully added the Hard Disk power on the virtual machine and check if the disks are successfully added to the VM or not.In order to check if the disk is attached use the below command:

fdisk -l
  • Step 2- Creating partition,Formatting and Mounting it

We can see that a hard disk of 15 GB is attached to the virtual machine.Now we have to create a partition, format it and then mount it.

For the partition we have to go in the /dev/sdc.Follow the below commands to create partitions.

Press n- for new partition
Press p- for primary partition
Press w- To save

Now that we have created a partition we have to format the partition that we have created.For that we can use the below command:

mkfs.ext4/dev/sdc1

After we successfully format the partition now we have to mount it to a directory.So first we need to create a directory.To create a directory use the below command:

mkdir (name)

Now after creating the directory we have to mount the created partition to the directory by using the below command and in order to check we can use lsblk command as follows:

mount /(partition)/(dir name)
lsblk

Now we are done with mounting.Lets keep some test files in the directory created so that we can prove that the data isnt affected by the increase or decrease of partition.

  • Step 3- Unmount the Created Partition

Now we will unmount the created partition for that we will will use the below command and in order to check wether the unmount is successfull we will use the df -hT command:

umount (dir name)
df -hT
  • Step 4 — Delete the partition and create a new partition with increased/decreased size

Delete the earlier partition and create a new onw using the same commands as we used earlier.The output looks as below:

fdisk dev/sdc
Press d- To delete partition

Now create a new partition with same size we have created earlier.The output is as follows:

Now we have to clean the partition to avoid unwanted values hence we can use the below command

e2fsck-f/dev/sdc1

Now we will resize and format the partition.We will use the below command to resize

resize2fs /dev/sdc1
  • Step 5- Mount the partition

Mount the new partition again using the previously used commands and now we can see that the data we had created for testing remains safe and there is no data loss even if we delete the partition.The size of the partition also gets increased or decreased.The final results will be like as follows:

--

--