1 |
commit: 743800055c2b0a4bcb6f674c7543598ed8f843e8 |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Aug 28 13:52:43 2020 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Aug 28 15:41:38 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=74380005 |
7 |
|
8 |
Use switch_root from util-linux |
9 |
|
10 |
switch_root from busybox does not move /dev, /sys, /proc and /run. |
11 |
If we do that manually there is a small window for a race condition |
12 |
when /dev, /sys or /proc is still needed but already moved. switch_root |
13 |
from util-linux will move these mounts on its own and will therefore |
14 |
avoid any potential problems. |
15 |
|
16 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
17 |
|
18 |
defaults/linuxrc | 32 ++------------------------------ |
19 |
gen_initramfs.sh | 24 ++++++++++++------------ |
20 |
gkbuilds/util-linux.gkbuild | 26 ++++++++++++++++++++++++-- |
21 |
3 files changed, 38 insertions(+), 44 deletions(-) |
22 |
|
23 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
24 |
index 5c3b0ce..afb91d8 100644 |
25 |
--- a/defaults/linuxrc |
26 |
+++ b/defaults/linuxrc |
27 |
@@ -1335,34 +1335,6 @@ then |
28 |
run pkill -9 udevd >/dev/null 2>&1 |
29 |
fi |
30 |
|
31 |
-# If devtmpfs is mounted, try move it to the new root |
32 |
-# If that fails, try to unmount all possible mounts of |
33 |
-# devtmpfs as stuff breaks otherwise |
34 |
-for fs in /run /dev /sys /proc |
35 |
-do |
36 |
- if grep -qs "${fs}" /proc/mounts |
37 |
- then |
38 |
- chroot_dir="${CHROOT}${fs}" |
39 |
- [ ! -d "${chroot_dir}" ] && run mkdir -p "${chroot_dir}" |
40 |
- |
41 |
- if ! run mount -o move ${fs} "${CHROOT}"${fs} |
42 |
- then |
43 |
- run umount ${fs} || \ |
44 |
- bad_msg "Failed to move and unmount the ramdisk ${fs}!" |
45 |
- fi |
46 |
- |
47 |
- unset chroot_dir |
48 |
- fi |
49 |
-done |
50 |
- |
51 |
-if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ] |
52 |
-then |
53 |
- bad_msg "ERROR: your real /dev is missing console and null" |
54 |
-elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ] |
55 |
-then |
56 |
- bad_msg "ERROR: your real /dev is missing tty1, required for splash" |
57 |
-fi |
58 |
- |
59 |
# Run debug shell if requested |
60 |
rundebugshell "before entering switch_root" |
61 |
|
62 |
@@ -1380,8 +1352,8 @@ elif [ $$ != 1 ] |
63 |
then |
64 |
bad_msg "PID was not 1! switch_root would fail" |
65 |
else |
66 |
- good_msg "Switching to real root: switch_root -c /dev/console ${CHROOT} ${init} ${init_opts}" |
67 |
- exec switch_root -c "/dev/console" "${CHROOT}" "${init}" ${init_opts} |
68 |
+ good_msg "Switching to real root: switch_root ${CHROOT} ${init} ${init_opts}" |
69 |
+ exec switch_root "${CHROOT}" "${init}" ${init_opts} |
70 |
fi |
71 |
|
72 |
# If we get here, something bad has happened |
73 |
|
74 |
diff --git a/gen_initramfs.sh b/gen_initramfs.sh |
75 |
index 875068c..479e6a6 100755 |
76 |
--- a/gen_initramfs.sh |
77 |
+++ b/gen_initramfs.sh |
78 |
@@ -635,9 +635,9 @@ append_bcache() { |
79 |
fi |
80 |
} |
81 |
|
82 |
-append_blkid() { |
83 |
- local PN="util-linux" |
84 |
- local TDIR="${TEMP}/initramfs-blkid-temp" |
85 |
+append_unionfs_fuse() { |
86 |
+ local PN=unionfs-fuse |
87 |
+ local TDIR="${TEMP}/initramfs-${PN}-temp" |
88 |
if [ -d "${TDIR}" ] |
89 |
then |
90 |
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" |
91 |
@@ -650,13 +650,9 @@ append_blkid() { |
92 |
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}" |
93 |
|
94 |
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" |
95 |
- |
96 |
- # Delete unneeded files |
97 |
- rm -rf usr/ |
98 |
- |
99 |
log_future_cpio_content |
100 |
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \ |
101 |
- || gen_die "Failed to append blkid to cpio!" |
102 |
+ || gen_die "Failed to append ${PN} to cpio!" |
103 |
|
104 |
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!" |
105 |
if isTrue "${CLEANUP}" |
106 |
@@ -665,9 +661,9 @@ append_blkid() { |
107 |
fi |
108 |
} |
109 |
|
110 |
-append_unionfs_fuse() { |
111 |
- local PN=unionfs-fuse |
112 |
- local TDIR="${TEMP}/initramfs-${PN}-temp" |
113 |
+append_util-linux() { |
114 |
+ local PN="util-linux" |
115 |
+ local TDIR="${TEMP}/initramfs-util-linux-temp" |
116 |
if [ -d "${TDIR}" ] |
117 |
then |
118 |
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" |
119 |
@@ -680,6 +676,10 @@ append_unionfs_fuse() { |
120 |
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}" |
121 |
|
122 |
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" |
123 |
+ |
124 |
+ # Delete unneeded files |
125 |
+ rm -rf usr/ |
126 |
+ |
127 |
log_future_cpio_content |
128 |
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \ |
129 |
|| gen_die "Failed to append ${PN} to cpio!" |
130 |
@@ -1930,11 +1930,11 @@ create_initramfs() { |
131 |
CPIO_ARCHIVE="${TMPDIR}/${GK_FILENAME_TEMP_INITRAMFS}" |
132 |
append_data 'devices' # WARNING, must be first! |
133 |
append_data 'base_layout' |
134 |
+ append_data 'util-linux' |
135 |
append_data 'eudev' |
136 |
append_data 'devicemanager' |
137 |
append_data 'auxilary' "${BUSYBOX}" |
138 |
append_data 'busybox' "${BUSYBOX}" |
139 |
- append_data 'blkid' "${DISKLABEL}" |
140 |
append_data 'b2sum' "${B2SUM}" |
141 |
append_data 'btrfs' "${BTRFS}" |
142 |
append_data 'dmraid' "${DMRAID}" |
143 |
|
144 |
diff --git a/gkbuilds/util-linux.gkbuild b/gkbuilds/util-linux.gkbuild |
145 |
index 81670c1..40ea1fb 100644 |
146 |
--- a/gkbuilds/util-linux.gkbuild |
147 |
+++ b/gkbuilds/util-linux.gkbuild |
148 |
@@ -1,6 +1,18 @@ |
149 |
# Copyright 1999-2020 Gentoo Authors |
150 |
# Distributed under the terms of the GNU General Public License v2 |
151 |
|
152 |
+src_prepare() { |
153 |
+ default |
154 |
+ |
155 |
+ # Build static switch_root |
156 |
+ sed -i \ |
157 |
+ -e '/^switch_root_SOURCES =.*/a switch_root_LDFLAGS = -all-static' \ |
158 |
+ sys-utils/Makemodule.am \ |
159 |
+ || die |
160 |
+ |
161 |
+ gkautoreconf |
162 |
+} |
163 |
+ |
164 |
src_configure() { |
165 |
export ac_cv_header_security_pam_misc_h=no |
166 |
export ac_cv_header_security_pam_appl_h=no |
167 |
@@ -16,6 +28,7 @@ src_configure() { |
168 |
--disable-widechar |
169 |
--without-python |
170 |
--disable-pylibmount |
171 |
+ --enable-switch_root |
172 |
--enable-static-programs=blkid |
173 |
) |
174 |
|
175 |
@@ -37,6 +50,15 @@ src_install() { |
176 |
cp -a blkid.static "${D}"/sbin/blkid \ |
177 |
|| die "Failed to copy '${S}/blkid.static' to '${D}/sbin/blkid'!" |
178 |
|
179 |
- "${STRIP}" --strip-all "${D}"/sbin/blkid \ |
180 |
- || die "Failed to strip '${D}/sbin/blkid'!" |
181 |
+ cp -a switch_root "${D}"/sbin/switch_root \ |
182 |
+ || die "Failed to copy '${S}/switch_root' to '${D}/sbin/switch_root'!" |
183 |
+ |
184 |
+ local sbin |
185 |
+ for sbin in \ |
186 |
+ "${D}/sbin/blkid" \ |
187 |
+ "${D}/sbin/switch_root" \ |
188 |
+ ; do |
189 |
+ "${STRIP}" --strip-all "${sbin}" \ |
190 |
+ || die "Failed to strip '${sbin}'!" |
191 |
+ done |
192 |
} |