commit:     8c19b84644d3a0b7f70b101b9c83931280028eb7
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 28 13:16:36 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Fri Aug 28 16:35:55 2020 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=8c19b846

defaults/linuxrc: Always preserve log

Now that we are using UDEV and have to preserve /run, we can also
use /run to always store log from initramfs.

This will make debugging easier because user don't have to explicit
enable logging (disabling is still possible).

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults |  4 +--
 defaults/initrd.scripts  | 74 +-----------------------------------------------
 defaults/linuxrc         | 39 ++++---------------------
 doc/genkernel.8.txt      | 13 +--------
 gen_initramfs.sh         | 10 ++-----
 5 files changed, 12 insertions(+), 128 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index e4c861b..e310f19 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -74,9 +74,7 @@ GK_BOOTFONT_DISABLED=0
 GK_DEBUGMODE_STATEFILE="/tmp/debug.enabled"
 GK_HW_LOAD_ALL_MODULES=0
 GK_HW_USE_MODULES_LOAD=0
-GK_INIT_LOG='/tmp/init.log'
-GK_INIT_LOG_COPYTO=
-GK_INIT_LOG_COPYTO_DEFAULT='/genkernel-boot.log'
+GK_INIT_LOG='/run/initramfs/init.log'
 GK_INIT_LOG_DISABLED='/tmp/no-init.log'
 GK_INIT_LOG_PREFIX=
 GK_NET_DHCP_PIDFILE='/var/run/udhcpc.pid'

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index b579e4f..ee7ca2c 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1177,78 +1177,6 @@ crypt_filter() {
        fi
 }
 
