VMware
VMware ESX Server 2.1
Features | Documentation | Knowledge Base | Discussion Forums

previous Prev   Contents   Last   Next next

Using vmkfstools

Using vmkfstools

The vmkfstools command supports the creation of a VMware ESX Server file system (VMFS) on a SCSI disk. Use vmkfstools to create, manipulate and manage files stored in VMFS volumes. You can store multiple virtual disk images on a single VMFS volume.

Note: You can also do most of the vmkfstools operations through the VMware Management Interface.

vmkfstools Command Syntax

vmkfstools Command Syntax

Note: You must be logged in as the root user to run the vmkfstools command.

vmkfstools Syntax When Specifying a SCSI Device

vmkfstools Syntax When Specifying a SCSI Device

The format for the vmkfstools command, when specifying a SCSI device, is:

vmkfstools <options> <device_or_VMFS_volume>[:<file>]

where <device_or_VMFS_volume> specifies a SCSI device (a SCSI disk or a partition on a SCSI disk) being manipulated or a VMFS volume, and <options> specifies the operation to be performed.

If <device_or_VMFS_volume> is a SCSI device, then it is specified in a form such as:

vmhba1:2:0:3

Here, vmhba1 specifies the second SCSI adapter activated by the command vmkload_mod .../XXX.o vmhba. (See VMkernel Module Loader for details on vmkload_mod.) The second number specifies the target on the adapter, the third number specifies the LUN (logical unit number) and the fourth number specifies the partition. Partition 0 (zero) implies the whole disk; otherwise, the number specifies the indicated partition.

<device_or_VMFS_volume> may also be a VMFS volume label, as set in the management interface or with the vmkfstools --setfsname command.

<file> is the name of a file stored in the file system on the specified device.

vmkfstools Syntax When Specifying a VMFS Volume or File

vmkfstools Syntax When Specifying a VMFS Volume or File

The format for the vmkfstools command, when specifying a VMFS volume or file, is:

vmkfstools <options> <path>

where <path> is an absolute path that names a directory or a file under the /vmfs directory.

For example, you can specify a VMFS volume by a path such as:

/vmfs/vmhba1:2:0:3

You can also specify a single VMFS file:

/vmfs/lun1/rh9.dsk

vmkfstools Options

vmkfstools Options

This section includes a list of all the options used with the vmkfstools command.

Some of the tasks in this section include options that are suggested for advanced users only. These advanced options are not available through the VMware Management Interface.

Note: The long and short (single letter) forms of options are equivalent. For example, the following commands are identical:

vmkfstools --createfs vmfs2 --blocksize 2m --numfiles 32 vmhba1:3:0:1

vmkfstools -C vmfs2 -b 2m -n 32 vmhba1:3:0:1

If the vmkfstools command fails, and you don't know why, then check the log files in /var/log/vmkernel or use the management interface to view the latest warning.

  1. Log in to the VMware Management Interface as root.

    The Status Monitor page appears.

  2. Click the Options tab.

    The Options page appears.

  3. Click System Logs.
Basic vmkfstools Options

Basic vmkfstools Options

Basic options are common tasks that you may perform frequently. You may also perform through the management interface.

<b>Creates a VMFS on the specified SCSI device </b>

Creates a VMFS on the specified SCSI device

-C --createfs [vmfs1|vmfs2]
-b --blocksize #[gGmMkK]
-n --numfiles #

This command creates a VMFS version1 (vmfs1) or version 2 (vmfs2) file system on the specified SCSI device.

For advanced users:

  • Specify the block size by using the -b option. The block size must be 2x (a power of 2) and at least 1MB. (The default file block size is 1MB.) You can specify the size in kilobytes, megabytes, or gigabytes by adding a suffix of k (kilobytes), m (megabytes), g (gigabytes) respectively.
  • Specify the maximum number of files in the file system with the -n option. The default maximum number of files is 256 files.
<b>Lists the attributes of a VMFS volume or a raw disk mapping </b>

Lists the attributes of a VMFS volume or a raw disk mapping

-P --querypartitions <VMFS_volume_name>
-P --querypartitions <VMFS_volume:fileName>

For a VMFS_volume_name, the listed attributes include the VMFS version number (VMFS-1 or VMFS-2), the number of physical extents (partitions) comprising the specified VMFS volume, the volume label (if any), the UUID (if any), and a listing of the SCSI device names of all the physical extents comprising the VMFS volume.

