我的知乎专栏:https://www.zhihu.com/column/c_1341027586424610816
修改qcow2镜像里的内容,可以通过guestmount工具来进行,guestmount工具包含在libguestfs工具集内,所以先执行 yum install libguestfs libguestfs-tools -y安装。
下面看怎么修改一个qcow2镜像内的内容,使用如下命令
# guestmount -a <qcow2镜像文件> -m <镜像内的磁盘分区> <宿主机上的挂载目录>
两个主要的参数说明下,其他参数可通过guestmount --help查看
-a 指定待挂载的镜像文件
-m 指定镜像文件中的客户系统的磁盘分区,如果分区写得不对,会有错误提示
$ guestmount -a centos7.qcow2 -m /dev/sda2 /mnt
libguestfs: error: mount_options: mount exited with status 32: mount: /dev/sda2 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
guestmount: ‘/dev/sda2’ could not be mounted.
guestmount: Did you mean to mount one of these filesystems?
guestmount: /dev/sda1 (vfat)
guestmount: /dev/sda2 (unknown)
guestmount: /dev/sda3 (ext4)