Resize QEMU-Image
A step-by-step guide to resizing a QEMU virtual machine image when the root partition becomes too small.
The Problem
Your QEMU virtual machine is running out of disk space, and you need to expand the virtual disk image to accommodate more data.
Solution Overview
The process involves three main steps:
- Resize the image file on the host
- Modify the partition table inside the VM
- Resize the filesystem
Step 1: Resize the Image on Host
First, resize the QEMU image file (run this on the host system):
qemu-img resize vm_image.qcow2 +10G
Replace vm_image.qcow2 with your actual image filename and adjust the size as needed.
Step 2: Modify Partition with fdisk
Boot your VM and run the following commands as root inside the guest system:
fdisk /dev/vda
In fdisk, perform these steps:
- Print current partition table: Type
pto see current partitions - Delete the partition: Type
dand select the partition number (usually 1) - Create new partition: Type
nfor new partition - Select primary: Type
pfor primary partition - Use same start sector: Press Enter to use the same starting position
- Use all space: Press Enter to use all available space
- Write changes: Type
wto write the partition table
Important: Make sure to use the same starting sector as the original partition!
Step 3: Reboot the System
Reboot your virtual machine to ensure the kernel recognizes the new partition size:
reboot
Step 4: Resize the Filesystem
After rebooting, resize the filesystem to use the additional space:
resize2fs /dev/vda1
Replace /dev/vda1 with your actual device name if different.
Verification
Check that the resize was successful:
df -h
You should now see the increased disk space available.
Important Notes
- Always backup your VM before performing these operations
- Replace
vm_image.qcow2and/dev/vdawith your actual system values - All commands must be run with root permissions
- The exact device names may vary depending on your system configuration
This procedure works for most Linux distributions running in QEMU/KVM virtual machines with ext2/ext3/ext4 filesystems.