For a VMFS_volume:fileName, the listed attributes include the vmhba name of the raw disk or partition, corresponding to the mapping referenced by fileName, and any identification information for the raw disk.

<b>Creates a file with the specified size on the file system of the specified SCSI device </b>

Creates a file with the specified size on the file system of the specified SCSI device

-c --createfile #[gGmMkK]

The size is specified in bytes by default, but you can specify the size in kilobytes, megabytes, or gigabytes by adding a suffix of k (kilobytes), m (megabytes), g (gigabytes) respectively.

<b>Exports the contents of the specified file on the specified SCSI device to a virtual disk on the file system of the service console </b>

Exports the contents of the specified file on the specified SCSI device to a virtual disk on the file system of the service console

-e --exportfile <dstFile>

After the export, you may transfer the virtual disk to another server machine and import it to a SCSI device on the remote machine.

If your virtual disk has redo logs, you have the following options:

  • If you use the exportfile option on the base virtual disk, only the base virtual disk is exported. Any uncommitted redo logs are not exported, but can be copied out separately.
  • If you use the exportfile option on a ESX Server redo log, the exported virtual disk contains the redo log, any previously created redo logs, and the base virtual disk. That is, the newly created exported virtual disk appears as if the redo log(s) was committed to its base virtual disk.

    Note: However, your original source redo log(s) and base virtual disk remain unchanged.

  • If you want to export your redo logs and base virtual disk separately, then use the exportfile option to export the base virtual disk, and the cp command to export each redo log separately.

Use the combination of exportfile and importfile together to copy VMFS files to remote machines. The virtual disk should take less space than the full size of the VMFS file, since the virtual disk does not include zeroed sectors of the VMFS file.

<b>Imports the contents of a VMware virtual, plain, or raw disk on the service console to the specified file on the specified SCSI device </b>

Imports the contents of a VMware virtual, plain, or raw disk on the service console to the specified file on the specified SCSI device

-i --importfile <srcFile>

This command is often used to import the contents of a VMware Workstation or VMware GSX Server virtual disk onto a SCSI device. You may also run this command to import a virtual disk, that was created by exporting the contents of a disk from another SCSI device.

Note: The destination device must have space for the entire size of the virtual disk, even if it is mostly free space, as the complete contents of the source disk are copied.

Caution: The vmkfstools command may fail when attempting to import plain disks created with version 2.5 or earlier of GSX Server. If vmkfstools returns an error when importing a plain disk, see Path Name Failures When Importing GSX Server Virtual Machines.

<b>Lists the files on the file system on the specified device </b>

Lists the files on the file system on the specified device

-l --list
-h --human-readable
-M --verbosemappings

The output includes permissions, sizes and the last modification time for redo logs, virtual disk files, and swap files. You can use the -h option to print the sizes in an easier-to-read format; for example, 5KB 12.1MB, and so on.

(Advanced users only) The -M option lists the vmhba name that corresponds to each raw disk mapping.

<b>Sets the name of the VMFS on the specified SCSI device </b>

Sets the name of the VMFS on the specified SCSI device

-S --setfsname <fsName>

You can see the VMFS name by running the vmkfstools command with the -l option, vmkfstools -l.

Advanced vmkfstools Options

Advanced vmkfstools Options

Advanced options are tasks that you may perform infrequently. These tasks are not available through the management interface, or are available in a limited form, and are suggested for advanced users only.

<b>Commits the redo log of the specified file, making the associated changes permanent </b>

Commits the redo log of the specified file, making the associated changes permanent

-m --commit

If a virtual machine is in undoable or append mode, then the redo log is created automatically. The name of the redo log is derived by appending .REDO to the name of the file that contains the base disk image. You can commit the changes to the disk that are stored in the redo log by using the commit option or eliminate the changes by using the rm command to delete the redo-log file.

<b>Sets the VMFS on the specified SCSI device to the specified mode </b>

Sets the VMFS on the specified SCSI device to the specified mode

-F --config [public|shared|writable]

Note: In ESX Server 2.1, private VMFS volumes are deprecated. If you have existing VMFS version 1 (VMFS-1) or VMFS version 2 (VMFS-2) private volumes, then change the access to public.

Public —

With public VMFS-2 volumes, multiple ESX Server computers can access the same VMware ESX Server VMFS volume concurrently. VMware ESX Server file systems with a public access mode use an automatic per-file locking to ensure file system consistency.

