Skip to content
Snippets Groups Projects
Commit fdbe7fe4 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Adadpt for Linux Kernel Programming lecture, some documentation

parent 65255327
Branches lkp
No related tags found
No related merge requests found
launch.1 0 → 100644
.Dd November 07, 2023
.Dt LAUNCH.SH 1
.Os
.Sh NAME
.Nm launch.sh
.Nd launch a Linux Kernel development VM
.Sh SYNOPSIS
.Nm
.Op Fl k Ar kernel
.Op Fl i Ar initrd
.Op Fl a Ar append
.Op Fl s Ar share
.Op Fl -
.Op Ar "extra qemu arguments"
.Sh DESCRIPTION
.Nm
launches a prepared VM image using
.Xr qemu 1 ,
suitable for Linux Kernel development.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl k Ar kernel
Use
.Ar kernel
to boot the VM.
.It Fl i Ar initrd
Provide
.Ar initrd
as initrd/initramfs image to the kernel.
Use an empty argument to boot
.Em without
an initrd/initramfs.
.It Fl a Ar append
Append
.Ar append
to the default kernel command line.
.It Fl s Ar share
Provide the directory
.Ar share
to the VM using virtfs/9p.
.It Ar "extra qemu arguments"
Specify extra arguments to pass to
.Xr qemu 1 .
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
The following invocation launches a VM with a custom kernel, no initramfs, and a
share directory:
.Dl $ ./ Ns Nm Fl k Pa ../linux/arch/x86/boot/bzImage Fl i Pa "''" Fl s Pa ../share
.Sh SEE ALSO
.Xr qemu 1
.Sh AUTHORS
.An Thomas Schneider Aq Mt thomas@fsmpi.rwth-aachen.de
.Sh BUGS
Currently, too many options that should be customisable are hard-coded.
#!/bin/sh
#!/usr/bin/env bash
set -e
H=$(dirname "$0")
kernel="$H/vmlinuz-virt"
initrd="$H/initramfs-virt"
append=""
share=""
optstring="k:i:a:s:"
while getopts $optstring opt; do
case $opt in
k)
kernel="$OPTARG"
;;
i)
initrd="$OPTARG"
;;
a)
append="$OPTARG"
;;
s)
share="$OPTARG"
;;
'?')
printf "Usage: %s [-k KERNEL] [-i INITRD] [-a APPEND] [-s SHARE] [...]\n" "$0" 1>&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
qargs=(
-kernel "$kernel"
)
test -n "$initrd" && qargs+=(-initrd "$initrd")
qargs+=(-append "root=/dev/vda overlaytmpfs console=hvc0 earlyprintk=hvc0 $append")
test -n "$share" && qargs+=(-virtfs "local,path=$share,mount_tag=share,security_model=mapped-file,id=share")
qargs+=("$@")
set -x
exec qemu-system-x86_64 \
-M microvm,x-option-roms=off,pit=off,pic=off,rtc=off,isa-serial=off,pcie=on \
......@@ -14,9 +52,6 @@ exec qemu-system-x86_64 \
-device virtio-rng-device \
-drive id=root,file=image.sqfs,format=raw,if=none \
-device virtio-blk-device,drive=root \
-kernel vmlinuz-virt \
-initrd initramfs-virt \
-append "root=/dev/vda overlaytmpfs console=hvc0 earlyprintk=hvc0" \
-chardev stdio,mux=on,id=stdio \
-device virtio-serial-device \
-device virtconsole,chardev=stdio,name=console.0 \
......@@ -25,7 +60,6 @@ exec qemu-system-x86_64 \
-device virtio-net-device,netdev=net \
-chardev socket,path=qga,server=on,wait=off,id=qga \
-device virtserialport,chardev=qga,name=org.qemu.guest_agent.0 \
-chardev socket,id=virtfs,path=/tmp/virtfs.sock \
-device vhost-user-fs-pci,chardev=virtfs,tag=virtfs,queue-size=1024 \
-object memory-backend-memfd,id=mem,size=1536M,share=on \
-numa node,memdev=mem
-numa node,memdev=mem \
"${qargs[@]}"
......@@ -13,10 +13,12 @@ ln -s "$PWD/apk-cache" /etc/apk/cache
ln -s "$PWD/apk-cache" /image/etc/apk/cache
cp -r /etc/apk/repositories /etc/apk/keys /image/etc/apk
apk add --root /image --update-cache --initdb alpine-base mkinitfs \
qemu-guest-agent git git-lfs gitlab-runner bash buildah
qemu-guest-agent
echo 'features="base squashfs virtio"' > /image/etc/mkinitfs/mkinitfs.conf
apk add --root /image linux-virt
echo "share /mnt 9p trans=virtio,version=9p2000.L,nofail" >> /image/etc/fstab
oldpwd="$PWD"
cd /image/etc/runlevels
for i in devfs dmesg mdev hwdrivers cgroups; do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment