How To Resize Filesystem with resize2fs

Quick note on filesystem resize on a typical virtual disk. I needed to resize root filesystem on my Ubuntu server to add extra space. This is an Ubuntu Linux hosted with Proxmox, so I first resized disk in the VM settings there.

After that the disk was resized from 20GB to 40GB:

GPT PMBR size mismatch (41943039 != 83886079) will be corrected by write.
The backup GPT table is not on the end of the device.
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8E89844F-8124-4401-8600-E322C15304CB

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  1054719  1050624  513M EFI System
/dev/sda3  1054720 41940991 40886272 19.5G Linux filesystem


Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

… it was time to resize the filesystem, but first you need to update the partition it’s on:

root@dev:~ # growpart /dev/sda 3
CHANGED: partition=3 start=1054720 old: size=40886272 end=41940992 new: size=82831327 end=83886047

Ok now you can resize the filesystem itself:

root@dev:~ # resize2fs /dev/sda3
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda3 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/sda3 is now 10353915 (4k) blocks long.

New filesystem size could be confirmed with df -h command right after resizing:

root@dev:~ # df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        39G   16G   22G  42% /

That’s it!