我有一台运行在 Ubuntu Server 10.04 上的 FreeNAS 0.7.1 Shere(修订版 5127)的 KVM VM,我无法让主机关闭 VM
virsh shutdown freenas
我希望它能向 VM 发送一些 ACPI?触发器,然后 FreeNAS 会执行它所要求的操作。
我不是 FreeBSD 的粉丝,所以我不知道要使用什么包或进程才能运行它。我曾尝试让 powerd 运行,但 VM CPU 没有所需的频率条目
Sysctl硬件
$ sysctl hw
hw.machine: amd64
hw.model: QEMU Virtual CPU version 0.12.3
hw.ncpu: 1
hw.byteorder: 1234
hw.physmem: 523116544
hw.usermem: 463806464
hw.pagesize: 4096
hw.floatingpoint: 1
hw.machine_arch: amd64
hw.realmem: 536850432
hw.aac.iosize_max: 65536
hw.amr.force_sg32: 0
hw.an.an_cache_iponly: 1
hw.an.an_cache_mcastonly: 0
hw.an.an_cache_mode: dbm
hw.an.an_dump: off
hw.ata.to: 15
hw.ata.wc: 1
hw.ata.atapi_dma: 1
hw.ata.ata_dma_check_80pin: 1
hw.ata.ata_dma: 1
hw.ath.txbuf: 200
hw.ath.rxbuf: 40
hw.ath.regdomain: 0
hw.ath.countrycode: 0
hw.ath.xchanmode: 1
hw.ath.outdoor: 1
hw.ath.calibrate: 30
hw.ath.hal.swba_backoff: 0
hw.ath.hal.sw_brt: 10
hw.ath.hal.dma_brt: 2
hw.bce.msi_enable: 1
hw.bce.tso_enable: 1
hw.bge.allow_asf: 0
hw.cardbus.cis_debug: 0
hw.cardbus.debug: 0
hw.cs.recv_delay: 570
hw.cs.ignore_checksum_failure: 0
hw.cs.debug: 0
hw.cxgb.snd_queue_len: 50
hw.cxgb.use_16k_clusters: 1
hw.cxgb.force_fw_update: 0
hw.cxgb.singleq: 0
hw.cxgb.ofld_disable: 0
hw.cxgb.msi_allowed: 2
hw.cxgb.txq_mr_size: 1024
hw.cxgb.sleep_ticks: 1
hw.cxgb.tx_coalesce: 0
hw.firewire.hold_count: 3
hw.firewire.try_bmr: 1
hw.firewire.fwmem.speed: 2
hw.firewire.fwmem.eui64_lo: 0
hw.firewire.fwmem.eui64_hi: 0
hw.firewire.phydma_enable: 1
hw.firewire.nocyclemaster: 0
hw.firewire.fwe.rx_queue_len: 128
hw.firewire.fwe.tx_speed: 2
hw.firewire.fwe.stream_ch: 1
hw.firewire.fwip.rx_queue_len: 128
hw.firewire.sbp.tags: 0
hw.firewire.sbp.use_doorbell: 0
hw.firewire.sbp.scan_delay: 500
hw.firewire.sbp.login_delay: 1000
hw.firewire.sbp.exclusive_login: 1
hw.firewire.sbp.max_speed: -1
hw.firewire.sbp.auto_login: 1
hw.mfi.max_cmds: 128
hw.mfi.event_class: 0
hw.mfi.event_locale: 65535
hw.pccard.cis_debug: 0
hw.pccard.debug: 0
hw.cbb.debug: 0
hw.cbb.start_32_io: 4096
hw.cbb.start_16_io: 256
hw.cbb.start_memory: 2281701376
hw.pcic.pd6722_vsense: 1
hw.pcic.intr_mask: 57016
hw.pci.honor_msi_blacklist: 1
hw.pci.enable_msix: 1
hw.pci.enable_msi: 1
hw.pci.do_power_resume: 1
hw.pci.do_power_nodriver: 0
hw.pci.enable_io_modes: 1
hw.pci.host_mem_start: 2147483648
hw.syscons.kbd_debug: 1
hw.syscons.kbd_reboot: 1
hw.syscons.bell: 1
hw.syscons.saver.keybonly: 1
hw.syscons.sc_no_suspend_vtswitch: 0
hw.usb.uplcom.interval: 100
hw.usb.uvscom.interval: 100
hw.usb.uvscom.opktsize: 8
hw.wi.debug: 0
hw.wi.txerate: 0
hw.xe.debug: 0
hw.intr_storm_threshold: 1000
hw.availpages: 127714
hw.bus.devctl_disable: 0
hw.ste.rxsyncs: 0
hw.busdma.total_bpages: 32
hw.busdma.zone0.total_bpages: 32
hw.busdma.zone0.free_bpages: 32
hw.busdma.zone0.reserved_bpages: 0
hw.busdma.zone0.active_bpages: 0
hw.busdma.zone0.total_bounced: 0
hw.busdma.zone0.total_deferred: 0
hw.busdma.zone0.lowaddr: 0xffffffff
hw.busdma.zone0.alignment: 2
hw.busdma.zone0.boundary: 65536
hw.clockrate: 2808
hw.instruction_sse: 1
hw.apic.enable_extint: 0
hw.kbd.keymap_restrict_change: 0
hw.acpi.supported_sleep_state: S3 S4 S5
hw.acpi.power_button_state: S5
hw.acpi.sleep_button_state: S3
hw.acpi.lid_switch_state: NONE
hw.acpi.standby_state: S1
hw.acpi.suspend_state: S3
hw.acpi.sleep_delay: 1
hw.acpi.s4bios: 0
hw.acpi.verbose: 0
hw.acpi.disable_on_reboot: 0
hw.acpi.handle_reboot: 0
hw.acpi.cpu.cx_lowest: C1
流程
$ ps ax
PID TT STAT TIME COMMAND
0 ?? DLs 0:00.00 [swapper]
1 ?? ILs 0:00.00 /sbin/init --
2 ?? DL 0:00.08 [g_event]
3 ?? DL 0:00.29 [g_up]
4 ?? DL 0:00.33 [g_down]
5 ?? DL 0:00.00 [crypto]
6 ?? DL 0:00.00 [crypto returns]
7 ?? DL 0:00.00 [xpt_thrd]
8 ?? DL 0:00.00 [kqueue taskq]
9 ?? DL 0:00.00 [acpi_task_0]
10 ?? RL 34:12.42 [idle: cpu0]
11 ?? WL 0:01.13 [swi4: clock sio]
12 ?? WL 0:00.00 [swi3: vm]
13 ?? WL 0:00.00 [swi1: net]
14 ?? DL 0:00.04 [yarrow]
15 ?? WL 0:00.00 [swi6: task queue]
16 ?? WL 0:00.00 [swi2: cambio]
17 ?? DL 0:00.00 [acpi_task_1]
18 ?? DL 0:00.00 [acpi_task_2]
19 ?? WL 0:00.00 [swi5: +]
20 ?? DL 0:00.01 [thread taskq]
21 ?? WL 0:00.00 [swi6: Giant taskq]
22 ?? WL 0:00.00 [irq9: acpi0]
23 ?? WL 0:00.09 [irq14: ata0]
24 ?? WL 0:00.11 [irq15: ata1]
25 ?? WL 0:00.57 [irq11: ed0 uhci0]
26 ?? DL 0:00.00 [usb0]
27 ?? DL 0:00.00 [usbtask-hc]
28 ?? DL 0:00.00 [usbtask-dr]
29 ?? WL 0:00.01 [irq1: atkbd0]
30 ?? WL 0:00.00 [swi0: sio]
31 ?? DL 0:00.00 [sctp_iterator]
32 ?? DL 0:00.00 [pagedaemon]
33 ?? DL 0:00.00 [vmdaemon]
34 ?? DL 0:00.00 [idlepoll]
35 ?? DL 0:00.00 [pagezero]
36 ?? DL 0:00.01 [bufdaemon]
37 ?? DL 0:00.00 [vnlru]
38 ?? DL 0:00.14 [syncer]
39 ?? DL 0:00.01 [softdepflush]
1221 ?? Is 0:00.00 /sbin/devd
1289 ?? Is 0:00.01 /usr/sbin/syslogd -ss -f /var/etc/syslog.conf
1608 ?? Is 0:00.00 /usr/sbin/cron -s
1692 ?? Ss 0:00.03 /usr/local/sbin/mDNSResponderPosix -b -f /var/etc/mdn
1730 ?? S 0:00.43 /usr/local/sbin/lighttpd -f /var/etc/lighttpd.conf -m
1882 ?? DL 0:00.00 [system_taskq]
1883 ?? DL 0:00.00 [arc_reclaim_thread]
4139 ?? S 0:00.03 /usr/local/bin/php /usr/local/www/exec.php
4144 ?? S 0:00.00 sh -c ps ax
4145 ?? R 0:00.00 ps ax
1816 v0 Is 0:00.01 login [pam] (login)
1818 v0 I+ 0:00.03 -tcsh (csh)
1817 v1 Is+ 0:00.00 /usr/libexec/getty Pc ttyv1
1402 con- I 0:00.00 /usr/local/sbin/afpd -F /var/etc/afpd.conf
1404 con- S 0:00.00 /usr/local/sbin/cnid_metad
1682 con- I 0:02.78 /usr/local/sbin/mt-daapd -m -c /var/etc/mt-daapd.conf
1789 con- S 0:00.18 /usr/local/bin/fuppesd --config-dir /var/etc --config
Libvert 代码片段
<domain type='kvm'>
<name>freenas</name>
<uuid>********-****-****-****-************</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc-0.12'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
这可能吗?理想情况下,我希望能够停止主机,而不必手动关闭虚拟机。
答案1
我发现实现此目的的唯一方法是将 -no-kvm-irqchip 参数传递给 kvm。在 libvirt 中执行此操作的最简单方法是创建一个包装器脚本(例如 /usr/local/bin/kvmbsd)
#!/bin/sh
exec /usr/bin/kvm "$@" -no-kvm-irqchip
并更改 libvirt 配置中的模拟器行以指向包装器脚本。
/usr/local/bin/kvmbsd
这使我能够干净地关闭(但不重新启动 - 这似乎尚未在 libvirt/kvm 中实现)基于 freebsd 的 vms。
答案2
确保虚拟机已启用 ACPI,这就是干净关机所做的 - 发送 ACPI 调用。但是还有其他方法,例如通过 ssh 编写关机命令脚本、使用 monitorCommand sendKey 发送旨在启动关机的按键、运行“销毁”命令(本质上是拔出插头)等。