centos8 kvm启用 virsh console
新建一个centos8的虚拟机,使用virsh console 虚拟机 连接失败,查阅一通资料后发现了解决方法
其中ttyS0中的S代表Serial Port Terminal,所以这是一个是虚拟串口,联系起来看就好理解许多,通过console使用串口登陆设备,前提是得有这么一个串口
虚拟机中执行以下命令:
grubby --update-kernel=ALL --args="console=ttyS0" && init 6
然后,物理机中执行以下命令:
virsh list --all
virsh console 虚拟机
# 阿里云主机的grub文件参考
]# cat /etc/default/grub GRUB_TIMEOUT=1 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=0M-2G:0M,2G-8G:192M,8G-128G:256M,128G-:384M cryptomgr.notests cgroup.memory=nokmem rcupdate.rcu_cpu_stall_timeout=300 vring_force_dma_api rhgb quiet biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8 noibrs nvme_core.io_timeout=4294967295 nvme_core.admin_timeout=4294967295" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true
# grep console /etc/grub2.cfg terminal_output console linux /boot/vmlinuz-4.19.90-2102.2.0.0062.el7.x86_64 root=UUID=f81deefa-c459-4ad6-bef7-111 ro net.ifnames=0 biosdevname=0 console=tty0 console=ttyS0,115200n8 crashkernel=512M linux /boot/vmlinuz-0-rescue-1c6406e0f root=UUID=f81deefa-c459-4ad6-bef7-111 ro net.ifnames=0 biosdevname=0 console=tty0 console=ttyS0,115200n8 crashkernel=512M
参考连接: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/3713851
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能