-preserve_log() {
-       is_log_enabled || return
-       [ ! -s "${GK_INIT_LOG}" ] && return
-       [ -z "${GK_INIT_LOG_COPYTO}" ] && return
-
-       local have_errors=0
-
-       local logfile_target="${CHROOT}/${GK_INIT_LOG_COPYTO#/}"
-       if ! echo "${logfile_target}" | grep -qE '^.*/[A-Za-z0-9._-]+$'
-       then
-               # The test above will make sure that a filename was given
-               # so we can be sure that dirname() will always return a
-               # path.
-               warn_msg "gk.log.keep value '${GK_INIT_LOG_COPYTO}' is invalid; 
Will copy log to '${GK_INIT_LOG_COPYTO_DEFAULT}' instead ..."
-               logfile_target="${CHROOT}/${GK_INIT_LOG_COPYTO_DEFAULT#/}"
-       fi
-
-       local fail_msg="Failed to copy '${GK_INIT_LOG}' to '${logfile_target}'"
-       local logfile_target_dir="$(dirname "${logfile_target}")"
-
-       if [ -z "${logfile_target_dir}" ]
-       then
-               bad_msg "${fail_msg}: Failed to determine dirname of 
'${logfile_target}'!"
-               return 1
-       fi
-
-       log_msg "Determining mountpoint of '${logfile_target}' ..."
-
-       local logfile_mountpoint="${logfile_target_dir}"
-       while [ true ]
-       do
-               if run mountpoint "${logfile_mountpoint}" 1>/dev/null 2>&1
-               then
-                       if run mount -o remount,rw "${logfile_mountpoint}" 
1>/dev/null 2>&1
-                       then
-                               break
-                       else
-                               bad_msg "${fail_msg}: 'mount -o remount,rw 
\"${logfile_mountpoint}\"' failed!"
-                               return 1
-                       fi
-               fi
-
-               logfile_mountpoint="$(dirname "${logfile_mountpoint}")"
-               if [ "${logfile_mountpoint}" = "/" ]
-               then
-                       # Stop here
-                       bad_msg "${fail_msg}: Failed to determine mountpoint 
for '${logfile_target}'!"
-                       return 1
-               fi
-       done
-
-       if [ ! -d "${logfile_target_dir}" ]
-       then
-               if ! run mkdir -p "${logfile_target_dir}" 2>/dev/null
-               then
-                       bad_msg "${fail_msg}: Failed to create 
'${logfile_target_dir}'!"
-                       return 1
-               fi
-       fi
-
-       good_msg "gk.log.keep set; Copying '${GK_INIT_LOG}' to 
'${logfile_target}' ..."
-       if ! run cp -f "${GK_INIT_LOG}" "${logfile_target}" 2>/dev/null
-       then
-               bad_msg "${fail_msg}!"
-       fi
-
-       if ! run mount -o remount,ro "${logfile_mountpoint}" 1>/dev/null 2>&1
-       then
-               bad_msg "Failed to re-mount ${logfile_mountpoint} read-only!"
-       fi
-}
-
 process_initramfs_mounts() {
        local fslist=
 
@@ -2388,7 +2316,7 @@ start_sshd() {
        run touch /var/log/lastlog
 
        good_msg "Starting dropbear sshd ..." ${QUIET}
-       run dropbear -p ${GK_SSHD_PORT} -R -P "${GK_SSHD_PIDFILE}" 
2>/var/log/dropbear.log
+       run dropbear -p ${GK_SSHD_PORT} -R -P "${GK_SSHD_PIDFILE}" 
2>/run/initramfs/dropbear.log
        if [ $? -eq 0 ]
        then
                if [ "${GK_PROMPT_TIMEOUT}" = '0' ]

diff --git a/defaults/linuxrc b/defaults/linuxrc
index afb91d8..a4ed811 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -35,6 +35,12 @@ mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 
2>&1
 mount -o remount,rw / >/dev/null 2>&1
 mount -t tmpfs -o rw,nosuid,nodev,relatime,mode=755 none /run 2>&1
 
+if [ ! -d /run/initramfs ]
+then
+       mkdir -p /run/initramfs
+       chmod 0750 /run/initramfs
+fi
+
 # Prevent superfluous printks from being printed to the console
 echo 1 > /proc/sys/kernel/printk
 
@@ -306,37 +312,6 @@ do
                        fi
                        unset tmp_disabled
                ;;
-               gk.log.keep=*)
-                       case "${x#*=}" in
-                               [Tt][Rr][Uu][Ee])
-                                       
GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}"
-                               ;;
-                               [Yy][Ee][Ss])
-                                       
GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}"
-                               ;;
-                               [Yy])
-                                       
GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}"
-                               ;;
-                               1)
-                                       
GK_INIT_LOG_COPYTO="${GK_INIT_LOG_COPYTO_DEFAULT}"
-                               ;;
-                               [Ff][Aa][Ll][Ss][Ee])
-                                       GK_INIT_LOG_COPYTO=
-                               ;;
-                               [Nn][Oo])
-                                       GK_INIT_LOG_COPYTO=
-                               ;;
-                               [Nn])
-                                       GK_INIT_LOG_COPYTO=
-                               ;;
-                               0)
-                                       GK_INIT_LOG_COPYTO=
-                               ;;
-                               *)
-                                       GK_INIT_LOG_COPYTO=${x#*=}
-                               ;;
-                       esac
-               ;;
                gk.sshd.port=*)
                        tmp_port=${x#*=}
                        if is_int "${tmp_port}"
@@ -1338,8 +1313,6 @@ fi
 # Run debug shell if requested
 rundebugshell "before entering switch_root"
 
-preserve_log
-
 # init_opts is set in the environment by the kernel when it parses the command 
line
 init=${REAL_INIT:-/sbin/init}
 if ! mountpoint "${CHROOT}" 1>/dev/null 2>&1

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 2625d6f..d8b9e09 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -827,20 +827,9 @@ when not set. This will allow remote user to provide 
answer through
 
 *gk.log.disabled*=<...>::
     By default, any shown message and external command calls will be logged
-    to '/tmp/init.log' in initramfs. This boolean option allows you to
+    to '/run/initramfs/init.log'. This boolean option allows you to
     disable logging for some reason.
 
-*gk.log.keep*=<...>::
-When set to a boolean value, genkernel will preserve '/tmp/init.log',
-see above, and copy file to '/genkernel-boot.log' on *root* device.
-You can also set your own file like '/root/my-genkernel-boot.log' to
-copy log to a custom path.
-
-NOTE: The default file '/genkernel-boot.log' on *root* was chosen because
-genkernel's initramfs will only mount root filesystem by default. If you
-want to store the log file in '/var/log/genkernel-boot.log' for example
-make sure that this mountpoint is accessible, see *initramfs.mounts*.
-
 *gk.userinteraction.disabled*=<...>::
 By default, genkernel will prompt on errors. In case this is not wanted
 or desired, e.g. for a kiosk system, this boolean option will disable

diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index 9852719..27e98fc 100755
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -294,7 +294,7 @@ append_base_layout() {
                lib/dracut \
                mnt \
                proc \
-               run/lock \
+               run \
                sbin \
                sys \
                tmp \
@@ -303,13 +303,11 @@ append_base_layout() {
                usr/lib \
                usr/sbin \
                var/log \
+               var/run/lock \
        ; do
                mkdir -p "${TDIR}"/${mydir} || gen_die "Failed to create 
'${TDIR}/${mydir}'!"
        done
 
-       ln -s ../run var/run || gen_die "Failed to create symlink 
'${TDIR}/var/run' to '${TDIR}/run'!"
-       ln -s ../run/lock var/lock || gen_die "Failed to create symlink 
'${TDIR}/var/lock' to '${TDIR}/run/lock'!"
-
        chmod 1777 "${TDIR}"/tmp || gen_die "Failed to chmod of '${TDIR}/tmp' 
to 1777!"
 
        # In general, we don't really need lib{32,64} anymore because we now
@@ -476,7 +474,7 @@ append_busybox() {
        done
 
        # Set up a few default symlinks
-       local required_applets='[ ash sh mknod mount uname echo cut cat'
+       local required_applets='[ ash sh mkdir mknod mount uname echo cut cat 
touch'
        local required_applet=
        for required_applet in ${required_applets}
        do
@@ -773,8 +771,6 @@ append_dmraid() {
 
        unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
 
-       mkdir -p "${TDIR}"/run/lock/dmraid || gen_die "Failed to create 
'${TDIR}/run/lock/dmraid'!"
-
        cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
 
        # Delete unneeded files

Reply via email to