use nspawn to bind mount needed directories

systemd-nspawn is capable of doing this as of systemd-198. Doing this
means we can remove all of our home grown chroot mount/umount logic, as
it's all performed by pacstrap or systemd-nspawn.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
This commit is contained in:
Dave Reisner 2013-03-10 15:11:26 -04:00 committed by Pierre Schmitz
parent 35dc7485fb
commit f03086a0e1
1 changed files with 16 additions and 37 deletions

View File

@ -78,31 +78,21 @@ if echo "${host_mirror}" | grep -q 'file://'; then
fi fi
# {{{ functions # {{{ functions
bind_mount() { build_mount_args() {
local mode="${2:-rw}" local p
local target="${working_dir}${1}" declare -g mount_args=()
if [[ ! -e "$target" ]]; then if [[ -n $host_mirror_path ]]; then
if [[ -d "$1" ]]; then printf -v p '%q' "$host_mirror_path"
install -d "$target" mount_args+=(--bind-ro="$p")
else
install -D /dev/null "$target"
fi
fi fi
mount -o bind "$1" "$target" printf -v p '%q' "${cache_dirs[0]}"
mount -o remount,${mode},bind "$target" mount_args+=(--bind="$p")
mount --make-slave "$target"
}
chroot_mount() {
trap 'trap_chroot_umount' EXIT INT QUIT TERM HUP
[[ -n $host_mirror_path ]] && bind_mount "$host_mirror_path" ro
bind_mount "${cache_dirs[0]}"
for cache_dir in ${cache_dirs[@]:1}; do for cache_dir in ${cache_dirs[@]:1}; do
bind_mount "$cache_dir" ro printf -v p '%q' "$cache_dir"
mount_args+=(--bind-ro="$p")
done done
} }
@ -121,16 +111,6 @@ copy_hostconf () {
sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i ${working_dir}/etc/pacman.conf sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i ${working_dir}/etc/pacman.conf
} }
trap_chroot_umount () {
trap 'trap_abort' INT QUIT TERM HUP
trap 'trap_exit' EXIT
for cache_dir in ${cache_dirs[@]}; do
umount "${working_dir}/${cache_dir}"
done
[[ -n $host_mirror_path ]] && umount "${working_dir}/${host_mirror_path}"
}
chroot_lock () { chroot_lock () {
# Only reopen the FD if it wasn't handed to us # Only reopen the FD if it wasn't handed to us
if [[ $(readlink -f /dev/fd/9) != "${working_dir}.lock" ]]; then if [[ $(readlink -f /dev/fd/9) != "${working_dir}.lock" ]]; then
@ -148,7 +128,7 @@ chroot_lock () {
chroot_run() { chroot_run() {
local dir=$1 local dir=$1
shift shift
eval systemd-nspawn -D "${dir}" -- ${@} 2>/dev/null eval systemd-nspawn -D "${dir}" "${mount_args[@]}" -- ${@} 2>/dev/null
} }
# }}} # }}}
@ -164,7 +144,7 @@ if [[ -n $RUN ]]; then
fi fi
chroot_lock chroot_lock
chroot_mount build_mount_args
copy_hostconf copy_hostconf
chroot_run "${working_dir}" ${RUN} chroot_run "${working_dir}" ${RUN}
@ -181,18 +161,17 @@ else
fi fi
chroot_lock chroot_lock
chroot_mount
pacargs="${cache_dirs[@]/#/--cachedir=}" pacargs=("${cache_dirs[@]/#/--cachedir=}")
if [[ -n $pac_conf ]]; then if [[ -n $pac_conf ]]; then
pacargs="$pacargs --config=${pac_conf}" pacargs+=("--config=${pac_conf}")
fi fi
if (( $# != 0 )); then if (( $# != 0 )); then
if [[ $FORCE = 'y' ]]; then if [[ $FORCE = 'y' ]]; then
pacargs="$pacargs --force" pacargs+=("--force")
fi fi
if ! pacstrap -GMcd "${working_dir}" ${pacargs} $@; then if ! pacstrap -GMcd "${working_dir}" "${pacargs[@]}" "$@"; then
die 'Failed to install all packages' die 'Failed to install all packages'
fi fi
fi fi