首页 > 系统相关 > centos8 kvm启用 virsh console

centos8 kvm启用 virsh console

时间:2022-12-07 17:03:23浏览次数:66  
标签:console ttyS0 kvm E6% etc init virsh conf root

新建一个centos8的虚拟机,使用virsh console连接失败,查阅一通资料后发现了解决方法

虚拟机中执行以下命令:

grubby --update-kernel=ALL --args="console=ttyS0"  && init 6

 

然后,物理机中执行以下命令:

 

virsh list --all
virsh console 虚拟机

 

参考连接:https://blog.51cto.com/coolsky/3713851

https://blog.51cto.com/coolsky/3713851#:~:text=%E6%96%B0%E5%AE%89%E8%A3%85%E4%B8%80%E5%8F%B0%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%90%8E%EF%BC%8C%E6%98%AF%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87virsh%20console,%E5%91%BD%E4%BB%A4%E8%BF%9E%E5%85%A5%E8%99%9A%E6%8B%9F%E6%9C%BA%E4%B8%AD%E7%9A%84%EF%BC%8C%E8%BF%99%E6%97%B6%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%BC%80%E5%90%AF%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84console%E5%8A%9F%E8%83%BD%E3%80%82%20RHEL%2FCentOS6%20%E4%B8%80%E3%80%81%E6%B7%BB%E5%8A%A0ttyS0%E7%9A%84%E8%AE%B8%E5%8F%AF%EF%BC%8C%E5%85%81%E8%AE%B8root%E7%99%BB%E9%99%86

 

其他:原文转载  

新安装一台虚拟机后,是无法通过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
View Code

 

标签:console,ttyS0,kvm,E6%,etc,init,virsh,conf,root
From: https://www.cnblogs.com/santia-god/p/16963578.html

相关文章

  • 解决Webstorm Nodejs console.log("这是中文") 控制台乱码
    设置文件编码自定义vm选项文件添加文件最后一行添加-Dfile.encoding=UTF-83.修改注册表Windows+R-->regedit-->计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsof......
  • virsh list报错: error: failed to connect to the hypervisor
    查看本地kvm虚机时,发现无法查看,出现报错#virshlisterror:failedtoconnecttothehypervisorerror:Failedtoconnectsocketto'/var/run/libvirt/libvirt-soc......
  • vmware workstation SCSI磁盘格式虚拟机迁移到KVM之后无法启动的问题解决办法
    原文链接:https://blog.51cto.com/duron/2125821转换磁盘镜像格式之后导入KVM系统无法启动,但是可以进入恢复模式,可能是virtio的内核模块没有加载,把磁盘改为IDE模式后正常......
  • KVM 虚拟机 热插拔硬盘
    新建硬盘分区,格式化,查看新盘uuidlvcreate-L200G-nlv02ssd01mkfs.xfs/dev/mapper/ssd01-lv02blkid|greplv02热插拔硬盘命令attach-diskdomainsourcetarget......
  • kvm图形化界面无法打开(virt-manager报错)
    问题:手动安装虚拟化,使用virt-manager无法打开虚拟化控制界面,报错:Unabletoinitserver:cloudnotconnect:Connectionrefused......cannotopendisplay: 原因......
  • !function(){console.log(12);}()
    小结:1、  微盟商家后台体验设计重塑全面解析https://mp.weixin.qq.com/s/et8KW1PvP_n4WYtU7fTwcA微盟商家后台体验设计重塑全面解析原创 微盟用户体验部 WEMO......
  • linux--kvm初步学习
    检查机器是否开启虚拟化支持[root@kvm~]#egrep-o'vmx|svm'/proc/cpuinfosvmsvmsvmsvm安装kvm依赖包yuminstalllibvirtvirt-installqemu-kvm-y开机自启......
  • kvm虚拟机添加虚拟磁盘
    1.概述本篇博客介绍为kvm虚拟机添加虚拟磁盘的操作,以便在日常工作学习使用。涉及到的命令包括:qemu-img,virsh-edit,virshattach-diskqemu-img:用于创建虚拟磁盘块文件......
  • 设置console打印样式
    在浏览器中:可以通过第一个参数加入%c来设置,第二个参数传css字符串  在node.js中Node的实现,是基于c语言的,因此Node的彩色打印其实与c语言类似\33[0m关闭所有属性......
  • how to run XPath in Chrome console All In One
    howtorunXPathinChromeconsoleAllInOnesolutions$x()function$x;//ƒ$x(){[nativecode]}$x(`/html/head/meta`);//(28) [meta,meta,meta,me......