I'm setting something up and needed to add a bunch of space to an EXT4 partition.

My current layout is this, a 128GB disk (/dev/sdb) and a single partition (/dev/sdb1) formatted with EXT4. It's a simple layout.

My need is to expand that to 500GB. I expanded the disk in Hyper-V to 500GB and, unfortunately, had to reboot the VM to get the system to pick up the new space on the disk. The logs showed that the disk size changed but I could not find a way to get the kernel to see it, very sad.

Once the reboot was completed I used fdisk to resize the partition then resize2fs to resize the filesystem. I did not unmount the filesystem during this process, EXT4 can be resized online.

Disclaimer: I can not be held for any damages caused by following these instructions. It is your responsibility to maintain proper backups and data retention policies in the case something goes awry.

  1. Prepare the VM:
    • Expand the disk in your hypervisor
    • Take a snapshot of the VM or disk you are expanding
  2. Repartition
    • sudo fdisk /dev/sdb
      • Command (m for help): p <- print the partition layout, take note of the start sector of the last partition. For me it was 2048 and I only had the one partition, so that was 1
      • Command (m for help): d 1 <- delete the last partition, replace 1 with the last partition number if it is not 1
      • Command (m for help): n <- create the new partition
      • Partition Number: 1 <- the number of the partition you just deleted
      • First sector (#-#): 2048 <- the start sector of the last partition. This is in the output of p from above
      • Last sector, +/-sectors or +/-size{K,M,G,T,P} (#-#, default #): <- just press enter here to use the entire disk.
      • Do you want to remove the signature? [Y]es/[N]o: N <- this was not in any guides I could find, since it sounded scary and a bad idea I chose No and it worked
      • Command (m for help): p <- verify the new partition table
      • Command (m for help): w <- write the new partition table
      • Command (m for help): q <- exit fdisk
  3. Expand the partition
    • sudo resize2fs /dev/sdb1
  4. Check the available space
    • df -h
  5. Remove the snapshot