Mounting VMDK disk image
Asked Answered
I

7

39

I have a single vmware disk image file with vmdk extension

I am trying to mount this and explore all of the partitions (including hidden ones).

I've tried to follow several guides, such as : http://forums.opensuse.org/showthread.php/469942-mounting-virtual-box-machine-images-host

I'm able to mount the image using vdfuse

vdfuse -w -f windows.vmdk /mnt/

After this I can see one partition and an entire disk exposed

# ll /mnt/
total 41942016
-r-------- 1 te users 21474836480 Feb 28 14:16 EntireDisk
-r-------- 1 te users  1569718272 Feb 28 14:16 Partition1

Continuing with the guide I try to mount either EntireDisk or Partition1 using

mount -o loop,ro /mnt/Partition1 mnt2/

But that gives me the error 'mount: you must specify a filesystem type'

In trying to find the correct type I tried

dd if=/mnt/EntireDisk | file -
which outputs a ton of information but of note is:
/dev/stdin: x86 boot sector; partition 1: ....... FATs ....

So i tired to mount as a vfat but that gave me

mount: wrong fs type, bad option, bad superblock ...etc

What am I doing wrong?

Inion answered 11/3, 2014 at 13:51 Comment(5)
Did you try ntfs? Did you try fdisk /mnt/EntireDisk or gparted /mnt/EntireDisk and looking at the partitions there? Do they show up correctly?Paraclete
fdisk returned: 'WARNING: GPT detected on '...'. The util fdisk doesnt support GPT'. gparted is able to show me there are 4 partitions but all fail to initalize. It lists several required packages for ntfs and fat32 that i might need so I'll install those and see if it gets me anythingInion
Try installing ntfs-3gParaclete
Also, you might want to move this question over to serverfault.com, I bet you would get more help there as this isn't really a software dev or computer science question.Paraclete
I saw a lot of solution, but finally I use the simple solution: add the VMDK file to an existed linux VM. Boot to that VM and mount the partition normally. You can use GUI tool to mount (such as gnome-disks in gnome) or mount command lineVitta
C
80

For newer Linux systems, you can use guestmount to mount the third partition within a VMDK image:

guestmount -a xyz.vmdk -m /dev/sda3 --ro /mnt/vmdk

Alternatively, to autodetect and mount an image (less reliable), you can try:

guestmount -a xyz.vmdk -i --ro /mnt/vmdk

Do note that the flag --ro simply mounts the image as read-only; to mount the image as read-write, just replace it with the flag --rw.

Installation

guestmount is contained in following packages per distro:

  • Ubuntu: libguestfs-tools
  • OpenSuse: guestfs-tools
  • CentOS / Fedora: libguestfs-tools-c

Troubleshooting

error: could not create appliance through libvirt

$ guestmount -a file.vmdk -i --ro /mnt/guest
libguestfs: error: could not create appliance through libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: Cannot access backing file '/path/to/file.vmdk' of storage file '/tmp/libguestfssF6WKX/overlay1.qcow2' (as uid:107, gid:107): Permission denied [code=38 int1=13]

Solution: use LIBGUESTFS_BACKEND=direct, as suggested:

LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest

fusermount: user has no write access to mountpoint

LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest/
fusermount: user has no write access to mountpoint /mnt/guest
libguestfs: error: fuse_mount failed: /mnt/guest/, see error messages above

Solution: use sudo, or change file permissions on the mountpoint

Culminant answered 12/5, 2015 at 20:49 Comment(6)
That's very helpful. Anyway, I had to use sudo and get to the directory as root to made this work.Sunder
This worked for me, although the -m argument needs a little more explanation. From the guestmount man page: Mount the named partition or logical volume on the given mountpoint in the guest (this has nothing to do with mountpoints in the host).. I found that mounting the first partition with /dev/sda1 worked, even though the host had it's own /dev/sda1Nanny
For debian and proxmox systems it is also the package libguestfs-toolsNomination
I don't understand the -m option, but -i worked fine. Why is -m /dev/xxx needed?Bailment
sudo guestmount -a abc.vmdk -o "ro" -i --ro /mnt/abc it only mounts readonly if i use -o roGlasshouse
The -m option is the partition on the vmdk. You can find this with virt-filesystems -a {path_to_vmdk_file}.Aymara
H
28

You can also use qemu:

For .vdi disks

sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi

if they are not installed, you can install them (issuing this command in Ubuntu)

sudo apt install qemu-utils

and then mount it with:

mount /dev/nbd1p1 /mnt

For .vmdk disks

sudo modprobe nbd
sudo qemu-nbd -r -c /dev/nbd1 ./linux_box/VM/image.vmdk

notice that I use the option -r, that's because VMDK version 3 must be read only to be able to be mounted by qemu

and then I mount it with

mount /dev/nbd1p1 /mnt

I use nbd1, because nbd0 sometimes gives: 'mount: special device /dev/nbd0p1 does not exist'

For .ova disks

tar -tf image.ova
tar -xvf image.ova

The above will extract the .vmdk disk and then mount it.

Hatch answered 27/2, 2018 at 2:55 Comment(2)
Additional info about mounting archives and virtual drives: unix.stackexchange.com/questions/31669/…Differentia
qemu-nbd: Failed to blk_new_open 'abc.vmdk': Could not open 'abc-s1016.vmdk': Too many open files it has a total of 1025 files btw, I guess I would have to recompile nbd to let more than 1017 files? the vmdk is split in growing files for a 2TB max sizeGlasshouse
P
7

Install affuse, then mount using it.

