Adding Space to a VM: Ending Disk Resize (Grow) of Primary Partition with QEMU Hypervisor
Virtual machines (VMs) are essential tools for modern computing, allowing for the creation of isolated environments for testing, development, and deployment. One common task when managing VMs is resizing disks, particularly the primary partition. This article will cover the process of adding space to a VM, focusing on ending disk resize (grow) of the primary partition with the QEMU hypervisor.
Understanding Disks and Partitions in VMs
In a VM, a disk is a virtual storage device that can be managed and resized using various tools and techniques. A partition is a logical division of a disk that contains a file system and is managed as a separate unit. The primary partition is the first partition on a disk and is typically used to install the operating system.
Preparing to Resize the Primary Partition
Before resizing the primary partition, it is essential to ensure that the VM is shut down, and no processes are using the disk. Additionally, it is necessary to identify the disk device name, which may vary depending on the VM's operating system and configuration.
Resizing the Disk with QEMU
To resize the disk with QEMU, it is necessary to use the qemu-img command-line tool. The following command can be used to increase the size of the disk:
qemu-img resize +
For example, to increase the size of a disk named /dev/vda by 10 GB, the following command can be used:
qemu-img resize /dev/vda +10240
Resizing the Primary Partition
After resizing the disk, it is necessary to resize the primary partition to use the additional space. This can be done using a partitioning tool such as fdisk or parted. The following steps can be used to resize the primary partition with fdisk:
- Start the VM and log in to the operating system.
- Launch
fdiskwith the disk device name as an argument:
sudo fdisk
- Delete the existing primary partition and create a new one that uses the entire disk, including the additional space.
- Write the changes to the disk and exit
fdisk. - Rescan the disk to detect the new partition:
sudo partprobe
- Format the new partition with a file system.
Ending the Disk Resize (Grow) of the Primary Partition
After resizing the primary partition, it is necessary to end the disk resize (grow) operation. This can be done using the blockdev command-line tool with the following command:
sudo blockdev --grow
Adding space to a VM by resizing the primary partition with QEMU involves several steps, including resizing the disk, resizing the primary partition, and ending the disk resize (grow) operation. By following the steps outlined in this article, it is possible to increase the size of the primary partition and make the most of the available disk space in a VM.
References
-
QEMU Image File Format documentation.
-
Partitioning disks with
fdiskman page. -
Resizing file systems with
resize2fsman page.