I am trying to install Debian (debian-9.9.0-amd64-netinst.iso) in QEMU on Windows. I created the disk using the command “qemu-img create -f qcow2 virtualdebian.img 30G” and the command “qemu-img info virtualdebian.img” returns the following:
image: virtualdebian.img
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 193K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
However, when I run the command:
qemu-system-x86_64 -accel hax -drive
file=virtualdebian.img,index=0,media=disk,format=raw -cdrom debian-9.9.0-amd64-netinst.iso -m 2G
The Debian installer only shows the size of the disk as 197kB, which is not enough to install Debian on. I don’t understand where it is getting the size of 197kB from?
3 Answers
The QEMU Disk is Displaying the Incorrect Size
QEMU is a popular open-source machine emulator and virtualizer that allows users to run operating systems and applications for various architectures on a host machine. It is a powerful tool for developers and testers who need to test their software on different operating systems and architectures. However, sometimes QEMU may display incorrect disk size, which can cause problems during installation or usage. In this blog post, we will discuss why QEMU disk is displaying the incorrect size and how to fix it.
What is QEMU Disk?
Before we dive into the issue of the incorrect disk size, let’s first understand what QEMU disk is. A QEMU disk is a virtual disk image that is used by QEMU to store the data of a virtual machine. It can be created using the “qemu-img” command-line tool, which is included in the QEMU package. A QEMU disk can be of different formats, such as raw, qcow2, vmdk, etc. The format determines how the data is stored in the disk image and how it is accessed by the virtual machine.
Why QEMU Disk is Displaying the Incorrect Size?
Now, let’s discuss why QEMU disk is displaying the incorrect size. There can be several reasons why this is happening. One of the common reasons is that the QEMU disk image has not been properly created or formatted. For example, if you create a QEMU disk image with a virtual size of 30GB, but the actual disk size is only a few kilobytes, then QEMU will only recognize the actual disk size and not the virtual size. This can happen if the disk image has not been properly allocated or initialized.
Another reason why QEMU disk is displaying the incorrect size could be due to the disk format. QEMU supports various disk formats, and each format has its own way of storing data. If the disk format is not compatible with the virtual machine’s operating system or application, then it may not recognize the disk size properly. For example, if you are trying to install a Windows operating system on a QEMU disk image that is formatted as EXT4, then the Windows installer may not recognize the disk size properly.
How to Fix the QEMU Disk Size Issue?
To fix the QEMU disk size issue, there are several things you can try. Here are some of the solutions:
1. Recreate the QEMU Disk Image
The first thing you can try is to recreate the QEMU disk image. Make sure you specify the correct virtual size and format when creating the disk image. For example, if you want to create a 30GB disk image in qcow2 format, use the following command:
qemu-img create -f qcow2 virtualdebian.img 30G
This will create a QEMU disk image with a virtual size of 30GB and qcow2 format. Then, use the “qemu-img info” command to verify the disk image information.
2. Convert the Disk Image to a Different Format
If the QEMU disk image format is not compatible with the virtual machine’s operating system or application, you can convert the disk image to a different format. QEMU supports various disk image conversion options, such as “qemu-img convert”, “qemu-img rebase”, etc. For example, to convert a qcow2 disk image to raw format, use the following command:
qemu-img convert -f qcow2 -O raw virtualdebian.img virtualdebian.raw
This will convert the qcow2 disk image to raw format. Then, use the raw format disk image in the QEMU command.
3. Use the Correct QEMU Command
Make sure you are using the correct QEMU command to launch the virtual machine. The QEMU command should specify the correct disk image file, format, and media type. For example, if you are launching a virtual machine with a raw format disk image, use the following command:
qemu-system-x86_64 -drive file=virtualdebian.raw,index=0,media=disk,format=raw -cdrom debian-9.9.0-amd64-netinst.iso -m 2G
This will launch the virtual machine with the correct disk image file and format.
4. Check the Disk Space on the Host Machine
Make sure you have enough disk space on the host machine to create and store the QEMU disk image. If the disk space is limited, it may cause issues with the disk image creation and usage. Check the disk space using the “df” command and make sure you have enough free space.
5. Check the QEMU Version and Configuration
Make sure you are using the latest version of QEMU and that the QEMU configuration is correct. Check the QEMU version using the “qemu-system-x86_64 –version” command and make sure it is up-to-date. Also, check the QEMU configuration file, such as “/etc/qemu/qemu.conf”, and make sure it is configured correctly.
Conclusion
In conclusion, the QEMU disk size issue can be caused by various factors, such as incorrect disk image creation, incompatible disk format, incorrect QEMU command, limited disk space, and incorrect QEMU configuration. To fix the issue, you can try recreating the disk image, converting the disk image to a different format, using the correct QEMU command, checking the disk space, and checking the QEMU version and configuration. By following these solutions, you should be able to fix the QEMU disk size issue and launch the virtual machine successfully.
The issue is that you are specifying the format as “raw” in the command: qemu-system-x86_64 -accel hax -drive file=virtualdebian.img,index=0,media=disk,format=raw -cdrom debian-9.9.0-amd64-netinst.iso -m 2G
This is causing the installer to see the disk as a raw image, which has a size of 193K. To fix this, you should remove the “format=raw” option from the command, so that it recognizes the disk as a qcow2 image with a size of 30G: qemu-system-x86_64 -accel hax -drive file=virtualdebian.img,index=0,media=disk -cdrom debian-9.9.0-amd64-netinst.iso -m 2G
You created the virtual disk in the QCOW2 format, which allows for grow-on-demand storage. This means that the virtual machine (VM) will see the disk as its full size, but the actual file on the host disk will start small and automatically grow as the VM writes data to it. Because the image is freshly made and doesn’t contain any data yet, its file size is currently at the minimum size.
However, when attaching the disk to QEMU, you specified the ‘raw’ format. This tells QEMU to ignore the QCOW2 header and treat the file as a fixed-size disk. This is not consistent with the dynamic QCOW2 image you created. To properly attach a dynamic QCOW2 image, use the -drive format=qcow2 option instead of raw.