Linuxinternals-qemu-hacking
Contents
Introduction
This is a guide to quickly setting a Qemu environment, suitable for kernel testing and hacking on an x86 host. The guide assumes that you are running an Ubuntu host.
Install libvirt / virt-manager
The easiest way to install qemu with a user-friendly front end (virt-manager) is to install virt-manager, which will pull all the dependencies including Qemu that you would need.
sudo apt-get install virt-manager
[Then, follow the instructions here to install the latest Ubuntu ISO https://help.ubuntu.com/community/KVM/VirtManager]
Configuration of your libvirt guest
Make sure to add bridged networking to your guest, give it enough CPUs and atleast 1GB RAM. Make sure openssh-server is installed in the guest, this will allow you to scp kernel images to your guest and test them.
Building kernel for the qemu guest
- Check out Linus's kernel tree on your host:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cd linux
- Assuming your host is running a fairly recent version of Ubuntu, run the following
cp /boot/config-`uname -r` .config
- If you're hacking on PSTORE, follow the section "Additional kernel steps for PSTORE" and come back here.
- Configure kernel
make olddefconfig
- Build the kernel (use the bindeb-pkg as below to build convenient Ubuntu debian packages)
make bindeb-pkg
- After a successful build, one directory below you'll find a linux-image .deb package (ignore the -dbg package), it should look something like
linux-image-4.7.0+_4.7.0+-1_amd64.deb
Now scp this deb pkg to your Qemu guest, ssh into your qemu guest and run:
dpkg -i linux-image-4.7.0+_4.7.0+-1_amd64.deb # or whatever the .deb filename is
Additional kernel build steps for PSTORE
- If you're hacking on pstore, edit .config and make sure the following options are enabled (=y):
CONFIG_PSTORE=y CONFIG_PSTORE_FTRACE=y CONFIG_PSTORE_PMSG=y CONFIG_PSTORE_RAM=y
- Also add the following to .config, this will make sure kernel reserves 64KB of RAM starting from 256MB:
CONFIG_CMDLINE_BOOL=y CONFIG_CMDLINE="memmap=64K$0x10000000 reboot=w"