Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootdev string processing for different disks #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 77 additions & 7 deletions pmon-update
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,57 @@ Update ()
fi
}


function disk2wd
{
flag=-1
index=0

local diskpart=${1##*/}
value=$(echo $diskpart | grep nvme)
if [ $? -eq 0 ]
then
local disk=$(echo "$diskpart" | grep '[[:digit:]]\+' -o | head -n1)
local order=$(echo "$diskpart" | grep '[[:digit:]]\+' -o | tail -n1)
str1=-1
flag=1
fi

value=$(echo $diskpart | grep -E 'sd|hd')
if [ $? -eq 0 ];
then
str=`echo ${diskpart//[0-9]}`
str1=`echo ${str:0-1}`
local order=$(echo "$diskpart" | grep '[[:digit:]]\+' -o | head -n1)
flag=0
fi

for i in {a..z}
do
if [[ $str1 != -1 && "$str1" == "$i" ]];
then
disk=$index
fi

((index++))

if [ "$order" == "$index" ];
then
part=$i
break
fi
done

if [ $flag == 1 ]
then
wdpart="nvme$disk$part"
else
wdpart="wd$disk$part"
fi

echo $wdpart
}

# FIXME: switch to check boot.cfg file can be written to
# User is unprivileged
if [ "$(id -u)" -ne 0 ]
Expand Down Expand Up @@ -66,17 +117,20 @@ fi
# Setting defaults if /etc/default/pmon-update is missing

PMON_ALTERNATIVES="${PMON_ALTERNATIVES:-default recovery}"
PMON_BOOTDEV="${PMON_BOOTDEV:-(wd0,0)}"
PMON_DEFAULT="${PMON_DEFAULT:-0}"
PMON_ENTRIES="${PMON_ENTRIES:-all}"
PMON_TIMEOUT="${PMON_TIMEOUT:-5}"
PMON_MENU_LABEL="${PMON_MENU_LABEL:-Debian GNU/Linux kernel}"
PMON_MENU_LABEL="${PMON_MENU_LABEL:-Loongnix-20 GNU/Linux kernel}"
PMON_PARAMETERS="${PMON_PARAMETERS:-ro quiet}"

# Find parameter for root from fstab
if [ -z "${PMON_ROOT}" ]
BOOTDEV=($(LANG= df ${_PMON_DIRECTORY} --output=source))
BOOTDEV=${BOOTDEV[1]}
WD_BOOTDEV=$(disk2wd ${BOOTDEV})

# Find parameter for root and boot from /etc/fstab
if [ -e /etc/fstab ]
then
# Find root partition
# Find root and boot partition
while read _LINE
do

Expand All @@ -89,13 +143,22 @@ EOF
case "${_FS_SPEC}" in
"#"*) ;;
*) PMON_ROOT="root=${_FS_SPEC}"
break ;;
continue ;;
esac
fi

if [ "${_FS_FILE}" = "${_PMON_DIRECTORY}" ]
then
case "${_FS_SPEC}" in
"#"*) ;;
*) PMON_BOOTDEV="/dev/fs/${_FS_VFSTYPE}@${WD_BOOTDEV}"
continue ;;
esac
fi
done < /etc/fstab
fi

# if not in fsrab, try from current kernel arguments
# if not in fstab, try from current kernel arguments
if [ -z "${PMON_ROOT}" ]
then
for param in `cat /proc/cmdline`
Expand All @@ -108,6 +171,13 @@ then
done
fi

# if not in fstab, get from df command
if [ -z "${PMON_BOOTDEV}" ]
then
BOOT_FSTYPE=($(LANG= df ${_PMON_DIRECTORY} --output=fstype))
BOOT_FSTYPE=${BOOT_FSTYPE[1]}
PMON_BOOTDEV="/dev/fs/${BOOT_FSTYPE}@${WD_BOOTDEV}"
fi

# Create extlinux.conf
_CONFIG="\
Expand Down