virsh链接虚拟机_KVM 通过virsh console连入虚拟机

本文介绍了如何在KVM虚拟机中通过virsh console命令连接到新安装的虚拟机。主要步骤包括:添加ttyS0权限,编辑grub.conf以启用console,更新inittab文件,以及在CentOS 6和7中不同的设置方法。完成这些步骤后,可以通过virsh console进行连接。
摘要由CSDN通过智能技术生成

新安装一台虚拟机后,是无法通过virsh console 命令连入虚拟机中的,这时我们需要开启虚拟机的console功能。

一、添加ttyS0的许可,允许root登陆

[root@localhost ~]# echo "ttyS0" >> /etc/securetty

二、编辑/etc/grub.conf中加入console=ttyS0

[root@localhost ~]# less /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/VolGroup-lv_root

# initrd /initrd-[generic-]version.img

#boot=/dev/sda

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/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=128M rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet console=ttyS0

initrd /initramfs-2.6.32-431.el6.x86_64.img

[root@localhost ~]#

三、编辑/etc/inittab,在最后一行加入内容 S0:12345:respawn:/sbin/agetty ttyS0 115200

[root@localhost ~]# less /etc/inittab

# inittab is only used by upstart for the default runlevel.

#

# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# System initialization is started by /etc/init/rcS.conf

#

# Individual runlevels are started by /etc/init/rc.conf

#

# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf

#

# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,

# with configuration in /etc/sysconfig/init.

#

# For information on how to write upstart event handlers, or how

# upstart works, see init(5), init(8), and initctl(8).

#

# Default runlevel. The runlevels used are:

# 0 - halt (Do NOT set initdefault to this)

# 1 - Single user mode

# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)

# 3 - Full multiuser mode

# 4 - unused

# 5 - X11

# 6 - reboot (Do NOT set initdefault to this)

#

id:5:initdefault:

S0:12345:respawn:/sbin/agetty ttyS0 115200

[root@localhost ~]#

四、重启服务器

[root@localhost ~]# reboot

五、在宿主机上测试连接

[root@study ~]# virsh list

Id Name State

----------------------------------------------------

4 centos running

[root@study ~]# virsh console 4

Connected to domain centos

Escape character is ^]

CentOS release 6.5 (Final)

Kernel 2.6.32-431.el6.x86_64 on an x86_64

localhost.localdomain login: root

Password:

Last login: Thu Oct 13 02:51:30 on ttyS0

[root@localhost ~]#

注:按 ctrl+] 组合键退出virsh console

对于centos 7

在虚机里运行

[root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0"

then

[root@localhost ~]# reboot

即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值