Commit 76d8f76d authored by Kirill Smelkov's avatar Kirill Smelkov

Script to run compiled linux kernel with root fs mounted from host

Useful to debug (via either printk or gdb) the kernel - one can boot it,
and tweak compile test program on host and be ready to test it inside
qemu on tested kernel. Another use case is to add tracing printk to
kernel and to boot it on each iteration. Booting via qemu means the
workflow is not disrupted as would with rebooting the hardware.

With this tool it was straightforward to find out why mmap-alias through
mremap does not work for huge pages:

static struct vm_area_struct *vma_to_resize(unsigned long addr,
        unsigned long old_len, unsigned long new_len, unsigned long *p)
{
        struct mm_struct *mm = current->mm;
        struct vm_area_struct *vma = find_vma(mm, addr);

        if (!vma || vma->vm_start > addr)
                goto Efault;

        if (is_vm_hugetlb_page(vma))            <--
                goto Einval;

mremap_to(...)
{
        /* lots of checks, then */
        vma_to_resize(...)
parent 8c935a5f
#!/bin/sh -e
# qemu-runlinux <kernel>
# run kernel in QEMU with root fs taken from host
#
# Useful to test/debug just compiled kernel via running programs
# edited/compiled on host.
kernel=$1
arch=`uname -m`
test -z "$kernel" && kernel=arch/$arch/boot/bzImage
# may be also useful:
# -serial stdio
# -serial file:ttyS0
# -monitor stdio
# -serial stdio
# -S -gdb tcp::1234
# NOTES
# - for kernel to mount root, 9P support must be compiled in:
# CONFIG_NET_9P=y
# CONFIG_NET_9P_VIRTIO=y
# CONFIG_9P_FS=y
#
# - mount_tag *must* be /dev/root - as of 3.17-rc1 the kernel hardcodes it
#
# References
# http://unix.stackexchange.com/questions/90423/can-virtfs-9p-be-used-as-root-file-system
# http://stackoverflow.com/questions/11408041/kernel-debugging-with-gdb-and-qemu
qemu-system-$arch \
-enable-kvm \
\
-nographic \
\
-fsdev local,id=R,path=/,security_model=none,readonly \
-device virtio-9p-pci,fsdev=R,mount_tag=/dev/root \
\
-kernel $kernel \
-append "ro rootfstype=9p rootflags=trans=virtio console=ttyS0 init=/bin/sh"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment