Increase or Decrease the size of static partition in Linux
Increase or Decrease the size of static partition in Linux

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

  1. 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

No alt text provided for this image

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

No alt text provided for this image

3. Now, I will mount the device with /fold, command ---> mount /dev/sdb6

No alt text provided for this image

now, create a file inside the it, so that we can check our process in future

No alt text provided for this image
No alt text provided for this image

we can see that current mounted file size of the fs is appx. 3GiB..

4. Now, we will delete the the partition /dev/sdb6...

No alt text provided for this image
No alt text provided for this image

Type "w" to save the changes made..

5. Now, we will again create a same logical partition, but this time of size 4GiB

No alt text provided for this image

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..

No alt text provided for this image

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)

No alt text provided for this image

7. Now, use the command ---> resize2fs /dev/sdb6, to make it into a suitable previously configured fs(ext4)

No alt text provided for this image

8. Now, we will confirm that the partition size has been increased or not..

No alt text provided for this image
No alt text provided for this image

we can also see that the file we stored still exists, bczz we haven't removed the signature.


Decreasing the Size

  1. Similarly, we will do to decrease the partition size..

we will create a file decrease.txt

No alt text provided for this image

2. Now, again run the command ---> e2fsck -f /dev/sdb6, to have a check on the fs(ext4 in this case)

No alt text provided for this image

3. Now, use the command ---> resize2fs /dev/sdb6 3G, to make it into a suitable previously configured fs(ext4)

No alt text provided for this image
No alt text provided for this image

we can see that, size of fs has been changed from 4GiB to 3GiB

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

5. Now, again mount dev/sdb6 /fold and use df -h..., it's working fine as previous

No alt text provided for this image

run the command --> fdisk -l /dev/sdb6, now it's coming what we want that is the size has been reduced to 3GiB

No alt text provided for this image

6. We can also check for the file we have stored previously name decrease.txt

No alt text provided for this image

!!! Task Completed !!!

To view or add a comment, sign in

More articles by Kapil Kumar

  • Creating a Simple Calculator with flutter

    I have used flutter to create a simple calculator app which can perform operations like +,-,*,/ Here, I will show you…

  • Docker Web Portal

    I have created a web portal related to docker, in which we can run docker commands..

  • Object Recognition and License plate detection with recognition

    I have created a machine learning mode: Object Detection. ---> Main objective is to detect the car.

  • Use case of Javascript : Uber

    I am doing this article on Uber company..

  • Kubernetes GUI(Web Portal)

    I have created a K8s GUI with my team members in summer training. It will run some of K8s commands for you, like:…

  • k-mean clustering and its real usecase in the security domain

    K-means clustering is one of the simplest and popular unsupervised machine learning algorithms. Typically, unsupervised…

  • Task 04

    Task 4.1: Create image by yourself Using Python Code Above is the code in which I have created "smiley face" and "sad…

  • IDS, Cyber crimes and confusion matrix

    Firstly, I will talk something about IDS(Intrusion Detection System). Intrusion Detection System is a software…

  • GUI container on the Docker

    I have already installed docker Going inside a particular folder or workspace, I will create a Dockerfile, to build an…

  • Creating a very simple ML model on Docker container

    Pulling the Docker container image of CentOS image from DockerHub 2. Creating a new container, using the following…

Others also viewed

Explore content categories