Cool Solutions

Retrieve/Modify/Backup Files Inside the VMDK in Offline Mode



By:

June 18, 2009 12:51 pm

Reads: 18567

Comments:0

Score:0

VMDK is a virtual disk format by VMware for its virtual machines for different types of servers. Like VMware ESX Server, VMware Workstation, VMware Player, VMware ACE, VMware Fusion, VMware Server, and VMware GSX Server 3.x and 2.5.

This is an emulation of a real hard disk. The more efficient virtual disk, the Guest OS will be running.

As IT is moving towards Server Consolidations, the need for knowledge of managing and administration of Virtual Machines is also necessary.

The important configurable elements of virtual machines are CPU, Memory, and Disk. We need to add the virtual disks or manage them very frequently depending on the demand or utilization of space by the workload in the Data Center.

What is a Virtual Disk?

A Virtual Disk is nothing but a file(s) that emulates a physical disk to the Guest Operating System when attached to it. These virtual disks can be in the same local machine or it may be in any remote storage reachable by the host. Remote Storage can be ISCSI, SAN, or NAS that are attached to the host. We can use virtual disks to store the data or install the OS in them.

We can configure virtual disks in two modes, Preallocated Disks and Growable Disks.

In Preallocated disks, the space for the virtual disk is allocated when it is created, but in Growable disks the space will get allocated to it whenever it requires, but it is suggested to use the “Preallocated disk” type mode for good performance of a VM because it takes longer to write the data to the virtual disks of Growable disk mode.

How the file system affects the size of Virtual disk.

The size of the virtual disk file is limited by both the Hypervisor and the file system. Suppose the support of storage file system max file size is 10GB, then we can’t create a virtual disk file more than 10GB. Instead we will create multiple max size files and attach to the virtual machine.

The hypervisor can also limit the max file size of a virtual disk for many reasons like performance or taking backups, etc.

For a VMware virtual disk we can configure the disk to be an Independent Disk type which adds a control and complexity layer to the virtual disks. Once the virtual disk is configured as an Independent disk then we can configure it as a Persistent or Non-Persistent disk.

In Persistent disks, the changes made to the disks are saved permanently, but in the Non-Persistent disks the changes are lost when the virtual machine is powered off.

Adding the virtual disk to the virtual machine isn’t enough for the Guest OS to start using it.
When we add the disk for the first time it will be in raw disk format.

This article explains about how to add the extra virtual disks to a Virtual Machine which is a very specific to vmware visualization solutions and a common procedure how to use them in the Guest OS.

The way to add virtual disks to a Virtual Machine may vary from one virtualization solution to the other virtualization solution but once it is added to the Virtual Machine the remaining process is common.

This article is useful for System Administrators, Software Developers, QA engineers, and anyone who wants to mount virtual hard disks outside of virtual machines.

The data will be locked inside the virtual disk. If the VM gets corrupted, it can be because of many reasons:

  1. Missing snapshots files
  2. Deleted log files
  3. Inside the guest OS some os files got deleted.
  4. Virus attack of the VMDK file or VM associated files. And many more unexpected reasons.

VMware Disk Mount Utility

VMware published a tool for mounting the VMDK image. The tool is the VMware Disk Mount Utility for Windows and Linux hosts.

This tool allows users to mount virtual disks of a virtual machine when it’s in the off state.

With this utility, if there are multiple partitions in the disk we can mount specific volumes.

We can mount the partitions in the disk both in read-only and read-write modes.

Using the Utility on Linux Hosts:

