首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VM上为使用virt-install的虚拟设备提供串行控制台。

在VM上为使用virt-install的虚拟设备提供串行控制台。
EN

Unix & Linux用户
提问于 2018-09-24 14:35:53
回答 1查看 7.4K关注 0票数 5

我有一个虚拟设备(qcow2映像),它需要VM上的串行控制台。换句话说,我不需要安装任何东西。我只需要从这个qcow2磁盘启动VM并通过串行接口访问虚拟设备。用virt-install可以做到这一点吗?当我将--extra-args="console=ttyS0,115200"添加到virt-install时,它要求我指定一个--location。是否存在使用virt-install启动串行启用但没有指定分发树安装源的虚拟机的解决办法?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-10-01 17:58:23

是的,这是可能的,尽管添加串行控制台有多个步骤。

--extra-args只能与--location结合使用。当您使用本地qcow2磁盘映像时,--location实际上不是您要寻找的机制。

相反,您需要的是--console

控制台:

代码语言:javascript
复制
--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系统上):

代码语言:javascript
复制
--console pty,target_type=virtio 

Note__:您可以在这里获得关于可用配置的更多选项:https://libvirt.org/formatdomain.html#elementsConsole

由于我已经准备了一个基于QCOW2的设备,所以我能够对其进行如下测试:

代码语言:javascript
复制
virt-install --name thing --memory 512 \
    --console pty,target_type=virtio --disk appliance.qcow2 --boot hd

在幕后,这将对“域”(存储主机配置的XML文件)执行许多添加。例如:

代码语言:javascript
复制
<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>

如果这不起作用,还可以通过使用guestfish(链接)这样的工具编辑设备内部的引导选项,或者指定内核initrd的位置,并手动使用--boot提供这些选项。在游鱼的例子中,甚至有一个实现你想要的东西的方法:食谱:在VM中编辑grub配置

引导:

代码语言:javascript
复制
--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.
票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/471097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档