Resize QEMU-Image

5GB are not enough for the root partition you have allocated for a VM? No problem! Lets fix it.

You need to run all commands with root permissions and you need to change vm_image.qcow2 and /dev/vda to values that match your system.

 # all command need to be run as root

# resize the image (host)
qemu-img resize vm_image.qcow2 +10G

# rewrite partion (client)
fdisk /dev/vda
# in fdisk
# - delete partition
# - recreate partition it with same stating position
# - write

# reboot (client)
reboot

# grow filesystem (client) - requires online growing
resize2fs /dev/vda

Below you will find a sample fdisk run:

$ fdisk /dev/vda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 9437183 4717568 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): p
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/vda1 2048 10485759 5241856 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Leave a Reply

Your email address will not be published. Required fields are marked *