I want to work on linux kernel development on Qemu. I want to modify few kernel files as part of my project. I am only able to find ISO files of the linux distros online which I think we cannot edit. Could anyone please point me in the right direction regarding this?
4 Answers
Buildroot to the rescue
Buildroot is a set of scripts that generates tiny distros with rootfs images smaller than 10MiB.
It downloads everything from source and compiles it, so it is trivial to patch packages up. There is a supported patching mechanism with BR2_GLOBAL_PATCH_DIR
https://buildroot.org/downloads/manual/manual.html#customize-patches
The generated images are so tiny, that it becomes possible to understand the entire userland setup, which will make it easier to focus on the kernel.
I have created this setup to automate things as much as possible: https://github.com/cirosantilli/linux-kernel-module-cheat
This setup also works great for ARM: How to use QEMU for learning ARM Linux kernel development?

- 347,512
- 102
- 1,199
- 985
Download Linux kernel source code from kernel.org, then modify, configure, build your kernel. After building you'll get a kernel image usually located at arch/x86/boot/bzImage (if your arch is x86, look at appropriate location for your arch), and this is what you need to test your modified kernel on Qemu. You'll also need a rootfs (use busybox) to run it properly. Use qemu's '-kernel' parameter to pass the bzImage. An example:
`qemu-system-x86_64 -m 1024 -smp 4 -kernel arch/x86/boot/bzImage -initrd initramfs.gz -append "rdinit=/ root=/dev/ram`
it tells qemu to use 1024 of ram, use 4 cpu.

- 136,911
- 4
- 20
- 26
-
Hi! Thanks a lot for the answer. I just tried to install busy box on my system following the steps in this link: [link](http://blog-junstrix.rhcloud.com/2013/01/23/compiling-linux-kernel-and-running-on-qemu/) but I am getting this error 'mount: mount point rootfs is not a directory' when i tried to run this command 'sudo mount -o loop ramdisk.img rootfs'. Could you please let me know how to proceed? – Srikanth Kandalam Oct 23 '13 at 05:18
-
That's a bit of different thing and on that tutorial shows how to run a program as part of init. You don't necessarily need to mount rootfs under some directory, if you use busybox, you'll get _install directory from there on you can create rootfs. – rakib_ Oct 23 '13 at 05:46
The best way I would recommend is to you ubuntu-vm-builder.
sudo ubuntu-vm-builder qemu precise --arch 'amd64' --mem '1024' --rootsize '4096' --swapsize '1024' --kernel-flavour 'generic' --hostname 'ubuntu' --components 'main' --name 'Srikanth' --user 'ubuntu' --pass 'ubuntu' --bridge 'br0' --libvirt 'qemu:///system'
and then run it in qemu.
This would build a qcow2 file, which is copy on write and would be faster than getting a kernel from the source and compiling it.

- 31
- 3
If you want to modify linux kernel, You can download kernel source from https://www.kernel.org/ . Install on Linux system after modifying code.

- 1,580
- 10
- 18

- 666
- 2
- 7
- 13
-
1Hi Thanks for the answer but I am interested in making changes in the kernel offline and then run the modified version on qemu and then I want to see if those changes I did have reflected or not in Qemu. But after I run the kernel through Qemu it's just loading the kernel and I am not able to do anything further. Please let me know if you need any more info. – Srikanth Kandalam Oct 23 '13 at 04:51
-
Please don't use signature and tagline in SO (http://meta.stackexchange.com/questions/5029/are-taglines-signatures-disallowed). – KBart Oct 23 '13 at 08:00