aboutsummaryrefslogtreecommitdiffstats
path: root/liveinit.tpl
diff options
context:
space:
mode:
Diffstat (limited to 'liveinit.tpl')
-rw-r--r--liveinit.tpl137
1 files changed, 92 insertions, 45 deletions
diff --git a/liveinit.tpl b/liveinit.tpl
index 55fd893..c4fd29a 100644
--- a/liveinit.tpl
+++ b/liveinit.tpl
@@ -2,7 +2,7 @@
#
# Copyright 2004 Slackware Linux, Inc., Concord, CA, USA
# Copyright 2007, 2008, 2009, 2010, 2012 Patrick J. Volkerding, Sebeka, MN, USA
-# Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Eric Hameleers, Eindhoven, NL
+# Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Eric Hameleers, Eindhoven, NL
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
@@ -168,6 +168,11 @@ if grep devtmpfs /proc/filesystems 1>/dev/null 2>/dev/null ; then
mount -n devtmpfs /dev -t devtmpfs -o size=8M
fi
+# Mount if this directory exists (so the kernel supports efivarfs):
+if [ -d /sys/firmware/efi/efivars ]; then
+ mount -o rw -t efivarfs none /sys/firmware/efi/efivars
+fi
+
# Parse command line
for ARG in $(cat /proc/cmdline); do
case $ARG in
@@ -195,7 +200,7 @@ for ARG in $(cat /proc/cmdline); do
# generic syntax: hostname=newname[,qualifier]
LIVE_HOSTNAME=$(echo $ARG | cut -f2 -d= | cut -f1 -d,)
# Allow for the user to (mistakenly) add a domain component:
- if [ $(echo $LIVE_HOSTNAME |cut -d. -f1- --output-delimiter ' '|wc -w) -gt 1 ]; then
+ if [ -n "$(echo "$LIVE_HOSTNAME". |cut -d. -f2-)" ]; then
LIVE_DOMAIN=$(echo $LIVE_HOSTNAME |cut -d. -f2-)
LIVE_HOSTNAME=$(echo $LIVE_HOSTNAME |cut -d. -f1)
fi
@@ -476,6 +481,8 @@ if [ "$RESCUE" = "" ]; then
echo "/run/dhcpcd-${MYDEV}.pid"
elif [ -s /run/dhcpcd-${MYDEV}-4.pid ]; then
echo "/run/dhcpcd-${MYDEV}-4.pid"
+ elif [ -s /run/${MYDEV}.pid ]; then
+ echo "/run/${MYDEV}.pid"
else
echo UNKNOWNLOC
fi
@@ -593,13 +600,13 @@ if [ "$RESCUE" = "" ]; then
mknod -m660 $lodev b 7 $(echo $lodev |sed 's%/dev/loop%%')
fi
echo "$lodev"
- }
+ } # End find_loop()
mod_base() {
MY_MOD="$1"
echo $(basename ${MY_MOD}) |rev |cut -d. -f2- |rev
- }
+ } # End mod_base()
find_mod() {
MY_LOC="$1"
@@ -621,7 +628,7 @@ if [ "$RESCUE" = "" ]; then
done
) | sort
fi
- }
+ } # End find_mod()
find_modloc() {
MY_LOC="$1"
@@ -639,14 +646,19 @@ if [ "$RESCUE" = "" ]; then
fi
echo "${MY_LOC}"
- }
+ } # End find_modloc()
load_modules() {
# SUBSYS can be 'system', 'addons', 'optional', 'core2ram':
SUBSYS="$1"
# Find all supported modules:
- for MODULE in $(find_mod /mnt/media/${LIVEMAIN}/${SUBSYS}/) $(find_mod ${SUPERMNT}/${LIVESLAKROOT}/${LIVEMAIN}/${SUBSYS}/) ; do
+ SUBSYSSET="$(find_mod /mnt/media/${LIVEMAIN}/${SUBSYS}/) $(find_mod ${SUPERMNT}/${LIVESLAKROOT}/${LIVEMAIN}/${SUBSYS}/)"
+ if [ "$SUBSYS" = "optional" ]; then
+ # We need to load any core2ram modules first:
+ SUBSYSSET="$(find_mod /mnt/media/${LIVEMAIN}/core2ram/) $(find_mod ${SUPERMNT}/${LIVESLAKROOT}/${LIVEMAIN}/core2ram/ ${SUBSYSSET})"
+ fi
+ for MODULE in ${SUBSYSSET} ; do
# Strip path and extension from the modulename:
MODBASE="$(mod_base ${MODULE})"
if [ "$SUBSYS" = "optional" ]; then
@@ -694,10 +706,10 @@ if [ "$RESCUE" = "" ]; then
echo "${MARKER}: '$SUBSYS' modules were not found. Trouble ahead..."
fi
fi
- }
+ } # End load_modules()
# Function input is a series of device node names. Return all block devices:
- ret_blockdev () {
+ ret_blockdev() {
local OUTPUT=""
for IDEV in $* ; do
if [ -e /sys/block/$(basename $IDEV) ]; then
@@ -707,10 +719,10 @@ if [ "$RESCUE" = "" ]; then
done
# Trim trailing space:
echo $OUTPUT |cat
- }
+ } # End ret_blockdev()
# Function input is a series of device node names. Return all partitions:
- ret_partition () {
+ ret_partition() {
local OUTPUT=""
for IDEV in $* ; do
if [ -e /sys/class/block/$(basename $IDEV)/partition ]; then
@@ -720,7 +732,7 @@ if [ "$RESCUE" = "" ]; then
done
# Trim trailing space:
echo $OUTPUT |cat
- }
+ } # End ret_partition()
# Return device node of Ventoy partition if found:
# Function input:
@@ -731,7 +743,7 @@ if [ "$RESCUE" = "" ]; then
# return the device node for the partition containing the ISO file;
# 'diskuuid' request: return the UUID for the disk;
# 'partnr' request: return the number of the partition containing the ISO;
- ret_ventoy () {
+ ret_ventoy() {
local VOSPARMS="$1"
local VACTION="$2"
local DISKSIZE=""
@@ -783,7 +795,38 @@ if [ "$RESCUE" = "" ]; then
echo scandev
fi
fi
- }
+ } # End ret_ventoy()
+
+ # Find partition on which a file resides:
+ # Function input:
+ # (param 1) Full path to the file we are looking for
+ # (param 2) Directory to mount the partition containing our file
+ # Use $(df $MYMNT |tail -1 |tr -s ' ' |cut -d' ' -f1) to find that partition,
+ # it will remain mounted on the provided mountpoint upon function return.
+ scan_part() {
+ local FILEPATH="$1"
+ local MYMNT="$2"
+ local ISOPART=""
+ local PARTFS=""
+ echo "${MARKER}: Scanning for '$FILEPATH'..."
+ for ISOPART in $(ret_partition $(blkid |cut -d: -f1)) $(ret_blockdev $(blkid |cut -d: -f1)) ; do
+ PARTFS=$(blkid $ISOPART |rev |cut -d'"' -f2 |rev)
+ mount -t $PARTFS -o ro $ISOPART ${MYMNT}
+ if [ -f "${MYMNT}/${FILEPATH}" ]; then
+ # Found our file!
+ unset ISOPART
+ break
+ else
+ umount $ISOPART
+ fi
+ done
+ if [ -n "$ISOPART" ]; then
+ echo "${MARKER}: Partition scan unable to find $(basename $FILEPATH), trouble ahead."
+ return 1
+ else
+ return 0
+ fi
+ } # End scan_part()
## End support functions ##
@@ -813,18 +856,32 @@ if [ "$RESCUE" = "" ]; then
VENTID="VentoyOsParam-77772020-2e77-6576-6e74-6f792e6e6574"
VENTVAR="/sys/firmware/efi/vars/${VENTID}"
if [ ! -d "${VENTVAR}" ]; then
+ # Newer Slackware will use 'efivars' rather than 'vars' directory;
VENTVAR="/sys/firmware/efi/efivars/${VENTID}"
fi
if [ -d "${VENTVAR}" ]; then
echo "${MARKER}: (UEFI) Ventoy ISO boot detected..."
ISOBOOT="ventoy"
VENTOSPARM="${VENTVAR}/data"
+ elif [ -f "${VENTVAR}" ]; then
+ # Kernel >= 6.x does not offer a clean data sctructure, so we need to
+ # find the offset of the data block in the efivars file:
+ cat "${VENTVAR}" > /vent.dmp
else
# Detect Ventoy in memory (don't use the provided hooks), see
# https://www.ventoy.net/en/doc_compatible_format.html:
dd if=/dev/mem of=/vent.dmp bs=1 skip=$((0x80000)) count=$((0xA0000-0x80000)) 2>/dev/null
+ fi
+ if [ -f /vent.dmp ]; then
+ # Use 'strings' to find the decimal offset of the magic string;
# With 'xargs' we remove leading and ending spaces:
- OFFSET=$(strings -t d /vent.dmp |grep ' www.ventoy.net' |xargs |cut -d' ' -f1)
+ if strings -t d /vent.dmp 1>/dev/null 2>/dev/null ; then
+ # Busybox in Slackware 15.0 or newer:
+ OFFSET=$(strings -t d /vent.dmp |grep ' www.ventoy.net' |xargs |cut -d' ' -f1)
+ else
+ # Busybox in Slackware 14.2 or older:
+ OFFSET=$(strings -o /vent.dmp |grep ' www.ventoy.net' |xargs |cut -d' ' -f1)
+ fi
if [ -n "${OFFSET}" ]; then
echo "${MARKER}: (BIOS) Ventoy ISO boot detected..."
ISOBOOT="ventoy"
@@ -932,25 +989,12 @@ if [ "$RESCUE" = "" ]; then
mkdir -p ${SUPERMNT}
#
if [ "$LIVEMEDIA" = "scandev" ]; then
- # Scan partitions to find the one with the ISO and set LIVEMEDIA:
- echo "${MARKER}: Scanning for '$LIVEPATH'..."
- for ISOPART in $(ret_partition $(blkid |cut -d: -f1)) $(ret_blockdev $(blkid |cut -d: -f1)) ; do
- PARTFS=$(blkid $ISOPART |rev |cut -d'"' -f2 |rev)
- # Abuse the $SUPERMNT a bit, we will actually use it later:
- mount -t $PARTFS -o ro $ISOPART ${SUPERMNT}
- if [ -f ${SUPERMNT}/${LIVEPATH} ]; then
- # Found our ISO!
- LIVEMEDIA=$ISOPART
- umount $ISOPART
- unset ISOPART
- break
- else
- umount $ISOPART
- fi
- done
- if [ -n "$ISOPART" ]; then
- echo "${MARKER}: Partition scan unable to find ISO, trouble ahead."
- fi
+ # Scan partitions to find the one with the ISO and set LIVEMEDIA.
+ # Abuse the $SUPERMNT a bit, we will actually use it later.
+ # TODO: proper handling of scan_part return code.
+ scan_part ${LIVEPATH} ${SUPERMNT}
+ LIVEMEDIA="$(df ${SUPERMNT} 2>/dev/null |tail -1 |tr -s ' ' |cut -d' ' -f1)"
+ umount ${SUPERMNT}
fi
# At this point we know $LIVEMEDIA - either because the bootparameter
# specified it or else because the 'scandev' found it for us.
@@ -1083,7 +1127,7 @@ if [ "$RESCUE" = "" ]; then
# Load a custom keyboard mapping:
if [ -n "$KEYMAP" ]; then
- echo "${MARKER}: Loading '$KEYMAP' keyboard mapping:"
+ echo "${MARKER}: Loading '$KEYMAP' keyboard mapping."
tar xzOf /etc/keymaps.tar.gz ${KEYMAP}.bmap | loadkmap
fi
@@ -1439,7 +1483,7 @@ if [ "$RESCUE" = "" ]; then
# Let Slackware mount the unlocked container:
luksfs=$(blkid /dev/mapper/$luksnam |rev |cut -d'"' -f2 |rev)
- if ! grep -q /dev/mapper/$luksnam /mnt/overlay/etc/fstab ; then
+ if ! grep -q "^/dev/mapper/$luksnam" /mnt/overlay/etc/fstab ; then
echo "/dev/mapper/$luksnam $luksmnt $luksfs defaults 1 1" >> /mnt/overlay/etc/fstab
fi
# On shutdown, ensure that the container gets locked again:
@@ -1629,7 +1673,7 @@ EOPW
mkdir -p /mnt/overlay/run/dhcpcd
mount --bind /run/dhcpcd /mnt/overlay/run/dhcpcd
fi
- cp -a /run/dhcpcd* /mnt/overlay/run/
+ cp -a /run/dhcpcd* /run/${INTERFACE}.pid /mnt/overlay/run/
cat /etc/resolv.conf > /mnt/overlay/etc/resolv.conf
# Disable NetworkManager:
@@ -1783,7 +1827,7 @@ EOT
done
if [ $RUN_DEPMOD -eq 1 ]; then
# This costs a few seconds in additional boot-up time unfortunately:
- echo "${MARKER}: Additional kernel module(s) found... need a bit"
+ echo "${MARKER}: Additional kernel module(s) found... need a bit"
chroot /mnt/overlay /sbin/depmod -a
fi
unset RUN_DEPMOD
@@ -1794,11 +1838,14 @@ EOT
# In case of network boot, do not kill the network, umount NFS prematurely
# or stop udevd on shutdown:
if [ -n "$NFSHOST" ]; then
- sed -i /mnt/overlay/etc/rc.d/rc.0 \
- -e "/on \/ type nfs/s%grep -q 'on / type nfs'%egrep -q 'on / type (nfs|tmpfs)'%" \
- -e '/umount.*nfs/s/nfs,//' \
- -e 's/rc.udev force-stop/rc.udev stop/' \
- -e 's/$(pgrep mdmon)/& $(pgrep udevd)/'
+ for RUNLVL in 0 6 ; do
+ sed -i /mnt/overlay/etc/rc.d/rc.${RUNLVL} \
+ -e "/on \/ type nfs/s%grep -q 'on / type nfs'%egrep -q 'on / type (nfs|tmpfs)'%" \
+ -e "s%'on / type nfs4'%& -e 'on / type overlay'%" \
+ -e '/umount.*nfs/s/nfs,//' \
+ -e 's/rc.udev force-stop/rc.udev stop/' \
+ -e 's/$(pgrep mdmon)/& $(pgrep udevd)/'
+ done
fi
# Copy contents of rootcopy directory (may be empty) to overlay:
@@ -1835,8 +1882,8 @@ fi
/sbin/udevadm control --exit
unset ERR
-umount /proc
-umount /sys
+umount /proc 2>/dev/null
+umount /sys 2>/dev/null
umount /run 2>/dev/null
echo "${MARKER}: Slackware Live system is ready."