Mount VMware Disk Images under Linux, using vmware-mount/vmware-loop

my

1.下载Linux版的vmware,我们需要用到tar包里的bin/vmware-loop和bin/vmware-mount.pl
jfo@jfo-laptop:~$ tar xvf VMware.Workstation.v5.5.1.19175.Linux.tar.gz ./vmware-distrib/bin


2.假设Windows下的虚拟机位于"/host/Virtual OS/Redhat9/"目录下,其Disk文件为Red Hat Linux.vmdk(Windows下和Linux下Disk文件通用),虚拟机配置文件为Red Hat Linux.vmx,需要建立一个指向这个配置文件的连接:
jfo@jfo-laptop:~$ sudo ln -sv "/host/Virtual OS/Redhat9/Red Hat Linux.vmx" /etc/vmware/config


3.添加一行内容:
jfo@jfo-laptop:~$ echo ‘loop.fullpath="/home/jfo/vmware-distrib/bin/vmware-loop"’ >> /etc/vmware/config


4.运行vmware-mount.pl

jfo@jfo-laptop:~/vmware-distrib/bin$ ./vmware-loop -p "/host/Virtual OS/Redhat9/Red Hat Linux.vmdk"

——————————————————————-
Virtual Hard Disk to Network Block Device mapper
Version: Releasebuild-19175
Copyright 1998-2003 VMware, Inc. All rights reserved.
——————————————————————-

Nr      Start       Size Type Id Sytem                  
– ———- ———- —- – ————————
1         63     208782 BIOS 83 Linux
2     208845   15518790 BIOS 83 Linux
3   15727635    1044225 BIOS 82 Linux swap

jfo@jfo-laptop:~$ sudo ~/vmware-distrib/bin/vmware-mount.pl "/host/Virtual OS/Redhat9/Red Hat Linux.vmdk" 2 ~/test/

vmware-mount.pl脚本实际上在/dev/目录下创建Network Block Device:
/dev/nb0: block special (43/0)
/dev/nbd0: block special (43/0)
/dev/nbd1: block special (43/1)


5.现在~/test/目录下就是VMware Disk Images的内容了


6.直接使用vmware-loop
vmware-mount.pl只是对vmware-loop做了一个wrap,当然也可以直接用vmware-loop
jfo@jfo-laptop:~$ sudo ~/vmware-distrib/bin/vmware-loop "/host/Virtual OS/Redhat9/Red Hat Linux.vmdk" 2 /dev/nbd3
jfo@jfo-laptop:~$ sudo mount /dev/nbd3 ~/test



my

http://www.vmware.com/support/reference/linux/loopback_linux.html#what
http://legroom.net/2007/08/05/how-mount-vmware-disk-images-under-linux

Accessing Virtual Hard Disks Outside of VMware Workstation for Linux

  1. Overview
  2. What is vmware-mount.pl?
  3. Requirements to run vmware-mount
  4. How to use vmware-mount
  5. Notes for advanced users
  6. Troubleshooting
  7. Download
  8. Known Problems


Overview

The easiest way to read or write files on a hard disk of a virtual machine is to start VMware Workstation, boot the virtual machine, then use a floppy disk drive or the network file system protocols (NFS, SMB/CIFS, etc.) to exchange data via your physical machine.

Sometimes, the amount of data you want to transfer is too large for a floppy, you don’t have the appropriate driver to run the network inside the virtual machine, or you cannot run a virtual machine because your license has expired For these reasons, you need a way to access the hard disk of the virtual machine directly from the host operating system, without having to run VMware Workstation.

When the hard disk of the virtual machine is a raw device or a raw disk (see Installing an Operating System onto a Raw Partition from a Virtual Machine or Configuring Dual/Multiboot Systems to Run With VMware Workstation), the problem is already solved: you can access the partition the same way you would access any other partition by first mounting it to a directory, then browsing the directory.

But when the hard disk of the virtual machine is a virtual disk (which is just a file when seen from your host operating system), you need the help of a program called vmware-mount.pl. This document describes how to use this program.

What is vmware-mount?

