Difference between revisions of "ESX common commands"

From Tech-Wiki
Jump to: navigation, search
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:VMware]]
 
[[Category:VMware]]
 +
 +
'''Virtual Machine Management'''
 +
 +
Listing all registered virtual machines
 +
  # vmware-cmd -l
 +
Registering a virtual machine
 +
  # vmware-cmd -s register /vmfs/volumes/storage/VM/MyVM.vmx
 +
VM operations<br>
 +
Possible values: start|stop|reset|suspend  hard|soft
 +
  # vmware-cmd -U user -P pass1234 -H VCServer1 -h ESXHost /vmfs/volumes/storage1/MyVMs/VM1.vmx stop soft
 +
 +
Creating a snapshot
 +
  # vmware-cmd -U user -P pass1234 -H VCServer1 -h ESXHost /vmfs/volumes/storage1/MyVMs/VM1.vmx createsnapshot
 +
 +
Relocating a virtual machine's storage (including the disks)
 +
  # svmotion --url=https://myvc.mycorp.com/sdk --datacenter=DC1 --vm="[storage1] myvm/myvm.vmx:new_datastore"
 +
Relocating a virtual machine's configuration file, but leaving the virtual disks
 +
  # svmotion --datacenter='My DC' --vm='[old_datastore] myvm/myvm.vmx:new_datastore'
 +
  --disks='[old_datastore] myvm/myvm_1.vmdk:old_datastore, [old_datastore] myvm/myvm_2.vmdk:old_datastore'
  
 
'''File Management'''
 
'''File Management'''
COMMAND: vmkfstools
 
This command helps in creating and manipulating virtual disks, file systems, logical volumes, and physical storage devices on an ESXi host. It also allows administrators to create and manage a VMFS on a physical partition of a disk and to manipulate files, such as virtual disks, stored on VMFS-3 and NFS. Here are some examples:
 
  
 
Creating a virtual disk
 
Creating a virtual disk
   # vmkfstools -c 2048m testvirtualdisk.vmdk
+
   # vmkfstools -c 2048m virtualdisk.vmdk
 
Creating a VMFS
 
Creating a VMFS
 
   # vmkfstools -C vmfs5 -b 1m -S my_test_vmfs /vmfs/devices/disks/test.ID:1
 
   # vmkfstools -C vmfs5 -b 1m -S my_test_vmfs /vmfs/devices/disks/test.ID:1
  
COMMAND: vifs
 
This command helps in performing file system operations like copying, removing, getting, and placing files and directories on remote hosts. Here are some examples:
 
 
Copying a file to another location
 
Copying a file to another location
   # vifs -c "[StorageName] VM/VM.vmx" "[StorageName] VM_backup/VM.vmx"
+
   # vifs -c "[StorageName] VM/VM.vmx" "[StorageName] Backups/VM.vmx"
 
Listing all the directories
 
Listing all the directories
   # vifs --server -D "[StorageName] vm"
+
   # vifs --server -D "[StorageName] vms"
  
 
'''Host Management'''
 
'''Host Management'''
COMMAND: vicfg-hostops
+
 
This command can be used to shut down or reboot an ESXi host. It can be used to shut down either a single host at a time or all the hosts in the data center or cluster, which disconnects the hosts from the vCenter Server System but does not remove them from the inventory. Here are some examples:
+
 
Shutting down a single host
 
Shutting down a single host
~ # vicfg-hostops --operation shutdown --force
+
  # vicfg-hostops --operation shutdown --force
 
Rebooting entire cluster
 
Rebooting entire cluster
~ # vicfg-hostops --operation reboot --cluster  
+
  # vicfg-hostops --operation reboot --cluster  
COMMAND: vicfg-cfgbackup
+
 
This command can be used to take a backup of host configuration data. This command is available only for ESXi hosts and not available on the vCenter Server system connections. Here are some examples:
+
 
Backing up configuration data
 
Backing up configuration data
~ # vicfg-cfgbackup -s /tmp/ESXi_181842_backup.txt
+
  # vicfg-cfgbackup -s /tmp/ESXi_backup.tgz
 
Restoring configuration data
 
Restoring configuration data
~ # vicfg-cfgbackup -l /tmp/ESXi_181842_backup.tgz
+
  # vicfg-cfgbackup -l /tmp/ESXi_backup.tgz
COMMAND: vicfg-authconfig
+
 
This command helps in remote configuration of Active Directory settings on ESXi hosts. It also allows administrators to obtain lists of supported and active authentication mechanisms, as well as lists of the current domain and join or part from an Active Directory domain. Here is an example:
+
 
To set up Active Directory, after synchronizing the ESXi host and Active Directory, the following command must be run:
 
