When configuring a QEMU-KVM virtual machine through libvirt, simply setting <boot dev='cdrom'/>
in the XML configuration might not be sufficient. The boot order is actually determined by multiple factors:
- The
os
section boot device specification - The bootable flag on storage devices
- The boot order attribute in device definitions
Here's how to properly configure your VM to boot from CDROM:
<domain type='kvm'>
<name>example-vm</name>
<os>
<type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
<boot dev='cdrom'/>
</os>
<devices>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/example.qcow2'/>
<target dev='vda' bus='virtio'/>
<boot order='2'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/path/to/install.iso'/>
<target dev='hda' bus='ide'/>
<readonly/>
<boot order='1'/>
</disk>
</devices>
</domain>
Three critical changes are needed:
- Explicit boot order numbering (1 for CDROM, 2 for HDD)
- Proper device addressing (IDE bus for CDROM works best for boot)
- Configuration reload after changes
After editing the XML file, you must:
# Define the VM (if new)
virsh define /etc/libvirt/qemu/example.xml
# For existing VMs:
virsh destroy example-vm
virsh undefine example-vm
virsh define /etc/libvirt/qemu/example.xml
virsh start example-vm
Check if your configuration was applied correctly:
virsh dumpxml example-vm | grep -A5 "boot order"
This should show the CDROM device with boot order="1" and the HDD with boot order="2".
- Ensure the ISO is properly mounted by checking with
virsh domblklist example-vm
- Verify the CDROM device is using IDE bus (not SCSI or virtio)
- Check QEMU command line with
ps aux | grep qemu
to see boot parameters
When working with QEMU-KVM virtual machines, you might encounter situations where the VM stubbornly boots from the hard drive despite explicit configuration to use the CDROM. The XML configuration appears correct with <boot dev='cdrom'/>
set, yet the VM ignores this setting.
The most reliable method involves multiple verification steps:
1. Full Domain Restart Required
Simple VM reboot isn't sufficient - you need to completely destroy and recreate the domain:
# virsh destroy vm_name
# virsh undefine vm_name
# virsh define /etc/libvirt/qemu/vm_name.xml
# virsh start vm_name
2. Verify CDROM Device Configuration
Your CDROM device must be properly defined in the XML. Here's a correctly configured example:
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/path/to/your.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
Method 1: Using virsh edit
Instead of manually editing XML files, use:
# virsh edit vm_name
Make your changes and save - libvirt will automatically reload the configuration.
Method 2: Temporary Boot Override
For one-time boot from CDROM without XML changes:
# virsh start vm_name --cdrom /path/to/your.iso
- Ensure the ISO path is accessible by the libvirt-qemu user
- Verify no other boot devices have higher priority
- Check for syntax errors in XML with
virt-xml-validate
- Some older libvirt versions require additional boot parameters
For complete control, you can specify the exact boot order:
<os>
<type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
<boot dev='hd'/>
<boot dev='cdrom'/>
<bootmenu enable='yes'/>
</os>
This ensures CDROM is tried before HDD during boot.