The goal of this assignment is to be able to compile and boot the Linux kernel on the KVM-qemu virtual machine. If you have never built or installed a kernel before then please start this assignment early. We will use the Ubuntu distribution of Linux.
There are three parts to this system: the KVM-qemu virtual machine, the virtual machine's disk image, and your own build of the Linux kernel. Modern versions of Linux allow you to boot another version of Linux inside a virtual machine. In order to boot Linux you need something that looks like a disk that has all of the programs and the file system that Linux needs in order to run. Finally, we want to play with the kernel, so we want to compile it ourselves.
Unfortunately, the CS machines do not support KVM, so you will need to find a machine that does. If you can't find one, let us know.
You should be able to get your VM running inside KVM by specifying the location of the VM with -drive. You may want to append --snapshot after the file name of your VM. This ensures that no changes are made to your image during an execution so you can do something dangerous and have the original image file preserved.
Once you've been able to get your VM running inside KVM, try installing a package using aptitude to verify your VM has network access.
Download the latest Linux kernel release from kernel.org.
yes "" | make -C <kernel dir> O=$(pwd) config
make INSTALL_MOD_PATH=<install_mod_dir> modules_install
You can also use nbd to mount a qcow2 image, though I have found it terribly slow.
My favorite trick is to convert the qcow2 to a raw disk image qemu-img convert -O raw test.qcow2 test.raw
, and then do a loopback mount mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
. Loopback mounts are fast.
Here is a good reference on qemu images.
Please complete a short writeup that you will print out and bring to class.
Identify completely your hardware and software.
Explain any changes you made to the kernel build process and why.
Report your qemu command line.
Boot the Kernel, and run dmesg
to capture the kernel output from the
boot. In your writeup, report the wall clock time for your boot, and compare that with the time reported by the kernel. Are they the same? Why or why not?
For each device, quote the parts of the dmesg
output that show the kernel discovering that device, and then report
what kind of device it is, and how you made your determination. You may also use lspci
.Please only quote a maximum of 3 lines.
#include<unistd.h>
#include<fcntl.h>
int main()
{
int fd = open("/dev/urandom", O_RDONLY);
char data[4096];
read(fd, &data, 4096);
close(fd);
fd = open("/dev/null", O_WRONLY);
write(fd, &data, 4096);
close(fd);
}
Please think of your report like the papers we are reading for the class. Organize the information that you gathered and present it logically. For example, early in your report specify your experimental platform, including the hardware, the OS, whether you are running qemu or a hypervisor, etc. Include anything relevent to understand the results, but keep your description concise. Of course balancing completeness and concision is difficult, but that balance is generally well accomplished by the (modern) papers we read.
Please report how much time you spent on the lab.