Creating a Smaller QEMU img for a Smaller SSD (475GB qcow2)
In this article, we will cover the process of converting a larger QEMU image file to a smaller one, specifically for a 475GB SSD. This is useful when you want to move a Windows installation in a QEMU/KVM VM and shrink the root partition. For example, if you have a 500GB (~475GiB) SSD and you want to create an image file for it, this guide will help you.
Background
QEMU (Quick Emulator) is a powerful open-source machine emulator and virtualizer. It can emulate a wide range of hardware platforms, including x86, ARM, PowerPC, and more. QEMU can also be used as a virtual machine monitor (VMM), allowing multiple virtual machines to run on a single physical machine.
QEMU images, also known as virtual hard disks, are used to store the data and operating system of a virtual machine. These images can be created in various formats, including qcow2, which is a popular choice due to its efficient use of disk space and support for advanced features such as copy-on-write and snapshotting.
Converting a QEMU Image to a Smaller Size
To convert a QEMU image to a smaller size, you can use the qemu-img command-line tool. This tool provides several options for manipulating QEMU images, including resizing and converting them to different formats.
In this example, we will start with a 500GB (~475GiB) qcow2 image that has been shrunk to ~470GiB using a tool such as GParted. We will then convert this image to a smaller 475GB qcow2 image using the following command:
qemu-img convert -O qcow2 -s 470G /path/to/original.qcow2 /path/to/smaller.qcow2This command uses the convert option to convert the original image to a smaller qcow2 image. The -O qcow2 option specifies the output format, and the -s 470G option sets the size of the new image to 470GiB. Finally, the /path/to/original.qcow2 and /path/to/smaller.qcow2 options specify the locations of the original and new images, respectively.
In this article, we have covered the process of converting a larger QEMU image file to a smaller one, specifically for a 475GB SSD. This is useful when you want to move a Windows installation in a QEMU/KVM VM and shrink the root partition. The qemu-img command-line tool can be used to convert and resize QEMU images, making it easy to create smaller images for smaller SSDs.