vCLI: Managing Storage

As I want to get deeper into VMware CLI (vCLI) I deciced to make a summary of the vSphere Command-Line Interface Installation and Scripting Guide. Every chapter will be a separate blog post.

This summary is meant for my documentation but feel free to make use of it.

In this blog post: Managing Storage

Examining LUNs

  • Listing all logical devices known on this system with detail information
    vicfg-scsidevs –list
  • List all logical devices with abbreviated information.
    vicfg-scsidevs –compact-listThe information includes the device ID, device type, size, plugin, and device display name.
  • List all device unique identifiers.
    vicfg-scsidevs –uids
    The command lists the primary UID for each device (naa.xxx or other primary name) and any other UIDs for each UID (VML name). You can specify –device to only list information for a specific device.
  • List a specific logical device with its detailed information.
    vicfg-scsidevs -l -d mpx.vmhba32:C0:T1:L0
  • Print mappings for VMFS volumes to the corresponding partition, path to that partition, VMFS uuid, extent number, and volume names.
    vicfg-scsidevs –vmfs
  • Print HBA devices with identifying information.
    vicfg-scsidevs –hbas
    The return value includes the adapter ID, driver ID, adapter UID, PCI, vendor, and model.
  • Print a mapping between HBAs and the devices it provides paths to.
    vicfg-scsidevs –hba-device-list

Managing paths with mpath

Listing paths

  • List all devices with their corresponding paths, state of the path, adapter type, and other information.
    vicfg-mpath <conn_options> –list-paths
  • Display a short listing of all paths.
    vicfg-mpath <conn_options> –list-compact
  • List all paths with adapter and device mappings.
    vicfg-mpath <conn_options> –list-map
  • List paths and detailed information by specifying the path UID (long path). The path UID is the first item
    in the vicfg-mpath –list display.
    vicfg-mpath <conn_options> –list -P sas.5001c231c79c4a00-sas.1221000001000000naa.5000c5000289c61b
  • List paths and detailed information by specifying the path runtime name.
    vicfg-mpath <conn_options> -l -P vmhba32:C0:T0:L0The return information includes the runtime name, device, device display name, adapter, adapter
    identifier, target identifier, plugin, state, transport, and adapter and target transport details.
  • List detailed information for the paths for the device specified with –device.
    vicfg-mpath <conn_options> -l -d mpx.vmhba32:C0:T1:L0
    vicfg-mpath <conn_options> –list –device naa.60060…

Changing the State of a Path

  • Set the state of a LUN to off
    vicfg-mpath <conn_options> –state off –path vmhba32:C0:T1:L0
  • Set the state of a LUN to on
    vicfg-mpath <conn_options> –state active –path vmhba32:C0:T1:L0

Note:
The change -PSPoperation will fail if I/O is active when the path setting is changed. Reissue the command.
You must issue at least one I/O operation before the change take effect.

Managing Path Policies

The following path selection policies are available with the NMP (Native Multipath Policy).

  • VMW_PSP_FIXED
    The host will always use the preferred path you have selected when it’s available. If the path ain’t available the policy will try another available path.
  • VMW_PSP_FIXED_AP
    Extension to the VMW_PSP_FIXED policy to active-passive and ALUA mode array’s
  • VMW_PSP_MRU
    The host will keep using the same path until it’s unavailable. If the current path is unavailable the host will try another path (random). When the first path come back the host will not fail back. It will keep using the same path.
  • VMW_PSP_RR
    The host will use round-robin through all available pahts. This policy is used for load balacing.

To change the path policy

  • To list the multipathing plugin loaded on the system
    vicfg-mpath <conn-options> –list-plugins
  • Set the path policy
    esxcli <conn_options> nmp device setpolicy –device naa.xxx –psp VMW_PSP_RR
  • Optional you have to specify the preffered path
    esxcli <conn_options> nmp fixed getpreferred –device naa.xxx
    esxcli <conn_options> nmp fixed setpreffered –device naa.xxx –path vmhba3:C0T2:L3
  • To view and manipulate round robin path selection settings
    esxcli <conn_options> nmp roundrobin getconfig –device na.xxx
    esxcli <conn_options> nmp roundrobin setconfig –type “bytes” -B 12345 –device naa.xxx (for bytes)
    esxcli <conn_options> nmp roundrobin setconfig –type=iops –iops 4200 –device naa.xxx (for iops)

