apenwarr-redo/docs/cookbook/container/default.runkvm.do
Avery Pennarun 6fbda9a7b3 docs/cookbook/container: don't delete *.out and *.code during build.
If mkdocs is running in parallel, it can get upset if one of these
files exists when it lists the directory, but doesn't exist when it
goes to generate the output.  Fundamentally this is a problem in mkdocs
more than in our code, but we might as well avoid it.
2019-02-02 23:54:27 -05:00

32 lines
814 B
Text

./need.sh python kvm busybox
redo-ifchange "$2.initrd" memcalc.py
rm -f "$1.out" "$1.code"
# Linux only allows an initrd of size < 50% of RAM,
# so set a RAM amount based on the initrd size.
mem=$(./memcalc.py "$2.initrd")
echo "$2: kvm memory required: $mem" >&2
kvm \
-m "$mem" \
-kernel /boot/vmlinuz-$(uname -r) \
-initrd "$2.initrd" \
-append 'rdinit=/rdinit panic=1 console=ttyS0 loglevel=4' \
-no-reboot \
-display none \
-chardev stdio,mux=on,id=char0 \
-chardev file,id=char1,path="$1.out" \
-chardev file,id=char2,path="$1.code" \
-serial chardev:char0 \
-serial chardev:char1 \
-serial chardev:char2 >&2
read rv <$1.code || true
[ -z "$rv" ] && exit 99
if [ "$rv" -eq 0 ]; then
sed -e 's/\r//g' "$1.out" >$3
echo "ok." >&2
else
echo "kvm program returned error: $rv" >&2
fi
exit "$rv"