KVM has several tools to manage VMs. The Virtual Machine Manager is a GUI tool that's quite easy to use. If you want more power you can use the virsh command-line tool, which has hundreds of subcommands useful for managing VMs, storage pools, and virtual networks.
- [Instructor] We can manage our guest VMs using the Virtual Machine Manager GUI. The default view shows our VMs and whether they're running or not. If they are running, it shows the guest CPU usage on the right. We can have it show our host CPU usage as well by going to View, Graph, and selecting Host CPU Usage. We can also double click on any guest VM to open the VM viewer. From that interface, we can pause, shut down, clone, migrate, or delete the VM by going to the Virtual Machine menu.
We can also go the View menu and click on Details to see all of the VM details. Here, we can add or configure the guest VM's virtual hardware. The Virtual Machine Manager's a very easy-to-use interface to KVM, but if you want more power, you'll need to use virsh, a command line tool. Virsh can work as a normal command, but also has an interactive tool with its own prompt. We're going to minimize the Virtual Machine Manager and go to a terminal. In the terminal, type in sudo, space, virsh, space, list, and hit Enter.
Type in your password if prompted. This command shows our running guest VMs and returns us back to the command prompt. We'll start looking at the virsh options by typing in sudo, space, virsh, space, help, space, pipe, space, less, and hit Enter. By scrolling down, you can see the vast number of sub-commands available. Thankfully, they're grouped by sub-command type. The first category's for domain management. These commands are used for interacting and configuring domains or VMs.
Examples would be start, autostart, reboot, shut down, destroy, and suspend. There are about 95 sub-commands in this category, so be sure to look them over. If we only want to see the help for the domain-specific sub-commands, we can type in sudo, space, virsh, space, help, space, domain. The next category comprises of domain monitoring commands. Domain monitoring commands are used to get information about VMs, such as dominfo, domstats, and list.
The next section is for managing the host and hypervisor. These commands get information about the host and the KVM hypervisor itself. The next three sections have to do with the network interfaces, network filtering, and networks themselves. There are commands for creating and configuring network interfaces and networks, as well as commands for configuring network filters. There are about 40 commands associated with networking.
After networking, we have commands for node devices. We'd handle passing through physical devices to VMs here. Snapshots are a very powerful feature of virtualization, and the snapshot category has commands to create, list, and delete VM snapshots. We also have commands for managing storage pools and volumes. Here, we'd create storage pools and volumes that go in them. Press Q to quit the help. To run virsh in interactive mode, don't provide any arguments.
Type in sudo, space, virsh, and hit Enter. Now we're in virsh and we don't have to keep typing in sudo each time. Any of the commands that we cover here can be used in either mode. Let's start by typing in list, space, dash, dash, all, and hit Enter. This shows us all VMs, whether they're running or not. To get information on a VM, we'd use dom info, so type in dominfo, space, centos7-ks, and hit Enter. This shows what type of VM it is, how much memory it has, and how many CPUs have been allocated.
Now let's shut down a VM. I'm going to choose centos7-ks since it's running. Type in shutdown, space, centos7-ks. If you have a different VM running, you'll want to choose one of those. I'm going to go ahead and hit Enter. We can see that it's being shut down. Give it a minute or two, and verify it by using list, space, dash, dash, all again. If the VM doesn't shut down gracefully, it's probably because the ACPID service isn't installed and running in the VM.
The kickstart file that we used installs and runs it by default, but you may run into this in other VMs. Starting a VM back up is very simple. Type in start, space, centos7-ks, and hit Enter. Attaching to the text console is also easy. Type in console, space, centos7-ks, and hit Enter. Each one of these commands just takes the VM name as an argument. If you're using a different VM, you'll want to substitute your VM name in place of centos7-ks.
To end the console, just type in Control, right square bracket, and you'll get your prompt back. Now that we have a working VM and we want to interact with it, we may want to make it start when the host boots up. To do this, we'll use a virsh sub-command again. Type in autostart, space, centos7-ks, and hit Enter. You can test this by rebooting the host computer and ensuring that the VM boots up automatically. Another easy task on the command line is creating a clone.
Before we leave virsh, let's get a list of all VMs again. Type in list, space, dash, dash, all, and hit Enter. And then type in quit. We'll want to create a clone of a VM that's not running. So to create a clone of our centos7.0 VM, we'll use virt-clone. Type in sudo, space, virt-clone, space, dash, dash, auto-clone, space, dash, dash, original, and then the VM name, in my case, centos7.0, and hit Enter.
Type in your password if prompted. I'm getting a warning message because I don't actually have enough physical space for my VM disk image. Because we're using qcow2 format for our disk images, we can over-provision our storage. Now, to view our clone, type in sudo, space, virsh, space, list, space, dash, dash, all, and hit Enter. We should now see our clone. We can also create a clone by going to our Virtual Machine Manager and right clicking on a VM and selecting Clone.
Instructor Grant McWilliams covers network and internet services administration, kernel management, and intrusion prevention. He shows how to make your systems more efficient with virtualization, manage users and groups, and lock everything down with SELinux mandatory access control. Plus, get access to 25 PDF "cheat sheets" and 100 practice questions so you can solidify and test your knowledge.
- Installing Linux on a physical machine
- Managing systemd services
- Managing reoccurring jobs with cron
- Limiting system access
- Configuring networking
- Creating, editing, and moving files and directories
- Analyzing text with grep and regular expressions
- Installing software and packages
- Managing the kernel
- Managing users, accounts, and groups
- Setting permissions
- Using access control lists
- Securing Linux with SELinux
- Accessing Linux remotely
- Configuring local storage