I build vmlinux and Bzimage from linux 4.18.
And to enable kernel stop in the breakpoint, I disable the random address feature in the kernel.
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)And I create
rootfs using busybox following steps
dd if=/dev/zero of=rootfs.img bs=1M count=10
mkfs.ext4 rootfs.img
sudo mount -t ext4 -o loop rootfs.img ./fs
sudo make install CONFIG_PREFIX=./fs
sudo mkdir proc dev etc home mnt
sudo cp -r ../examples/bootfloppy/etc/* etc/
sudo chmod -R 777 fs/
And run qemu with command
qemu-system-x86_64 -kernel ./bzImage \
-hda ./busybox-1.32.0/rootfs.img \
-append "root=/dev/sda rw console=ttyS0" -s -S -smp 2 -nographic -hdb ext4.img
And then I build a hello world program and put its object to rootfs after compiling.
#include<stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
I run the hello program in QEMU. QEMU reports that
-/bin/sh: ./hello: not found
And then I try to build it with static option
gcc hello.c -static -o hello
Running the hello program in QEMU, it reports "Segmentation fault".