ARCH VM resize root partition

First of all - back up your data!!! While we hope not to destroy your data, a single typo could nuke the VM. Of if there's an error in the instructions, etc. While this worked great for me several times, I can provide no guarantees that this will work nor that it will preserve your data, use at your own risk.

The three main steps are

  1. Resize the disk in the hypervisor
  2. Update the partition table to take up the full disk
  3. Increase the size of the filesystem to take up the full partition

Resize the disk in the hypervisor

First, you need to increase the size of the disk in whatever virtualization software you're using.

In Proxmox, select the VM, go to the Hardware tab, select the drive and hit "Disk Action." Then hit "Resize" and enter the number of GB you'd like to add to the disk. Note, you can only increase the size, not decrease it, so don't go too crazy! I just need a little room so I'm adding 4GB.

Update the partition table

lsblk
df -h
Find the disk and partition you need to resize (probably your root partition)
fdisk /dev/sda
open the disk with fdisk

You may see a warning like this:

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.

Again, continue at your own risk, and only if your data is backed up.

># Command (m for help): p # select p for partitions to see your partitions - again make SURE you know what partition you want to resize

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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: 7BB1AE60-B6B0-6743-6C49-1ACCAD9BF33C
Device       Start      End  Sectors  Size Type
/dev/sda1     2048  1050623  1048576  512M BIOS boot
/dev/sda2  1050624 12580863 11530240  5.5G Linux filesystem

># Command (m for help): d # select d for delete

># Partition number (1,2, default 2): 2 # select 2 to delete partition 2

># Partition 2 has been deleted.

># Command (m for help): n # select n to create a new partition

># Partition number (2-128, default 2): 2 # 2 to number the new partition 2

># First sector (1050624-20971486, default 1050624):
># Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-20971486, default 20969471): ENTER just hit the enter key to use the default

># Created a new partition 2 of type 'Linux filesystem' and of size 9.5 GiB.
># Partition #2 contains a ext4 signature.

># Do you want to remove the signature? [Y]es/[N]o: n n to leave ext4 signature as is - we don't want to delete anything, just make it larger!

># Command (m for help): p # select p for partitions to see your partitions again - make sure the starting location of the second partition is where it was when you first ran p and that the first partition is unchanged  

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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: 7BB1AE60-B6B0-6743-6C49-1ACCAD9BF33C
Device       Start      End  Sectors  Size Type
/dev/sda1     2048  1050623  1048576  512M BIOS boot
/dev/sda2  1050624 20969471 19918848  9.5G Linux filesystem

And only when your SURE  things line up

># Command (m for help): w # select w to write the new partition table

># Command (m for help): d # select d for delete

lsblk
look at the partitions again to make sure the size has increased

Increase the size of the filesystem to take up the full partition

resize2fs /dev/sda2
resize the filesystem to take up the full partition
df -h
you should now see lots of space remaining (if you don't you may need to reboot the VM)

A lot of this information came from AskUbuntu, but was modified slightly for Arch Linux. Please see below for the Ubuntu directions:

How can I resize an ext root partition at runtime?
How can I increase the size of the root partition of a system at runtime? I have a partition that is not allocated after the root partition (which is also ext4), how can I add that unallocated sp...