Fixed: Resizing an ext4 filesystem and fixing a no-boot issue
Today I built a OpenWrt router in Hyper-V for my lab. Part of that required resizing the ext4 filesystem, something I hadn't done before.
It's supposed to be pretty straightforward. You boot up to another Linux distro, identify the disk with lsblk, fdisk to print the partition table, note the start of the partition you are resizing, delete the partition, create a new one with the same starting sector, and save the change. With that done you run resize2fs /dev/sda2, it squawks at you to check the filesystem, you do that, run resize2fs again, and you're all done. Right?
Well so that didn't exactly "boot" afterwards. Whoopsie.
I figured it out. If you work with Legacy Bios systems, yes that is all that is required. If the root partition you're resizing is an EFI partition in a UEFI boot system, there is another step required. You have to update grub with the new/changed partition ID so it can find the kernel.
If you don't, it hangs shortly after the grub OS selection screen. :(
To do that I booted back up to my .ISO, used lsblk -n -o PARTUUID /dev/sda2 to get the UUID of the partition. Then I mounted my boot partition and edited the /boot/grub/grub.conf with the new UUID. (mkdir /mnt/sda2 && mount /dev/sda2 /mnt/sda2 && nano /mnt/sda2/boot/grub/grub.conf then change the root=UUID=XYZYZYZYZ bit).
That was fun; Now I can do some real work.