Check dmesg output in the guest for disk detection messages
Ensure the virtio-scsi controller is present in the VM configuration
When working with KVM virtualization, properly hotplugging virtio disks requires precise XML configuration and guest OS cooperation. The key pain points emerge when:
The libvirt XML gets incorrect driver specifications (file vs qemu)
The guest kernel fails to recognize new devices without rescan
The original approach had incorrect driver declaration. Here's the proper virsh command:
For Ubuntu guests, trigger device rescan with these steps:
# First check current PCI devices
ls /sys/bus/pci/devices/
# Find the new device (should appear as virtio-pci)
# Then trigger rescan:
echo 1 > /sys/bus/pci/rescan
# Alternative method for block devices:
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
Create a complete hotplug script:
#!/bin/bash
VM_NAME="vps_59"
DISK_PATH="/home/cloud/vps_59/test.img"
DISK_NAME="vdd"
# Create disk if not exists
[[ ! -f $DISK_PATH ]] && \
truncate -s 5G $DISK_PATH
# Attach disk
virsh attach-disk $VM_NAME $DISK_PATH $DISK_NAME \
--driver qemu --subdriver raw --targetbus virtio --persistent
# Connect to guest and trigger rescan
virsh qemu-agent-command $VM_NAME \
'{"execute":"guest-exec","arguments":{"path":"sh","arg":["-c","echo 1 > /sys/bus/pci/rescan"]}}'
For Windows guests, use the devcon utility to scan for hardware changes.
Verify QEMU guest agent is running in the VM
Check kernel messages with dmesg | grep virtio
Ensure the virtio-scsi controller is enabled in VM configuration
For file-based disks, verify SELinux contexts if applicable