affuse /path/file.vmdk /mnt/vmdk

The raw disk image is now found under /mnt/vmdk. Check its sector size:

fdisk -l /mnt/vmdk/file.vmdk.raw

# example

Disk file.vmdk.raw: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000da525

Device       Boot Start      End  Sectors Size Id Type
/mnt/vmdk/file.vmdk.raw1 *     2048 41943039 41940992  20G 83 Linux

Multiply sector size and start sector. In the example it would be 2048*512:

echo '2048*512' | bc
1048576

Mount the raw file using that offset:

mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk

The disk should now be mounted and readable on /mnt/vmdisk.

Phototaxis answered 6/9, 2016 at 13:25 Comment(6)
No need in manual calculation: just use offset=$((2048*512))Nucleotide
If you have the error: mount: /mnt/vmdisk: cannot mount /dev/loop0 read-only. use the norecovery option: mount -o ro,norecovery,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdiskAbiosis
mount: /mnt/vmdkraw: failed to setup loop device for /mnt/vmdk/MSEdge - Win10-disk001.vmdk.raw Its HPFS/NTFS/exFAT, but don't suppose that makes a difference.Undersized
used this however the mounted folder was emptyDebase
ls:-r--r--r-- 1 root root 1536 Dec 31 1969 abc.vmdk.raw fdisk:cannot open abc.vmdk.raw: Permission denied, any idea?Glasshouse
For those wondering: affuse is part of afflib.Arieariel
G
3

Here is an answer from commandlinefu.com that worked for me:

kpartx -av <image-flat.vmdk>; mount -o /dev/mapper/loop0p1 /mnt/vmdk

You can also activate LVM volumes in the image by running

vgchange -a y

and then you can mount the LV inside the image.

To unmount the image, umount the partition/LV, deactivate the VG for the image

vgchange -a n <volume_group>

then run

kpartx -dv <image-flad.vmdk>

to remove the partition mappings.

Gastrointestinal answered 11/11, 2015 at 20:36 Comment(4)
@AntonioPetricca If you say something does not work, you may also provide details on what exactly did not work. Like posting an error message or explaining what exactly is wrong. That would greatly increase value of the comment.Gastrointestinal
Sorry! KPARTX says that the VMDK file format is not recognized.Brummell
This is for ESX's "someimage-flat.vmdk" format, where it works as described.Acetyl
sudo kpartx -av abc.vmdk gives llseek error on ubuntu22.04Glasshouse
D
2

You can take a look in this article for a download link for VMware Virtual Disk Development Kit (VDDK). Once downloaded and installed:

vmware-mount -p path_to_vmdk will show the partitions inside the VMDK file. For example:

Nr      Start       Size Type Id Sytem                   
-- ---------- ---------- ---- -- ------------------------
 1       2048  461371392 BIOS 83 Linux

Then just do:

sudo vmware-mount path_to_vmdk 1 /mnt/mount_point

I tried guestmount, but it is very, very slow. Underneath it creates a virtual machine, uses KVM and so on. Crazy stuff, slow as hell.

Debauchee answered 20/3, 2020 at 14:43 Comment(1)
Excellent recommendation. IMHO, many people downvoted without giving any rationale. Whereas this is a very high speed method to mount and use vmdk. I copied out 204,803 files in under 9 minutes (even faster than local filesystem copy). @Debauchee You don't need the whole VDDK if you already have vmware player or workstation (and possibly any other vmware product) because vmware-mount is already installed.Sissel
S
0

I needed to modify the contents of a VMware4 vmdk file. Had issues with the existing solutions:

  • guestmount is able to mount the vmdk in read-only, but I was not able to mount the disk in r/w (error: "cannot mount /dev/sda4 read-only")
  • kpartx does not find any partition (kpart -l returns blank).
  • The VDDK link is not working anymore apparently, and the latest VDDK does not provide vmware-mount.

My solution was to use another auxiliary VM to mount the vmdk file. This procedure uses VirtualBox console. Assuming $VM points to the auxiliary VM and $VBOX_DISK to the vmdk disk:

  1. Make sure the auxiliary VM is stopped, e.g.

    host # VBoxManage controlvm $VM poweroff

  2. Attach the vmdk file

    host # VBoxManage storageattach $VM --storagectl "IDE Controller" \ --port 0 --device 1 --type hdd --medium "$VBOX_DISK"

  3. Boot the auxiliary VM

    host # VBoxManage startvm $VM --headless

  4. Access the auxiliary VM, via SSH or GUI, then check and mount the drive you need:

    vm # lsblk vm # mount /dev/sdb4 /mnt

  5. After making the necessary changes to the vmdk filesystem, unmount and exit the VM

    vm # unmount /mnt vm # exit

  6. Power off the VM and detach the drive

    host # VBoxManage controlvm $VM poweroff host # VBoxManage storageattach $VM --storagectl "IDE Controller" \ --port 0 --device 1 --type hdd --medium none

Submaxillary answered 13/4 at 15:58 Comment(0)
S
-4

Have you got the software package for ntfs?

Try

apt-get install ntfs-3g

on debian based systems.

Sartre answered 11/3, 2014 at 15:17 Comment(2)
What does the OP's problem have to do with NFS? Did you mean ntfs? An NTFS package would be something like ntfs-3g.Paraclete
@Paraclete Sorry I've understood your question wrong and SO keeps giving me a prompt of read-only mode. Have you try to mount the vmdk file by vmware-mount, which can be extracted from the VMware-Workstation.Sartre

© 2022 - 2024 — McMap. All rights reserved.