kvm 配置 console

1. 配置 kvm virsh console 连接虚拟机

1.1. 新增 /etc/init/ttyS0.conf 配置文件

1
2
3
4
5
6
7
cat > /etc/init/ttyS0.conf
stop on runlevel[016]
start on runlevel[345]
respawn
instance /dev/ttyS0
exec /sbin/mingetty /dev/ttyS0

1.2. 允许 从 ttyS0 登录

1
2
3
cat >> /etc/securetty
ttys0

1.3. 开启 ttyS0

1
initctl start ttyS0

1.4. 测试 virsh console 连接到虚拟机

出现 ‘Escape character is ^]’ 时,按下回车

1
2
3
4
5
6
7
Connected to domain test.jy
Escape character is ^]
CentOS release 6.4 (Final)
Kernel 2.6.32-358.el6.x86_64 on an x86_64
test.jy login:

1.5. 配置grub.conf 引导时 可从console 输出

删除 grub.conf中 kernel行结尾的 rhgb quiet
并在行尾追加 console=ttyS0

1
2
3
4
5
6
7
vim /etc/grub.conf
# 修改前
kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=30169634-251c-4337-8b3e-3660f934c1d2 nomodeset rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM rhgb quiet
# 修改后
kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=30169634-251c-4337-8b3e-3660f934c1d2 nomodeset rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM console=ttyS0