Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
13d2d1f8
Commit
13d2d1f8
authored
Feb 12, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
ea15cec7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
23 deletions
+65
-23
t/qemu-runlinux
t/qemu-runlinux
+65
-23
No files found.
t/qemu-runlinux
View file @
13d2d1f8
#!/bin/sh -e
#!/bin/sh -e
# qemu-runlinux [options] <kernel> <program> ...
# 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
# Copyright (C) 2014-2019 Nexedi SA and Contributors.
# edited/compiled on host.
# 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.
# pid=1: we are running inside booted kernel as init.
# mount /sys /proc etc and tail to the program.
# mount /sys /proc etc and tail to the program.
qshutdown
()
{
if
[
$$
==
1
]
;
then
echo
1
>
/proc/sys/kernel/sysrq
echo
"qinit ..."
echo
o
>
/proc/sysrq-trigger
# shutdown
}
qshutdown
()
{
echo
1
>
/proc/sys/kernel/sysrq
echo
o
>
/proc/sysrq-trigger
# shutdown
qdie
()
{
}
echo
"E:
$*
"
1>&2
qshutdown
qdie
()
{
sleep
1d
# give time for shutdown to happen
echo
"E:
$*
"
1>&2
exit
1
# just in case
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
sysfs none /sys
mount
-t
debugfs none /sys/kernel/debug
mount
-t
debugfs none /sys/kernel/debug
#mount -t bpf none /sys/fs/bpf
#mount -t bpf none /sys/fs/bpf
...
@@ -48,8 +73,9 @@ if [ $$ == 1 ]; then
...
@@ -48,8 +73,9 @@ if [ $$ == 1 ]; then
test
$#
!=
0
||
qdie
"no program to run"
test
$#
!=
0
||
qdie
"no program to run"
#cat /proc/cmdline
#cat /proc/cmdline
#env
#env
#set +e -x
#set -x
setsid
"
$@
"
<
>
/dev/ttyS0
>
&0 2>&1
# run argv[1:] passes to init
set
+e
setsid
"
$@
"
<
>
/dev/ttyS0
>
&0 2>&1
# run argv[1:] passed to init
echo
"exit code:
$?
"
echo
"exit code:
$?
"
qshutdown
qshutdown
...
@@ -58,20 +84,40 @@ if [ $$ == 1 ]; then
...
@@ -58,20 +84,40 @@ if [ $$ == 1 ]; then
fi
fi
# ----
--------------------------------
----
# ----
qemu setup
----
die
()
{
die
()
{
echo
"
$*
"
1>&2
echo
"
$*
"
1>&2
exit
1
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
nographic
=
y
while
test
$#
!=
0
while
test
$#
!=
0
do
do
case
"
$1
"
in
case
"
$1
"
in
-g
)
-g
)
# with graphics UI, /dev/console goes to VGA; program to /dev/ttyS0
nographic
=
;;
nographic
=
;;
-h
)
usage
exit
0
;;
*
)
*
)
break
;;
break
;;
esac
esac
...
@@ -121,7 +167,3 @@ ${nographic:+console=ttyS0} init="$(realpath $0)" \
...
@@ -121,7 +167,3 @@ ${nographic:+console=ttyS0} init="$(realpath $0)" \
CWD="
$dir
" HOME="
$HOME
" LANG="
$LANG
" TERM="
$TERM
" PATH="
$PATH
"
\
CWD="
$dir
" HOME="
$HOME
" LANG="
$LANG
" TERM="
$TERM
" PATH="
$PATH
"
\
--
$prog
\
--
$prog
\
"
"
# \
# -nographic \
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment