Qemu shows a black screen - linux

When the run following command on the teriminal
qemu-system-arm -M versatilepb -m 128M -kernel /home/<name>/linux-3.10.10/arch/arm/boot/uImage
A window with black screen will be opened and remain blank with no messages, but I am expecting Kernel messages on this screen. Please suggest a solution.

You have no console. Use '-append "console=tty1"' as shown below. Append gives command line arguments to kernel. Also, after the console issue is fixed, you will probably see a need for a root filesystem; many options exist there, I use a previously-mounted disk image, I have shown a commandline with both below.
qemu-system-arm -M versatilepb -m 128M -kernel /home/<name>/linux-3.10.10/arch/arm/boot/uImage -append "console=tty1 root=/dev/mmcblk0p1 rootfstype=ext3" -drive file=disk.img,if=sd

If you are trying to emulate a Raspberry Pi, use follow the advice in Joe Kul's answer, but instead of tty1, use ttyAMA0 instead.

Related

How to build the Linux kernel for powerpc and boot it on qemu?

I had compile a linux kernel and generating root file system using buildroot for 64-bit powerpc. Target CPU POWER7.
Output of buildroot:
1] rootfs.cpio 2] rootfs.ext2 3] rootfs.tar.gz 4] vmlinux
Start qemu simulation with
qemu-system-ppc64 -m 1024 -kernel output/images/vmlinux -initrd output/images/rootfs.cpio -serial stdio
--> Output:
Output Of 1st command
qemu-system-ppc64 -M pseries -cpu POWER7 -m 1024 -kernel output/images/vmlinux -append 'console=hvc0 root=/dev/sda' -drive file=output/images/rootfs.ext2,if=scsi,index=0,format=raw -serial stdio
--> Output:
Output of 2nd command
What have I done wrong and what can I do to fix it?
How long did you wait for it? I assume a while. In which case it looks like the kernel has crashed somewhere very early in boot, before it could detect the console. That can happen if you have far too little memory, but 1G should be enough. It can also happen if you build the kernel for the wrong machine/CPU type, but you seem to have gotten that right.
There's some instructions here that you could try and are known to work.
Buildroot
https://buildroot.org/
I haven't tested it for powerpc specifically, but I bet it will all just work out of the box just like it worked for every arch I've tried so far (x86, ARM and MIPS) :-)
Just follow the steps explained at: How to download the Torvalds Linux Kernel master, (re)compile it, and boot it with QEMU? and replace arm with ppc.
Then to use your own Linux kernel source, you basically just have to use LINUX_OVERRIDE_SRCDIR as explained at: How to modify the source of Buildroot packages for package development?
Edit: I knew it was just a formality, but I actually tested the commands below after writing this question and the boot worked out of the box as expected:
unset LD_LIBRARY_PATH
make qemu_ppc64_pseries_defconfig
printf '
BR2_CCACHE=y
BR2_PACKAGE_HOST_QEMU=y
BR2_PACKAGE_HOST_QEMU_LINUX_USER_MODE=n
BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
BR2_PACKAGE_HOST_QEMU_VDE2=y
' >>.config
make olddefconfig
time make BR2_JLEVEL="$(nproc)" HOST_QEMU_OPTS='--enable-sdl --with-sdlabi=2.0'
./output/host/usr/bin/qemu-system-ppc64 -M pseries -cpu POWER7 -m 256 -kernel output/images/vmlinux -append 'console=hvc0 root=/dev/sda' -drive file=output/images/rootfs.ext2,if=scsi,index=0,format=raw -serial stdio -display curses

Kernel debugging - gdb step jumps out of function

I'm trying to do understand the kernel network stack for a security research for my university. That's why I try to debug the linux kernel.
So far I'm doing quite well but I ran in a problem when trying to use qemu and gdb for debugging.
The problem is as follows:
I boot my linux system: make boot
boot:
#qemu-system-x86_64 \
-kernel ${KERNEL_IMAGE} \
-drive file=${DRIVE_IMAGE},index=0,media=disk,format=raw \
-append "root=/dev/sda rw console=ttyS0 nokaslr gdbwait" \
-m ${RAM} \
--nographic \
--enable-kvm \
-s
And connect with gdb: make debug
debug:
#gdb -iex "target remote localhost:1234" ${KERNEL_DIRECTORY}/vmlinux
I set a breakpoint e.g. at icmp_rcv and continue
b icmp_rcv
Breakpoint 1 at 0xffffffff81808910: file net/ipv4/icmp.c, line 989.
c
Know I ping myself -> breakpoint hit:
Breakpoint 1, icmp_rcv (skb=0xffff88007c24ee00) at net/ipv4/icmp.c:989
Great so far everything worked as expected.
Know I press n/s (next or step) and instead of net/ipv4/icmp.c:990
It says:
native_apic_mem_write (reg=896, v=52414) at ./arch/x86/include/asm/apic.h:99
Know I press n until I come back to icmp_rcv:989.
I tried to set a breakpoint to icmp_rcv_990 but gdb never stops there.
Has anybody an idea how to fix this?
Thank you!
Yours
Honestly I have no glue why but removing --enable-kvm from my Makefile helped to get it working. I hope this helps other people.

running linux kernel image with qemu

I used these options to indicate which console to use by qemu
-nographic -serial stdio -append "console=ttyS0"
linux boot normally until this step, and when I hit enter the qemu> appear as the next picture illustrate:
It was me who types stop and quit
why did linux stop and qemu appear. I want to work with linux and execute programs from linux bin?

GUI for qemu-static & chroot

Is there any standard way to have a GUI for an emulated system using qemu and chroot? I searched about 'curses' , 'qtemu' ,etc. but I don't know how to use former and the latter was buggy. any suggestions ?
I'm using this command and I'm happy with bash interface:
LANG=C sudo chroot mnt /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/bash
You can always run guest machine(s) with a vncserver attached to the video console. To do this, run qemu/kvm with the -vnc option:
/usr/bin/qemu-arm-static -cpu cortex-a9 -vnc :1
This will start qemu in the background with a vncserver usually listening on "localhost:5901". You cand now start a vnc client to have access to the guest GUI.
Further info here:
http://doc.opensuse.org/products/draft/SLES/SLES-kvm_sd_draft/cha.qemu.running.html#cha.qemu.running.vnc

redirect QEMU window output to terminal running qemu

Im trying to debug the boot sequence of a linux kernel with qemu,
the command i'm running is:
qemu -serial stdio -kernel <path to kernel> -hda <path to rootfs> -append "root=/dev/sda terminal = ttyS0"
During boot all the kernel messages are printed to the QEMU window.
Only when the boot has finished i get my prompt back to the terminal i ran QEMU in.
Now i can start using the kernel terminal I'm running and seeing the output in the terminal and not in QEMU window.
How do i get all messages including the boot messages to my terminal and not to QEMU window (because i cant scroll up in that window..) ?
remove -serial stdio parameter
add -nographic parameter
and change the kernel parameter terminal = ttyS0 to console=ttyS0. This should do the trick.
qemu -nographic -kernel ./bzImage -hda ./image.hda -append root=/dev/sda console=ttyS0
You may want to check the script I use for kernel development: https://github.com/arapov/wrap-qemukvm (it's not very "production", but you can find useful qemu cli parameters there)
refer this Redirect Qemu console to a file or the host terminal?
to get the log on both qemu and your terminal .use
"console=ttyAMA0,115200 console=tty highres=off console=ttyS0"
Redirecting Qemu output to terminal might cause some problem (personally i don't like it). You can using options like -noframe (this will create new window but won't any window frame) or -curses to experience qemu output on terminal.

Resources