Wanted to start with kernel development and experiment with it. But i did not want to have to have to install the kernel in my main machine. In this case the virtualization is the answer. I write the steps i did and the link(s) i used in order to get started.
To put everything together this is what i needed to do:
- install necessary packages
- download the kernel and build it
- create a root filesystem for qemu using buildroot
- run the kernel with the root filesystem with qemu
https://medium.com/@clem.boin/creating-a-minimal-kernel-development-setup-using-qemu-and-archlinux-987896954d84 has every detail to get started. There is no need to create a disk on anything and the debugging is a bonus. Although i dont know if the configure as it describes actually works, as i follow slightly different approach here.
Basic, i download the latest kernel (5.6.10) from https://www.kernel.org/ in a directory and then i did the normal make menuconfig, make and sudo make modules_install. If i wanted to install the kernel in my system and boot into it i will have to run also sudo make install and then configure the bootloader with sudo grub2-mkconfig -o /boot/grub2/grub.cfg.
Before go on, i want to share the parameters i used to build the kernel. I was actually trying to follow the http://linuxdocs.org/HOWTOs/Kernel-HOWTO.html#toc4 so the first thing i did was to disable the CONFIG_MODVERSIONS. That was for some convenience as i was just experiment. to find this when the menuconfig opens type / and copy paste the name that you are looking for. This will provide the path of where the config is located and exit. I had to repeat this for another error as the first attempt to build failed.
At the end build was ready and the modules were installed. now i had to build the filesystem. I cloned the buildroot, cd into it and i run make. This also takes some time and apparently you need Internet as it seems to download stuff (if you have perl installed and PERL_MM_OPT is set you will have to unset it).
finally i run the kernel in the qemu:
qemu-system-x86_64 -no-kvm -kernel arch/x86_64/boot/bzImage -boot c -m 2049M -hda ../buildroot/output/images/rootfs.ext2 -append "root=/dev/sda rw console=ttyS0,115200 acpi=off" -serial stdio -display none