commit:     0048f44c081dce2e296b48c71a208abf2a815c84
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 23 20:00:12 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Thu Jul 23 20:00:12 2020 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=0048f44c

defaults/linuxrc: Support devices with symlinks

/dev/vg/foo can be a symlink to ../dm-1. This commit will allow
to use such a value for devices, i.e. ROOT=/dev/vg/foo.

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

 defaults/initrd.scripts | 24 ++++++++++++++++--------
 defaults/linuxrc        |  5 ++++-
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 6dc588f..3bede8a 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -905,31 +905,39 @@ findnfsmount() {
 }
 
 find_real_device() {
-       local DEVICE="${1}"
-       case "${DEVICE}" in
+       local device="${1}"
+       local real_device=
+       local candidate=
+       case "${device}" in
                UUID\=*|LABEL\=*|PARTLABEL=*|PARTUUID\=*)
-                       local REAL_DEVICE=""
                        local retval=1
 
                        if [ ${retval} -ne 0 ]
                        then
-                               REAL_DEVICE=$(findfs "${DEVICE}" 2>/dev/null)
+                               candidate=$(findfs "${device}" 2>/dev/null)
                                retval=$?
                        fi
 
                        if [ ${retval} -ne 0 ]
                        then
-                               REAL_DEVICE=$(blkid -o device -l -t "${DEVICE}" 
2>/dev/null)
+                               candidate=$(blkid -o device -l -t "${device}" 
2>/dev/null)
                                retval=$?
                        fi
 
-                       if [ ${retval} -eq 0 ] && [ -n "${REAL_DEVICE}" ]
+                       if [ ${retval} -eq 0 ] && [ -n "${candidate}" ]
                        then
-                               DEVICE="${REAL_DEVICE}"
+                               real_device="${candidate}"
                        fi
                ;;
+               *)
+                       candidate=$(readlink -f "${device}")
+                       if [ -b "${candidate}" ]
+                       then
+                               real_device="${candidate}"
+                       fi
        esac
-       printf "%s" "${DEVICE}"
+
+       printf "%s" "${real_device}"
 }
 
 check_loop() {

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 5354d09..f1357f6 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -783,15 +783,18 @@ do
                                        fi
                                ;;
                                *)
-                                       if [ -b "${REAL_ROOT}" ]
+                                       ROOT_DEV=$(readlink -f "${REAL_ROOT}")
+                                       if [ -b "${ROOT_DEV}" ]
                                        then
                                                got_good_root=1
+                                               REAL_ROOT=${ROOT_DEV}
                                                echo
                                                good_msg "Root device detected 
as ${REAL_ROOT}!"
                                                break
                                        fi
                                ;;
                        esac
+                       unset ROOT_DEV
 
                        if [ "${got_good_root}" != '1' ]
                        then

Reply via email to