-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/dracut/ignition-ostree: add a bwrap-in-sysroot helper
This introduces a new `coreos-sysroot-bwrap` helper in initramfs, for binaries that need to be executed with the final sysroot as a target, but before the pivot-root happens.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/coreos-sysroot-bwrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Needed to work around the initrd `rootfs` / filesystem not being a valid | ||
# mount to pivot out of. For reference, see: | ||
# - https://github.com/torvalds/linux/blob/26bc672134241a080a83b2ab9aa8abede8d30e1c/fs/namespace.c#L3605 | ||
# - https://gist.github.com/jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033 | ||
set -euo pipefail | ||
|
||
TMP_CHROOT_DIR="" | ||
|
||
main() { | ||
setup_chroot_tmpdir | ||
run_chrooted_bwrap "$@" | ||
} | ||
|
||
setup_chroot_tmpdir() { | ||
TMP_CHROOT_DIR=$(mktemp --directory --tmpdir=/mnt '.coreos-sysroot-bwrap.tmp.XXXXXXXXXX') | ||
mount --bind / "${TMP_CHROOT_DIR}" | ||
mount --make-private "${TMP_CHROOT_DIR}" | ||
mount --bind "${TMP_CHROOT_DIR}" "${TMP_CHROOT_DIR}" | ||
for mnt in proc sys dev; do | ||
mount --bind /$mnt "${TMP_CHROOT_DIR}"/$mnt | ||
done | ||
touch "${TMP_CHROOT_DIR}"/run/ostree-booted | ||
mount --bind /sysroot "${TMP_CHROOT_DIR}"/sysroot | ||
} | ||
|
||
run_chrooted_bwrap() { | ||
chroot "${TMP_CHROOT_DIR}" \ | ||
/usr/bin/env --chdir /sysroot \ | ||
bwrap \ | ||
--unshare-pid --unshare-uts --unshare-ipc --unshare-net \ | ||
--unshare-cgroup-try --dev /dev --proc /proc --chdir / \ | ||
--ro-bind usr /usr --bind etc /etc --dir /tmp --tmpfs /var/tmp \ | ||
--tmpfs /run --ro-bind /run/ostree-booted /run/ostree-booted \ | ||
--symlink usr/lib /lib \ | ||
--symlink usr/lib64 /lib64 \ | ||
--symlink usr/bin /bin \ | ||
--symlink usr/sbin /sbin -- "$@" | ||
} | ||
|
||
cleanup() { | ||
if test -z "${TMP_CHROOT_DIR}"; then | ||
return | ||
fi | ||
|
||
umount --lazy --recursive "${TMP_CHROOT_DIR}" | ||
umount --recursive "${TMP_CHROOT_DIR}" | ||
rmdir "${TMP_CHROOT_DIR}" | ||
} | ||
|
||
trap cleanup EXIT | ||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters