From 85c2b4d28d66bad39ef8989b313dab3d1356429f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 10:04:49 +0100 Subject: add a mmdebstrap example hook for mounting 9p file systems --- 9pmounthook/customize.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 9pmounthook/customize.sh diff --git a/9pmounthook/customize.sh b/9pmounthook/customize.sh new file mode 100755 index 0000000..67c4240 --- /dev/null +++ b/9pmounthook/customize.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Copyright 2022 Helmut Grohne +# SPDX-License-Identifier: MIT +# +# This is a mmdebstrap customize hook that adds a systemd-generator that causes +# 9p filesystems to be automatically mounted to /media/$SOMETAG during boot. +# You can enable it by passing the containing directory to --hook-dir. +# In order to add a 9p filesystem to your VM, pass +# -virtfs local,security_model=none,mount_tag=$SOMETAG,path=$SOMEDIR +# Note that the linux-image-cloud-* does not include a 9p driver. + +set -eu +GENERATOR_PATH="$1/etc/systemd/system-generators/9p-generator" +mkdir -p "${GENERATOR_PATH%/*}" +cat >"$GENERATOR_PATH" << 'ENDOFGENERATOR' +#!/bin/sh + +UNITDIR=$1 + +modprobe 9pnet_virtio || exit 0 + +for tagfile in /sys/bus/virtio/devices/*/mount_tag; do + tag=$(cat "$tagfile") || continue + test -z "$tag" && continue + mountpoint="/media/$tag" + mkdir -p "$mountpoint" + unitname="$(systemd-escape -p "$mountpoint").mount" + cat > "$UNITDIR/$unitname" <