Linux - Increase or Decrease Static Partitions without losing your data!

Linux - Increase or Decrease Static Partitions without losing your data!

We often see cases where we fall short on storage after our initial partition. Or we need to decrease the partition due to wastage.

Please NOTE: missing out on steps can corrupt your drive.

Let us start first by initializing a 10 GiB partition

STEPS TO FOLLOW:

1. ATTACH DISK
2. CREATE NEW PARTITION OF 10 GiB
3. FORMAT DRIVE
4. MOUNT TO FOLDER AND STORE DATA
  1. I have attached a 20GiB disk to the system.
No alt text provided for this image

2. Create a new 10G partition in it and save it.

No alt text provided for this image

Let us view if it was successful. Yep! /dev/sdc1 created

No alt text provided for this image

3. Now we need to format it (make file system)

No alt text provided for this image

4. Mount it to a folder and create a file.

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



INCREASE PARTITION SIZE

Let us see how to increase partition size to 15 GiB without losing data.

STEPS TO FOLLOW:

1. UMOUNT DRIVE : #umount folderlocation/name
2. DELETION OLD PARTITION AND CREATE NEW OF 15G
3. CLEAN AND SCAN
4. RESIZE FILESYSTEM
5. MOUNT TO FOLDER AND CHECK DATA
  1. Unmount : #umount /t7
  2. Delete old partition and create a new 15 G
No alt text provided for this image

3. Clean and scan using e2fsck

No alt text provided for this image

4. Resize file system using resize2fs

No alt text provided for this image

5. Mount to the folder and check data. Yep! Safe!

No alt text provided for this image


DECREASE STATIC PARTITION SIZE

We will now see how to resize the partition to 5 GiB

STEPS TO FOLLOW:

1. UNMOUNT DRIVE
2. CLEAN AND SCAN DRIVE
3. RESIZE FILESYSTEM TO 5G
4. DELETE OLD PARTITION AND CREATE NEW OF 5G
5. MOUNT TO FOLDER AND CHECK DATA
  1. umount /t7
  2. Use e2fsck to clean and scan drive
No alt text provided for this image

3. Resize the filesystem to 5G

No alt text provided for this image

4. Delete and create new partiton

No alt text provided for this image

5. Mount and check data

No alt text provided for this image


If you observe, the steps for increasing and decreasing are just the opposite. In case of increasing -> clean / scan and resize filesystem is done after partition. But in case of decreasing -> clean / scan and resize filesystem is done before partition.

To view or add a comment, sign in

More articles by Ishan Singhal

Others also viewed

Explore content categories