Wednesday, October 5, 2011

Virtual Machine File Management using vmkfstools

n Introduction to Virtual Machine File Management


n Managing the Virtual Machine File System with vmkfstools

vmkfstools  File System Options
Using vmkfstools file system commands, yopu can create, query, and extend a VMFS file system. These options do not apply to NFS file systems.
(1) Creating a VMFS File System
     vmkfstools  <conn_options>  -C vmfs3 -b <block_size>kK|mM  -S <fsName>
     vmkfstools  <conn_options>  --createfs vmfs3 --blocksize <block_size>kK|mM  --setfsname <fsName>


(2) Listing VMFS Volume Attributes
    vmkfstools   <conn_options>  -P  /vmfs/volumes/my_vmfs
    vmkfstools   <conn_options>  --queryfs  /vmfs/volumes/my_vmfs

C:\>vmkfstools.pl --server esx1.virtuallab.com --username root --password esxsvr40  -P /vmfs/volumes/Storage1
VMFS-3.33 file system spanning 1 partitions.
Capacity : 41607495680, 33135001600 avail
File system label : Storage1
UUID : 4e7361ce-9cb305f4-f136-000c29f15a51
path : /vmfs/volumes/4e7361ce-9cb305f4-f136-000c29f15a51
Partitions spanned:
mpx.vmhba0:C0:T0:L0:5

C:\>vmkfstools.pl --server esx1.virtuallab.com --username root --password esxsvr40  --queryfs /vmfs/volumes/Storage1
VMFS-3.33 file system spanning 1 partitions.
Capacity : 41607495680, 33135001600 avail
File system label : Storage1
UUID : 4e7361ce-9cb305f4-f136-000c29f15a51
path : /vmfs/volumes/4e7361ce-9cb305f4-f136-000c29f15a51
Partitions spanned:
mpx.vmhba0:C0:T0:L0:5

(3) Extending VMFS Partitions by Spanning
  vmkfstools  <conn_options>   -Z            <span-partition>  <head-partition>
  vmkfstools  <conn_options>   --spanfs   <span-partition>  <head-partition>


vmkfstools Virtual Disk Options
(1) Supported Disk Formats

zeroedthick(default)
Space required for the virtual disk is allocated during creation. Any data remaining on the physical device is not erased during creation, but will be zeroed out on demand the first time the virtual machine writes to disk. The virtual machine does not read stale data from disk.
eagerzeroedthick
Space required for the virtual disk is allocated at creation time. In contrast to zeroedthick format, the data remaining on the physical device zeroed out during creation. It night take much longer to create disks in this format than to create other types of disks.
thin
Thin-provisioned virtual disk. Space required for the virtual disk is not allocated during creation, but is supplied, zeroed out, on demand at a later time. Convert thin-provisioned disks wth the -j option.
rdm
virtual compatibility mode raw disk mapping
rdmp
Physical compatibility mode (pass-through) raw disk mapping
2gbsparese
Sparse disk with 2GB maximum extent size. You can use disks in this format with other VMware products such as VMware Workstation. You cannot power on a sparse disk on an ESX/ESXi host unless you first reimport the disk in a compatible format, such as thin, with vmkfstools.



With NFS files, vmkfstools supports only thin, zeroedthick, and 2gdsparse format. Because the NFS server and not the ESX/ESXi system decides the allocation policy, zeroedthick, and thin usually have the same result. The default allocation policy on most NFS servers is thin.
(2) Creating Virtual Disks
     With  -C/--createvirtualdisk option, vmkfstools accepts zeroedthick, eagerzeroedthick and thin format.
      -C/--createvirtualdisk  <size>[kK|mM|gG]   -a/--adaptortype [buslogic|lsilogic|ide] <srcfile>  -d/--diskformat [thin|zeroedthick|eagerzeroedthick] <location>

(3) Initializing Virtual Disks
-w/--writezeros

(4) Inflating Thin Virtual Disks
-j/--inflatedisk
The -j option converts a tin provisioned disk to eagerzeroedthick format and preserves all existing data. vmkfstools allocates and zeros out any blocks that were not allocated.

(5) Deleting Virtual Disks
-U/--deletevirtualdisk  <conn_options>  <location>

(6) Renaming Virtual Disk
-E/--renamevirtualdisk  <oldname> <newname>

(7) Cloning Virtual or Raw Disks
     With -i/--clonevirtualdisk option, vmkfstools accepts zeroedthick, thin, eagerzeroedthick, rdm:<device>, rdmp:<device> and 2gpsparse format.
-i/--clonevirtualdisk  <srcfile>  <destfile>  -d/--diskformat [zeroedthick|thin|eagerzeroedthick|rdm:<device>|rdmp:<device>|2gbsparse]  -a/--adaptertype  <type>   

