CSE 522S: Studio 14

QEMU/KVM Virtual Machines

Virtual machines provide machine abstractions that make workload consolidation, isolation, and even full machine emulation possible. Today's studio will focus on the QEMU (pronounced "Q-em-you") machine emulator and the KVM hypervisor, showing you how to boot virtual machines and explore the differences between software emulation and hardware virtualization in Linux.

In this studio, you will:

  1. Install a version of the Linux kernel that has KVM virtualization enabled on your Raspberry Pi
  2. Use QEMU to boot virtual machines on the Raspberry Pi
  3. Measure the time it takes to boot a hardware virtualized VM
  4. Compare with the time it takes to boot an emulated VM

Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete.

As you work through these exercises, please record your answers, and when finished upload your results to the appropriate page in Canvas.

Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.


Required Exercises

  1. As the answer to the first exercise, list the names of the people who worked together on this studio.

  2. We will be overwriting the operating system on your Raspberry Pi in this step. If there are source files for your labs/studios or any other data you need, you must first copy it to another system, as this studio will overwrite everything on the filesystem.

    Navigate to https://github.com/sakaki-/gentoo-on-rpi-64bit and follow the instructions to install the Gentoo operating system on your microSD card. You should start from the section titled Prerequisites and download the "full image" rather than the "lite" one.

    This link will first walk you through the process of formatting your Raspberry Pi's microSD card. This will in turn require access to another computer system that you will plug the microSD card into (e.g., using either a USB or microSD to SD memory card adapter, provided with your Raspberry Pi if you purchased from the Canakit website). You will then overwrite the microSD contents with the Gentoo system files. Note: decompressing and copying the genpi64.img.xz image to your microSD will likely take around 20 minutes

    Once you have formatted your microSD card and installed the Gentoo files on it, proceed to the section titled Booting!. This will require your Raspberry Pi to be connected to a keyboard/monitor/power supply. The process of bringing up the new OS may take a few minutes and will require a couple of reboot cycles, so be patient and follow the on-screen instructions. Once the new system has booted, make sure you at least change the password for the default user demouser and for root. Both passwords are initially set to "raspberrypi64"

    Once you've booted into the new OS, open up a terminal, and as the answer to this exercise, show the output of the command uname -a

  3. Navigate to https://www.raspberrypi.org/forums/viewtopic.php?t=224057 and follow the instructions in the first post to create and boot a virtual machine on your Raspberry Pi. The virtual machine contains a small installation of the Ubuntu operating system, and thus once successfully created you will be runnning an Ubuntu guest on top of the Gentoo host. Note that the linked instructions indicate to boot the VM as a regular user, but I found that I had to use root or it wouldn't boot. Your milage may vary. -James

    During the guest booting process, you may see some error messages, but they are non-catastrophic. The VM will ask you to "Press any key to continue". Do so, and then once the VM has booted, you can login with the username 'ubuntu' and password 'passw0rd'

    As the answer to this exercise, show the output of running uname -a in the Ubuntu VM

  4. Teardown the virtual machine by typing shutdown -h now in the guest console. Open up a separate terminal window, issue the following command:

    time while [ 1 -eq 1 ]; do sleep 10; done

    Now, restart the VM by running the same QEMU command line to boot the VM, and, once you have logged in to the VM, type "Ctrl+C" in the window in which you ran the time command. As the answer to this exercise, list the amount of time it took to boot the VM.

  5. Finally, again teardown the VM, and restart the makeshift timer as shown above. This time, reboot the QEMU VM, but remove the "-accel kvm" and "-cpu host" options from the QEMU command line. Wait a few minutes (or as long as the initial boot process took with KVM enabled) and as the answer to this question, describe what you see on the QEMU console window. Based on your understanding of KVM and hardware virtualization, describe why the behavior is different in the two different QEMU boot commands when KVM is enabled vs disabled.


    Things to Turn In: