在使用libvrit+virsh配置KVM虚拟机时,使用vish console ${domain}出现如下情况而不能进入虚拟机。
[root@kvm01 ~]# virsh console instance001
Connected to domain instance001
Escape character is ^]
Press any key to continue. # 可能该line不存在
其实在配置模板的时候已经添加了配置,但是更新后,启用了新的内核导致配置没有生效。编辑本文档只为存档记录。
一、删除更新系统后老内核kernel
- 1. 查看系统存在的内核
[root@centos6 ~]# rpm -qa | grep kernel
dracut-kernel-004-409.el6_8.2.noarch
kernel-firmware-2.6.32-642.4.2.el6.noarch
kernel-2.6.32-642.4.2.el6.x86_64
kernel-2.6.32-431.el6.x86_64
- 2. 确认系统已经使用最新的内核启动
[root@centos6 ~]# uname -a
Linux centos6 2.6.32-642.4.2.el6.x86_64 #1 SMP Tue Aug 23 19:58:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@centos6 ~]# yum remove kernel-2.6.32-431.el6.x86_64
其他blog上写到remove kernel-devel 但是CentOS6.5最小化安装环境已经没有安装该rpm包。
- 4. 查看grub.conf文件可以看到老的kernel在menu中也已经移除
[root@centos6 ~]# 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_linux-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-642.4.2.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-642.4.2.el6.x86_64 ro root=/dev/mapper/vg_linux-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_linux/lv_swap rd_NO_MD rd_LVM_LV=vg_linux/lv_root SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.4.2.el6.x86_64.img
二、配置虚拟机模板支持vish console功能
- 1. 添加ttyS0的安全许可
# 添加ttyS0的许可,允许root登陆
[root@centos6 ~]# echo "ttyS0" >> /etc/securetty
- 2. 编辑/etc/inittab,添加如下
[root@centos6 ~]# cat /etc/inittab
... ...
S0:12345:respawn:/sbin/agetty ttyS0 115200,1152000 xterm
- 3. 配置grub.conf
在kernel行添加如下配置console=tty0 console=ttyS0,115200n8
[root@centos6 ~]# cat /etc/grub.conf
... ... #省略
default=0
timeout=5
splashimage=(hd0,0)
kernel /vmlinuz-2.6.32-642.4.2.el6.x86_64 ro root=/dev/mapper/vg_linux-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_linux/lv_swap rd_NO_MD rd_LVM_LV=vg_linux/lv_root SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet console=tty0 console=ttyS0,115200n8
initrd /initramfs-2.6.32-642.4.2.el6.x86_64.img
- 4. 重启虚拟机
[root@centos6 ~]# reboot
- 5. 确认配置生效
在KVM宿主机执行命令
[root@kvm01 ~]# virsh console instance001
virsh console instance001
Connected to domain instance001
Escape character is ^] #此处[Enter]
CentOS release 6.8 (Final)
Kernel 2.6.32-642.4.2.el6.x86_64 on an x86_64
centos6 login: root
Password: #此处输入root密码
Last login: Fri Sep 2 03:53:22 on ttyS0