(8) Migrating VMware Workstation and VMware GSX Server Virtual Machines
You cannot use the vSphere Client to migrate virtual machines created with VMware Workstation or VMware GSX Server to your ESX/ESXi system. However, you can use the vmkfstools -i command to import the virtual disk into your ESX/ESXi system. You can then attach this disk to a new virtual machine that you create in the ESX/ESXi system. You must import the virtual disk first, because you cannot power on disks exported in 2gbsparse format on an ESX/ESXi host.

(9) Extending Virtual Disks
-X/--extendvirtualdisk  [-d  eagerzeroedthick]  <newsize> [kK|mM|gG]  <v_disk>

newsize defines the entire new size, not just the increment that you add to the disk.

1.         Shut down the virtual machine associated with the disk, either by using the vSphere Client or by using vmware-cmd .
vmware-cmd -H <vc_system> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx stop  <powerop_mode>
Specify hard to force the shutdown, or soft to have the system attempt to shut down the guest operating system.
2.         Run vmkfstools -X with connection options, the new size, an optional new format, and the location for the virtual disk.
vmkfstools <conn_options> -X 50M /vmfs/volumes/Storage2/testvm/testvm.vmdk


(10) Displaying Virtual Disk Geometry
-g/--geometry

(11) Managing Raw Device Mapping Files
Creating virtual compatibility mode raw device mappings
-r/--createrdm  <device>  <rdm_file>

1.         Run vmkfstools -r with connection options, the device to map as a raw disk, and the name of the RDM file.
vmkfstools <conn_options> -r /vmfs/devices/disks/naa.<naa_id>  /vmfs/volumes/storage1/rdm210.vmdk
The command creates a virtual compatibility mode RDM file /vmfs/volumes/storage1/rdm210.vmdk and maps the /vmfs/devices/disks/naa.<naa_id> raw disk to that file.
2.         Configure a virtual machine to use the my_rdm.vmdk mapping file by using the vSphere Client or by adding the following lines to the virtual machine configuration file.
scsi0:0.present = TRUE
scsi0:0.fileName = /vmfs/volumes/myVMFS/my_rdm.vmdk
You can use vifs to copy the file from the remote ESX/ESXi system to your local machine and back


creating physical compatibility mode raw device mappings
-z/--createrdmpassthru   <device>  <map_file>
1.         Run vmkfstools -z with connection options, the device to map as a raw disk, and the name of the RDM file.
vmkfstools <conn_options> -z /vmfs/devices/disks/naa.<naa_id>  /vmfs/volumes/storage1/rdmpass.vmdk
The command creates a physical compatibility mode RDM file /vmfs/volumes/storage1/rdmpass.vmdk and maps the /vmfs/devices/disks/naa.<naa_id> raw disk to that file. You cannot use the name of a file that already exists.
2.         Configure a virtual machine to use the rdmpass.vmdk mapping file by using the vSphere Client or by adding the following lines to the virtual machine configuration file:
scsi0:0.present = TRUE
scsi0:0.fileName = /vmfs/volumes/myVMFS/rdmpass.vmdk


RDM Virtual and Physical Compatibility Modes
You can use RDMs in virtual compatibility or physical compatibility modes. Virtual mode specifies full virtualization of the mapped device. Physical mode specifies minimal SCSI virtualization of the mapped device. Physical mode allows the greatest flexibility for SAN management software.
n In virtual compatibility mode, the mapped device appears to the guest operating system exactly the same as a virtual disk file in a VMFS volume. The actual hardware characteristics are hidden. If you use a raw disk in virtual mode, you can realize the benefits of VMFS such as advanced file locking for data protection and snapshots for streamlining development processes. Virtual mode is also more portable across storage hardware than physical mode. A virtual mode mapped device presents the same behavior as a virtual disk file.
n In physical compatibility mode, the VMkernel passes all SCSI commands to the device, with one exception: the REPORT LUNs command is virtualized so that the VMkernel can isolate the LUN for the owning virtual machine. Otherwise, all physical characteristics of the underlying hardware are exposed. Physical mode is useful to run SAN management agents or other SCSI targetbased software in the virtual machine. Physical mode also allows virtualtophysical clustering for costeffective high availability.





C:\ >vmkfstools.pl --help

Synopsis: C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\vmkfstools.pl OPTIONS [<diskpath>]


