黑帽联盟

标题: 解决virsh console不能操作虚机方法 [打印本页]

作者: admin    时间: 昨天 18:26
标题: 解决virsh console不能操作虚机方法
步骤1、登录虚机

步骤2、配置 GRUB 添加串口支持
  1. # 编辑 GRUB 配置文件
  2. vim /etc/default/grub
复制代码

找到 GRUB_CMDLINE_LINUX 这一行,在引号内添加:
  1. console=ttyS0,115200 console=tty0
复制代码

修改后示例:
  1. GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet console=ttyS0,115200 console=tty0"
复制代码

保存退出后,重新生成 GRUB 配置:
  1. # CentOS 7/RHEL 7
  2. grub2-mkconfig -o /boot/grub2/grub.cfg

  3. # CentOS 6/RHEL 6
  4. grub-mkconfig -o /boot/grub/grub.cfg

  5. # Ubuntu/Debian
  6. update-grub
复制代码

步骤3:启用串口登录服务bash
  1. # 启动 serial-getty 服务(ttyS0)
  2. systemctl enable serial-getty@ttyS0
  3. systemctl start serial-getty@ttyS0

  4. # 查看服务状态
  5. systemctl status serial-getty@ttyS0
复制代码

步骤4:检查并确认配置bash
  1. # 查看是否有 ttyS0 设备
  2. ls -l /dev/ttyS0

  3. # 查看服务是否监听
  4. ps aux | grep ttyS0

  5. # 查看启动日志
  6. dmesg | grep ttyS0
复制代码
步骤5:在宿主机测试
# 立即连接
virsh console centos7.0
# 按回车键


应该能直接看到登录提示:
  1. CentOS Linux 7 (Core)
  2. Kernel 3.10.0-1160.el7.x86_64 on an x86_64

  3. localhost login:
复制代码







欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5