Starting a virtual machine using QEMU and libvirt

After the deployment process, we can start managing our virtual machines. We will use MasteringKVM01 and MasteringKVM02 as an example. Let’s start them by using the virsh command, along with the start keyword:

Figure 3.8 – Using the virsh start command

Figure 3.8 – Using the virsh start command

Let’s say that we created all five of our virtual machines from the shell script example and that we left them powered on. We can easily check their status by issuing a simple virsh list command:

Figure 3.9 – Using the virsh list command

Figure 3.9 – Using the virsh list command

If we want to gracefully shut down the MasteringKVM01 virtual machine, we can do so by using the virsh shutdown command:

Figure 3.10 – Using the virsh shutdown command

Figure 3.10 – Using the virsh shutdown command

If we want to forcefully shut down the MasteringKVM02 virtual machine, we can do so by using the virsh destroy command:

Figure 3.11 – Using the virsh destroy command

Figure 3.11 – Using the virsh destroy command

If we want to completely remove a virtual machine (for example, MasteringKVM02), you’d normally shut it down first (gracefully or forcefully) and then use the virsh undefine command:

Figure 3.12 – Using the virsh destroy and undefine commands

Figure 3.12 – Using the virsh destroy and undefine commands

Bear in mind that you can actually do virsh undefine first, and then destroy, and that the end result is going to be the same. However, that may go against the expected behavior in which you first shut down an object before you actually remove it.

We just learned how to use the virsh command to manage a virtual machine – start it and stop it – forcefully and gracefully. This will come in handy when we start extending our knowledge of using the virsh command in the following chapters, in which we’re going to learn how to manage KVM networking and storage.

We could do all these things from the GUI as well. As you may recall, earlier in this chapter, we installed a package called virt-manager. That’s actually a GUI application for managing your KVM host. Let’s use that to play with our virtual machines some more. This is the basic GUI interface of virt-manager:

Figure 3.13 – The virt-manager GUI – we can see the list of registered  virtual machines and start managing them

Figure 3.13 – The virt-manager GUI – we can see the list of registered virtual machines and start managing them

If we want to do our regular operations on a virtual machine – start, restart, shut down, turn off – we just need to right-click it and select that option from the menu. For all the operations to become visible, first, we must start a virtual machine; otherwise, only four actions are usable out of the available seven – Run, Clone, Delete, and Open. The Pause, Shut Down sub-menu, and Migrate options will be grayed-out as they can only be used on a virtual machine that’s powered on. So, after we – for example – start MasteringKVM01, the list of available options is going to get quite a bit bigger:

Figure 3.14 – The virt-manager options – after powering the virtual machine on,  we can now use many more options

Figure 3.14 – The virt-manager options – after powering the virtual machine on, we can now use many more options

We will use virt-manager for various operations throughout this book, so make sure that you familiarize yourself with it. It is going to make our administrative jobs quite a bit easier in many situations.

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

fifteen − two =