Commit 13d2d1f8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ea15cec7
#!/bin/sh -e
# qemu-runlinux [options] <kernel> <program> ...
# run kernel in QEMU with root fs taken from host
# run kernel/program in QEMU with root fs taken from host
#
# Useful to test/debug just compiled kernel via running programs
# edited/compiled on host.
# Copyright (C) 2014-2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# qemu-runlinux spawns linux kernel under qemu, setups rootfs to be taken from
# / of host, and runs specified program inside.
#
# It might be useful, for example, to test/debug just compiled kernel via
# running programs edited/compiled on host.
# ---- init under spawned kernel ----
# pid=1: we are running inside booted kernel as init.
# mount /sys /proc etc and tail to the program.
qshutdown() {
echo 1 >/proc/sys/kernel/sysrq
echo o >/proc/sysrq-trigger # shutdown
if [ $$ == 1 ]; then
echo "qinit ..."
}
qshutdown() {
echo 1 >/proc/sys/kernel/sysrq
echo o >/proc/sysrq-trigger # shutdown
qdie() {
echo "E: $*" 1>&2
qshutdown
sleep 1d # give time for shutdown to happen
exit 1 # just in case
}
}
qdie() {
echo "E: $*" 1>&2
qshutdown
sleep 1d # give time for shutdown to happen
exit 1 # just in case
}
if [ $$ == 1 ]; then
echo "qinit ..."
mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug
#mount -t bpf none /sys/fs/bpf
......@@ -48,8 +73,9 @@ if [ $$ == 1 ]; then
test $# != 0 || qdie "no program to run"
#cat /proc/cmdline
#env
#set +e -x
setsid "$@" <>/dev/ttyS0 >&0 2>&1 # run argv[1:] passes to init
#set -x
set +e
setsid "$@" <>/dev/ttyS0 >&0 2>&1 # run argv[1:] passed to init
echo "exit code: $?"
qshutdown
......@@ -58,20 +84,40 @@ if [ $$ == 1 ]; then
fi
# ----------------------------------------
# ---- qemu setup ----
die() {
echo "$*" 1>&2
exit 1
}
usage() {
cat <<EOF
Usage: qemu-runlinux [options] <kernel> <program> ...
Run linux/program under QEMU with rootfs taken from host.
<kernel> is path vmlinuz-like kernel image
<program> ... is program to run and arguments to it.
Options:
-g run with graphics
EOF
}
# by default output goes to stdout with both /dev/console and /dev/ttyS0 (where
# program is run) attached there.
nographic=y
while test $# != 0
do
case "$1" in
-g)
-g) # with graphics UI, /dev/console goes to VGA; program to /dev/ttyS0
nographic=;;
-h)
usage
exit 0
;;
*)
break;;
esac
......@@ -121,7 +167,3 @@ ${nographic:+console=ttyS0} init="$(realpath $0)" \
CWD="$dir" HOME="$HOME" LANG="$LANG" TERM="$TERM" PATH="$PATH" \
-- $prog \
"
# \
# -nographic \
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