新建一个centos8的虚拟机,使用virsh console连接失败,查阅一通资料后发现了解决方法
虚拟机中执行以下命令:
grubby --update-kernel=ALL --args="console=ttyS0" && init 6
然后,物理机中执行以下命令:
virsh list --all
virsh console 虚拟机
参考连接:https://blog.51cto.com/coolsky/3713851
其他:原文转载
新安装一台虚拟机后,是无法通过virsh console 命令连入虚拟机中的,这时我们需要开启虚拟机的console功能。 RHEL/CentOS6 一、添加ttyS0的许可,允许root登陆 [root@Inf-c6-n0 ~]# echo "ttyS0" >> /etc/securetty 二、编辑/etc/grub.conf 加入console=ttyS0 登录后复制 [root@Inf-c6-n0 ~]# 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/c01-root # initrd /initrd-[generic-]version.img #boot=/dev/vda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS 6 (2.6.32-754.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-754.el6.x86_64 ro root=/dev/mapper/c01-root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=c01/root rd_LVM_LV=c01/swap KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet console=ttyS0 initrd /initramfs-2.6.32-754.el6.x86_64.img ----------------------------------- 三、编辑/etc/inittab 在最后一行加入内容 S0:12345:respawn:/sbin/agetty ttyS0 115200 登录后复制 [root@Inf-c6-n0 ~]# cat /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:3:initdefault: S0:12345:respawn:/sbin/agetty ttyS0 115200 ----------------------------------- 三、编辑/etc/inittab 在最后一行加入内容 S0:12345:respawn:/sbin/agetty ttyS0 115200 登录后复制 [root@Inf-c6-n0 ~]# cat /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:3:initdefault: S0:12345:respawn:/sbin/agetty ttyS0 115200 ----------------------------------- 三、编辑/etc/inittab 在最后一行加入内容 S0:12345:respawn:/sbin/agetty ttyS0 115200 登录后复制 [root@Inf-c6-n0 ~]# cat /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:3:initdefault: S0:12345:respawn:/sbin/agetty ttyS0 115200 ----------------------------------- RHEL/CentOS8 在虚拟机里执行 [root@inf-r8-n0 ~]# grubby --update-kernel=ALL --args="console=ttyS0" [root@inf-r8-n0 ~]# [root@inf-r8-n0 ~]# reboot 1. 2. 3. 在宿主机上测试 登录后复制 [root@localhost vmfs]# virsh start Rocky8 Domain Rocky8 started [root@localhost vmfs]# virsh console Rocky8 Connected to domain Rocky8 Escape character is ^] [ OK ] Started Show Plymouth Boot Screen. [ OK ] Started Forward Password Requests to Plymouth Directory Watch. [ OK ] Reached target Paths. [ OK ] Found device /dev/mapper/r01-root. [ OK ] Reached target Initrd Root Device. [ OK ] Found device /dev/mapper/r01-swap. Starting Resume from hibernation using device /dev/mapper/r01-swap... [ OK ] Started Resume from hibernation using device /dev/mapper/r01-swap. [ OK ] Reached target Local File Systems (Pre). [ OK ] Reached target Local File Systems. Starting Create Volatile Files and Directories... [ OK ] Started dracut initqueue hook. Starting File System Check on /dev/mapper/r01-root... [ OK ] Reached target Remote File Systems (Pre). [ OK ] Reached target Remote File Systems. ----------------------------------- https://blog.51cto.com/coolsky/3713851View Code
标签:console,ttyS0,kvm,E6%,etc,init,virsh,conf,root From: https://www.cnblogs.com/santia-god/p/16963578.html