To set up Active Directory, after synchronizing the ESXi host and Active Directory, the following command must be run:
~ # vicfg-authconfig --server=
+
  # vicfg-authconfig --server=  --username=  --password=  --authscheme AD --joindomain   --adusername=   --adpassword=
  --username=
+
  --password=
+
  --authscheme AD --joindomain  
+
  --adusername=  
+
  --adpassword=
+
  
'''Virtual Machine Management'''
+
'''User Management'''
Managing virtual machines involves tasks like registering and unregistering virtual machines, retrieving virtual machine information, managing snapshots, turning virtual machines on and off, adding and removing virtual devices, and prompting for user input.
+
COMMAND: svmotion
+
Storage vMotion (or svmotion) helps in moving a virtual machine's configuration file, and, optionally, its disks, to a different location while the virtual machine is running. This can help in moving all virtual machines and disks to a single target location, or choosing different locations for configuration files and virtual disks. Here are some examples:
+
Relocating a virtual machine's storage (including the disks)
+
~ # svmotion - -url=https://myvc.mycorp.com/sdk - -datacenter=DC1 - -vm="[storage1] myvm/myvm.vmx:new_datastore"
+
Relocating a virtual machine's configuration file, but leaving the virtual disks
+
~ # svmotion - -datacenter='My DC' - -vm='[old_datastore]
+
myvm/myvm.vmx:new_datastore' - -disks='[old_datastore] myvm/myvm_1.vmdk:old_datastore, [old_datastore] myvm/myvm_2.vmdk: old_datastore'
+
COMMAND: vmware-cmd
+
This command helps in performing virtual machine operations including creating a snapshot, powering a virtual machine on or off, and getting information about a virtual machine. It also helps administrators register and unregister virtual machines, retrieve virtual machine information, manage snapshots, turn virtual machines on and off, add and remove virtual devices, and prompt for user input. Here are some examples:
+
Listing all registered virtual machines
+
~ # vmware-cmd -l
+
Registering a virtual machine
+
~ # vmware-cmd -s register /vmfs/volumes/storage/VM/MyVM.vmx
+
Creating a snapshot
+
~ # vmware-cmd -U -P -H VCServerABC -h ESXHost
+
   /vmfs/volumes/storage1/MyVM/MyVM.vmx createsnapshot
+
  
'''User Management'''
 
In a VMware virtual environment only authorized users with appropriate access permissions are allowed to access any information or resources. Administrators are provided with several ways to manage these users and their associated tasks and permissions.
 
COMMAND: vicfg-user
 
This command helps create, modify, delete, and list local direct access users and groups of users on an ESXi host. This command cannot be targeted to a vCenter Server system. Here are some examples:
 
 
Listing the existing users
 
Listing the existing users
~ # vicfg-user -e user -o list
+
  # vicfg-user -e user -o list
 
Adding a new user with specified login ID and password
 
Adding a new user with specified login ID and password
~ # vicfg-user -e user -o add -l user27 -p 27_password
+
  # vicfg-user -e user -o add -l userx -p password1234
 
Creating a group
 
Creating a group
~ # vicfg-user -e group -o add -d test
+
  # vicfg-user -e group -o add -d test
  
 
'''Virtual Network Management'''
 
'''Virtual Network Management'''
Virtual network management includes activities like setting up a vSphere virtual switch, setting the DNS configuration, adding and starting an NTP Server, managing the IP gateway and more.
+
 
COMMAND: esxcli network vswitch
+
This command can be used to create or manipulate virtual switches. It also helps in obtaining detailed information about the virtual switches. Here are some examples:
+
 
Listing all virtual switches and associated port groups
 
Listing all virtual switches and associated port groups
~ # esxcli network vswitch standard list
+
  # esxcli network vswitch standard list
COMMAND: vicfg-vswitch
+
 
This command works pretty much the same as the "esxcli network vswitch" command above, helping administrators create, manage, and manipulate virtual switches. Here is an example:
+
 
Listing all virtual switches and associated port groups
 
Listing all virtual switches and associated port groups
~ # vicfg-vswitch -l
+
  # vicfg-vswitch -l
COMMAND: esxcfg-vswitch
+
 
This command helps in viewing and configuring virtual switches. It helps configure the port groups and link physical network interface cards (NICs) to them. It also helps in configuring virtual LAN IDs, Cisco Discovery Protocol (CDP), and the maximum transmission unit (MTU) of vswitches. Here are some examples:
+
 
Creating a new virtual switch
 
Creating a new virtual switch
~ # esxcfg-vswitch a TestvSwitch
+
  # esxcfg-vswitch a TestvSwitch
 
Adding or removing network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS)  
 
Adding or removing network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS)  
~ # esxcfg-vswitch -P vmnic -V unused_dvPort_ID dvSwitch  
+
  # esxcfg-vswitch -P vmnic -V unused_dvPort_ID dvSwitch  
COMMAND: esxcfg-nics
+
 
This command helps in viewing and configuring physical NICs. It provides information about NIC status and also allows administrators to configure the speed of the NICs. Here is an example:
+
 
Viewing the list of physical adapters and their link status
 
Viewing the list of physical adapters and their link status
~ # esxcfg-nics l  
+
  # esxcfg-nics l  
  
 
'''Storage Management'''
 
'''Storage Management'''
COMMAND: vicfg-scsidevs or esxcli storage core device list
+
 
This command helps in displaying the available logical unit numbers (LUNs) and mappings for each VMFS volume to its corresponding partition. Here is an example:
+
 
Listing all logical devices known on the system
 
Listing all logical devices known on the system
~ # esxcli storage core device list
+
  # esxcli storage core device list
OR
+
OR
~ # vicfg-scsidevs --list
+
  # vicfg-scsidevs --list
COMMAND: vicfg-mpath or esxcli storage core path
+
 
This command helps in obtaining information about Fibre Channel or iSCSI LUNs and to change a path's state. Here are some examples:
+
 
Listing all devices, along with corresponding paths, state of the path, adapter type, and other information
 
Listing all devices, along with corresponding paths, state of the path, adapter type, and other information
~ # esxcli storage core path list
+
  # esxcli storage core path list
OR
+
OR
~ # vicfg-mpath --list-paths
+
  # vicfg-mpath --list-paths
 
Setting the state of a LUN path to "off"
 
Setting the state of a LUN path to "off"
~ # esxcli storage core path set --state off --path vmhba32:C0:T1:L0
+
  # esxcli storage core path set --state off --path vmhba32:C0:T1:L0
OR
+
OR
~ # vicfg-mpath --state off --path vmhba32:C0:T1:L0
+
  # vicfg-mpath --state off --path vmhba32:C0:T1:L0
COMMAND: vicfg-rescan adapter rescan or esxcli storage core adapter rescan
+
 
This command helps perform a rescan operation each time the storage setup is reconfigured. Here is an example:
+
 
Rescanning a storage adapter
 
Rescanning a storage adapter
~ # esxcli storage core adapter rescan --adapter=TestAdapter
+
  # esxcli storage core adapter rescan --adapter=TestAdapter
OR
+
OR
~ # vicfg-rescan TestAdapter
+
  # vicfg-rescan TestAdapter
COMMAND: esxcfg-mpath
+
 
This command helps in displaying and setting (enabling and disabling) all paths from a host to its storage devices. Here is an example:
+
 
Enabling or disabling a path
 
Enabling or disabling a path
~ # esxcfg-mpath -P path -s state  
+
  # esxcfg-mpath -P path -s state  
COMMAND: esxcfg-info
+
 
This command helps in obtaining detailed information about the host from which the command is fired. Its output can be stored directly into a text file, allowing direct documentation of the host configuration. Here are some examples:
+
Checking the ESXi host hardware info
Checking the ESX/ESXi host for host hardware info
+
  # esxcfg-info | less i
~ # esxcfg-info | less i
+
 
Filtering out information about a specific system
 
Filtering out information about a specific system
~ # esxcfg-info | grep 'system uuid'
+
  # esxcfg-info | grep 'system uuid'
 +
 
 +
Listing paths to a single device
 +
  # esxcli storage nmp path list --device
 +
Setting configuration parameters for third-party extensions
 +
  # esxcli storage nmp roundrobin setconfig
  
 
'''iSCSI Storage Management'''
 
'''iSCSI Storage Management'''
ESXi systems include iSCSI storage technology, which is used to access files stored at remote locations over an IP network. For better automation, the hardware and software for iSCSI storage can be configured using the vCLI commands.
+
 
COMMAND: esxcli iscsi
+
This command helps in performing a variety of iSCSI management tasks, like setting up iSCSI storage, listing and setting iSCSI options, enabling iSCSI authentication, and more. Here are some examples:
+
 
Enabling software iSCSI
 
Enabling software iSCSI
~ # esxcli iscsi software set --enabled=true
+
  # esxcli iscsi software set --enabled=true
 +
OR
 +
  # vicfg-iscsi --swiscsi enable
 +
 
 
Adding a new adapter
 
Adding a new adapter
esxcli iscsi networkportal add -n -A  
+
# esxcli iscsi networkportal add -n -A  
COMMAND: vicfg-iscsi
+
 
This command is similar to "esxcli iscsi" discussed above. It also helps in performing a variety of iSCSI management tasks, like setting up iSCSI storage, listing and setting iSCSI options, enabling iSCSI authentication, and more. Here are some examples:
+
Enabling software iSCSI
+
~ # vicfg-iscsi --swiscsi enable
+
 
Setting the iSCSI name and alias
 
