Virtualization has become an integral part of modern IT infrastructure, enabling organizations to maximize their resources, increase efficiency, and reduce costs. One of the most widely used virtualization platforms is VMware ESXi, which provides a robust and reliable hypervisor that allows for the creation and management of virtual machines (VMs).
While the graphical user interface (GUI) is a popular way to manage ESXi, the command-line interface (CLI) provides administrators with greater control and flexibility over their virtual environment. In this beginner’s guide, we will explore the ESXi CLI and provide you with the knowledge and tools to manage your virtual environment from the command line.
Getting Started with the ESXi CLI To access the ESXi CLI, you need to open a console session to the ESXi host. This can be done by logging in directly to the ESXi host, or by connecting remotely using SSH. Once connected, you will be presented with a command prompt where you can enter commands to manage your ESXi host and VMs.
Navigating the ESXi CLI The ESXi CLI uses a Linux-based command shell, which should be familiar to Linux or Unix users. The shell provides a set of commands that you can use to navigate the file system, manage processes, and perform other administrative tasks.
Here are some basic commands to get started with:
- cd: change directory
- ls: list directory contents
- pwd: print working directory
- cat: display file contents
- echo: display text on the screen
- vi: text editor
Managing ESXi Hosts and VMs The ESXi CLI provides a comprehensive set of commands to manage your virtual environment. Here are some of the most commonly used commands:
- esxcli: ESXi command-line interface
- vmware-cmd: control virtual machines
- vim-cmd: virtual machine control daemon
- vicfg-*: ESXi host configuration commands
- vmkfstools: create, manage, and manipulate virtual disk files
- vifs: manipulate files on VMFS file systems
Let’s take a closer look at some of these commands.
esxcli The esxcli command is the primary command-line interface for managing ESXi hosts. It provides access to a wide range of management tasks, including networking, storage, system, and hardware.
To get a list of all available esxcli commands, enter the following command:
esxcli --help
To get more information about a specific command, enter the following command:
esxcli <namespace> <command> --help
For example, to get more information about the network command, enter the following command:
esxcli network --help
vmware-cmd The vmware-cmd command is used to control virtual machines. It provides a set of subcommands that allow you to start, stop, pause, and resume VMs.
How to get a list of all available vmware-cmd commands, enter the following command:
vmware-cmd --help
Start a VM, enter the following command:
vmware-cmd <vmname> start
Stop a VM, enter the following command:
vmware-cmd <vmname> stop
vim-cmd The vim-cmd command is used to control the virtual machine control daemon. It provides access to a wide range of virtual machine management tasks, including power on/off, snapshot, and clone.
How to get a list of all available vim-cmd commands, enter the following command:
vim-cmd vmsvc/help
Power on a VM, enter the following command:
vim-cmd vmsvc/power.on <vmid>
vicfg-* The vicfg-* commands are used to configure ESXi hosts. They provide access to a wide range of system configuration tasks, including network, storage, and security.
To get a list of all available vicfg-* commands, enter the following command:
vicfg-<namespace> --help
For example, to get more information about the network commands, enter the following command:
vicfg-network --help
vmkfstools The vmkfstools command is used to create, manage, and manipulate virtual disk files. It provides a set of subcommands that allow you to create, delete, resize, and clone virtual disks.
To get a list of all available vmkfstools commands, enter the following command:
vmkfstools --help
To create a new virtual disk, enter the following command:
vmkfstools -c <size> <filename> -a <diskformat>
For example, to create a new 20GB virtual disk in the thin-provisioned format, enter the following command:
vmkfstools -c 20G /vmfs/volumes/datastore1/vm1/vmdisk1.vmdk -a thin
vifs The vifs command is used to manipulate files on VMFS file systems. It provides a set of subcommands that allow you to create, delete, and copy files on VMFS datastores.
To get a list of all available vifs commands, enter the following command:
vifs --help
To copy a file from the local file system to a VMFS datastore, enter the following command:
vifs -i put <localfile> <datastorefile>
For example, to copy a file named myfile.txt from the local file system to the root of the datastore1 datastore, enter the following command:
vifs -i put /tmp/myfile.txt /vmfs/volumes/datastore1/myfile.txt
Conclusion
In this beginner’s guide, we have explored the ESXi CLI and provided you with the knowledge and tools to manage your virtual environment from the command line. We have covered basic commands for navigating the ESXi CLI, as well as more advanced commands for managing ESXi hosts and VMs.
While the GUI provides a graphical interface to manage ESXi, the CLI provides administrators with greater control and flexibility over their virtual environment. By mastering the ESXi CLI, you can streamline your management tasks, automate routine tasks, and gain a deeper understanding of your virtual infrastructure.
ESXi Security Best Practices: Using Command Line to Secure Your Virtual Environment