37

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?

Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
Without Me It Just Aweso
  • 4,593
  • 10
  • 35
  • 53
  • 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? – voidlogic Mar 11 '14 at 15:24
  • 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 anything – Without Me It Just Aweso Mar 12 '14 at 12:45
  • 1
    Try installing `ntfs-3g` – voidlogic Mar 12 '14 at 14:24
  • 2
    Also, you might want to move this question over to http://serverfault.com/, I bet you would get more help there as this isn't really a software dev or computer science question. – voidlogic Mar 12 '14 at 14:25
  • 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 line – binhgreat Sep 05 '22 at 11:24

6 Answers6

77

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

supervacuo
  • 9,072
  • 2
  • 44
  • 61
Thomas
  • 1,622
  • 17
  • 24
  • 1
    That's very helpful. Anyway, I had to use `sudo` and get to the directory as `root` to made this work. – realhu Nov 20 '17 at 17:03
  • 1
    This worked for me, although the `-m` argument needs a little more explanation. From the [`guestmount` man page](https://linux.die.net/man/1/guestmount): `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/sda1` – Kryten Jun 21 '20 at 20:17
  • For debian and proxmox systems it is also the package libguestfs-tools – sneaky Sep 09 '20 at 14:20
  • I don't understand the `-m` option, but `-i` worked fine. Why is `-m /dev/xxx` needed? – guettli Jan 11 '21 at 12:40
  • `sudo guestmount -a abc.vmdk -o "ro" -i --ro /mnt/abc` it only mounts readonly if i use `-o ro` – Aquarius Power Jun 01 '22 at 11:44
  • The `-m` option is the partition on the vmdk. You can find this with `virt-filesystems -a {path_to_vmdk_file}`. – mitchellJ Jan 18 '23 at 20:17
23

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.

user3694243
  • 234
  • 3
  • 13
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
  • 1
    Additional info about mounting archives and virtual drives: https://unix.stackexchange.com/questions/31669/is-it-possible-to-mount-a-gzip-compressed-dd-image-on-the-fly – user1742529 Dec 25 '19 at 15:25
  • `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 size – Aquarius Power Jun 01 '22 at 11:57
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.

Axel Beckert
  • 6,814
  • 1
  • 22
  • 23
MetalGodwin
  • 3,784
  • 2
  • 17
  • 14
  • 1
    No need in manual calculation: just use `offset=$((2048*512))` – Ruslan Feb 17 '20 at 08:56
  • 1
    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/vmdisk – Ponytech Mar 05 '20 at 18:35
  • `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. – caduceus May 27 '20 at 07:42
  • used this however the mounted folder was empty – Avizipi Feb 15 '22 at 13:38
  • ls:`-r--r--r-- 1 root root 1536 Dec 31 1969 abc.vmdk.raw` fdisk:`cannot open abc.vmdk.raw: Permission denied`, any idea? – Aquarius Power Jun 01 '22 at 12:06
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.

Illia Bobyr
  • 730
  • 6
  • 16
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.

Community
  • 1
  • 1
georgiptr
  • 111
  • 9
  • 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). @georgiptr 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. – LMSingh Jul 26 '21 at 08:34
-3

Have you got the software package for ntfs?

Try

apt-get install ntfs-3g

on debian based systems.

sjas
  • 18,644
  • 14
  • 87
  • 92
Jiang
  • 590
  • 2
  • 10
  • 1
    What does the OP's problem have to do with NFS? Did you mean ntfs? An NTFS package would be something like `ntfs-3g`. – voidlogic Mar 11 '14 at 15:25
  • @voidlogic 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. – Jiang Mar 11 '14 at 16:06