With a public VMFS-1 volume, multiple ESX Server computers have the ability to access the VMware ESX Server VMFS volume, as long as the VMFS volume is on a shared storage system (for example, a VMFS on a storage area network). However, only one ESX Server can access the VMFS-1 volume at a time.

Note: ESX Server creates VMFS volumes as public by default.

Shared —

The shared access mode allows virtual machines on multiple servers to access the same virtual disk on a VMFS-2 volume simultaneously. (In public mode, virtual machines can only access the same VMFS volume, never the same virtual disk, at the same time.)

Note: A VMFS volume that is used for failover-based clustering should have its mode set to shared.

Writable —

When virtual machines access a file on a shared VMFS, the file system metadata becomes read-only. That is, no virtual machine or user command can create, delete or change the attributes of a file.

If you need to create, remove, or change the length of a file (vmkfstools -X), then you need to change the volume to "writable". First, be sure that no virtual machines are accessing the VMFS volume (all virtual machines are powered off or suspended), then change the file system metadata to writable with the command, vmkfstools --config writable. Once you power on or resume a virtual machine, the file system metadata reverts to being read-only.

<b>Extends an existing logical VMFS-2 volume by spanning multiple partitions </b>

Extends an existing logical VMFS-2 volume by spanning multiple partitions

-Z --extendfs <extension-SCSIDevice>
-n --numfiles #

This option adds another physical extent (designated by <extension-SCSIDevice>), starting at the specified SCSI device. By running this option, you lose all data on <extension-SCSIDevice>.

Note: A logical VMFS-2 volume can have at most 32 physical extents.

This operation is not supported on the VMFS-1 file system and in fact, returns an error if the specified SCSI device is formatted as VMFS-1. Each time you use this option and extend a VMFS-2 volume with a physical extent, the VMFS volume supports, by default, an additional 64 files. You can change this default number of files by using the -n option.

<b>Maps a Raw Disk or Partition to a File on a VMFS-2 Volume </b>

Maps a Raw Disk or Partition to a File on a VMFS-2 Volume

-r --maprawdisk <raw-SCSI-device>

Once this mapping is established, you can access the raw disk like a normal VMFS file. The file length of the mapping is the same as the size of the raw disk or partition. The mapping can be queried for the raw SCSI device name by using the -P option.

By mapping a raw disk or partition to a file, you can manipulate this raw disk or partition as any other file. In addition, this mapping enables you to have undoable, append, and nonpersistent "raw disks".

All VMFS-2 file-locking mechanisms apply to raw disks.

<b>Displays Disk Geometry for a VMware Workstation or GSX Server Virtual Disk </b>

Displays Disk Geometry for a VMware Workstation or GSX Server Virtual Disk

-g -- geometry <virtual-disk>

The output is in the form: Geometry information C/H/S is 1023/128/32, where C represents the number of cylinders, H represents the number of heads, and S represents the number of sectors.

When importing VMware Workstation or VMware GSX virtual disks to VMware ESX Server, you may see a disk geometry mismatch error message. A disk geometry mismatch may also be the cause if you have problems loading a guest operating system, or running a newly created virtual machine.

View the events log through the VMware Management Interface (Users and Events page for the virtual machine) or through the service console (the vmware.log file, found, by default, in the <user>/vmware/<guest_operating_system> directory). Look for C/H/S and compare this with the output of the vmkfstools -g command.

If the disk geometry information is different, then specify the correct information, from the output of the vmkfstools -g command, in the configuration file of the newly created virtual machine.

See Migrating VMware Workstation and VMware GSX Server Virtual Machines for complete details on specifying the disk geometry in a virtual machine's configuration file.

<b>Extends the specified VMFS to the specified length </b>

Extends the specified VMFS to the specified length

-X --extendfile #[gGmMkK]

Use this command to extend the size of a disk allocated to a virtual machine, after the virtual machine has been created. The virtual machine that uses this disk file must be powered off when you enter this command. Also, the guest operating system must be able to recognize and use the new size of the disk, for example by updating the file system on the disk to take advantage of the extra space.

You specify the size in kilobytes, megabytes, or gigabytes by adding a suffix of k (kilobytes), m (megabytes), g (gigabytes) respectively.

<b>Manages SCSI reservations of physical targets or LUNs </b>

Manages SCSI reservations of physical targets or LUNs

-L --lock [reserve|release|reset]

