我的理解是,我可以在 Ubuntu 22.04 上使用 LibVirt 和 QEMU,而无需使用 KVM。为了做到这一点,我使用以下命令:
#!/bin/bash
sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get -y install qemu-system qemu-efi qemu-user qemu-utils libvirt-clients libvirt-daemon libvirt-daemon-system libvirt-daemon-driver-qemu
sudo mkdir /home/foo && sudo useradd -d /home/foo nomad
sudo usermod -a -G kvm,libvirt-qemu,libvirt foo
sudo mkdir -p /home/foo/libvirt/images
sudo mkdir -p /home/foo/libvirt/isos
sudo chown :kvm /home/foo/libvirt/images
sudo rmdir /var/lib/libvirt/images
sudo ln -s /home/foo/libvirt/images /var/lib/libvirt/images
sudo ln -s /home/foo/libvirt/isos /var/lib/libvirt/isos
sudo mkdir -p /home/foo/.config/libvirt
sudo cp -rv /etc/libvirt/libvirt.conf /home/nomad/.config/libvirt/
sudo chown foo: /home/foo/.config/libvirt/libvirt.conf
sed -i 's\#uri_default\uri_default\g' /home/foo/.config/libvirt/libvirt.conf
sed -i 's\#user = "root"\user = "foo"\g' /etc/libvirt/qemu.conf
sed -i 's\#group = "root"\group = "libvirt-qemu"\g' /etc/libvirt/qemu.conf
sudo systemctl start libvirtd
systemctl status libvirtd
脚本的最后一行告诉我:
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq-dhcp[750]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq-dhcp[750]: DHCP, sockets bound exclusively to interface virbr0
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq[750]: reading /etc/resolv.conf
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq[750]: using nameserver 127.0.0.53#53
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq[750]: read /etc/hosts - 7 addresses
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq[750]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Nov 06 13:58:52 ip-172-31-28-212 dnsmasq-dhcp[750]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Nov 06 13:58:53 ip-172-31-28-212 libvirtd[546]: libvirt version: 8.0.0, package: 1ubuntu7.7 (Michal Maloszewski <[email protected]> Fri, 04 Aug 2023 10:42:25 +0200)
Nov 06 13:58:53 ip-172-31-28-212 libvirtd[546]: hostname: ip-172-31-28-212
Nov 06 13:58:53 ip-172-31-28-212 libvirtd[546]: Unable to open /dev/kvm: No such file or directory
我的问题是,如何使用 libvirtd 以使其不寻找 /dev/kvm。