Creating a Virtual Machine Using qemu and libvirt

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

The leadership team at your company has initiated a new project to reduce hardware expenses and reduce the total cost of ownership. Your manager has assigned you to a team focused on reducing the need of physical hardware for development and evaluation projects. You have been assigned the task of creating a minimal virtualization environment for testing the viability of virtualizing servers for the development team.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install qemu and libvirt from the Command Line

Use apt to install the following packages

  • qemu
  • qemu-kvm
  • libvirt-bin
  • bridge-utils
  • virtinst
Confirm libvirtd Service Status and Add the User Account to the libvirt Group
  • Use systemctl to confirm the libvirtd service started.
  • Add the cloud_user account to the libvirt group.
  • Use the su command to open a new session for the cloud_user, to pick up the group changes.
Create a Virtual Machine Using the Available CirrOS Image
  • Use elevated privileges to copy the Cirros image from the home directory to the /var/lib/libvirt/images directory.
  • Use the virt-install command to create a virtual machine using the appropriate parameters.
Log into the Virtual Machine and Confirm Its Status
  • Log into the virtual machine.
  • Execute a few basic commands to confirm system functionality.
  • Log out of the virtual machine.

Additional Resources

The leadership team at your company has initiated a new project to reduce hardware expenses and reduce the total cost of ownership. Your manager has assigned you to a team focused on reducing the need of physical hardware for development and evaluation projects. You have been assigned the task of creating a minimal virtualization environment for testing the viability of virtualizing servers for the development team.

To complete the request and provide the environment to the development team, you will need to complete the following tasks.

  1. Use apt to install qemu and libvirt from the command line:
    • qemu
    • qemu-kvm
    • libvirt-bin
    • bridge-utils
    • virtinst
  2. Confirm the service status and grant proper permissions to the user account:
    • Use systemctl to confirm the libvirtd service is running.
    • Add the cloud_user account to the libvirt group.
    • Use the su command to switch to a new session for the cloud_user, to pick up the group changes.
  3. Create a virtual machine using the available CirrOS image:
    1. Use elevated privileges to copy the CirrOS image to the /var/lib/libvirt/images directory.
    2. Use the virt-install command to create a virtual machine using the following parameter values:
      • Name: Name for the virtual machine, such as cirros
      • Connection: qemu (qemu:///system)
      • Description: Free text description, such as "Cirros 0.5.1"
      • OS type: Linux
      • RAM: 256
      • VCPU: 1
      • Disk Path: /var/lib/libvirt/images, set the bus to virtio and the size to 8
      • Graphics: none
      • Network bridge: virbr0, set the model to virtio
      • Console: Set it to pty, and target type to serial
      • Boot: hd
  4. Log into the virtual machine and confirm it is working properly:
    • When presented the CirrOS login prompt, log in using the cirros username and the password gocubsgo.
    • Run a few basic commands to confirm the system is functional. Good examples could be pwd, ls, and viewing the contents of /etc/os-release.
    • Log out of the virtual machine.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?