# How to Create a Virtual Machine on QEMU-KVM
# GUI
# TUI
You can use virt-install to create a VM via the terminal:
# Install from local ISO | |
virt-install \ | |
--virt-type kvm \ | |
--name vm1 \ | |
--memory 512 \ | |
--vcpus 1 \ | |
--os-type linux \ | |
--os-variant centos7.0 \ | |
--network bridge=virbr1 \ | |
--disk /var/lib/libvirt/images/vm1.qcow2,size=10,bus=virtio,format=qcow2 \ | |
--location /soft/CentOS-7-x86_64-DVD-2009.iso -x console=ttyS0 \ | |
--graphics none | |
# Install from network location | |
virt-install \ | |
--virt-type kvm \ | |
--name vm1 \ | |
--memory 2048 \ | |
--vcpus 1 \ | |
--os-type linux \ | |
--os-variant centos7.0 \ | |
--network bridge=virbr1 \ | |
--disk /var/lib/libvirt/images/vm1.qcow2,size=10,bus=virtio,format=qcow2 \ | |
--location http://192.168.3.112/assets/tmp/mnt -x console=ttyS0 \ | |
--graphics none | |
# To configure the kernel console on ttyS0 | |
grubby --update-kernel=ALL --args="console=ttyS0,115200n8" | |
# Connect to VM console | |
virsh console vm1 --force |
Press CTRL + ] to escape console.
# Command
# Update kernel to enable serial console | |
grubby --update-kernel=ALL --args="console=ttyS0,115200n8" |
# Delete VMs
# Kill the VM process | |
ps aux | grep [v]m1 | awk '{print $2}' | xargs kill -15 | |
# Poweroff VM | |
virsh destroy vm1 | |
# Remove VM definition and storage | |
virsh undefine vm1 --remove-all-storage |
# Troubleshooting
# Issue: curl: (7) Failed connect to 192.168.3.112:80; Connection timed out
[ 9.842048] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready | |
[ 12.874243] dracut-initqueue[744]: RTNETLINK answers: File exists | |
[ 140.788907] dracut-initqueue[744]: Warning: can't find installer mainimage path in .treeinfo | |
... | |
curl: (7) Failed connect to 192.168.3.112:80; Connection timed out | |
... | |
[ 268.229474] dracut-initqueue[744]: Warning: Downloading 'http://192.168.3.112/assets/tmp//LiveOS/squashfs.img' failed! | |
[ 268.231758] dracut-initqueue[744]: Warning: anaconda: failed to fetch stage2 from http://192.168.3.112/assets/tmp/ | |
... | |
[ 393.986291] dracut-initqueue[744]: Warning: dracut-initqueue timeout - starting timeout scripts |
Cause:
The VM's eth0 cannot connect to the HTTP server.
Workaround:
Check the network settings of the virtual machine.
# Issue: curl: (23) Failed writing body (12033 != 16384)
[ 13.762605] dracut-initqueue[744]: curl: (23) Failed writing body (12033 != 16384) | |
... | |
[ 14.040573] dracut-initqueue[744]: /sbin/dmsquash-live-root: line 286: printf: write error: No space left on device | |
... | |
[ 139.573351] dracut-initqueue[744]: Warning: dracut-initqueue timeout - starting timeout scripts |
Cause:
/sbin/dmsquash-live-root: line 286: printf: write error: No space left on device
Workaround:
- For RHEL 7, increase the VM's memory to 2 GiB.
- For RHEL 8/9, increase the VM's memory to 3 GiB.
Reference:
・ Kickstart Fails With Curl Error
# Issue: qcow2: Image is corrupt; cannot be opened read/write
~]# virsh start vm2 | |
error: Failed to start domain vm2 | |
error: internal error: qemu unexpectedly closed the monitor: 2025-08-27T03:39:34.228948Z qemu-kvm: -drive file=/var/lib/libvirt/images/vm2.qcow2,format=qcow2,if=none,id=drive-virtio-disk0: could not open disk image /var/lib/libvirt/images/vm2.qcow2: qcow2: Image is corrupt; cannot be opened read/write |
Workaround:
~]# qemu-img check -r all /var/lib/libvirt/images/vm2.qcow2 | |
Leaked cluster 163869 refcount=1 reference=0 | |
Repairing cluster 163869 refcount=1 reference=0 | |
The following inconsistencies were found and repaired: | |
1 leaked clusters | |
0 corruptions | |
Double checking the fixed image now... | |
No errors were found on the image. | |
163840/163840 = 100.00% allocated, 0.00% fragmented, 0.00% compressed clusters | |
Image end offset: 10739318784 |
# Issue: cdrom and floppy device hotplug isn't supported by libvirt
~]# virsh attach-disk vm2 /soft/CentOS-7-x86_64-DVD-2009.iso hdb --driver qemu --type cdrom --mode readonly | |
error: Failed to attach disk | |
error: internal error: No device with bus 'ide' and target 'hdb'. cdrom and floppy device hotplug isn't supported by libvirt |
Workaround:
~]# virsh shutdown vm2 | |
~]# virsh edit vm2 | |
<disk type='file' device='cdrom'> | |
<driver name='qemu' type='raw'/> | |
<source file='/soft/CentOS-7-x86_64-DVD-2009.iso'/> | |
<target dev='hda' bus='ide'/> | |
<readonly/> | |
</disk> |
# Issue: XFS (vda3): metadata I/O error in "xfs_buf_iodone_callback_error"
[ 334.287041] XFS (vda3): metadata I/O error in "xfs_buf_iodone_callback_error" at daddr 0x13ff6e0 len 32 error 5 | |
[ 334.836243] blk_update_request: 993 callbacks suppressed | |
[ 334.839413] blk_update_request: I/O error, dev vda, sector 20971704 | |
[ 334.844636] blk_update_request: I/O error, dev vda, sector 20971712 | |
[ 334.849579] blk_update_request: I/O error, dev vda, sector 20971744 | |
[ 334.855046] blk_update_request: I/O error, dev vda, sector 25165504 | |
[ 334.860136] blk_update_request: I/O error, dev vda, sector 25165536 | |
[ 334.865183] blk_update_request: I/O error, dev vda, sector 29359296 | |
[ 334.870404] blk_update_request: I/O error, dev vda, sector 29359328 | |
[ 334.885488] blk_update_request: I/O error, dev vda, sector 20971704 | |
[ 334.889038] blk_update_request: I/O error, dev vda, sector 25165504 | |
[ 334.894376] blk_update_request: I/O error, dev vda, sector 29359296 | |
[ 339.135292] XFS: Failing async write: 4183 callbacks suppressed | |
[ 339.138493] XFS (vda3): Failing async write on buffer block 0xfff8e0. Retrying async write. | |
[ 339.143453] XFS (vda3): Failing async write on buffer block 0xfff8c0. Retrying async write. | |
[ 339.148493] XFS (vda3): Failing async write on buffer block 0x17ff4e0. Retrying async write. | |
[ 339.154292] XFS (vda3): Failing async write on buffer block 0x17ff4c0. Retrying async write. | |
[ 339.159837] XFS (vda3): Failing async write on buffer block 0x13ff6e0. Retrying async write. | |
[ 339.164055] XFS (vda3): Failing async write on buffer block 0x13ff6c0. Retrying async write. | |
[ 339.168882] XFS (vda3): Failing async write on buffer block 0xfff8b8. Retrying async write. | |
[ 339.184288] XFS (vda3): metadata I/O error in "xlog_iodone" at daddr 0x8026a7 len 64 error 5 | |
[ 339.189152] XFS (vda3): xfs_do_force_shutdown(0x2) called from line 1238 of file fs/xfs/xfs_log.c. Return address = ffffffffc0466810 | |
[ 339.195251] XFS (vda3): Log I/O Error Detected. Shutting down filesystem | |
[ 339.199252] XFS (vda3): Please umount the filesystem and rectify the problem(s) | |
~]# reboot | |
-bash: reboot: command not found | |
~]# ls | |
-bash: /bin/ls: Input/output erro |
The root partiton xfs filesystem I/O error and has been force shutdown.
Workaround:
~]# qemu-img check -r all /var/lib/libvirt/images/vm2.qcow2 | |
Repairing refcount block 0 is outside image | |
ERROR could not resize image: Invalid argument | |
... | |
Repairing refcount block 27 is outside image | |
ERROR could not resize image: Invalid argument | |
Can't get refcount for cluster 0: Invalid argument | |
Can't get refcount for cluster 1: Invalid argument | |
... | |
Can't get refcount for cluster 163880: Invalid argument | |
Can't get refcount for cluster 163881: Invalid argument | |
Rebuilding refcount structure | |
Repairing cluster 1 refcount=1 reference=0 | |
The following inconsistencies were found and repaired: | |
0 leaked clusters | |
23 corruptions | |
Double checking the fixed image now... | |
No errors were found on the image. | |
163843/262144 = 62.50% allocated, 0.00% fragmented, 0.00% compressed clusters | |
Image end offset: 10739777536 |