我尝试在 macOS Monterey (12.3.1) 上的 MacBook 14 M1 Pro 上使用模拟运行 VM。我通过 brew 安装了 libvirt 8.2.0 和 virt-manager 4.0.0。
我对 virt-manager 使用了这个公式:
class VirtManager < Formula
include Language::Python::Virtualenv
desc "Desktop tool for managing virtual machines via libvirt"
homepage "https://virt-manager.org/"
url "https://releases.pagure.org/virt-manager/virt-manager-4.0.0.tar.gz"
sha256 "515aaa2021a4bf352b0573098fe6958319b1ba8ec508ea37e064803f97f17086"
license "GPL-2.0-or-later"
head "https://github.com/virt-manager/virt-manager.git"
depends_on "docutils" => :build
depends_on "gettext" => :build
depends_on "adwaita-icon-theme"
depends_on "cdrtools"
depends_on "glib"
depends_on "gtk+3"
depends_on "gtk-vnc"
depends_on "gtksourceview4"
depends_on "libosinfo"
depends_on "libvirt"
depends_on "libvirt-glib"
depends_on "libxml2"
depends_on "pygobject3"
depends_on "python"
depends_on "spice-gtk"
depends_on "vte3"
# To update:
#
# cd "$(mktemp -d)" &&
# python3 -m venv venv &&
# . venv/bin/activate &&
# pip install libvirt-python argcomplete requests homebrew-pypi-poet &&
# poet libvirt-python -a argcomplete -a requests &&
# deactivate &&
# rm -Rf venv
resource "argcomplete" do
url "https://files.pythonhosted.org/packages/05/f8/67851ae4fe5396ba6868c5d84219b81ea6a5d53991a6853616095c30adc0/argcomplete-2.0.0.tar.gz"
sha256 "6372ad78c89d662035101418ae253668445b391755cfe94ea52f1b9d22425b20"
end
resource "certifi" do
url "https://files.pythonhosted.org/packages/6c/ae/d26450834f0acc9e3d1f74508da6df1551ceab6c2ce0766a593362d6d57f/certifi-2021.10.8.tar.gz"
sha256 "78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"
end
resource "charset-normalizer" do
url "https://files.pythonhosted.org/packages/56/31/7bcaf657fafb3c6db8c787a865434290b726653c912085fbd371e9b92e1c/charset-normalizer-2.0.12.tar.gz"
sha256 "2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"
end
resource "idna" do
url "https://files.pythonhosted.org/packages/62/08/e3fc7c8161090f742f504f40b1bccbfc544d4a4e09eb774bf40aafce5436/idna-3.3.tar.gz"
sha256 "9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"
end
resource "libvirt-python" do
url "https://files.pythonhosted.org/packages/50/cf/3703fc97df6292c9c0ac8b828a85ca11f492f7bffd190f191ea7484024ed/libvirt-python-8.2.0.tar.gz"
sha256 "f8b8cea67ff0d64d63029cc3410a4656e04ee9f26837a856bc0c287da55d053a"
end
resource "pycairo" do
url "https://files.pythonhosted.org/packages/92/a4/506564f574fa74c90b98690e8ecc8dbae1629f31fcfe0be69de45d9e1605/pycairo-1.21.0.tar.gz"
sha256 "251907f18a552df938aa3386657ff4b5a4937dde70e11aa042bc297957f4b74b"
end
resource "requests" do
url "https://files.pythonhosted.org/packages/60/f3/26ff3767f099b73e0efa138a9998da67890793bfa475d8278f84a30fec77/requests-2.27.1.tar.gz"
sha256 "68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"
end
resource "urllib3" do
url "https://files.pythonhosted.org/packages/1b/a5/4eab74853625505725cefdf168f48661b2cd04e7843ab836f3f63abf81da/urllib3-1.26.9.tar.gz"
sha256 "aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
end
def install
venv = virtualenv_create(libexec, "python3")
venv.pip_install resources
# virt-manager uses distutils, so we can't use Homebrew's helper methods
args = %w[
--no-user-cfg
--no-update-icon-cache
--no-compile-schemas
]
# virt-manager requires --prefix to match between `configure` and `install`
system "#{libexec}/bin/python3", "setup.py", *args,
"configure", "--prefix=#{libexec}", "--default-hvs", "qemu,lxc"
system "#{libexec}/bin/python3", "setup.py", *args,
"install", "--prefix=#{libexec}"
bin.install_symlink Dir["#{libexec}/bin/virt-*"]
share.install Dir["#{libexec}/share/{bash-completion,glib-2.0,icons,locale,man}"]
end
def post_install
system "#{Formula["glib"].opt_bin}/glib-compile-schemas", "#{HOMEBREW_PREFIX}/share/glib-2.0/schemas"
system "#{Formula["gtk+3"].opt_bin}/gtk3-update-icon-cache", "-f", "-t", "#{HOMEBREW_PREFIX}/share/icons/hicolor"
end
test do
system "#{bin}/virt-manager", "--version"
end
end
启动 VM 的参数:
virt-install --name guest1-rocky8_5 --memory 4096 --vcpus 4 --disk work_space/packer/rocky8_5.qcow2 --qemu-commandline='-netdev user,id=net0,hostfwd=tcp::5555-:22 -device e1000e,netdev=net0 -accel tcg' --import --virt-type qemu --arch x86_64 --os-variant rhel8.0 -d
我得到了以下输出:
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (cli:204) Launched with command line: /opt/homebrew/bin/virt-install --name guest1-rocky8_5 --memory 4096 --vcpus 4 --disk workspace/packer/rocky8_5.qcow2 --qemu-commandline=-netdev user,id=net0,hostfwd=tcp::5555-:22 -device e1000e,netdev=net0 -accel tcg --import --virt-type qemu --arch x86_64 --os-variant rhel8.0 -d
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (virtinstall:212) Distilled --network options: ['default']
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (virtinstall:142) Distilled --disk options: ['workspace/packer/rocky8_5.qcow2']
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (cli:216) Requesting libvirt URI default
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (cli:219) Received libvirt URI qemu:///session
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (guest:330) Setting Guest osinfo name <_OsVariant name=generic>
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (guest:330) Setting Guest osinfo name <_OsVariant name=rhel8.0>
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (installer:542) No media for distro detection.
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (installer:544) installer.detect_distro returned=None
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (osdict:216) No recommended value found for key='n-cpus', using minimum=1 * 2
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (guest:535) Prefer EFI => False
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (graphics:157) App is configured with default_graphics=spice
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (graphics:167) spice requested but HV doesn't support it. Using vnc.
[Sun, 10 Apr 2022 01:52:05 virt-install 58583] DEBUG (guest:1094) Using num_pcie_root_ports=14
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (disk:236) DeviceDisk.check_path_search path=/Users/alexey/workspace/packer/rocky8_5.qcow2
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (cli:265)
Starting install...
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (installer:587) Generated initial_xml: None required
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (installer:589) Generated final_xml:
<domain type="qemu">
<name>guest1-rocky8_5</name>
<uuid>c9af9024-c29b-411c-b36c-ff9e9073f95a</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://redhat.com/rhel/8.0"/>
</libosinfo:libosinfo>
</metadata>
<memory>4194304</memory>
<currentMemory>4194304</currentMemory>
<vcpu>4</vcpu>
<os>
<type arch="x86_64" machine="q35">hvm</type>
<boot dev="hd"/>
</os>
<features>
<acpi/>
<apic/>
</features>
<clock offset="utc">
<timer name="rtc" tickpolicy="catchup"/>
<timer name="pit" tickpolicy="delay"/>
<timer name="hpet" present="no"/>
</clock>
<pm>
<suspend-to-mem enabled="no"/>
<suspend-to-disk enabled="no"/>
</pm>
<devices>
<emulator>/opt/homebrew/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"/>
<source file="/Users/alexey/workspace/packer/rocky8_5.qcow2"/>
<target dev="vda" bus="virtio"/>
</disk>
<controller type="usb" model="qemu-xhci" ports="15"/>
<controller type="pci" model="pcie-root"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<controller type="pci" model="pcie-root-port"/>
<interface type="user">
<mac address="52:54:00:d8:a2:6d"/>
<model type="virtio"/>
</interface>
<console type="pty"/>
<channel type="unix">
<source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/>
</channel>
<input type="tablet" bus="usb"/>
<graphics type="vnc" port="-1"/>
<video>
<model type="virtio"/>
</video>
<memballoon model="virtio"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
<qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
<qemu:arg value="-netdev"/>
<qemu:arg value="user,id=net0,hostfwd=tcp::5555-:22"/>
<qemu:arg value="-device"/>
<qemu:arg value="e1000e,netdev=net0"/>
<qemu:arg value="-accel"/>
<qemu:arg value="tcg"/>
</qemu:commandline>
</domain>
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (installer:642) XML fetched from libvirt object:
<domain type='qemu' id='25' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>guest1-rocky8_5</name>
<uuid>c9af9024-c29b-411c-b36c-ff9e9073f95a</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://redhat.com/rhel/8.0"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-q35-6.2'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='full'>
<model fallback='forbid'>qemu64</model>
<feature policy='require' name='hypervisor'/>
<feature policy='require' name='lahf_lm'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/opt/homebrew/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/Users/alexey/workspace/packer/rocky8_5.qcow2' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</disk>
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
<controller type='pci' index='0' model='pcie-root'>
<alias name='pcie.0'/>
</controller>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x10'/>
<alias name='pci.1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='2' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='2' port='0x11'/>
<alias name='pci.2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
</controller>
<controller type='pci' index='3' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='3' port='0x12'/>
<alias name='pci.3'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
</controller>
<controller type='pci' index='4' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='4' port='0x13'/>
<alias name='pci.4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
</controller>
<controller type='pci' index='5' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='5' port='0x14'/>
<alias name='pci.5'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
</controller>
<controller type='pci' index='6' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='6' port='0x15'/>
<alias name='pci.6'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
</controller>
<controller type='pci' index='7' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='7' port='0x16'/>
<alias name='pci.7'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
</controller>
<controller type='pci' index='8' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='8' port='0x17'/>
<alias name='pci.8'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
</controller>
<controller type='pci' index='9' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='9' port='0x18'/>
<alias name='pci.9'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='10' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='10' port='0x19'/>
<alias name='pci.10'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
</controller>
<controller type='pci' index='11' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='11' port='0x1a'/>
<alias name='pci.11'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
</controller>
<controller type='pci' index='12' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='12' port='0x1b'/>
<alias name='pci.12'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
</controller>
<controller type='pci' index='13' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='13' port='0x1c'/>
<alias name='pci.13'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
</controller>
<controller type='pci' index='14' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='14' port='0x1d'/>
<alias name='pci.14'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
</controller>
<controller type='sata' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</controller>
<interface type='user'>
<mac address='52:54:00:d8:a2:6d'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/ttys004'/>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/ttys004'>
<source path='/dev/ttys004'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<channel type='unix'>
<source mode='bind' path='/Users/alexey/.config/libvirt/qemu/channel/target/domain-25-guest1-rocky8_5/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
<alias name='channel0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'>
<alias name='input0'/>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'>
<alias name='input1'/>
</input>
<input type='keyboard' bus='ps2'>
<alias name='input2'/>
</input>
<graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<audio id='1' type='none'/>
<video>
<model type='virtio' heads='1' primary='yes'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<alias name='rng0'/>
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</rng>
</devices>
<qemu:commandline>
<qemu:arg value='-netdev'/>
<qemu:arg value='user,id=net0,hostfwd=tcp::5555-:22'/>
<qemu:arg value='-device'/>
<qemu:arg value='e1000e,netdev=net0'/>
<qemu:arg value='-accel'/>
<qemu:arg value='tcg'/>
</qemu:commandline>
</domain>
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (cli:383) Running: virt-viewer --connect qemu:///session --wait guest1-rocky8_5
[Sun, 10 Apr 2022 01:52:06 virt-install 58583] DEBUG (cli:265) Running graphical console command: virt-viewer --connect qemu:///session --wait guest1-rocky8_5
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(virt-viewer:58588): virt-viewer-WARNING **: 01:52:06.563: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
[Sun, 10 Apr 2022 01:52:10 virt-install 58583] DEBUG (cli:255) File "/opt/homebrew/bin/virt-install", line 8, in <module>
virtinstall.runcli()
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 1220, in runcli
sys.exit(main())
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 1213, in main
start_install(guest, installer, options)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 961, in start_install
fail(e, do_exit=False)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/cli.py", line 255, in fail
log.debug("".join(traceback.format_stack()))
[Sun, 10 Apr 2022 01:52:10 virt-install 58583] ERROR (cli:256) operation failed: cannot read cputime for domain
[Sun, 10 Apr 2022 01:52:10 virt-install 58583] DEBUG (cli:258)
Traceback (most recent call last):
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 949, in start_install
_process_domain(domain, guest, installer,
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 900, in _process_domain
_wait_for_domain(installer, instdomain, autoconsole, waithandler)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 837, in _wait_for_domain
if instdomain.check_inactive():
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 817, in check_inactive
dominfo = self._domain.info()
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/lib/python3.9/site-packages/libvirt.py", line 1659, in info
raise libvirtError('virDomainGetInfo() failed')
libvirt.libvirtError: operation failed: cannot read cputime for domain
[Sun, 10 Apr 2022 01:52:10 virt-install 58583] DEBUG (cli:271) Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
virsh --connect qemu:///session start guest1-rocky8_5
otherwise, please restart your installation.
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
virsh --connect qemu:///session start guest1-rocky8_5
otherwise, please restart your installation.
如果我添加,--autoconsole text
我可以在输出中看到以下内容:
Creating domain... | 0 B 00:00:00
[Sun, 10 Apr 2022 02:08:07 virt-install 59096] DEBUG (cli:383) Running: virsh --connect qemu:///session console guest1-rocky8_5
[Sun, 10 Apr 2022 02:08:07 virt-install 59096] DEBUG (cli:265) Running text console command: virsh --connect qemu:///session console guest1-rocky8_5
Running text console command: virsh --connect qemu:///session console guest1-rocky8_5
Connected to domain 'guest1-rocky8_5'
Escape character is ^] (Ctrl + ])
什么也没有出来。
如果我尝试通过 SSH 端口 5555 获得:
ssh localhost -p 5555
kex_exchange_identification: read: Connection reset by peer
Connection reset by 127.0.0.1 port 5555
如果取消运行:
Running text console command: virsh --connect qemu:///session console guest1-rocky8_5
Connected to domain 'guest1-rocky8_5'
Escape character is ^] (Ctrl + ])
^]
[Sun, 10 Apr 2022 02:24:38 virt-install 59378] DEBUG (cli:255) File "/opt/homebrew/bin/virt-install", line 8, in <module>
virtinstall.runcli()
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 1220, in runcli
sys.exit(main())
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 1213, in main
start_install(guest, installer, options)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 961, in start_install
fail(e, do_exit=False)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/cli.py", line 255, in fail
log.debug("".join(traceback.format_stack()))
[Sun, 10 Apr 2022 02:24:38 virt-install 59378] ERROR (cli:256) operation failed: cannot read cputime for domain
[Sun, 10 Apr 2022 02:24:38 virt-install 59378] DEBUG (cli:258)
Traceback (most recent call last):
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 949, in start_install
_process_domain(domain, guest, installer,
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 900, in _process_domain
_wait_for_domain(installer, instdomain, autoconsole, waithandler)
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 837, in _wait_for_domain
if instdomain.check_inactive():
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/share/virt-manager/virtinst/virtinstall.py", line 817, in check_inactive
dominfo = self._domain.info()
File "/opt/homebrew/Cellar/virt-manager/4.0.0/libexec/lib/python3.9/site-packages/libvirt.py", line 1659, in info
raise libvirtError('virDomainGetInfo() failed')
libvirt.libvirtError: operation failed: cannot read cputime for domain
[Sun, 10 Apr 2022 02:24:38 virt-install 59378] DEBUG (cli:271) Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
virsh --connect qemu:///session start guest1-rocky8_5
otherwise, please restart your installation.
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
virsh --connect qemu:///session start guest1-rocky8_5
otherwise, please restart your installation.
但如果我尝试仅使用 qemu-system-x86_64,它就会运行良好:
qemu-system-x86_64 -m 4G -machine type=q35,accel=tcg -smp 2 -netdev user,id=net0,hostfwd=tcp::5555-:22 -device e1000e,netdev=net0 -drive file=workspace/packer/rocky8_5.qcow2,if=ide
ssh localhost -p 5555 cat /etc/redhat-release
root@localhost's password:
Rocky Linux release 8.5 (Green Obsidian)
我认为当我在 virt-install 中运行 VM 时,会默认添加一些参数,这会导致 VM 无法正常启动。也许我需要更改一些论点或添加新的论点通过 virt-install 才能使 VM 正确运行?
如果我使用默认参数在 virt-manager 中运行 VM,我会遇到同样的问题。
尽管通过 virt-install 或 virt-manager 运行出现错误,但我可以在 libvirt 中看到此 VM:
virsh list
Id Name State
---------------------------------
1 guest1-rocky8_5 running
我可以通过 VNC 连接到该 VM,但是正如我上面所写,端口 5555 上的 ssh 无法转发。
答案1
我已转换命令qemu-system-x86_64 -m 4G -machine type=q35,accel=tcg -smp 2 -netdev user,id=net0,hostfwd=tcp::5555-:22 -device e1000e,netdev=net0 -drive file=workspace/packer/rocky8_5.qcow2,if=ide
通过virsh domxml-from-native
XML 传输到 libvirt,然后我定义了 VM。
我使用了一个带有旧版本 libvirt 的 docker 容器来使用domxml-from-native
,因为这个操作不支持自 v5.5.0 起
如果我单击按钮来运行虚拟机,它不会改变状态,并且我会在 virt-manager 的日志中看到之前的错误(cannot read cputime for domain)
:
[Mon, 11 Apr 2022 14:03:48 virt-manager 5263] DEBUG (connection:631) domain lifecycle event: domain=unnamed state=VIR_DOMAIN_EVENT_DEFINED reason=VIR_DOMAIN_EVENT_DEFINED_ADDED
[Mon, 11 Apr 2022 14:03:48 virt-manager 5263] DEBUG (connection:1077) domain=unnamed status=Shutoff added
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (vmmenu:210) Starting vm 'unnamed'
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (connection:631) domain lifecycle event: domain=unnamed state=VIR_DOMAIN_EVENT_RESUMED reason=VIR_DOMAIN_EVENT_RESUMED_UNPAUSED
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (connection:631) domain lifecycle event: domain=unnamed state=VIR_DOMAIN_EVENT_STARTED reason=VIR_DOMAIN_EVENT_STARTED_BOOTED
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (libvirtobject:261) Error refreshing <vmmDomain name=unnamed id=0x10ae59b80> from events: operation failed: cannot read cputime for domain
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (libvirtobject:265) Scheduling priority tick with: {'force': True, 'pollvm': True}
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (libvirtobject:261) Error refreshing <vmmDomain name=unnamed id=0x10ae59b80> from events: operation failed: cannot read cputime for domain
[Mon, 11 Apr 2022 14:05:25 virt-manager 5263] DEBUG (libvirtobject:265) Scheduling priority tick with: {'force': True, 'pollvm': True}
但virsh list
显示 VM 正在运行,这次我可以通过端口 5555 上的 SSH 进行连接:
Id Name State
-------------------------
8 unnamed running
ssh localhost -p 5555 cat /etc/redhat-release
root@localhost's password:
Rocky Linux release 8.5 (Green Obsidian)
这看起来像是一个问题获取域信息当我通过 virt-install 或 virt-manager 运行 VM 时,函数而不是默认参数。
此外,该问题可能与virConnectNodeDeviceEventRegisterAny功能,因为我在运行 virt-manager 时看到错误:
[Mon, 11 Apr 2022 16:08:55 virt-manager 6759] DEBUG (connection:967) Connection doesn't seem to support nodedev APIs.
[Mon, 11 Apr 2022 16:08:55 virt-manager 6759] DEBUG (connection:739) Using domain events
[Mon, 11 Apr 2022 16:08:55 virt-manager 6759] DEBUG (connection:778) Using network events
[Mon, 11 Apr 2022 16:08:55 virt-manager 6759] DEBUG (connection:797) Using storage pool events
[Mon, 11 Apr 2022 16:08:55 virt-manager 6759] DEBUG (connection:825) Error registering node device events: this function is not supported by the connection driver: virConnectNodeDeviceEventRegisterAny
我打开了票在 libvirt-python repo 中,因为 virt-manager 和 virt-install 使用此库。我还打开了票在 libvirt repo 中,因为我认为这个问题与获取域信息当在 Apple M1 Pro CPU 下运行的域调用该函数时。
总结:virt-manager 可能无法在配备 Apple Silicon M1 CPU 的 macOS 上使用。
更新:此错误已修复. 详情请参阅票。