qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to run C program in QEMU(running 4.18 linux kernel)


From: Taiyu
Subject: How to run C program in QEMU(running 4.18 linux kernel)
Date: Wed, 8 Dec 2021 10:19:06 +0800

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".

reply via email to

[Prev in Thread] Current Thread [Next in Thread]