2

I have the exported disk image of a VM from XenCenter in VHD format. I used compress from the settings, if that has any impact. How I can access the files without creating VM? I have the VM settings as well the disk. Fdisk can read the image but it does not lists any partitions. I don't care about the system itself, only the files. More notably /etc and /home.

VM was created in XenServer 6.2 (if I recall correctly) and it's using LVM. Later as I upgraded to Debian 8 I also upgraded XenServer to 6.5 and installed SP1. I must note that hard drive of XenXerver got corrupted but before doing the export guest OS worked without problems. I'm fairly positive the image I have is functional.

What I have tried so far:

  • Importing the VM into new master (different hardware). It failed to import. As it takes around 10 hours to do this, I'm not very keen to try this any more.
  • Importing the VM into old master (same hardware)
  • Importing the VM into new master (same hardware)
  • Converted VHD into VDI and mounted it to VirtualBox. It failed saying no bootable media found. Reason for convert is that VirtualBox didn't allow mounting VHD directly.
  • Tried to install new VM where I used virtualbox-fuse to mount it. But it sayd that VHD is in unknown format.
  • Tried to use losetup to pass boot sector of image and then mount it. But it can not find filesystem while mounting. At least ext4 or ext2.
  • Tried to attach VHD into Windows machine. It says it's either corrupted or unreadable.

There might be something else I have tried but I don't recall right now. I'm totally helpless right now.

user715517
  • 23
  • 4

1 Answers1

0

you'll need a number of steps to mount & read the image. Firstly convert VHD to RAW

qemu-img convert -f vmdk -O raw myfile.vhd myfile.img

The original file will of course stay intact. Next you will have to mount the file. For this there are several steps involved

Firstly, connect the raw image to a loopback device.

losetup /dev/loop0 myfile.img

If I have understood correctly you are using a logical volume. This means you can't mount it directly but you find & active the volume group per

lvs

vgchange -ay YourVG

If lvs doesn't find your volume, you will have to change the lvm filter in

/etc/lvm/lvm.conf

and set it to

filter = [ "a/.*/" ]

with that done you can mount the logical volume.

mount /dev/mapper/lvol01 /mnt

Hope this was helpful.

Eamonn Travers
  • 614
  • 4
  • 11
  • I didn't get this method to work. When trying the convert it says "qemu-img: Could not open 'disk.vhd': Invalid argument. Then I did look into man page of qemu-img and it says that if format is not given it will try to guess it. I dropped the -f parameter and it started to convert it. Ok. Next I did run losetup and it returned instantly without error. But lvs only shows the current LV's on the running OS. I did check the filter and it seems to default what you suggested. – user715517 Sep 23 '15 at 07:40
  • Hi, try changing the default to include the loopback devices. And try vgs. The Volume group may be inactive. – Eamonn Travers Sep 23 '15 at 08:19
  • Can you mount the loopback directly? – Eamonn Travers Sep 23 '15 at 08:27
  • I did modify filter = ["a/.*/", "a/loop/", "r/.*/"]. Tho a/.*/ should already include loopback devices. After restart on LVM it did not help. Trying to mount the loop (mount /dev/loop0 /mnt/disk/) resulted: VFS: Can't find ext4 filesystem. And same for ext2. – user715517 Sep 23 '15 at 09:19
  • I'm afraid I'm flummoxed. What does fdisk -l say about the image? – Eamonn Travers Sep 23 '15 at 09:26
  • fdisk reports the correct size but warns about not having valid partition table in side it. On both vhd and converted raw img. Is there a way to view contents of the img in any sensible way without hexeditor? Just to confirm that it actually has the files inside. – user715517 Sep 23 '15 at 09:32
  • I don't know any way which doesn't involve mounting the image. What do losetup & pvs return? – Eamonn Travers Sep 23 '15 at 09:49
  • losetup returns instantly without any message. pvs lists one physical volume that is used by the running VM. – user715517 Sep 23 '15 at 09:54
  • The image isn't connected to the loopback losetup /dev/loop0 myfile.img – Eamonn Travers Sep 23 '15 at 09:58
  • Well running losetup again results in: "device is busy" error. – user715517 Sep 23 '15 at 10:00
  • Try losetup /dev/loop1 myfile.img – Eamonn Travers Sep 23 '15 at 10:01
  • No difference on lvs, pvs etc. – user715517 Sep 23 '15 at 10:03
  • Is the image connected to the loop back? You should get something like this from losetup /dev/loop0 0 10795089920 0 0 /srv/myfile.img – Eamonn Travers Sep 23 '15 at 10:06
  • I don't know how to check if it is. losetup returns absolutely nothing. Just instantly finishes without returning anything. – user715517 Sep 23 '15 at 10:12
  • Your image is not connecting to the loopback. You need to find out why. Without the loop device you can't read the logical volume. Sorry, I wish I could be more help. – Eamonn Travers Sep 23 '15 at 10:16