vmware-mount is a program that runs on the host operating system. It makes a virtual disk file appear as a hard disk to the operating system.

Requirements to run vmware-mount

vmware-mount requires a Linux kernel version 2.1.101 or higher (including the stable 2.2.x series) because this version introduced the concept of network block devices, which is heavily used by vmware-mount. vmware-mount is available as an add-on to VMware Workstation for Linux for both evaluation users and licensed customers. To install vmware-mount:

  1. Download the file
  2. Type:      su [ROOT PASSWORD]
  3. Type:      tar zxvf vmware-mount-addonXXX.tar.gz
  4. Type:      cd vmware-mount-addonXXX
  5. Type:      ./addon-install.pl

How to Use vmware-mount.pl

Say, for example, that your virtual hard disk file is ~/vmware/vhd.dsk. Follow these steps:

  1. Become root:
            su

  2. Determine the partition of the virtual hard disk to export: Issue the following command to print the partition table of the virtual hard disk:
       vmware-mount.pl -p ~/vmware/vhd.dsk

    ——————————————–
    VMware Workstation for Linux - Virtual Hard Disk Mounter
    Copyright (C) 1999 VMware, Inc.
    ——————————————–

    Nr Start Size Id Sytem
    – ——– ——— – ——————-
    1 63 4092417 C Win95 FAT32 (LBA)

    Now, find the partition number (first column) you want to export. Let’s say it is 1.

  3. Mount the disk partition on a directory. Let’s say you want to mount your partition on the directory /mnt/vhd. Issue the following command:
       vmware-mount.pl ~/vmware/vhd.dsk 1 /mnt/vhd

    ——————————————–
    VMware Workstation for Linux - Virtual Hard Disk Mounter
    Copyright (C) 1999 VMware, Inc.
    ——————————————–

    Network Block Device driver detected.

    Trying to map the partition to the /dev/nb0 Network
    Block Device.. Success.

    You can now browse your Virtual Hard Disk partition
    in /mnt/vhd Hit Control-C in this terminal when done.

    You can now browse /mnt/vhd as usual. It works as if a physical device were mounted on the directory When you are finished, simply kill vmware-mount.pl by typing Ctrl-C in its terminal.

Notes for Advanced Users

By using the vmware-loop binary directly, you can map the partition of a virtual hard disk to any network block device (which you can then mount). This mapping can be done in read-only mode if you use the -r command line option of vmware-loop.

Currently, a virtual hard disk can not be accessed in read/write mode by more than one application (VMware Workstation or vmware-mount for example) at a time.

Troubleshooting

vmware-mount claims that my Linux kernel is too old

See the Requirements section. You need to upgrade to a newer kernel. To do so, the easiest way is to upgrade your Linux distribution (installing the package corresponding to the most recent kernel). If you are able, you can also grab the latest kernel sources and compile your own kernel. Take a kernel version 2.1.101 or higher and set the CONFIG_BLK_DEV_NBD option (which you can find under Block devices > Network block device support) to "y" or "m" If you don’t want to mess with kmod (the kernel module loader formerly known as kerneld), we recommend to use "y".

Once you have rebooted your new kernel, rerun vmware-mount.pl.

vmware-mount keeps saying that it cannot open my virtual hard disk because it is locked by other VMs. What does that mean?

See the Notes for Advanced Users section. vmware-mount.pl has detected that several applications (VMware Workstation or vmware-mount.pl) are trying to access your virtual disk at the same time. First, be sure that this is not true If you are certain that two processes (including processes running on some remote machine) are not trying to simultaneously access your virtual hard disk, then it is probably a stale lock that hasn’t been cleaned up as it should have been. You can remove it safely.

If you experience further problems, please file a report. Be sure to select the "vmware-mount" category, and to include the output of your session with your report.


Known Problems

Under severe load, your host operating system may hang (lock solid) if you are writing to a virtual disk using vmware-mount.pl. VMware is aware of the problem and is working on a solution.

To avoid this problem, either use the read-only mode (see Notes for Advanced Users) or try to limit the throughput of data you write to your virtual disk.






end