Masking Paths with esxcli corestorage claimrule

  1. Run esxcli corestorage claimrules list to determine the next available rule ID.
    User rule IDs start at 101

    • Rules 0-100 are reserved for internal use by VMware.
    • Rules 101-65435 are available for general use.
    • Rules 65436-65535 are reserved for internal use by VMware.
  2. Decide which rule ID to use.
    The rules are used sequential. So make sure you use the correct rule ID or another claimrule will be used.
  3. Add the MASK_PATH plugin to the claim rule with the ID you decided to use.
    esxcli <conn_options> corestorage claimrule add –plugin MASK_PATH –rule <ruleID>
    –type <type> -A <adapter>
  4. Verify that the claim rule was added correctly.
    esxcli <conn_options> corestorage claimrule list
  5. Load the path claiming rules.
    esxcli <conn_options> corestorage claimrule load
  6. Release the device from the current plugin so that it can be claimed by another rule. For example, you
    might run the following command for each path:
    esxcli <conn_options> corestorage claiming unclaim -t location -A vmhba0 -C 0 -T 0 -L 149
  7. Run the path claiming rules, which include the newly added rules.
  8. esxcli <conn_options> corestorage claimrule run

To unmask the path

  1. Delete the MASK_PATH claim rule.
    esxcli <conn_options> corestorage claimrule delete -r <rule#>
  2. Verify that the claim rule was deleted correctly.
    esxcli <conn_options> corestorage claimrule list
  3. Reload the path claiming rules from the configuration file into the VMkernel.
    esxcli <conn_options> corestorage claimrule load
  4. Run esxcli corestorage claiming unclaim for each path to the masked device, for example:
    esxcli <conn_options> corestorage claiming unclaim -t location -A vmhba0 -C 0 -T 0 -L 149
  5. Run the path claiming rules.
    esxcli <conn_options> corestorage claimrule run

Managing NFS/NAS DAtastores

  • List all known NAS file systems.
    vicfg-nas <conn_options> -l
  • Add a new NAS file system to the ESX/ESXi host.
    vicfg-nas <conn_options –add –nasserver dir42.eng.vmware.com -s /<mount_dir> nfsstore-dir42
  • Add a second NAS file system with read‐only access.
    vicfg-nas <conn_options> -a -y –n esx42nas2 -s /home FileServerHome2
  • Delete one of the NAS file systems.
    vicfg-nas <conn_options> -d FileServerHome1

Migrating Virtual Machines with svmotion

  • Running svmotion in interactive mode (you will be prompted for the information)
    svmotion <conn_options> –interactive
  • Running svmotion in noninteracitve mode
    svmotion [standard vCLI options] –datacenter=<datacenter_name>
    –vm <VM config datastore path>:<new datastore>
    [–disks <virtual disk datastore path>:<new datastore>,
    <virtual disk datastore path>:<new datastore>]

    By default the –vm option will migrate the completed Virtual Machine to the new location (config files and vmdks)
    The –disks option will migrate only that vmdk.

Managing Duplicate VMFS Datastores with vicfg-volume

Each VMFS datastore created in a LUN has a unique UUID that is stored in the file system superblock. When
the LUN is replicated or a snapshot made, the resulting LUN copy is identical, byte‐for‐byte, to the original
LUN. As a result, if the original LUN contains a VMFS datastore with UUID X, the LUN copy appears to
contain an identical VMFS datastore, or a VMFS datastore copy, with the same UUID X.
ESX/ESXi hosts can determine whether a LUN contains the VMFS datastore copy, and either mount the
datastore copy with its original UUID or change the UUID to resignature the datastore.
When a LUN contains a VMFS datastore copy, you can mount the datastore with the existing signature or
assign a new signature.

To mount a datastore

  1. List all volumes that have been detected as snapshots or replicas.
    vicfg-volume <conn_options> –list
  2. Run vicfg-volume –persistent-mount with the VMFS‐UUID or label as an argument to mount a
    volume.
    vicfg-volume <conn_options> –persistent-mount <VMFS-UUID|label>

To umount a datastore

  1. vicfg-volume <conn_options> –unmount <VMFS-UUID|label>

