CSL862 : Virtualization and Cloud Computing : HW3 : Hardware Virtualization Techniques

In this homework, you will study KVM, a hardware-assisted VMM.

Building and Running Linux/KVM

You will need a 64-bit x86 machine with a processor which supports Intel-VT or AMD-V hardware virtualization extensions. You will need root privileges on this machine. Download the latest version of the Linux kernel from kernel.org and copy it to /usr/src directory.

Building Linux Kernel

  1. Untar the linux tarball using, tar -xvf linux-x.x.xx.x.tar.bz2
  2. cd linux-x.x.xx.x folder
  3. Get into the root shell, using sudo su
  4. Copy your current kernel configuration file (/boot/config-x.x.xx.x) to the current working directory (linux-x.x.xx.x) and rename it to .config.
  5. Install libncurses5-dev: apt-get install libncurses5-dev.
  6. Run command: make menuconfig.
  7. Select option Load an Alternate Configuration File. You will be prompted for .config. Click Yes.
  8. Go to Virtualization, and select all KVM options to be compiled in the kernel as modules (M).
  9. Go to General Setup, select option Local version- append to kernel release, and put suffix -custom, for example
  10. Exit from the configuration menu. You will be prompted to save your configuration to .config. Select Yes.
  11. Optionally, to make the build process faster, set environment variable CONCURRENCY_LEVEL to be the one greater than the number of processors on your system.
  12. make -j $CONCURRENCY_LEVEL && make_modules install && make install && make headers_install
  13. Wait for minutes/hours (depends on your system)
  14. Move to /boot directory and run: makeinitramfs -o initrd.img-new_kernel_version new_kernel_version. The new_kernel_version is appended to newly created vmlinuz-x.x.xx.x img, for example
  15. Configure your bootloader. For example, uun update-grub if using GRUB on Ubuntu.
  16. Congrats, you are done. Reboot, select your newly compiled kernel and enjoy.

Running Qemu/KVM

Run KVM by using the --enable-kvm flag to your Qemu commandline. For example: qemu --enable-kvm linux.img

Recompile KVM Module

For this assignment, you will be making changes to the KVM module compiled as part of the kernel. We give you some instructions on how to compile and test your changes to the KVM module.
  1. Make changes to your kvm module.
  2. For convenience, create a shell script (e.g., call it recompile) in your linux source folder /usr/src/linux-x.x.xx.x. Here are the contents of the recompile shell script:
    make M=arch/x86/kvm
    rmmod kvm_intel kvm
    cp arch/x86/kvm/*ko /lib/modules/LINUX_KERNEL_VERSION/kernel/arch/x86/kvm/
    modprobe kvm_intel
    modprobe kvm
  3. Make the script executable: chmod +x recompile
  4. Run the script with root privileges to recompile your kernel with new KVM module. The modprobe commands in the script reload the modules (without the need to reboot): sudo ./recompile

Creating a VM Disk Image

Here is a page with more information. Here are some examples:



[1] vIOMMU: Efficient IOMMU Emulation, N. Amit, M. Ben-Yehuda, D. Tsafrir, A. Schuster. USENIX ATC 2011