Requirements: FUSE libraries should be installed. Refer to (http://fuse.sourceforge.net/) for downloading the FUSE libraries, configuring and installing it. Install the FUSE libraries before installing the VMware Disk Mount utility.

Steps to use the utility in Linux Hosts:

Step 1: Download the VMware vix disklib from the location (http://www.vmware.com/download/download.do?downloadGroup=VDDK-1-0).
Step 2: Unzip and file with tar command.
Step 3: Open the terminal and navigate to the extracted folder and execute the command vmware-CHECK this.
Step 4: After installing the utility check by typing vmware-mount –help
We can use this utility for mounting both the local and remote disks.

How to mount a local disk:

Suppose the virtual machine folder is in /home/tux/VM/mylinux

First, we will find how many volumes are present in the virtual disk. To find the number of volumes in the virtual disk:

code:

syntax:

vmware-mount -p <absolute path of the vmdk file>
vmware-mount -p /home/tux/VM/mylinux/mylinux.vmdk

output:

		Nr      Start       Size Type Id Sytem                   
-- ---------- ---------- ---- -- ------------------------ 
 1         63    1060227 BIOS 82 Linux swap 
 2    1060290    9414090 BIOS 83 Linux
 

It’s up to us on how many partitions to be mounted from the virtual disk.

To mount the partition first create a mount point.

code:

mkdir $HOME/diskpart1

syntax:

vmware-mount <absolute path> -v 1
vmware-mount /home/tux/VM/mylinux/mylinux.vmdk -v 2

If there are no errors, then the partition is successfully mounted.

NOTE: We can’t mount the SWAP partition with vmware-mount.

NOTE: A log file will be created with the results of each operation at
/tmp/vmware-<username>/fuseMount.log.

If you get an error like the following:

"/dev/loop0 looks like swapspace - not mounted 
	mount: you must specify the filesystem type"

It means you are trying to mount the swap partition of a disk.

In this manner we can mount the local VMDK disks and backup or copy the files to the disk when the VM is in shutdown state.

How to unmount the disk:

vmware-mount -d <mountpoint>

Ex:

vmware-mount -d /mnt/mount1

How to mount a remote VMDK disk:

To mount the Remote VMDK disk we should know the following information of the vmdk file:

Command to find the number of partitions in the disk.

vmware-mount -p -v "${inv_path}" -u "${user}" -h "${host}" -F "${passwdfile}" 
"${img_path}" 

Command to mount the partitions in the disk.

vmware-mount -v "${inv_path}" -u "${user}" -h "${host}" -F "${passwdfile}" "${img_path}" "${part_no}" "${mount_dir}"

inv_path = inventory path of the VM (explained in the below section How to find the Inventory Path of the Virtual Machine)
host = Vcenter host or the Esx Server
user = Vcenter username or the Esx user name (user should have rights to access the disks)
passwordfile = the password should be stored in a file in the local machine and provide the path of the file.
img_path / path of the disk = in the below section, discussed how to find the path of the disk or image path
part_no = which partition number to be mounted.
mount_dir = mount point in the local machine.

Use the first command to print the partitions.
Use the second command to mount the partitions.

How to unmount the remote disk:

vmware-mount -d <mountpoint>

Or you can use the disk id to unmount the disk.

vmware-mount -k root@esx3.myhost.com:[storage1]sles11/sles11.vmdk

You can use the -x or -X option to unmount, or force-unmount, all partitions.

How to find the Inventory Path of the Virtual Machine:

Step 1: Login to the webaccess of the ESX Machine or vCenter Machine.

Open the browser and type the url as https://<server ip or hostname>/mob
The login page will appear.
Provide the necessary credentials.

After a successful login, the above page will appear for browsing the Managed Objects of The ESX Server.

Step 2: Click on the “Content” link.

A similar page will appear. Each link corresponds to view the specific managed objects.

Click on the “ha-folder-root” link.

The above page should appear when you click on the ha-folder-root link. This is the starting page for the Datacenter Managed Objects.

Click on the “ha-datacenter” link.

This page lists all the Managed objects that are accessed in the DataCenter. Like datastores, Virtual machines, networks, etc.

Click the “ha-folder-vm” link. This will direct you to all the Virtual Machines Managed Objects.

In the page, look at the properties.

In the first row, childEntity, all the values which are integer values are the managed objects of a Virtual Machine.

Find the VM by clicking on the values. When you click on a particular number it will redirect to the MO of a VM.

Click on the value (64), it will direct you to the Managed Object VM name “base linux”.

In the properties section, check the “name” property to find the name of the Virtual Machine.

Now we need to start creating the Inventory path for the VM.

Take the value of the VM name and append it to the Invpath= \baselinux.

In the same page look over the “parent” property and click on it (ha-folder-vm) and get the value of the property “name” and prepend it to the Invpath = \vm\baselinux

Again click on the “parent” property and collect the “name” property and append the value to the Invpath= \ha-datacenter\vm\baselinux

Keep on repeating the process until you reach the parent folder as “ha-folder-root”.

DON’T add the “ha-folder-root” property name.

This is how to find the Inventory path of a VM when managing from the vCenter or ESX Server.

NOTE: Inventory path is required only if we are mounting the Disks remotely either from vCenter or from ESX Server.

How to find the path of the disk:

Login to the VI Client on the machine where the virtual machine is residing.
Right click on the VM.
Select “Edit Settings”.
The Virtual Machine properties Dialog appears.
Select the hard disk to be mounted.
The Disk File value is the “path of the disk”.

Using the utility on Windows Hosts:

After installing, go the installed folder (C:\Program Files_XP\VMware\VMware Virtual Disk Development Kit\bin), add the path to the system path.

How to add the path to the system path:

Right click on the MyComputer, select properties.

Go to the “Advanced” tab. Click on “Environment Variables”.

Click on the “PATH” and add the bin folder path to it. (C:\Program Files_XP\VMware\VMware Virtual Disk Development Kit\bin). (“;” is the delimiter);

How to mount a local disk:

E:\>vmware-mount /?
VMware-mount [driveletter:] [path-to-virtual-disk] [options]
VMware DiskMount Utility version 3.0.3 build-99018
Copyright (c) 1998-2008 VMware, Inc. All rights reserved.
This utility mounts VMware virtual disks under Microsoft Windows.
Use "VMware-mount" without arguments to list the currently-mounted volumes.

/v:N             mounts volume N of a virtual disk (default=1)
/d               deletes the mapping to a virtual drive volume
/f               forcibly deletes the mapping to a virtual drive volume
/p               displays the partitions (volumes) on a virtual disk (local di
sks only)
/L               lists the currently-mounted volumes
/i:InventoryPath inventory path of the VM owning the virtual disk
/m:[w|n]         mount in read-'w'rite or 'n'on-persistent mode
/h:host          name or address of server to access managed virtual disk
/u:userid        user name on the server
/s:password      password on the server
/P:port#         port number to access the server (default=902)
/?               displays this usage information

To find the number of partitions in the disk:

Vmware-mount /p <path of the .vmdk file>

To mount the partitions ( say 1 ):

vmware-mount <drive letter> /v:<partition number> <path of the virtual disk.vmdk>

In the above example, the first partition is mounted as Z:

We can mount the partitions both in read and write modes or persistent mode with the /m[w:n] option in the command.

To find all the mounted volumes:

vmware-mount /L command will list all the mappings and the mounted partitions

C:\>vmware-mount /L
Z:\  =>  C:\srm-srv-winvista32.vmdk

To unmount the mounted volumes, use the /d with the driver letter to unmount them.

NOTE: When unmounting the drives make sure that the drive is not in use by any other programs to ensure data integrity.

NOTE: The logs for vmware-mount operations will be created at the location
C:\Documents and Settings\<user>\Local Settings\Temp\vmware-<user>-<nnnn>/vmount.log

How to mount a remote disk:

The following information should be known to mount the remote disk:

  1. Inventory path
  2. Username (vCenter or ESX server depends which inventory path)
  3. Password
  4. Path to the disk

The above section “How to find the Inventory Path of the Virtual Machine” will guide you how to find the inventory path of a VM (when managing from vCenter or ESX Server).

Provide the necessary credentials. (Depends from which service we want to access the disk.

NOTE: From the Windows host for the remote disks, it’s not possible to find the number of partitions in the virtual disk.

Command:

vmware-mount K: "[storage1] <VMname>/<VMname>.vmdk" /i:<invpath> /h:<host> /u:<user> 	/s:<password>

Example:

vmware-mount K: "[storage2] win2k3/win2k3vmdk" /i:Datacenter/vm/win2k3  /h:vchost /u:administrator /s:tux

To find all the mounted disks:

Vmware-mount /L 

How to unmount the disk:

vmware-mount <driveletter> /d

NOTE: vmware-mount might produce an error saying “failed to load library libcrypto.so.0.9.8 [or] libssl.so.0.9.8… cannot open shared object file.”

FUSE mount requires these libraries, but does not install them.

If vmware-mount complains about missing libraries:

To avoid this problem, add the location of the missing libraries to your LD_LIBRARY_PATH environment as in this example, and run vmware-mount again:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib:
/usr/local/lib/vmware/lib/libcrypto.so.0.9.8:/usr/local/lib/vmware/lib/libssl.so.0.9.8
ldd /usr/bin/vmware-mount
vmware-mount

The first two lines constitute a single command, so type Enter only after 0.9.8. The ldd command is diagnostic, to verify dependencies.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags:
Categories: Uncategorized

Disclaimer: This content is not supported by Novell. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.

Comment

RSS