1 |
commit: ab6d73225f21be7d55649363ceb460d91270638d |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Feb 8 01:25:50 2021 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 8 21:20:28 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=ab6d7322 |
7 |
|
8 |
linuxrc: Add gk.preserverun.disabled |
9 |
|
10 |
When this boolean option is set and enabled, genkernel initramfs will unmount /run |
11 |
before calling switch_root. |
12 |
|
13 |
This can help in SELinux context for example where labeling is required which is |
14 |
not supported by genkernel. |
15 |
|
16 |
Bug: https://bugs.gentoo.org/739424 |
17 |
Bug: https://bugs.gentoo.org/740576 |
18 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
19 |
|
20 |
defaults/initrd.defaults | 1 + |
21 |
defaults/linuxrc | 15 +++++++++++ |
22 |
doc/genkernel.8.txt | 6 +++++ |
23 |
....1-switch_root-check-if-mountpoint-exists.patch | 31 ++++++++++++++++++++++ |
24 |
4 files changed, 53 insertions(+) |
25 |
|
26 |
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults |
27 |
index ac3b072..7ee78e9 100644 |
28 |
--- a/defaults/initrd.defaults |
29 |
+++ b/defaults/initrd.defaults |
30 |
@@ -87,6 +87,7 @@ GK_NET_TIMEOUT_DAD=10 |
31 |
GK_NET_TIMEOUT_DECONFIGURATION=10 |
32 |
GK_NET_TIMEOUT_DHCP=10 |
33 |
GK_NET_TIMEOUT_INTERFACE=10 |
34 |
+GK_PRESERVE_RUN=1 |
35 |
GK_PROMPT_FILE='/tmp/current_prompt' |
36 |
GK_PROMPT_TIMEOUT=0 |
37 |
GK_ROOTFS_DETECTED_STATEFILE="/tmp/rootfs.detected" |
38 |
|
39 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
40 |
index e33576d..d8fee73 100644 |
41 |
--- a/defaults/linuxrc |
42 |
+++ b/defaults/linuxrc |
43 |
@@ -372,6 +372,15 @@ do |
44 |
fi |
45 |
unset tmp_disabled |
46 |
;; |
47 |
+ gk.preserverun.disabled=*) |
48 |
+ tmp_disabled=${x#*=} |
49 |
+ if is_true "${tmp_disabled}" |
50 |
+ then |
51 |
+ warn_msg "gk.preserverun.disabled is set; /run will not be moved to newroot!" |
52 |
+ GK_PRESERVE_RUN=0 |
53 |
+ fi |
54 |
+ unset tmp_disabled |
55 |
+ ;; |
56 |
gk.prompt.timeout=*) |
57 |
tmp_timeout=${x#*=} |
58 |
if is_int "${tmp_timeout}" |
59 |
@@ -1336,6 +1345,12 @@ fi |
60 |
# Run debug shell if requested |
61 |
rundebugshell "before entering switch_root" |
62 |
|
63 |
+if [ "${GK_PRESERVE_RUN}" = '0' ] |
64 |
+then |
65 |
+ GK_INIT_LOG= |
66 |
+ run umount /run |
67 |
+fi |
68 |
+ |
69 |
# init_opts is set in the environment by the kernel when it parses the command line |
70 |
init=${REAL_INIT:-/sbin/init} |
71 |
if ! mountpoint "${CHROOT}" 1>/dev/null 2>&1 |
72 |
|
73 |
diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt |
74 |
index ddccd9f..74729be 100644 |
75 |
--- a/doc/genkernel.8.txt |
76 |
+++ b/doc/genkernel.8.txt |
77 |
@@ -745,6 +745,12 @@ recognized by the kernel itself. |
78 |
By default we will wait up to 120 seconds (UDEV default) for |
79 |
UDEV event queue to become empty. |
80 |
|
81 |
+*gk.preserverun.disabled*=<...>:: |
82 |
+ By default, *switch_root* will preserve and move already mounted '/run' |
83 |
+ to *newroot*. This boolean option allows you to disable preserving of |
84 |
+ '/run', which is maybe required for SELinux due to missing labeling |
85 |
+ support in genkernel. |
86 |
+ |
87 |
*gk.prompt.timeout*=<...>:: |
88 |
By default a prompt within genkernel initramfs like shown when set |
89 |
*root* could not be found will never timeout. Use this option to set |
90 |
|
91 |
diff --git a/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch b/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch |
92 |
new file mode 100644 |
93 |
index 0000000..17bcd91 |
94 |
--- /dev/null |
95 |
+++ b/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch |
96 |
@@ -0,0 +1,31 @@ |
97 |
+switch_root: check if mount point to move even exists |
98 |
+ |
99 |
+--- a/sys-utils/switch_root.c |
100 |
++++ b/sys-utils/switch_root.c |
101 |
+@@ -131,7 +131,12 @@ static int switchroot(const char *newroot) |
102 |
+ int i; |
103 |
+ int cfd; |
104 |
+ pid_t pid; |
105 |
+- struct stat newroot_stat, sb; |
106 |
++ struct stat newroot_stat, oldroot_stat, sb; |
107 |
++ |
108 |
++ if (stat("/", &oldroot_stat) != 0) { |
109 |
++ warn(_("stat of %s failed"), "/"); |
110 |
++ return -1; |
111 |
++ } |
112 |
+ |
113 |
+ if (stat(newroot, &newroot_stat) != 0) { |
114 |
+ warn(_("stat of %s failed"), newroot); |
115 |
+@@ -143,6 +148,11 @@ static int switchroot(const char *newroot) |
116 |
+ |
117 |
+ snprintf(newmount, sizeof(newmount), "%s%s", newroot, umounts[i]); |
118 |
+ |
119 |
++ if ((stat(umounts[i], &sb) == 0) && sb.st_dev == oldroot_stat.st_dev) { |
120 |
++ /* mount point to move seems to be a normal directory or stat failed */ |
121 |
++ continue; |
122 |
++ } |
123 |
++ |
124 |
+ if ((stat(newmount, &sb) != 0) || (sb.st_dev != newroot_stat.st_dev)) { |
125 |
+ /* mount point seems to be mounted already or stat failed */ |
126 |
+ umount2(umounts[i], MNT_DETACH); |
127 |
+ |