Mount VMWare Disk Images Under Linux

34,875

Solution 1

You can also use qemu:

For .vdi

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

if they are not installe you can install them (on Ubuntu is this comand)

sudo apt install qemu-utils

and then mount it

mount /dev/nbd1p1 /mnt

For .vmdk

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

notice tha 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

mount /dev/nbd1p1 /mnt

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

For .ova

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

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

My configuration:

Ubuntu: 16.04.3 LTS 
Kernel: 4.4.0-112-generic  
Package: qemu-utils version: 1:2.5+dfsg-5ubuntu10.22 
Vmdk: 3 but should be any

Solution 2

Install affuse, then mount file with it:

affuse /path/file.vmdk /mnt/vmdk

Check 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 sectorsize and startsector. In example it would be 2048*512

echo 2048*512 | bc
1048576

Mount using that offset

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

Disk should now be mounted and readable on /mnt/vmdisk

Solution 3

In my machine the loop devices are in /dev. This article mentions /dev/wrapper and /dev, so it could be of help to you.

On the other hand, this other article uses the vmware-mount command to accomplish the same.

Note: My system is Slackware64-current (mostly), but with mainly gtk-based software.

Share:
34,875

Related videos on Youtube

xpt
Author by

xpt

Updated on September 18, 2022

Comments

  • xpt
    xpt over 1 year

    Is it still possible to mount VMWare disk images under Linux?

    I found the following two articles, both of them recommend to use kpartx -av diskimage-flat.vmdk. However both the articles are old and, when I try it on my Ubuntu Utopic 14.10, it no longer works any more.

    $ sudo kpartx -av MyWin81.vmdk
    
    $ sudo ls /dev/mapper/loop* | wc -l 
    ls: cannot access /dev/mapper/loop*: No such file or directory
    0
    

    Disclosure: My VMWare disk image IS a flat disk image. Furthermore (before you recommend loop mount), it is a multi-partition disk image, with first partition being Window8 and next two in Linux. It is the next two Linux partitions that I'm more interested to work on.

    Can someone confirm please? Thanks.

    Mount Flat VMWare Disk Images Under Linux http://cromoteca.com/en/blog/mountflatvmwarediskimagesunderlinux/

    Mount a VMware virtual disk (.vmdk) file on a Linux box http://www.commandlinefu.com/commands/view/12554/mount-a-vmware-virtual-disk-.vmdk-file-on-a-linux-box

    UPDATE:

    vmware-mount looks very promising, but I can't get it working yet:

    $ vmware-mount -p Win81.vmdk
    VixDiskLib: Invalid configuration file parameter. Failed to read configuration file.
    Nr      Start       Size Type Id Sytem                   
    -- ---------- ---------- ---- -- ------------------------
     1       2048   78643200 BIOS  7 HPFS/NTFS
     2   78645248    6039552 BIOS 83 Linux
     3   84684800   41144320 BIOS 83 Linux
    
    % vmware-mount Win81.vmdk 1 /mnt/tmp1/
    VixDiskLib: Invalid configuration file parameter. Failed to read configuration file.
    Failed to mount partition 1 of disk 'Win81.vmdk' on '/mnt/tmp1/': Insufficient permissions to perform this operation
    
    % vmware-mount -L
    VixDiskLib: Invalid configuration file parameter. Failed to read configuration file.
    No mounted disks.
    
    $ vmware-mount | head -3
    VixDiskLib: Invalid configuration file parameter. Failed to read configuration file.
    VMware DiskMount Utility version 6.0.0, build-2496824
    
    Usage: vmware-mount diskPath [partition num] mountPoint
    

    NB, the 2nd and 3rd command is run directly as root, yet I get "Insufficient permissions to perform this operation"?

    • farosch
      farosch about 9 years
      Confirmed. Or maybe try vboxmanage?
  • xpt
    xpt about 9 years
    Thanks. a) Please run lsb_release -a and uname -a and post back your results, so that people would know what OS your machine is, which has the loop devices. b) The 1st article you mentioned is the one I've already included in my OP. c) Thanks for the 2nd article, I'll give it a try.
  • jcoppens
    jcoppens about 9 years
    lsb_release is not a command which is available by default with all distros. I read your results. I use Virtualbox here, so I have no vmdk files to test on,
  • jcoppens
    jcoppens about 9 years
    Just another idea: It seems Virtualbox recognizes vmdk images. So maybe the remark from sehams on your original question is not as farfetched as it seemed to me. If you install VB, you could possibly use vboxmanage to convert, then just mount it with loop device.
  • Antonio Petricca
    Antonio Petricca almost 7 years
    How could I made it r/w?
  • xpt
    xpt over 6 years
    Thanks Eduard. Please let people know what OS your machine is on, e.g., run lsb_release -a and/or uname -a, and tell us the version of qemu and vmdisk that you are using now, then post back the results.
  • xpt
    xpt over 6 years
    Thanks MetalGodwin. Please let people know what OS your machine is on, e.g., run lsb_release -a and/or uname -a, and tell us the version of affuse and vmdisk that you are using now, then post back the results. Thx.
  • Stuart Cardall
    Stuart Cardall almost 6 years
    works with qemu-nbd 2.12.0 on Arch Linux - I had to skip using -r for a file on a filesystem mounted ro