您的位置:首页 > 其它

使用virsh console连接虚拟机

2014-08-26 15:53 701 查看
在网络控制的比较严格的情况下,远程桌面等连接虚拟机的方式可能会受到限制。virsh有一个现有的命令,可以在需要的时候应应急

[root@pc ~]# virsh help console
NAME
console - connect to the guest console

SYNOPSIS
console <domain> [--devname <string>] [--force] [--safe]

DESCRIPTION
Connect the virtual serial console for the guest

OPTIONS
[--domain] <string> domain name, id or uuid
--devname <string> character device name
--force force console connection (disconnect already connected sessions)
--safe only connect if safe console handling is supported
但是默认的情况下,执行virsh console dom_name的时候,会发现hang住,没有任何反应。

原因是kernel在启动的时候并没有打开对ttyS0的支持,console其实是通过这个字符设备进行通信的。只需要简单的在grub对应的选项里面加上启动参数即可:
[root@cent65 ~]# cat /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_cent65-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/vda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_cent65-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_cent65/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg_cent65/lv_root rd_NO_DM rhgb quiet <span style="font-size:18px;color:#ff0000;"><strong>console=ttyS0</strong></span>

不管是grub还是grub2,只要在对应处进行设置就可以正常连接了。
[root@pc ~]# virsh console cent65
Connected to domain cent65
Escape character is ^]
root
Password:
Last login: Mon May 19 15:40:28 on ttyS0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  KVM virsh console