libguestfs介绍
libguestfs 是一组 Linux 下的 C 语言的 API ,用来访问或修改虚拟机的磁盘映像文件的工具。具体介绍请浏览:https://libguestfs.org/
下载qcow格式的centos镜像
启动libvirtd服务
[root@localhost tmp]# openssl passwd -1 123456 #利用openssl生成123456的加密密文
$1$igJ4poz3$pp1r0UaCtDfii244r0dpe/
[root@localhost tmp]# guestfish CentOS-7-x86_64-GenericCloud-2009.qcow2c
CentOS-7-x86_64-GenericCloud-2009.qcow2c: unknown command
Did you mean to open a disk image? guestfish -a disk.img
For a list of commands: guestfish -h
For complete documentation: man guestfish
[root@localhost tmp]# guestfish --rw -a CentOS-7-x86_64-GenericCloud-2009.qcow2c
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: ‘help’ for help on commands
‘man’ to read the manual
‘quit’ to quit the shell
><fs> run
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
><fs> list-filesystems
/dev/sda1: xfs
><fs> mount /dev/sda1 /
><fs> vi /etc/shadow #替代root的秘密,利用前面openssl生成的密码
><fs> quit