Linux Resize GPT/ext4 Partition

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!

  1. Unmount the partition umount /dev/sda1

  2. Check the file system for errors. e2fsck -f /dev/sda1

  3. Resize the file system (replace 500G with your new partition size). resize2fs /dev/sda1 500G

  4. 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)
    
  5. Fix the file system. This time with no size at the end. resize2fs /dev/sda1

  6. Check the file system for errors just to be safe. e2fsck -f /dev/sda1

  7. Mount the partition and make sure your files are still there.

Now you can create new partitions using gdisk.

Comments