1 |
commit: 848f9d5eb48f6fe7cf1d11a2ccb2df9198f474f1 |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Aug 19 21:29:34 2020 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Aug 19 21:29:34 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=848f9d5e |
7 |
|
8 |
defaults/linuxrc: Process /etc/initramfs.mounts multiple times |
9 |
|
10 |
We need to mount mountpoints listed in /etc/initramfs.mounts |
11 |
before validating REAL_INIT in case init is located on seperate |
12 |
mount. |
13 |
|
14 |
In addition the code was moved to a dedicated function named |
15 |
process_initramfs_mounts() to allow to run it multiple times |
16 |
which is needed if REAL_INIT wasn't verified (in case system |
17 |
was booted from livecd). |
18 |
|
19 |
Link: https://forums.gentoo.org/viewtopic-t-1117762.html |
20 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
21 |
|
22 |
defaults/initrd.scripts | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ |
23 |
defaults/linuxrc | 41 +++++++---------------------------------- |
24 |
2 files changed, 56 insertions(+), 34 deletions(-) |
25 |
|
26 |
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts |
27 |
index 14f3c4e..f34e5a3 100644 |
28 |
--- a/defaults/initrd.scripts |
29 |
+++ b/defaults/initrd.scripts |
30 |
@@ -1249,6 +1249,55 @@ preserve_log() { |
31 |
fi |
32 |
} |
33 |
|
34 |
+process_initramfs_mounts() { |
35 |
+ local fslist= |
36 |
+ |
37 |
+ if [ -f "${NEW_ROOT}/etc/initramfs.mounts" ] |
38 |
+ then |
39 |
+ fslist="$(get_mounts_list)" |
40 |
+ else |
41 |
+ fslist="/usr" |
42 |
+ fi |
43 |
+ |
44 |
+ local dev= fs= fstype= opts= mnt= cmd= |
45 |
+ for fs in ${fslist} |
46 |
+ do |
47 |
+ mnt="${NEW_ROOT}${fs}" |
48 |
+ if run mountpoint -q "${mnt}" |
49 |
+ then |
50 |
+ good_msg "${fs} already mounted, skipping..." |
51 |
+ continue |
52 |
+ fi |
53 |
+ |
54 |
+ dev=$(get_mount_device "${fs}") |
55 |
+ [ -z "${dev}" ] && continue |
56 |
+ # Resolve it like util-linux mount does |
57 |
+ [ -L "${dev}" ] && dev=$(realpath "${dev}") |
58 |
+ # In this case, it's probably part of the filesystem |
59 |
+ # and not a mountpoint |
60 |
+ [ -z "${dev}" ] && continue |
61 |
+ |
62 |
+ fstype=$(get_mount_fstype "${fs}") |
63 |
+ if get_mount_options "${fs}" | grep -Fq bind |
64 |
+ then |
65 |
+ opts="bind" |
66 |
+ dev="${NEW_ROOT}${dev}" |
67 |
+ else |
68 |
+ # ro must be trailing, and the options will always |
69 |
+ # contain at least 'defaults' |
70 |
+ opts="$(get_mount_options ${fs} | strip_mount_options)" |
71 |
+ opts="${opts},ro" |
72 |
+ fi |
73 |
+ |
74 |
+ cmd="mount -t ${fstype} -o ${opts} ${dev} ${mnt}" |
75 |
+ good_msg "Mounting ${dev} as ${fs}: ${cmd}" |
76 |
+ if ! run ${cmd} |
77 |
+ then |
78 |
+ bad_msg "Unable to mount ${dev} for ${fs}" |
79 |
+ fi |
80 |
+ done |
81 |
+} |
82 |
+ |
83 |
prompt_user() { |
84 |
# $1 = variable whose value is the path (examples: "REAL_ROOT", |
85 |
# "LUKS_KEYDEV") |
86 |
|
87 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
88 |
index 3ca7e86..e0704f7 100644 |
89 |
--- a/defaults/linuxrc |
90 |
+++ b/defaults/linuxrc |
91 |
@@ -930,6 +930,11 @@ do |
92 |
# else not a good root and start over. |
93 |
if [ "${mountret}" = '0' ] |
94 |
then |
95 |
+ # Make sure that entries from $NEWROOT/etc/initramfs.mounts |
96 |
+ # are mounted before validating $REAL_INIT in case init isn't |
97 |
+ # located on $REAL_ROOT. |
98 |
+ process_initramfs_mounts |
99 |
+ |
100 |
init_binary_file="${NEW_ROOT}${REAL_INIT:-/sbin/init}" |
101 |
init_binary_fallback_file="${NEW_ROOT}/bin/sh" |
102 |
|
103 |
@@ -1261,40 +1266,8 @@ else |
104 |
fi |
105 |
fi # if [ "${CDROOT}" = '1' ] |
106 |
|
107 |
-# Mount the additional things as required by udev & systemd |
108 |
-if [ -f ${NEW_ROOT}/etc/initramfs.mounts ] |
109 |
-then |
110 |
- fslist=$(get_mounts_list) |
111 |
-else |
112 |
- fslist="/usr" |
113 |
-fi |
114 |
- |
115 |
-for fs in ${fslist} |
116 |
-do |
117 |
- dev=$(get_mount_device ${fs}) |
118 |
- [ -z "${dev}" ] && continue |
119 |
- # Resolve it like util-linux mount does |
120 |
- [ -L ${dev} ] && dev=$(readlink ${dev}) |
121 |
- # In this case, it's probably part of the filesystem |
122 |
- # and not a mountpoint |
123 |
- [ -z "${dev}" ] && continue |
124 |
- fstype=$(get_mount_fstype ${fs}) |
125 |
- if get_mount_options ${fs} | grep -Fq bind |
126 |
- then |
127 |
- opts='bind' |
128 |
- dev=${NEW_ROOT}${dev} |
129 |
- else |
130 |
- # ro must be trailing, and the options will always contain at least 'defaults' |
131 |
- opts="$(get_mount_options ${fs} | strip_mount_options),ro" |
132 |
- fi |
133 |
- mnt=${NEW_ROOT}${fs} |
134 |
- cmd="mount -t ${fstype} -o ${opts} ${dev} ${mnt}" |
135 |
- good_msg "Mounting ${dev} as ${fs}: ${cmd}" |
136 |
- if ! ${cmd} |
137 |
- then |
138 |
- bad_msg "Unable to mount ${dev} for ${fs}" |
139 |
- fi |
140 |
-done # for fs in $fslist; do |
141 |
+# Re-run to ensure $NEWROOT/etc/initramfs.mounts was processed at least once |
142 |
+process_initramfs_mounts |
143 |
|
144 |
# Execute script on the cdrom just before boot to update things if necessary |
145 |
cdupdate |