Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

23.17.16. 主机物理接口

字符设备会将自己的主机物理机器作为以下类型之一:

表 23.26. 字符设备元素

参数 描述 XML 片断
域日志文件 禁用字符设备上的所有输入,并将输出发送到虚拟机的日志文件中。
<devices>
   <console type='stdio'>
     <target port='1'/>
   </console>
</devices>
设备日志文件 一个文件被打开,发送到字符设备的所有数据都会写入该文件。请注意,目标目录必须具有 virt_log_t SELinux 标签,以便具有此设置的 guest 标签才能成功启动。
<devices>
   <serial type="file">
      <source path="/var/log/vm/vm-serial.log"/>
      <target port="1"/>
   </serial>
</devices>
虚拟控制台 在虚拟控制台中将字符设备连接到图形帧缓冲。这通常使用一个特殊的热键序列,如 "ctrl+alt+3"。
<devices>
   <serial type='vc'>
      <target port="1"/>
   </serial>
</devices>
null 设备 将字符设备连接到 void。没有为输入提供任何数据。写入的所有数据都会被丢弃。
<devices>
   <serial type='null'>
      <target port="1"/>
   </serial>
</devices>
伪 TTY 使用 /dev/ptmx 分配 Pseudo TTY。virsh console 等合适的客户端可以在本地与串行端口交互。
<devices>
   <serial type="pty">
      <source path="/dev/pts/3"/>
      <target port="1"/>
   </serial>
</devices>
NB 特殊情况 如果 <控制台类型='pty',则 TTY 路径也会作为顶层 <控制台> > 标签上的属性 tty='/dev/pts/3' 重复。这为 <console> 标签提供了与现有的语法。 
主机物理机器设备代理 字符设备通过 传递到底层物理字符设备。设备类型必须匹配,例如,模拟串行端口应仅连接到主机物理机器串行端口 - 不将串行端口连接到并行端口。
<devices>
   <serial type="dev">
      <source path="/dev/ttyS0"/>
      <target port="1"/>
   </serial>
</devices>
命名管道 字符设备将输出写入命名管道。有关详细信息,请参见 pipe(7)手册页。
<devices>
   <serial type="pipe">
      <source path="/tmp/mypipe"/>
      <target port="1"/>
   </serial>
</devices>
TCP client-server 字符设备充当连接到远程服务器的 TCP 客户端。
<devices>
   <serial type="tcp">
      <source mode="connect" host="0.0.0.0" service="2445"/>
      <protocol type="raw"/>
      <target port="1"/>
   </serial>
</devices>
或者作为 TCP 服务器等待客户端连接。
<devices>
   <serial type="tcp">
      <source mode="bind" host="127.0.0.1" service="2445"/>
      <protocol type="raw"/>
      <target port="1"/>
   </serial>
</devices>
或者,您可以使用 telnet 而不是原始 TCP。另外,您还可以使用 telnet(安全 telnet)和 tls。
<devices>
   <serial type="tcp">
      <source mode="connect" host="0.0.0.0" service="2445"/>
      <protocol type="telnet"/>
      <target port="1"/>
   </serial>
      <serial type="tcp">
      <source mode="bind" host="127.0.0.1" service="2445"/>
      <protocol type="telnet"/>
      <target port="1"/>
   </serial>
</devices>
UDP 网络控制台 字符设备充当 UDP netconsole 服务、发送和接收数据包。这是丢失的服务。
<devices>
   <serial type="udp">
      <source mode="bind" host="0.0.0.0" service="2445"/>
      <source mode="connect" host="0.0.0.0" service="2445"/>
      <target port="1"/>
   </serial>
</devices>
UNIX 域套接字客户端-服务器 字符设备充当 UNIX 域套接字服务器,接受本地客户端的连接。
<devices>
   <serial type="unix">
      <source mode="bind" path="/tmp/foo"/>
      <target port="1"/>
   </serial>
</devices>