add file-mirror-automount hook-dir

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-05-24 13:16:24 +02:00
parent cc3150ef04
commit b99f1d53d5
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1
4 changed files with 110 additions and 2 deletions

View file

@ -126,8 +126,23 @@ if [ ! -e shared/hooks/eatmydata/customize.sh ] || [ hooks/eatmydata/customize.s
cp -a /usr/share/mmdebstrap/hooks/eatmydata/customize.sh shared/hooks/eatmydata/ cp -a /usr/share/mmdebstrap/hooks/eatmydata/customize.sh shared/hooks/eatmydata/
fi fi
fi fi
mkdir -p shared/hooks/file-mirror-automount
if [ ! -e shared/hooks/file-mirror-automount/setup00.sh ] || [ hooks/file-mirror-automount/setup00.sh -nt shared/hooks/file-mirror-automount/setup00.sh ]; then
if [ -e hooks/file-mirror-automount/setup00.sh ]; then
cp -a hooks/file-mirror-automount/setup00.sh shared/hooks/file-mirror-automount/
else
cp -a /usr/share/mmdebstrap/hooks/file-mirror-automount/setup00.sh shared/hooks/file-mirror-automount/
fi
fi
if [ ! -e shared/hooks/file-mirror-automount/customize00.sh ] || [ hooks/file-mirror-automount/customize00.sh -nt shared/hooks/file-mirror-automount/customize00.sh ]; then
if [ -e hooks/file-mirror-automount/customize00.sh ]; then
cp -a hooks/file-mirror-automount/customize00.sh shared/hooks/file-mirror-automount/
else
cp -a /usr/share/mmdebstrap/hooks/file-mirror-automount/customize00.sh shared/hooks/file-mirror-automount/
fi
fi
starttime= starttime=
total=183 total=184
skipped=0 skipped=0
runtests=0 runtests=0
i=1 i=1
@ -1556,6 +1571,27 @@ else
skipped=$((skipped+1)) skipped=$((skipped+1))
fi fi
print_header "mode=$defaultmode,variant=apt: test file-mirror-automount hook"
cat << END > shared/test.sh
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
if [ ! -e /mmdebstrap-testenv ]; then
echo "this test requires the cache directory to be mounted on /mnt and should only be run inside a container" >&2
exit 1
fi
$CMD --mode=$defaultmode --variant=apt --hook-dir=./hooks/file-mirror-automount --customize-hook='rmdir "\$1"/mnt/cache/debian/ "\$1"/mnt/cache' $DEFAULT_DIST /tmp/debian-chroot.tar "deb file:///mnt/cache/debian $DEFAULT_DIST main"
tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt -
rm /tmp/debian-chroot.tar
END
if [ "$HAVE_QEMU" = "yes" ]; then
./run_qemu.sh
runtests=$((runtests+1))
else
echo "HAVE_QEMU != yes -- Skipping test..." >&2
skipped=$((skipped+1))
fi
print_header "mode=$defaultmode,variant=apt: mirror is deb..." print_header "mode=$defaultmode,variant=apt: mirror is deb..."
cat << END > shared/test.sh cat << END > shared/test.sh
#!/bin/sh #!/bin/sh

View file

@ -0,0 +1,26 @@
#!/bin/sh
set -eu
if [ "$MMDEBSTRAP_VERBOSITY" -ge 3 ]; then
set -x
fi
rootdir="$1"
if [ ! -e "$rootdir/run/mmdebstrap/file-mirror-automount" ]; then
exit 0
fi
xargsopts="--null --no-run-if-empty -I {} --max-args=1"
echo "unmounting the following mountpoints:" >&2
cat "$rootdir/run/mmdebstrap/file-mirror-automount" \
| xargs $xargsopts echo " $rootdir/{}"
cat "$rootdir/run/mmdebstrap/file-mirror-automount" \
| xargs $xargsopts umount "$rootdir/{}"
rm "$rootdir/run/mmdebstrap/file-mirror-automount"
rmdir --ignore-fail-on-non-empty "$rootdir/run/mmdebstrap"

View file

@ -0,0 +1,20 @@
#!/bin/sh
set -eu
if [ "$MMDEBSTRAP_VERBOSITY" -ge 3 ]; then
set -x
fi
rootdir="$1"
env APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get indextargets --no-release-info \
| sed -ne 's/^Repo-URI: file:\/\+//p' \
| sort -u \
| while read path; do
echo "bind-mounting /$path into the chroot" >&2
mkdir -p "$rootdir/run/mmdebstrap"
mkdir -p "$rootdir/$path"
mount -o ro,bind "/$path" "$rootdir/$path"
printf '/%s\0' "$path" >> "$rootdir/run/mmdebstrap/file-mirror-automount"
done

View file

@ -2176,7 +2176,10 @@ sub run_download() {
if (rindex $deb, $options->{root}, 0) { if (rindex $deb, $options->{root}, 0) {
if (!-e "$options->{root}/$deb") { if (!-e "$options->{root}/$deb") {
error "package file $deb not accessible from chroot directory" error "package file $deb not accessible from chroot directory"
. " -- use copy:// instead of file:// or a bind-mount"; . " -- use copy:// instead of file:// or a bind-mount. You"
. " can also try using --hook-dir=/usr/share/mmdebstrap/"
. "hooks/file-mirror-automount to automatically create"
. " the necessary bind-mounts.";
} }
push @essential_pkgs, $deb; push @essential_pkgs, $deb;
next; next;
@ -6203,6 +6206,11 @@ architecture specific symlinks
--hook-dir=/usr/share/mmdebstrap/hooks/merged-usr --hook-dir=/usr/share/mmdebstrap/hooks/merged-usr
Example 4: Automatically mount all directories referenced by C<file://> mirrors
into the chroot
--hook-dir=/usr/share/mmdebstrap/hooks/file-mirror-automount
=item B<--skip>=I<stage>[,I<stage>,...] =item B<--skip>=I<stage>[,I<stage>,...]
B<mmdebstrap> tries hard to implement sensible defaults and will try to stop B<mmdebstrap> tries hard to implement sensible defaults and will try to stop
@ -6899,6 +6907,24 @@ inside the chroot.
--customize-hook='sync-out /var/cache/apt/archives ./cache' \ --customize-hook='sync-out /var/cache/apt/archives ./cache' \
unstable /dev/null unstable /dev/null
Instead of copying potentially large amounts of data with B<sync-in> you can
also use a bind-mount in combination with a C<file://> mirror to make packages
from the outside available inside the chroot:
$ mmdebstrap --variant=apt --skip=essential/unlink \
--setup-hook='mkdir "$1/tmp/mirror"' \
--setup-hook='mount -o ro,bind /tmp/mirror "$1/tmp/mirror"' \
--customize-hook='sync-out /var/cache/apt/archives ./cache' \
--customize-hook='umount "$1/tmp/mirror"; rmdir "$1/tmp/mirror";' \
unstable /dev/null file:///tmp/mirror http://deb.debian.org/debian
To automatically mount all directories referenced by C<file://> mirrors
into the chroot you can use a hook:
$ mmdebstrap --variant=apt \
--hook-dir=/usr/share/mmdebstrap/hooks/file-mirror-automount \
unstable /dev/null file:///tmp/mirror1 file:///tmp/mirror2
Create a system that can be used with docker: Create a system that can be used with docker:
$ mmdebstrap unstable | sudo docker import - debian $ mmdebstrap unstable | sudo docker import - debian