#!/bin/bash
#该脚本使用 guestmount 工具,Centos7.2 中安装 libguestfs-tools-c 可以获得 guestmount 工具

read -p "请输入虚拟机名称:" name
if virsh domstate $name | grep -q running ;then

# virsh domstate 显示虚拟机当前状态
# grep -q running 查找到running字符串
    echo "破解,需要关闭虚拟机"
    virsh destroy $name
fi

mountpoint="/media/virtimage"
[ ! -d $mountpoint ]  && mkdir $mountpoint
     echo "请稍后..."
if mount | grep -q "$mountpoint" ;then
     umount $mountpoint
fi

guestmount -d $name -i $mountpoint
#将 passwd 中密码占位符号 x 删除,该账户即可实现无密码登陆系统
sed -i "/^root/s/x//" $mountpoint/etc/passwd

相关文章:

  • 2021-12-20
  • 2021-07-12
  • 2021-06-27
  • 2022-12-23
  • 2021-06-18
  • 2021-11-17
  • 2021-11-26
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案