Caution: Be careful when using these commands. The reserve, release, and reset commands can interrupt the operations of other servers on a storage area network (SAN), so use these commands with great caution.

The -L reserve command reserves the specified raw disk, or the disk containing the specified VMFS volume. After the reservation, other servers will get a SCSI reservation error if they attempt to access that disk, but the server that did the reservation will be able to access the disk normally.

The -L release command releases the reservation on the specified disk, or disk containing the specified VMFS volume. Any other server can access the disk again.

The -L reset command does a SCSI reset to the specified disk. Any reservation held by another server is released.

<b>Recovers a VMFS </b>

Recovers a VMFS

-R --recover

This command enables you to recover a VMFS (accessible by multiple ESX servers) when other vmkfstools commands indicate that the file system is locked by another ESX Server machine, but, in fact, no other server is currently accessing this file system. This situation may occur if the VMFS was being accessed by a server (for example, running a virtual machine) and that server crashed.

Note: You should only use this command if you are certain that no other ESX Server is still accessing the file system.

<b>Scans the specified vmhba adapter for devices and LUNs </b>

Scans the specified vmhba adapter for devices and LUNs

-s --scan <FC_SCSI_adapter>

This option is particularly useful for adapters connected to storage area networks, particularly if you are reconfiguring your SAN. If a new device or LUN becomes accessible through the adapter, then ESX Server registers this new virtual device for use by virtual machines. If an existing device or LUN is no longer used and appears to be gone, then it is removed from use by virtual machines.

Note: Only use this -s option for Fibre Channel adapters.

You can see the results of the scan by using ls /vmfs or looking at the contents of /proc/vmware/scsi.

<b>Create or Resize a Swap File in a VMFS Volume of the specified SCSI device </b>

Create or Resize a Swap File in a VMFS Volume of the specified SCSI device

-k --createswapfile #[gGmMkK]

The size is specified in bytes by default, but you can specify the size in kilobytes, megabytes, or gigabytes by adding a suffix of k (kilobytes), m (megabytes), or g (gigabytes), respectively.

Note: You must be logged in to the Service Console with root user permissions to create a swap file.

You can resize an existing swap file by specifying the new file size as an argument to the -k option:

  1. Deactivate the swap file, if it is active, with vmktools -y.
  2. Resize the swap file with the -k option.
  3. Activate the swap file with vmktools -w filename.

If you try to resize an active swap file, ESX Server returns an error message.

ESX Server does not automatically activate a swap file after it is created. Use vmkfstools with the -w option to activate a swap file. You can set a swap file to be activated automatically after a system reboot with the Activation Policy option of the Swap Management section in the Options tab of the Management Interface.

Activate a Swap File

Activate a Swap File

-w --activateswapfile

This command activates the specified swap file.

Note: You must be logged in to the Service Console with root user permissions to activate a swap file.

Deactivate a Swap File

Deactivate a Swap File

-y --deactivateswapfile <fileID>

ESX Server assigns a fileID tag to a swap file when it is activated. You must identify a swap file by its fileID tag when specifying which swap file to deactivate with the -y option.

Note: You must be logged in to the Service Console with root user permissions to activate a swap file.

You can find the fileID tag assigned to a swap file in the swap status file, /proc/vmware/swap/stats.

Note: You must shutdown all virtual machines before deactivating a swap file. Entering a vmkfstools -y command returns an error message if any virtual machines are powered on.

<b>Migrate a VMFS from VMFS-1 to VMFS-2 </b>

Migrate a VMFS from VMFS-1 to VMFS-2

-T --tovmfs2

This command converts the VMFS volume on the specified partitions from VMFS-1 to VMFS-2, while preserving all files in the volume. ESX Server's locking mechanism attempts to ensure that no remote ESX Server or local process is accessing the VMFS volume that is being converted.

Note: If you have an active swap partition, you must deactivate it before running this command. Deactivate swap through the VMware Management Interface and reboot your server. Once this vmkfstools -T command completes, you can reactivate your swap file.

This conversion may take several minutes. When your prompt returns, the conversion is complete.

Note: In ESX Server 2.1, private VMFS volumes are deprecated. If you have an existing VMFS version 1 (VMFS-1) private volume, then the newly created VMFS-2 volume's access mode is automatically changed to public.

