1 |
commit: 271c330b15d16c318cfed654d029be4b026eb770 |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Aug 16 19:12:04 2019 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Aug 16 19:12:04 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=271c330b |
7 |
|
8 |
initrd.scripts: preserve_log(): Add support for additional mountpoints |
9 |
|
10 |
This commit will add support for copying init.log to $NEWROOT/var/log/genkernel-boot.log |
11 |
for example even when $NEWROOT/var/log is an own partition. |
12 |
|
13 |
To make this work, you must tell genkernel via /etc/initramfs.mounts |
14 |
to mount the additional mount point. |
15 |
|
16 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
17 |
|
18 |
defaults/initrd.defaults | 1 + |
19 |
defaults/initrd.scripts | 68 ++++++++++++++++++++++++++++++++++-------------- |
20 |
defaults/linuxrc | 8 +++--- |
21 |
3 files changed, 54 insertions(+), 23 deletions(-) |
22 |
|
23 |
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults |
24 |
index 06057d7..8fa2822 100644 |
25 |
--- a/defaults/initrd.defaults |
26 |
+++ b/defaults/initrd.defaults |
27 |
@@ -73,6 +73,7 @@ IP='dhcp' |
28 |
GK_DEBUGMODE_STATEFILE="/tmp/debug.enabled" |
29 |
GK_INIT_LOG='/tmp/init.log' |
30 |
GK_INIT_LOG_COPYTO= |
31 |
+GK_INIT_LOG_COPYTO_DEFAULT='/genkernel-boot.log' |
32 |
GK_INIT_LOG_DISABLED='/tmp/no-init.log' |
33 |
GK_INIT_LOG_PREFIX= |
34 |
GK_NET_DHCP_PIDFILE='/var/run/udhcpc.pid' |
35 |
|
36 |
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts |
37 |
index 1d2fa20..2c57ff4 100644 |
38 |
--- a/defaults/initrd.scripts |
39 |
+++ b/defaults/initrd.scripts |
40 |
@@ -1052,37 +1052,67 @@ preserve_log() { |
41 |
[ -z "${GK_INIT_LOG_COPYTO}" ] && return |
42 |
|
43 |
local have_errors=0 |
44 |
+ |
45 |
local logfile_target="${CHROOT}/${GK_INIT_LOG_COPYTO#/}" |
46 |
- local logfile_target_dir="$(dirname "${logfile_target}")" |
47 |
+ if ! echo "${logfile_target}" | grep -qE '^.*/[A-Za-z0-9._-]+$' |
48 |
+ then |
49 |
+ # The test above will make sure that a filename was given |
50 |
+ # so we can be sure that dirname() will always return a |
51 |
+ # path. |
52 |
+ warn_msg "gk.log.keep value '${GK_INIT_LOG_COPYTO}' is invalid; Will copy log to '${GK_INIT_LOG_COPYTO_DEFAULT}' instead ..." |
53 |
+ logfile_target="${CHROOT}/${GK_INIT_LOG_COPYTO_DEFAULT#/}" |
54 |
+ fi |
55 |
+ |
56 |
local fail_msg="Failed to copy '${GK_INIT_LOG}' to '${logfile_target}'" |
57 |
+ local logfile_target_dir="$(dirname "${logfile_target}")" |
58 |
|
59 |
- if run mount -o remount,rw ${CHROOT} |
60 |
+ if [ -z "${logfile_target_dir}" ] |
61 |
then |
62 |
- if [ -z "${logfile_target_dir}" ] |
63 |
- then |
64 |
- have_errors=1 |
65 |
- bad_msg "${fail_msg}: Failed to determine dirname of '${logfile_target}'!" |
66 |
- elif [ ! -d "${logfile_target_dir}" ] |
67 |
+ bad_msg "${fail_msg}: Failed to determine dirname of '${logfile_target}'!" |
68 |
+ return 1 |
69 |
+ fi |
70 |
+ |
71 |
+ local logfile_mountpoint="${logfile_target_dir}" |
72 |
+ while [ true ] |
73 |
+ do |
74 |
+ if run mountpoint "${logfile_mountpoint}" 1>/dev/null 2>&1 |
75 |
then |
76 |
- if ! run mkdir -p "${logfile_target_dir}" 2>/dev/null |
77 |
+ if run mount -o remount,rw "${logfile_mountpoint}" 1>/dev/null 2>&1 |
78 |
then |
79 |
- have_errors=1 |
80 |
- bad_msg "${fail_msg}: Failed to create '${logfile_target_dir}'!" |
81 |
+ break |
82 |
+ else |
83 |
+ bad_msg "${fail_msg}: 'mount -o remount,rw \"${logfile_mountpoint}\"' failed!" |
84 |
+ return 1 |
85 |
fi |
86 |
fi |
87 |
|
88 |
- if [ ${have_errors} = 0 ] |
89 |
+ logfile_mountpoint="$(dirname "${logfile_mountpoint}")" |
90 |
+ if [ "${logfile_mountpoint}" = "${CHROOT}" ] |
91 |
then |
92 |
- good_msg "gk.log.keep set; Copying '${GK_INIT_LOG}' to '${logfile_target}' ..." |
93 |
- if ! cp "${GK_INIT_LOG}" "${logfile_target}" 2>/dev/null |
94 |
- then |
95 |
- bad_msg "${fail_msg}!" |
96 |
- fi |
97 |
+ # Stop here |
98 |
+ bad_msg "${fail_msg}: Failed to determine mountpoint for '${logfile_target}'!" |
99 |
+ return 1 |
100 |
fi |
101 |
+ done |
102 |
|
103 |
- mount -o remount,ro ${CHROOT} |
104 |
- else |
105 |
- bad_msg "${fail_msg}: 'mount -o remount,rw ${CHROOT}' failed!" |
106 |
+ if [ ! -d "${logfile_target_dir}" ] |
107 |
+ then |
108 |
+ if ! run mkdir -p "${logfile_target_dir}" 2>/dev/null |
109 |
+ then |
110 |
+ bad_msg "${fail_msg}: Failed to create '${logfile_target_dir}'!" |
111 |
+ return 1 |
112 |
+ fi |
113 |
+ fi |
114 |
+ |
115 |
+ good_msg "gk.log.keep set; Copying '${GK_INIT_LOG}' to '${logfile_target}' ..." |
116 |
+ if ! run cp -f "${GK_INIT_LOG}" "${logfile_target}" 2>/dev/null |
117 |
+ then |
118 |
+ bad_msg "${fail_msg}!" |
119 |
+ fi |
120 |
+ |
121 |
+ if ! run mount -o remount,ro "${logfile_mountpoint}" 1>/dev/null 2>&1 |
122 |
+ then |
123 |
+ bad_msg "Failed to re-mount ${logfile_mountpoint} read-only!" |
124 |
fi |
125 |
} |
126 |
|
127 |
|
128 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
129 |
index 1bd6dc9..cd3a6d7 100644 |
130 |
--- a/defaults/linuxrc |
131 |
+++ b/defaults/linuxrc |
132 |
@@ -288,16 +288,16 @@ do |
133 |
gk.log.keep=*) |
134 |
case "${x#*=}" in |
135 |
[Tt][Rr][Uu][Ee]) |
136 |
- GK_INIT_LOG_COPYTO=/genkernel-boot.log |
137 |
+ GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}" |
138 |
;; |
139 |
[Yy][Ee][Ss]) |
140 |
- GK_INIT_LOG_COPYTO=/genkernel-boot.log |
141 |
+ GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}" |
142 |
;; |
143 |
[Yy]) |
144 |
- GK_INIT_LOG_COPYTO=/genkernel-boot.log |
145 |
+ GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}" |
146 |
;; |
147 |
1) |
148 |
- GK_INIT_LOG_COPYTO=/genkernel-boot.log |
149 |
+ GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}" |
150 |
;; |
151 |
[Ff][Aa][Ll][Ss][Ee]) |
152 |
GK_INIT_LOG_COPYTO= |