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
本文介绍了libguestfs,一个用于访问和修改虚拟机磁盘映像的Linux工具。通过实例展示了如何下载qcow格式的CentOS镜像,启动libvirtd服务,并利用openssl生成密码加密root账户。然后在guestfish中挂载和编辑虚拟机文件系统,如修改/etc/shadow文件替换root密码。
2273

被折叠的 条评论
为什么被折叠?