Command-specific options:
   --adapterType
    -a
         The adapter type of a disk to be created. Accepts buslogic, lsilogic or ide.

   --blocksize
    -b
         The block size of the VMFS file system to create. When omitted, the creation defaults to using 1MB for the blocksize.

   --clonevirtualdisk
    -i
         Create a copy of a virtual disk or raw disk. The copy will be in the specified disk format. Takes source disk as argument.

   --createfs
    -C
         Creates a VMFS file system, requires -S, and optionally -b

   --createrdm
    -r
         Creates raw disk mapping, takes the disk device path. Map a raw disk to a file on a VMFS file system. Once the mapping is established, it can be used to access the raw disk like a normal VMFS virtual disk. The 'file length' of the mapping is the same as the size of the raw disk that it points to.

   --createrdmpassthru
    -z
         Creates passthrough raw disk mapping, takes the disk device path. Once the mapping is established, it can be used to access the raw disk like a normal VMFS virtual disk. The 'file length' of the mapping is the same as the size of the raw disk that it points to.

   --createvirtualdisk
    -c
         Creates a virtual disk takes size argument (of the form #gGmMkK). It can be used with -a|--adapterType, -d|--diskformat. If -a is not specified, 'busLogic' will be used. If -d is not specified, 'zeroedthick' will be used.

   --deletevirtualdisk
    -U
         Delete files associated with the specified virtual disk.

   --diskformat
    -d
         Specify the target disk format. Applies to -c, -i, -X. Accepts zeroedthick|eagerzeroedthick|thin for -c. Accepts zeroedthick|eagerzeroedthick|thin|rdm:dev|rdmp:dev|2gbsparse for -i. Accepts eagerzeroedthick for -X.

   --extendvirtualdisk
    -X
         Takes size argument (of the form #gGmMkK) Extend the specified VMFS virtual disk to the specified length. This command is useful for extending the size of a virtual disk allocated to a virtual machine after the virtual machine has been created. However, this command requires that the guest operating system has some capability for recognizing the new size of the virtual disk and taking advantage of this new size (e.g. by updating the file system on the virtual disk to take advantage of the extra space). Since ESX 4.0 and ESXi 4.0, --diskformat can be used to specify grow the disk in eagerzeroedthick format. If the diskformat is not specified, the extended disk region of a zeroedthick disk will be zeroedthick; the extended disk region of a eagerzeroedthick disk will be eagerzeroedthick; a thin-provisioned disk will be extended as a thin-provisioned disk.

   --geometry
    -g
         Get the geometry information (cylinders, heads, sectors) of a virtual disk.

   --inflatedisk
    -j
         Convert a `thin` virtual disk to `eagerzeroedthick` with the additional guarantee that any data on `thin` disk is preserved and any blocks that were not allocated get allocated and zeroed out.

   --queryfs
    -P
         Prints information about a vmfs file system. Displays VMFS version number, the partitions constituting the vmfs file system, the capacity and availabe space.

   --queryrdm
    -q
         List the attributes of a raw disk mapping. When used with a 'rdm:' or 'raw:' specification, it prints out the vmhba name of the raw disk corresponding to the mapping referenced by the _device_. It also prints out identification information for the raw disk (if any). This option is currently not yet supported.

   --renamevirtualdisk
    -E
         Rename files associated with a specified virtual disk to the specified name. Takes source disk as argument.

   --setfsname
    -S
         The name of the VMFS file system to create.

   --spanfs
    -Z
         Extends this partition onto the head partition.

   --vihost
    -h
          The host to use when connecting via Virtual Center.

   --writezeros
    -w
         Initialize the virtual disk with zeros. Any existing data on virtual disk is lost.


Common VI options:
   --config (variable VI_CONFIG)
      Location of the VI Perl configuration file
   --credstore (variable VI_CREDSTORE)
      Name of the credential store file defaults to <HOME>/.vmware/credstore/vicredentials.xml on Linux and <APPDATA>/VMware/credstore/v
icredentials.xml on Windows
   --encoding (variable VI_ENCODING, default 'utf8')
      Encoding: utf8, cp936 (Simplified Chinese), iso-8859-1 (German), shiftjis (Japanese)
   --help
      Display usage information for the script
   --passthroughauth (variable VI_PASSTHROUGHAUTH)
      Attempt to use pass-through authentication
   --passthroughauthpackage (variable VI_PASSTHROUGHAUTHPACKAGE, default 'Negotiate')
      Pass-through authentication negotiation package
   --password (variable VI_PASSWORD)
      Password
   --portnumber (variable VI_PORTNUMBER)
      Port used to connect to server
   --protocol (variable VI_PROTOCOL, default 'https')
      Protocol used to connect to server
   --savesessionfile (variable VI_SAVESESSIONFILE)
      File to save session ID/cookie to utilize
   --server (variable VI_SERVER, default 'localhost')
      VI server to connect to. Required if url is not present
   --servicepath (variable VI_SERVICEPATH, default '/sdk/webService')
      Service path used to connect to server
   --sessionfile (variable VI_SESSIONFILE)
      File containing session ID/cookie to utilize
   --url (variable VI_URL)
      VI SDK URL to connect to. Required if server is not present
   --username (variable VI_USERNAME)
      Username
   --verbose (variable VI_VERBOSE)
      Display additional debugging information
   --version
      Display version information for the script



No comments: