Vathsa's VmWare Usuefull Commands
Most Useful ESXCLI and ESXi Shell Commands for Your VMware Environment
Check the status of active network connections:
esxcli network ip connection list
Display the information about network interfaces:
esxcli network ip interface list
Display the information about IP addresses of the network interfaces that are present on the server:
esxcli network ip interface ipv4 get
Display the network information for VMs:
esxcli network vm list
View the domain search settings:
esxcli network ip dns search list
View the DNS servers set in the network settings:
esxcli network ip dns server list
List vSwitchs and port groups:
esxcli network vswitch standard list
Show statistics for the vmnic0 network interface:
esxcli network nic stats get -n vmnic0<
Check the firewall status and rule settings:
esxcli network firewall get
esxcli network firewall ruleset list
Note: The default firewall policy is to drop traffic if the opposite rules are not set.
You can temporary disable the firewall on an ESXi host for troubleshooting:
esxcli network firewall set --enabled false
The firewall must be enabled with the command:
esxcli network firewall set --enabled true
It is recommended to have the ESXi firewall enabled for security reasons.
Storage
The storage namespace allows you to check and edit storage settings.
Check the information about mounted VMFS volumes:
esxcli storage vmfs extent list
View mappings of VMFS file systems to disk devices:
esxcli storage filesystem list
List all the iSCSI paths on the system:
esxcli storage core path list
Display the list of mounted NFS shares:
esxcli storage nfs list
Check the SNMP configuration:
esxcli system snmp get
Enter the ESXi host to the maintenance mode:
esxcli system maintenanceMode set --enable yes
Exit the maintenance mode:
esxcli system maintenanceMode set --enable no
After entering an ESXi host to the maintenance mode, you can shut down or reboot the host.
Power off an ESXi host:
esxcli system shutdown poweroff
The command for rebooting the host is similar:
esxcli system shutdown reboot
You can also set a delay and write a reason of rebooting the host to be saved in system logs:
esxcli system shutdown reboot -d 60 -r “Installing patches”
iSCSI
iSCSI is a widely used protocol for accessing shared storage on a block level, and there is a separate iscsi namespace in ESXCLI for managing the iSCSI storage.
Show the list of available iSCSI adapters:
esxcli iscsi adapter list
Re-discover and re-scan iSCSI adapters:
esxcli iscsi adapter discovery rediscover -A adapter_name
esxcli storage core adapter rescan -A adapter_name
Instead of -A adapter_name you can rescan all adapters by using the --all option.
Software
You can view the list of VIB packages installed on your ESXi host:
esxcli software vib list
You can install a VIB with ESXCLI (the ESXi host must be in maintenance mode):
esxcli software vib install -d /vmfs/volumes/datastore1/patches/patch_name.zip
VM operations
esxcli vm process kill -w 75498 -t hard
There are three available command options for the kill command:
soft – a correct signal is sent in the guest operating system to shut down a VM correctly;
hard – a VM is shut down immediately;
force -VM is powered off similarly to how a computer is powered off when unplugging the power cable. Only use this type of powering off the VM if the previous two types were unsuccessful.
Convert a thick provisioned virtual disk to a thin provisioned virtual disk by using vmkfstools:
vmkfstools -i /vmfs/volumes/vmfs_datastore/vm_name/thick_disk.vmdk -d thin /vmfs/volumes/vmfs_datastore/vm_name/new_thin_disk_name.vmdk
Open the ESXi task manager:
esxtop
After opening the task manager with the esxtop command, you can switch between tabs by pressing the appropriate keys:
C – CPU
I – interrupt
M – memory
N – network
D – disk adapter
U – disk device
V – disk VM
P – power management
esxcli system account add -d="user2" -i="user2" -p -c
esxcli esxcli command list
The list of available ESXCLI commands depends on the ESXi version.
Hence, the list of top ESXCLI namespaces for ESXi 6.7 is as follows:
- device – device manager commands
- esxcli – commands related to ESXCLI itself
- fcoe – Fibre Channel over Ethernet commands
- graphics – VMware graphics commands
- hardware – commands for checking hardware properties and configuring hardware
- iscsi – VMware iSCSI commands
- network – this namespace includes a wide range of commands for managing general host network settings (such as the IP address, DNS settings of an ESXi host, firewall) and virtual networking components such as vSwitch, portgroups etc.
- nvme – managing extensions for VMware NVMe driver
- rdma – commands for managing the remote direct memory access protocol stack
- sched – commands used for configuring scheduling and VMkernel system properties
- software – managing ESXi software images and packages for ESXi
- storage – commands used to manage storage
- system – commands for configuring VMkernel system properties, the kernel core system and system services
- vm – some commands that can be used to control virtual machine operations
- vsan – VMware vSAN commands
The main commands appear as verbs indicating the same action:
- list – show the list of objects available for the defined namespace (for example, esxcli hardware bootdevice list – list available boot devices)
- get – get the value of the defined setting or property (for instance,
- esxcli hardware clock get – check the time set)
- set – set the necessary parameter manually (for example,
- esxcli hardware clock set -y 2019 -s 00 – set the year to 2019 and set the seconds to 00)
- load/unload – load/unload system configuration (esxcli network firewall load – load the firewall module and firewall settings stored in the configuration file)
Datastore conflicts with an existing datastore in the datacenter that has the same URL" error in vCenter Server
- Connect to the VCSA through SSH.
- Access the Bash Shell with the command shell.set --enabled true or just type shell.
- Stop the vpxd service with the command: service-control --stop vmware-vpxd
- Access the Postgres DB using this command:
/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
- vCenter 6.5: Run the query select id,storage_url from vpx_datastore;
- vCenter 6.7/7.x: select * from vpx_datastore;
- Alternatively, you may also run:
select * from vpx_datastore where storage_url='<storage URL from the error message>';- Look for the affected datastore (DS) UUID and find the ID.
- To confirm the correct ID as needed, run select * from vpx_entity where id=(ID found on previous step);
- Delete the entry from vpx_ds_assignment, vpx_vm_ds_space, vpx_datastore and vpx_entity using query delete from vpx_ds_assignment where DS_id=XXXX;
Sample were the ID = 461:
delete from vpx_ds_assignment where ds_id=461;
delete from vpx_vm_ds_space where ds_id=461;
delete from vpx_datastore where id=461;
delete from vpx_entity where id=461; - To quit from database use \q
- Start the vmware-vpxd service in order for changes to be reflected:
service-control --start vmware-vpxd
- Once the vmware-vpxd service is up again, proceed to add the ESXi host again back to the vCenter Server.
Comments
Post a Comment