virsh 连接虚拟机 (vnc 或 控制台)

第一种方式

1.如果虚拟机登录方式为VNC,在ubuntu机器上安装vncviewer

在虚拟机的配置xml中

<graphics type="vnc" autoport="yes" keymap="en-us" listen="0.0.0.0"/>

安装vncviewer

$apt-get install vncviewer

查看该虚拟机的端口地址

$virsh vncdisplay controller

显示 :0

通过该端口地址连接该虚拟机

$vncviewer 127.0.0.1:0

 第二种方式

2.如果是客户端登录方式,则按照如下方案登录

虚拟机的配置xml中

    <serial type='pty'>
          <target port='0'/>
    </serial>
    <console type='pty'>
          <target type='serial' port='0'/>
    </console>

登录命令

$virsh console 虚拟机名称

 

但是却在界面上一直卡住在界面下:

连接到域:虚拟机名称

换码符为 ^]

原来需要设置一下:

$echo "ttyS0" >> /etc/securetty
$echo "S0:12345:respawn:/sbin/agetty/ ttyS0 115200" >> /etc/inittab
$echo "console=ttyS0" >> /etc/grub.conf

重新启动虚拟机

$virsh reboot 虚拟机名称
原文地址:https://www.cnblogs.com/yasmi/p/5177668.html