commit: 743800055c2b0a4bcb6f674c7543598ed8f843e8 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> AuthorDate: Fri Aug 28 13:52:43 2020 +0000 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> CommitDate: Fri Aug 28 15:41:38 2020 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=74380005
Use switch_root from util-linux switch_root from busybox does not move /dev, /sys, /proc and /run. If we do that manually there is a small window for a race condition when /dev, /sys or /proc is still needed but already moved. switch_root from util-linux will move these mounts on its own and will therefore avoid any potential problems. Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> defaults/linuxrc | 32 ++------------------------------ gen_initramfs.sh | 24 ++++++++++++------------ gkbuilds/util-linux.gkbuild | 26 ++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 5c3b0ce..afb91d8 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -1335,34 +1335,6 @@ then run pkill -9 udevd >/dev/null 2>&1 fi -# If devtmpfs is mounted, try move it to the new root -# If that fails, try to unmount all possible mounts of -# devtmpfs as stuff breaks otherwise -for fs in /run /dev /sys /proc -do - if grep -qs "${fs}" /proc/mounts - then - chroot_dir="${CHROOT}${fs}" - [ ! -d "${chroot_dir}" ] && run mkdir -p "${chroot_dir}" - - if ! run mount -o move ${fs} "${CHROOT}"${fs} - then - run umount ${fs} || \ - bad_msg "Failed to move and unmount the ramdisk ${fs}!" - fi - - unset chroot_dir - fi -done - -if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ] -then - bad_msg "ERROR: your real /dev is missing console and null" -elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ] -then - bad_msg "ERROR: your real /dev is missing tty1, required for splash" -fi - # Run debug shell if requested rundebugshell "before entering switch_root" @@ -1380,8 +1352,8 @@ elif [ $$ != 1 ] then bad_msg "PID was not 1! switch_root would fail" else - good_msg "Switching to real root: switch_root -c /dev/console ${CHROOT} ${init} ${init_opts}" - exec switch_root -c "/dev/console" "${CHROOT}" "${init}" ${init_opts} + good_msg "Switching to real root: switch_root ${CHROOT} ${init} ${init_opts}" + exec switch_root "${CHROOT}" "${init}" ${init_opts} fi # If we get here, something bad has happened diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 875068c..479e6a6 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -635,9 +635,9 @@ append_bcache() { fi } -append_blkid() { - local PN="util-linux" - local TDIR="${TEMP}/initramfs-blkid-temp" +append_unionfs_fuse() { + local PN=unionfs-fuse + local TDIR="${TEMP}/initramfs-${PN}-temp" if [ -d "${TDIR}" ] then rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" @@ -650,13 +650,9 @@ append_blkid() { unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}" cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" - - # Delete unneeded files - rm -rf usr/ - log_future_cpio_content find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \ - || gen_die "Failed to append blkid to cpio!" + || gen_die "Failed to append ${PN} to cpio!" cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!" if isTrue "${CLEANUP}" @@ -665,9 +661,9 @@ append_blkid() { fi } -append_unionfs_fuse() { - local PN=unionfs-fuse - local TDIR="${TEMP}/initramfs-${PN}-temp" +append_util-linux() { + local PN="util-linux" + local TDIR="${TEMP}/initramfs-util-linux-temp" if [ -d "${TDIR}" ] then rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" @@ -680,6 +676,10 @@ append_unionfs_fuse() { unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}" cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" + + # Delete unneeded files + rm -rf usr/ + log_future_cpio_content find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \ || gen_die "Failed to append ${PN} to cpio!" @@ -1930,11 +1930,11 @@ create_initramfs() { CPIO_ARCHIVE="${TMPDIR}/${GK_FILENAME_TEMP_INITRAMFS}" append_data 'devices' # WARNING, must be first! append_data 'base_layout' + append_data 'util-linux' append_data 'eudev' append_data 'devicemanager' append_data 'auxilary' "${BUSYBOX}" append_data 'busybox' "${BUSYBOX}" - append_data 'blkid' "${DISKLABEL}" append_data 'b2sum' "${B2SUM}" append_data 'btrfs' "${BTRFS}" append_data 'dmraid' "${DMRAID}" diff --git a/gkbuilds/util-linux.gkbuild b/gkbuilds/util-linux.gkbuild index 81670c1..40ea1fb 100644 --- a/gkbuilds/util-linux.gkbuild +++ b/gkbuilds/util-linux.gkbuild @@ -1,6 +1,18 @@ # Copyright 1999-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 +src_prepare() { + default + + # Build static switch_root + sed -i \ + -e '/^switch_root_SOURCES =.*/a switch_root_LDFLAGS = -all-static' \ + sys-utils/Makemodule.am \ + || die + + gkautoreconf +} + src_configure() { export ac_cv_header_security_pam_misc_h=no export ac_cv_header_security_pam_appl_h=no @@ -16,6 +28,7 @@ src_configure() { --disable-widechar --without-python --disable-pylibmount + --enable-switch_root --enable-static-programs=blkid ) @@ -37,6 +50,15 @@ src_install() { cp -a blkid.static "${D}"/sbin/blkid \ || die "Failed to copy '${S}/blkid.static' to '${D}/sbin/blkid'!" - "${STRIP}" --strip-all "${D}"/sbin/blkid \ - || die "Failed to strip '${D}/sbin/blkid'!" + cp -a switch_root "${D}"/sbin/switch_root \ + || die "Failed to copy '${S}/switch_root' to '${D}/sbin/switch_root'!" + + local sbin + for sbin in \ + "${D}/sbin/blkid" \ + "${D}/sbin/switch_root" \ + ; do + "${STRIP}" --strip-all "${sbin}" \ + || die "Failed to strip '${sbin}'!" + done }