Setting the iSCSI name and alias
~ # vicfg-iscsi --iscsiname name
+
  # vicfg-iscsi --iscsiname name
COMMAND: esxcli storage nmp
+
This command can be used to manage devices associated with NMP, to set path policies, and to obtain information about the path policies. Here are some examples:
+
Listing paths to a single device
+
~ # esxcli storage nmp path list --device
+
Setting configuration parameters for third-party extensions
+
~ # esxcli storage nmp roundrobin setconfig
+

Latest revision as of 14:51, 15 September 2017


Virtual Machine Management

Listing all registered virtual machines

 # vmware-cmd -l

Registering a virtual machine

 # vmware-cmd -s register /vmfs/volumes/storage/VM/MyVM.vmx

VM operations
Possible values: start|stop|reset|suspend hard|soft

 # vmware-cmd -U user -P pass1234 -H VCServer1 -h ESXHost /vmfs/volumes/storage1/MyVMs/VM1.vmx stop soft

Creating a snapshot

 # vmware-cmd -U user -P pass1234 -H VCServer1 -h ESXHost /vmfs/volumes/storage1/MyVMs/VM1.vmx createsnapshot

Relocating a virtual machine's storage (including the disks)

 # svmotion --url=https://myvc.mycorp.com/sdk --datacenter=DC1 --vm="[storage1] myvm/myvm.vmx:new_datastore"

Relocating a virtual machine's configuration file, but leaving the virtual disks

 # svmotion --datacenter='My DC' --vm='[old_datastore] myvm/myvm.vmx:new_datastore' 
 --disks='[old_datastore] myvm/myvm_1.vmdk:old_datastore, [old_datastore] myvm/myvm_2.vmdk:old_datastore'

File Management

Creating a virtual disk

 # vmkfstools -c 2048m virtualdisk.vmdk

Creating a VMFS

 # vmkfstools -C vmfs5 -b 1m -S my_test_vmfs /vmfs/devices/disks/test.ID:1

Copying a file to another location

 # vifs -c "[StorageName] VM/VM.vmx" "[StorageName] Backups/VM.vmx"

Listing all the directories

 # vifs --server -D "[StorageName] vms"

Host Management

Shutting down a single host

 # vicfg-hostops --operation shutdown --force

Rebooting entire cluster

 # vicfg-hostops --operation reboot --cluster 

Backing up configuration data

 # vicfg-cfgbackup -s /tmp/ESXi_backup.tgz

Restoring configuration data

 # vicfg-cfgbackup -l /tmp/ESXi_backup.tgz

To set up Active Directory, after synchronizing the ESXi host and Active Directory, the following command must be run:

 # vicfg-authconfig --server=  --username=  --password=  --authscheme AD --joindomain   --adusername=   --adpassword=

User Management

Listing the existing users

 # vicfg-user -e user -o list

Adding a new user with specified login ID and password

 # vicfg-user -e user -o add -l userx -p password1234

Creating a group

 # vicfg-user -e group -o add -d test

Virtual Network Management

Listing all virtual switches and associated port groups

 # esxcli network vswitch standard list

Listing all virtual switches and associated port groups

 # vicfg-vswitch -l

Creating a new virtual switch

 # esxcfg-vswitch a TestvSwitch

Adding or removing network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS)

 # esxcfg-vswitch -P vmnic -V unused_dvPort_ID dvSwitch 

Viewing the list of physical adapters and their link status

 # esxcfg-nics l 

Storage Management

Listing all logical devices known on the system

 # esxcli storage core device list
OR
 # vicfg-scsidevs --list

Listing all devices, along with corresponding paths, state of the path, adapter type, and other information

 # esxcli storage core path list
OR
 # vicfg-mpath --list-paths

Setting the state of a LUN path to "off"

 # esxcli storage core path set --state off --path vmhba32:C0:T1:L0
OR
 # vicfg-mpath --state off --path vmhba32:C0:T1:L0

Rescanning a storage adapter

 # esxcli storage core adapter rescan --adapter=TestAdapter
OR
 # vicfg-rescan TestAdapter

Enabling or disabling a path

 # esxcfg-mpath -P path -s state 

Checking the ESXi host hardware info

 # esxcfg-info | less i

Filtering out information about a specific system

 # esxcfg-info | grep 'system uuid'

Listing paths to a single device

 # esxcli storage nmp path list --device 

Setting configuration parameters for third-party extensions

 # esxcli storage nmp roundrobin setconfig

iSCSI Storage Management

Enabling software iSCSI

 # esxcli iscsi software set --enabled=true
OR
 # vicfg-iscsi --swiscsi enable

Adding a new adapter

# esxcli iscsi networkportal add -n -A 

Setting the iSCSI name and alias

 # vicfg-iscsi --iscsiname name