-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquiz-root
executable file
·89 lines (74 loc) · 2.52 KB
/
quiz-root
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2023-2025, Rob Norris <[email protected]>
set -uo pipefail
usage() {
cat <<EOF
create a minimal root filesystem for the quiz microvm
usage: quiz-root
-a <arch>
architecture to create root for
EOF
exit 1
}
trace() {
local STAMP=$(date +%Y%m%d-%H:%M:%S)
echo "[quiz-root] $STAMP $@" >&2
}
fail() {
local TEXT=${@:-}
if [[ -z $TEXT ]] ; then
TEXT="[${BASH_SOURCE[0]}:${BASH_LINENO[0]}: $BASH_COMMAND]"
fi
trace "FATAL $TEXT"
exit 1
}
trap fail ERR
RUNDIR=$(realpath $(dirname $0))
source $RUNDIR/quiz-config
source $RUNDIR/quiz-lib
opt_arch=""
OPTIND=1
while getopts "a:h" opt
do
case "$opt" in
'a') opt_arch=$OPTARG ;;
'h') usage ;;
*) exit 1 ;;
esac
done
shift $(expr $OPTIND - 1)
quiz_arch_vars ${opt_arch:-$QUIZ_ARCH}
quiz_debian_vars
trace "building root image"
# XXX this lists should be source from somewhere else -- robn, 2025-01-10
quiz_extras=tini,udev,coreutils,procps,kmod,gdisk,dmsetup,tmux,cryptsetup
zfs_extras=libtirpc3,libjemalloc2,libasan8
zfstest_extras=ksh,bc,bzip2,cpio,file,acl,sysstat,samba-common-bin,openssl,pamtester,pax,iputils-ping,python3-minimal,rsync,openssh-client,binutils,attr,nfs-kernel-server,lsscsi,parted,linux-base,sudo,xxhash
debug_extras=jq,gdb,strace,bpftrace,linux-perf,xxd,blktrace,mdadm
# XXX add things back in the can't be in the default lists because they're
# not installable from debian unstable right now. this is all a mess, as
# you see -- robn, 2025-01-10
if [[ $_quiz_debian_arch == "amd64" ]] ; then
zfstest_extras="$zfstest_extras,fio"
fi
image_basefile=$_quiz_debian_release.$_quiz_debian_arch
mmdebstrap \
--arch=$_quiz_debian_arch \
--variant=minbase \
--include=$quiz_extras,$zfs_extras,$zfstest_extras,$debug_extras \
--customize-hook='install -m 755 init/init1 "$1"/sbin/init' \
--customize-hook='mkdir "$1"/mnt/quiz-init' \
--customize-hook='mkdir "$1"/mnt/quiz-user' \
--customize-hook='mkdir "$1"/mnt/quiz-kernel' \
--customize-hook='mkdir "$1"/mnt/quiz-system' \
--customize-hook='mkdir "$1"/mnt/lower "$1"/mnt/top "$1"/mnt/newroot' \
$_quiz_debian_release $RUNDIR/system/$image_basefile.new.ext2 "$_quiz_debian_mirror"
mv -vf $RUNDIR/system/$image_basefile.new.ext2 $RUNDIR/system/$image_basefile.ext2
trace "done"
# vim: ft=bash