Qemu

使用 virt-install 在虛擬機上為虛擬設備配置串列控制台

  • October 1, 2018

我有一個虛擬設​​備(qcow2圖像),它需要 VM 上的串列控制台。換句話說,我不需要安裝任何東西。我只需要從這個qcow2磁碟啟動虛擬機並通過串列介面訪問虛擬設備。有可能做到這一點virt-install嗎?當我添加--extra-args="console=ttyS0,115200"tovirt-install時,它需要我指定一個--location. 是否有解決方法可以使用 啟動啟用串列的虛擬機virt-install,但不指定分發樹安裝源?

是的,這是可能的,儘管添加串列控制台有多個步驟。

--extra-args只能與 結合使用--location。當您從本地qcow2磁碟映像工作時,--location實際上並不是您正在尋找的機制。

相反,您正在尋找--console

安慰:

--console
 Connect a text console between the guest and host. Certain guest and 
 hypervisor combinations can automatically set up a getty in the guest, so an
 out of the box text login can be provided (target_type=xen for xen paravirt
 guests, and possibly target_type=virtio in the future).

在實踐中,添加如下(在現代 Linux 系統上):

--console pty,target_type=virtio 

注意:您可以在此處獲得有關可用配置的更多選項:https ://libvirt.org/formatdomain.html#elementsConsole

由於我已經準備好了基於 QCOW2 的設備,因此我可以進行如下測試:

virt-install --name thing --memory 512 \
   --console pty,target_type=virtio --disk appliance.qcow2 --boot hd

在幕後,這是對“域”(儲存主機配置的 XML 文件)執行許多添加操作。例如:

<controller type='virtio-serial' index='0'>
 <alias name='virtio-serial0'/>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>

<console type='pty' tty='/dev/pts/14'>
 <source path='/dev/pts/14'/>
 <target type='virtio' port='0'/>
 <alias name='console0'/>
</console>

<channel type='spicevmc'>
 <target type='virtio' name='com.redhat.spice.0' state='disconnected'/>
 <alias name='channel0'/>
 <address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>

如果這不起作用,您還可以通過使用( link ) 之類的工具編輯設備的引導選項或通過指定核心的位置 initrd 並手動提供選項來實現此目的。在 guestfish 的情況下,甚至有一個方法可以實現您正在尋找的內容:guestfish-recipies:在 VM 中編輯 grub 配置guestfish``--boot

開機:

--boot 
 Optionally specify the post-install VM boot configuration. This option
 allows specifying a boot device order, permanently booting off
 kernel/initrd with option kernel arguments, and enabling a BIOS boot menu
 (requires libvirt 0.8.3 or later)

      --boot kernel=KERNEL,initrd=INITRD,kernel_args="console=/dev/ttyS0"
          Have guest permanently boot off a local kernel/initrd pair, with the 
          specified kernel options.

引用自:https://unix.stackexchange.com/questions/471097