Before starting this conversion, check the following:

  • Back up the VMFS-1 volume that is being converted
  • Be sure there are no virtual machines powered on using this VMFS-1 volume
  • (SAN only) Be sure no other ESX Server is accessing this VMFS-1 volume
  • (SAN only) Be sure this VMFS-1 volume is not mounted on any other ESX Server

Caution: The VMFS- 1 to VMFS-2 conversion is a one-way process. Once the VMFS volume is converted to VMFS-2, you cannot revert it back to a VMFS-1 volume.

Note: The first time you access a newly converted VMFS-2 volume, the initial access will be slow, because of internal volume consistency checking.

Examples Using vmkfstools

Examples Using vmkfstools

This section includes examples using the vmkfstools command with the different options described previously.

<b>Create a new file system </b>

Create a new file system

vmkfstools -C vmfs2 -b 2m -n 32 vmhba1:3:0:1

This example illustrates creating a new VMFS version 2 (vmfs2) on the first partition of target 3, LUN 0 of SCSI adapter 1. The file block size is 2MB and the maximum number of files is 32.

<b>Extends the new logical volume by spanning two partitions </b>

Extends the new logical volume by spanning two partitions

vmkfstools -Z vmhba0:1:2:4 vmhba1:3:0:1

This example illustrates extending the new logical file system by adding the 4th partition of target 1 (and LUN 2) of vmhba adapter 0. The extended file system supports a maximum of 64 (2 X 32) files, and spans two partitions — vmhba1:3:0:1 and vmhba0:1:2:4.

You can address the file system by using the name of its head partition; for example, vmhba1:3:0:1.

<b>Names a VMFS volume </b>

Names a VMFS volume

vmkfstools -S mydisk vmhba1:3:0:1

This example illustrates assigning the name of mydisk to the new file system.

<b>Creates a new VMFS virtual disk file </b>

Creates a new VMFS virtual disk file

vmkfstools -c 2000m mydisk:rh6.2.dsk

This example illustrates creating a 2GB VMFS file with the name of rh6.2.dsk on the VMFS volume named mydisk. The rh6.2.dsk file represents an empty disk that may be accessed by a virtual machine.

<b>Imports the contents of a virtual disk to the specified file on a SCSI device </b>

Imports the contents of a virtual disk to the specified file on a SCSI device

vmkfstools -i ~/vms/nt4.dsk vmhba0:2:0:0:nt4.dsk

The example illustrates importing the contents of a virtual disk (that contains Windows NT 4.0) from the service console's file system to a file named nt4.dsk on target 2 of SCSI adapter 0.

You can configure a virtual machine to use this virtual disk by adding the following lines to its configuration file:

scsi0.virtualDev = vmxbuslogic
scsi0:0.present = TRUE
scsi0:0.name = vmhba0:2:0:0:nt4.dsk

<b>Migrate virtual machines to VMware GSX Server or VMware Workstation, then back to VMware ESX Server </b>

Migrate virtual machines to VMware GSX Server or VMware Workstation, then back to VMware ESX Server

Note: The following example, illustrating the -e and -i options, result in the export or import of a virtual disk.

This example illustrates migrating a virtual machine's virtual disk file from ESX Server to VMware GSX Server or VMware Workstation, then migrating the virtual disk back to ESX Server.

vmkfstools -e winXP.vmdk vmhba0:6:0:1:winXP.dsk

The preceding command exports the winXP.dsk virtual disk file to one or more .vmdk files, maximum size 2GB, that you can use as a virtual disk in a virtual machine on GSX Server or Workstation. The resultant winXP.vmdk file(s) can reside on a VMFS volume, or an /ext2, /ext3, or NFS file system.

The following example imports a GSX Server or Workstation virtual disk file into the VMFS volume on the specified SCSI device.

vmkfstools -i winXP.vmdk vmhba0:6:0:1:winXP.dsk

By contrast, if you are importing directly into a raw partition, the example becomes:

vmkfstools -i winXP.vmdk vmhba0:6:0:1

<b>Lists the files on the VMFS of the specified device </b>

Lists the files on the VMFS of the specified device

vmkfstools -l vmhba0:2:0:0

This command illustrates listing the contents of the file system, including redo logs, virtual disk files, and swap files on target 2 of SCSI adapter 0.

<b>Scans a vmhba adapter </b>

Scans a vmhba adapter

This example illustrates scanning the vmhba1 adapter for any new or removed targets or LUNs.

vmkfstools -s vmhba1

previous Prev   Contents   Last   Next next