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
- I have attached a 20GiB disk to the system.
2. Create a new 10G partition in it and save it.
Let us view if it was successful. Yep! /dev/sdc1 created
3. Now we need to format it (make file system)
4. Mount it to a folder and create a file.
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
- Unmount : #umount /t7
- Delete old partition and create a new 15 G
3. Clean and scan using e2fsck
4. Resize file system using resize2fs
5. Mount to the folder and check data. Yep! Safe!
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
- umount /t7
- Use e2fsck to clean and scan drive
3. Resize the filesystem to 5G
4. Delete and create new partiton
5. Mount and check data
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.