How to check compiled linux kernel? - linux

I am new to Linux Kernel Development. I have got the linux source code and added a Hello World system call just to get started. But now I am not able to figure out how to go about testing this code. How can I run the changed kernel?
I think I can use VirtualBox to check, but would not I have to make a new iso everytime I make a change and compile the kernel?
Sorry for asking such a naive question, but I am very confused here

You can launch a qemu virtual machine with an external kernel, so you don't need to keep modifying a disk image to test your kernel. For example:
qemu-kvm -kernel arch/x86/boot/bzImage -initrd initramfs.gz -append "console=ttyS0" -nographic
That example comes from this article which contains a lot of information on how to set up a development environment.

Related

Booting a Graphical MIPS QEMU Machine

I would like to boot a QEMU MIPS architecture machine running some distribution of Linux. I have been looking through this documentation (https://www.linux-mips.org/wiki/QEMU), but I am getting stuck at this part
[ralf#box qemu]$ qemu-system-mips -kernel /tftboot/192.168.0.1/vmlinux.bin -m 16 -nographic
(qemu) mips_r4k_init: start
mips_r4k_init: load BIOS '/usr/local/share/qemu/mips_bios.bin' size 131072
qemu: could not load MIPS bios '/usr/local/share/qemu/mips_bios.bin'
[ralf#box qemu]$
There currently is no MIPS BIOS file for QEMU (see firmware). However if passed a
-kernel argument qemu will not call the firmware at all, so this does no harm at all. Therefore, a command such as
dd if=/dev/zero of=/usr/local/share/qemu/mips_bios.bin bs=1024 count=128
will generate a firmware file that will do the job for now.
I am confused what arguement I am supposed to pass for kernel? Is that /usr/local/share/qemu/mips_bios.bin argument a compiled Linux image?
If possible, I would like the emulator to have a GUI. I am not sure how this is accomplished either.
Thanks.
You no longer need to create a mips_bios.bin file. If you have a file by that name in the same folder when you run qemu-system-mips it will pick it up. I'd remove it if you do. Here's the wiki link for a little history about it:
https://www.linux-mips.org/wiki/QEMU
For a nice example of a mips specific kernel working with graphics and qemu please check this link out:
http://shadow-file.blogspot.com/2013/05/running-debian-mips-linux-in-qemu.html

Can KVM work without libvirt?

I am sorry for silly question, but could you please tell: can KVM work without
libvirt?
From my poor experience I have seen KVM functionality which based on libvirt.
Thanks for your reply in advance.
I've used KVM without libvirt. libvirt is just a group that you assign a user to so that you are not rooted when you execute the virtual machine. You have to have qemu installed.
sudo apt-get install qemu
Then you would use the qemu package that supports the type of iso you are trying to install. Then you would write something like this
qemu-system-x86_64 -m 2048 -cdrom /path/to/Windows10.iso -enable-kvm
If you already have windows extracted onto the hard drive then you would write it like this
qemu-system-x86_64 -m 2048 -hda /path/to/Windows10.iso -enable-kvm
You can find out the different kinds of qemu packages that you have just typing in qemu in the terminal, and this will tell you the types of OSes that can be run inside of KVM using the specified package.

Can we use terminal to test the modified kernel code?

I am working on linux on ubuntu. I am modifying the source code of linux 2.6.25 by adding a system call while my operating system has some other version of linux installed. To test my modified code, do I need to install an emulator or can I test it on the terminal window itself?
If I can build and compile my linux 2.6.25 on the terminal, how should I do it?
You can test your modified kernel by installing that kernel in your current Ubuntu system.
Please follow following steps to install kernel in your system.
1) compile your modified linux kernel
make
2) Install that kernel using following command
make modules_install install
3) update initramfs as per the changes made in kernel using following command
update-initramfs -u -k 3.0.0
4) Finally, Update the grub loader to add the entry of your kernel in boot loader using following command.
update-grub
5) Reboot the system and execute the uname -r command to verify that you have updated your kernel or not.
reboot
uname -r
You can find your updated kernel with your existing kernel on next reboot and check your updated kernel which you have modified with that kernel.
Please let me know if you need any more information,
You can use User Mode Linux.
Using UML, you can even use gdb to debug it.
http://user-mode-linux.sourceforge.net/
http://user-mode-linux.sourceforge.net/hacking.html
Although the document is rather old, it still works in recent kernel.

Mini2440 Emulation Procedure : please, how to?

I want to emulate the friendlyARM board, the Mini2440 or the mini6410, so I can get to practice the embedded programming, the QT programming and this due to some financial difficulties and strange import policy in my country.
Anyway, the problem is that I can't seem to understand what's the first step to proceed the emulation: Am running ubuntu 12.04 on VirtualBox then, I installed the qemu-kvn-extras then what ?
Do I need a new kernel for qemu and the emulation process ? What's its specifications ?
In the other hand, when I read all of the tutorials in the net, I can't see the hardware specification part : I mean where is the part in the "qemu-i386 command" that refers to the fact that I'm using Mini2440 ?
After a long period of research, I don't know whether I can emulate the board so I can get used to the u-boot and cross compiling, etc.. or it's just a dream I can't reach ..
(Sorry for reviving an old thread but I had similar issues, so this might be useful for some other people, too)
To run my tests I used (see also man qemu-system-arm):
$ qemu-system-arm -machine versatilepb -cpu arm1176 -m 128M -nographic -kernel kernel.img
You might not want the -nographic here when you are testing Qt and need to replace kernel.img with the image you want to run. However, note that you need the ARM version of qemu qemu-system-arm. It will not work with the Intel version qemu-i386 as the mini6410 runs an ARM processor (the ARM1176JZF-S).
For me, connecting with gdb was also useful (-S halts the CPU at start, -s starts a gdbserver on port 1234):
$ qemu-system-arm -machine versatilepb -cpu arm1176 -S -s -m 128M -nographic -kernel kernel.img
And then:
$ arm-none-eabi-gdb
(gdb) target remote localhost:1234
By the way, host system can be any Linux distribution, so you do not need VirtualBox if your host is already Linux.
Another remark: I am currently struggling to get the interrupts to run on qemu (see also ARM Interrupt Handling in QEMU), so not sure if everything will work for you though.
Good luck! ;)
The closest thing I know about emulating the Mini2440 is that it's emulated on MAME.
The only problem is that you're not only stuck with the 3 pre installed OSes (Windows Mobile, old version Android and a Linux distro) but it's also slow and you can't connect to anything outside of the device itself.
You'll probably need a beefy computer if you want to run this, the beefier the PC is, the faster you can run it.
Plus, you can't use your mouse as a touch screen. You'll need to map out the touch screen controls that are already present in MAME if you want something like that.

Linux kernel development with KVM

I'm trying to run Linux in a VM so I can make changes and test them quickly. I came upon this tutorial...
http://blog.vmsplice.net/2011/02/near-instant-kernel-development-cycle.html
I tried the following command (in the linux-2.6 directory, checked out via git)...
kvm -kernel arch/x86/boot/bzImage -initrd /boot/initrd.img-2.6.38-10-generic -append "console=ttyS0" -nographic
I created the initrd.img-2.6.38-10-generic with the update-initramfs tool. Here is the output when I run that...
http://pastebin.com/HxGMMHSt
Failing to load some modules and not mounting anything. I think I'm missing some crucial step, I'm pretty unfamiliar with virtualization.
Running Ubuntu 11.04
Any help is appreciated, thanks.
Seems you did not installed the modules and kvm can not find them in /lib/modules. make modules_install may help.

Resources