Resignature  a VMFS copy

  • Datastore resignaturing is irreversible.
  • The LUN copy that contains the VMFS datastore that you resignature is no longer treated as a LUN copy.
  • A spanned datastore can be resignatured only if all its extents are online.
  • The resignaturing process is crash and fault tolerant. If the process is interrupted, you can resume it later.
  • You can mount the new VMFS datastore without a risk of its UUID conflicting with UUIDs of any other
    datastore, such as an ancestor or child in a hierarchy of LUN snapshots.
  1. Make sure the copy is not mounted.
  2. Run vicfg-volume with the resignature option.
    vicfg-volume <conn_options> –resignature <VMFS-UUID|label>
    The command returns to the prompt or signals an error.
  3. It’spossible that vmx, vmdk, vmsd or vmsn file has a reference to the original signature. You will have to change these.

Rescanning Storage Adapters

  • vicfg-rescan <conn_options> vmhba1

VMware Update Manager (VUM) on a 64bits OS

I Googled for this article many time and I was wondering why I haven’t made a post about this on my blog for my own documentation.
When you want to install VUM on a 64bits OS for example Windows 2008 R2 you need to create a 32bit odbc database connection because VUM is still 32bit.

Everytime I search for this article I end up at boche.net website. He made a great post about creating a 32bit odbc databse connection. So for your and mine convenience here is the link.

Apache with iPrint won’t start even if CUPS is disabled with VMware Tools

A while ago I wrote a post about that the installation of the VMware tools enable the start of Cups at boot time. The was easy to fix by disabling the start of Cups at boot time with the insserv -r /etc/init.d/cups or chkconfig cups off command.

While upgrading a vSphere ESX4.0 to 4.1 site I ran into the same problem. So I thought: “No problem, I dealt with this before”. But after disabling the start of Cups at boot time and a restart of the Virtual Machine Cups still was started. The problem is that in the init script of the VMware tools check if Cups isn’t started and if not it will start Cups. This causes that Apache with iPrint won’t start because iPrint and Cups use the same port (TCP 631).

To make sure Cups won’t start at boot time we have to alter the init script in /etc/init.d. To do this:

  1. Open with vi (or another text editor) the /etc/init.d/vmware-tools file
  2. Go to the section where it say’s

    # If we found CUPS, start it, wait, then start tpvmlpd
    if [ $cupsscript ]; then
    $cupsscript start
    sleep 2

  3. Put a # before $cupsscript start
  4. Save the file and make sure Cups won’t start with the command chkconfig cups off

I know this ain’t the best way to deal with this problem. Probably running iPrint on a separate IP address is better but when your upgrading it’s not easy to change the ip address of your iPrint environment.

vCLI: Managing Files


As I want to get deeper into VMware CLI (vCLI) I deciced to make a summary of the vSphere Command-Line Interface Installation and Scripting Guide. Every chapter will be a separate blog post.
This summary is meant for my documentation but feel free to make use of it.

In this blog post: Managing Files

VMFS file systems
/vmfs/volumes/[filesystem-UUID]
/vmfs/volumes/[filesystem-label]

VMFS file
/vmfs/volumes/[filesystem-label or filesystem-UUID]/[dir]/disk.vmdk

Syntax: vmkfstools [connection options] [options] [target]
connection options: See Running vCLI Commands

File system options
–blocksize (-b) [1m, 2m, 4m, 8m]
Specify the blocksize. Used with –createfs
–createfs (-C) vmfs3
Create a VMFS file system
–queryfs (-p)
List attributes of a file system
–setfsname (-S) [label]
Sets the label of the file system. Used with –createfs
–spanfs (-Z)
Extends the VMFS file system

Virtual Disk options
–adaptertype (-a) [buslogic,lsilogic,ide]
Specify adapter type. Used with –createvirtualdisk and –clonevirtualdisk
–clonevirtualdisk [source] [destination]
clones the virtual disk
–createrdm (-r) [device] [rdm_file]
Maps a raw disk to a file on a VMFS file system
–createrdmpassthru (-z)
Map a passthrough raw disk to a file on a VMFS file system
–createvirtualdisk (-c) [size kK,mM,gG]
Create a virtual disk
–deletevirtualdisk (-U)
Deletes a virtual disk
–diskformat (-d) [zeroedthick(default), eagerzeroedthick, thin, rdm, rdmp, 2gbparse]
Specify virtual disk format
–extendvirtualdisk (-x)
Extends the virtual disk
–geometry (-g)
Display the virtual disk geomerty in C/H/S (Cylinders, Heads and Sectors)
–inflatedisk (-j)
converts a thin virtual disk to eagerzeroedthick format
–renamevirtualdisk (-E)
renames the virtual disk
–writezeros (-w)
Cleans the virtual disk by writing zeros over all its data

