Linux Resize GPT/ext4 Partition
Jul 16, 2015
I needed to resize my RAID array to test the speed of AES encryption with LUKS on the same controller but I had partitioned the array to use the entire thing.
For the entire guide /dev/sda will be my RAID array and /dev/sda1 will be my only partition. I strongly recommend you backup your data first!
-
Unmount the partition
umount /dev/sda1
-
Check the file system for errors.
e2fsck -f /dev/sda1
-
Resize the file system (replace 500G with your new partition size).
resize2fs /dev/sda1 500G
- Delete the old partition and create a new one with the desired size.
gdisk /dev/sda
p (show the partition table, you should write down the starting sector) d (delete partition) n (new) enter (partition number, should be 1) 2048 (starting sector from earlier) 500G (new partition size, replace it with the desired size) enter (partition type, 8300 is fine) w (write the new partition table) Y (yes I'm sure)
-
Fix the file system. This time with no size at the end.
resize2fs /dev/sda1
-
Check the file system for errors just to be safe.
e2fsck -f /dev/sda1
- Mount the partition and make sure your files are still there.
Now you can create new partitions using gdisk.