guestmount方式打开exsi镜像文件遇到的问题
2018-07-25
先将.vmdk
格式转换为.qcow2
[root@host106 xxxxx]# qemu-img convert -f vmdk -O qcow2 Linux.vmdk linux6.3.qcow2
安装依赖包后就可以挂载了,/tmp/x
目录下就是镜像里面的文件了
[root@host106 xxxxx]# yum install libguestfs libguestfs-tools -y
[root@host106 xxxxx]# guestmount -a linux6.3.qcow2 -i --rw /tmp/x/
问题一,找不到libvirt服务,可能是libvirtd
没有启动,启动一下即可
[root@host106 xxxxx]# guestmount -a linux6.3.qcow2 -i --rw /tmp/x/
libvirt: XML-RPC error : Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
libguestfs: error: could not connect to libvirt (URI = qemu:///system): Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory [code=38 domain=7]
[root@host106 xxxxx]# systemctl start libvirtd
问题二,挂载时候报错,但看不到具体错误信息,按下面网址的提示,通过2个环境变量,可以在guestmount的时候显示详细信息
[root@host106 xxxxx]# guestmount -a linux6.3.qcow2 -i --rw /tmp/x/
libguestfs: error: /usr/bin/supermin5 exited with error status 1.
To see full error messages you may need to enable debugging.
See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
[root@host106 xxxxx]# export LIBGUESTFS_DEBUG=1
[root@host106 xxxxx]# export LIBGUESTFS_TRACE=1
问题三,遇到断言错误Assertion `n == 1 || dest[n-1] != '/''
这个是由于默认的supermin5有bug导致,网上搜一个更高版本的升级一下supermin5即可
此处我升级的是supermin5-5.1.19-1.el7.x86_64.rpm
[root@host106 xxxxx]# guestmount -a linux6.3.qcow2 -i --rw /tmp/x/
...
supermin: ext2: creating empty ext2 filesystem '/var/tmp/.guestfs-0/appliance.d.pkt2mrpn/root'
supermin: ext2: populating from base image
supermin: ext2: copying files from host filesystem
supermin5: ext2fs-c.c:584: ext2_copy_file: Assertion `n == 1 || dest[n-1] != '/'' failed.
libguestfs: error: /usr/bin/supermin5 killed by signal 6 (Aborted), see debug messages above
libguestfs: clear_socket_create_context: setsockcreatecon failed: NULL: Invalid argument [you can ignore this UNLESS using SELinux + sVirt]
libguestfs: trace: launch = -1 (error)
libguestfs: trace: close
libguestfs: closing guestfs handle 0x7f4b9c1745e0 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsJxsXTc
...
[root@host106 xxxxx]# rpm -Uvh supermin5-5.1.19-1.el7.x86_64.rpm