In the world of virtualization, efficient management of virtual machines (VMs) is paramount. While graphical user interfaces (GUIs) offer convenience, mastering command line tools provides a deeper level of control and automation. This guide explores essential commands for managing VMs via the command line interface (CLI).

1. How do I list all VMs on my system?

To list all VMs on your system, utilize the virsh command with the list option:

				
					sudo virsh list --all

				
			

This command displays a comprehensive list of all VMs, including their current status and names.

2. How do I start a VM from the command line?

To start a VM from the command line, employ the virsh command with the start option:

				
					sudo virsh start <vm_name>

				
			

Replace <vm_name> with the specific name of the VM you intend to start. Remember to run the command with administrative privileges if required.

3. How can I gracefully shut down a VM via CLI?

To shut down a VM gracefully using the command line, again, rely on the virsh command:

				
					sudo virsh shutdown <vm_name>

				
			

Substitute <vm_name> with the name of the VM you wish to shut down. This command sends an ACPI shutdown signal to the VM, ensuring a proper shutdown process.

4. How do I check the status of a specific VM?

To check the status of a particular VM, utilize the virsh command with the domstate option:

				
					sudo virsh domstate <vm_name>

				
			

Replace <vm_name> with the name of the VM you want to inspect. This command provides a comprehensive overview of the VM’s configuration, including memory allocation, CPU usage, and more.

To retrieve the IP address of a virtual machine, you can use various methods depending on your virtualization environment. One common approach is to use the virsh command combined with the domifaddr option. Here’s how:

				
					sudo virsh domifaddr <vm_name>

				
			

Replace <vm_name> with the name of your virtual machine. This command will display the IP addresses associated with each network interface of the specified VM.

Mastering command line VM management empowers administrators with greater flexibility, automation, and control. By leveraging these commands effectively, you can streamline your virtualization workflow and ensure optimal performance of your virtualized infrastructure.