以下三步解决问题:

在虚拟机中执行如下步骤

  1.  echo "ttyS0" >> /etc/securetty

  2. 在/etc/grub.conf中添加内容

title CentOS 6 (2.6.32-504.el6.x86_64)

        root (hd0,0)

        kernel /boot/vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=ee25ae67-9474-4364-8b10-0aeb4e8d6758 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  rhgb crashkernel=auto quiet rd_NO_LVM rd_NO_DM rhgb quiet console=ttyS0

3. echo "S0:12345:respawn:/sbin/agetty ttyS0 115200"  >> /etc/inittab


对于centos 7 系统的虚拟机,就比较简单了。

With KVM, to access the virtual machine’s console under X Window, type:

# virt-manager

If you aren’t under X Window, there is another way to access a virtual machine’s console: you can go through a serial console.

On the virtual machine, add ‘console=ttyS0‘ at the end of the kernel lines in the /boot/grub2/grub.cfg file:

# grubby --update-kernel=ALL --args="console=ttyS0"

Note: Alternatively, you can edit the /etc/default/grub file, add ‘console=ttyS0‘ to the GRUB_CMDLINE_LINUX variable and execute ‘# grub2-mkconfig -o /boot/grub2/grub.cfg‘.

Now, reboot the virtual machine:

# reboot