QEMU
How to Convert a VirtualBox Disk to QEMU (QCOW2 or RAW)
This article explains how to convert a VirtualBox disk image (VDI) to a QEMU-compatible format (QCOW2 or RAW) and how to resolve common permission issues when launching a virtual machine with the converted disk.
Requirements
- A Linux system (e.g., Ubuntu)
- `qemu-utils` package (contains `qemu-img`)
- Access to the original `.vdi` file
- Optional: `libvirt` or `virt-manager` if managing VMs through them
Step 1: Install Required Tools
Install `qemu-utils`:
sudo apt update
sudo apt install qemu-utils
Step 2: Convert the Disk Image
Convert VDI to QCOW2
qemu-img convert -O qcow2 input.vdi output.qcow2
Convert VDI to RAW (optional)
qemu-img convert -O raw input.vdi output.raw
Check the Output Disk
qemu-img info output.qcow2
Step 3: Fix "qemu: the emulator may not have search permission" Error
This error means the QEMU process (often running as user `qemu`) cannot access the disk image due to file or directory permissions.
A. Change File Ownership and Permissions
If using `libvirt`/`virt-manager`, you can move the disk to the default image directory:
sudo mv output.qcow2 /var/lib/libvirt/images/
sudo chown qemu:qemu /var/lib/libvirt/images/output.qcow2
Alternatively, if keeping it in your home directory:
sudo chmod o+rx /home/yourusername
This allows the QEMU process to traverse into the home directory.
B. Set SELinux Context (if applicable)
On systems with SELinux enabled (e.g., Fedora, CentOS):
sudo chcon --type=virt_image_t /var/lib/libvirt/images/output.qcow2
C. Update VM Definition (XML or virt-manager)
Ensure the VM definition points to the correct and accessible disk image path.
In Ubuntu, disks mounted under `/media/<username>` are only accessible to that user. To access it from another user account:
A. Grant Read Access
sudo chmod -R o+rx /media/username/diskname
Unmount the disk and remount manually:
sudo mkdir /mnt/sharedusb
sudo mount /dev/sdX1 /mnt/sharedusb
sudo chmod -R 755 /mnt/sharedusb
Replace `/dev/sdX1` with your actual USB device.
Add an entry in `/etc/fstab`:
UUID=XXXX-XXXX /mnt/sharedusb vfat defaults,umask=0022 0 0
Find the UUID using:
sudo blkid
Conclusion
Converting a VirtualBox VDI to QEMU format is straightforward using `qemu-img`. However, disk access issues may arise if the VM emulator lacks permission to the image file. These can be resolved by setting correct file ownership, adjusting SELinux contexts (if needed), and mounting shared media in accessible locations.