Manipulate files on remote ESX/ESXi host using vifs (not vCenter)
Groups:
Host
The hostname. syntax: host/[path]
Temp
The temp directory of the host. Syntax: tm/dir/subdir
Datastore
The datatstore name. Syntax: ‘[datastorename]/vm1/vm1.vmx’

Options
–copy (-c) [source] [target] –force
Copy files between datastores. –force is optional
–dir (-D) [remote dir]
List content
–force (-F)
Overwrite files
–get (-g) [remote path] [local path]
Download file from ESX/ESXI to machine where vCLI is running
–listdc (-S)
List datastore names
–mkdir (-M) [remote dir]
Create directory on remote dir
–move (-m) [source] [target] –force
Move files between or on datastores. –force option is optional
–put (-p) [local path] [remote path]
Upload files from machine where vCLI is running to a datastore
–rm (-r) [remote path]
Delete a file on a datastore
–rmdir (-R) [remote dir]
Deletes a directory on a datastore

vCLI: Managing Hosts

As I want to get deeper into VMware CLI (vCLI) I decided to make a summary of the vSphere Command-Line Interface Installation and Scripting Guide. Every chapter will be a separate blog post.
This summary is meant for my documentation but feel free to make use of it.

In this blog post: Managing Hosts

reboot, shutdown a host
shutdown hosts in maintenance mode
vicfg-hostops [connect options] –operation shutdown

shutdown hosts not in maintenance mode
vicfg-hostops [connect options] –operation shutdown –force

shutdown hosts in cluser or datacenter
vicfg-hostops [connect options] –operation shutdown –cluster [clustername]
vicfg-hostops [connect options] –operation shutdown –datacenter [datacentername]

Reboot hosts
Change the operation shutdown into reboot

Maintenance Mode
Entering Maintenance Mode
vicfg-hostops –operation enter (–cluser or –datacenter)

Check Maintenance Mode
Entering Maintenance Mode
vicfg-hostops –operation check

Exiting Maintenance Mode
vicfg-hostops –operation exit

Backup Configuration (host has to be in maintenanc mode)
Backup configuration information
vicfg-cfgbackup [connection options] -s /tmp/esxi-backup.txt

Restore configuration information
vicfg-cfgbackup [connection options] -l /tmp/esxi-backup.txt

Restore factory settings
vicfg-cfgbackup [connection options] -r

Host updates
which bulletins are installed
vihostupdate [connection options] –query

Which bulletins are available in the bundle
vihostupdate [connection options] –list –bundle https://webserver/bundle.zip

Which bulletions in the bundle are applicable to your host
vihostupdate [connection options] –scan –bundle https://webserver/bundle.zip

Install all or some bulletins from the bundle on your host
vihostupdate [connection options] –install –bundle https://webserver/bundle.zip,https://webserver2/budle2.zip

Make use of a metadata file
vihostupdate [connection options] –list –metadata https://webserver/metadata.zip

Install all bulletions using a metadata file
vihostupdate [connection options] –install –metadata https://webserver/metadata.zip

Install some bulletins using a metadata file
vihostupdate [connection options] –list –metadata https://webserver/metadata.zip –bulletin bulletin1,bulletin2

Removing a bulletin from a host (not vmware patches or updates)
vihostupdate [connection options] –remove –bulletin bulletin1

Active Directory Configuartion

  • Make sure time is synchronized between ESXi host and AD Server
  • ESX host is pingable from AD Server by DNS name
  • AD server is pinable form ESX host by DNS name

vicfg-authconfig –server=[ESX server ip adress]
–username=[ESX server admin name]
–password=
–authschema AD –hoindomain [ad domain name]
–adusername=[AD admnistration name]
–adpassword=

Check authentication
vicfg-authconfig –list