Files
webgui/etc/rc.d/rc.S
T

157 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
#
# /etc/rc.d/rc.S: System initialization script.
#
# Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
# LimeTech - Modified for Unraid OS
#
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
# Mount /proc if it is not already mounted:
if [ ! -d /proc/sys ]; then
/sbin/mount -v proc /proc -n -t proc 2> /dev/null
fi
# Mount /sys if it is not already mounted:
if [ ! -d /sys/kernel ]; then
/sbin/mount -v sysfs /sys -n -t sysfs 2> /dev/null
fi
# The efivarfs filesystem is used for reading and writing EFI variables, such
# as the boot menu entries. By default efivarfs will be mounted read-write on
# the /sys/firmware/efi/efivars directory. To modify this behavior, edit the
# file: /etc/default/efivarfs
# Only try to mount if this directory exists (so the kernel supports efivarfs):
if [ -d /sys/firmware/efi/efivars ]; then
# Only try to mount if efivarfs is not already mounted:
if ! /sbin/mount | /bin/grep -wq efivarfs ; then
# Mount according to /etc/default/efivarfs:
if [ -r /etc/default/efivarfs ]; then
. /etc/default/efivarfs
else # default
EFIVARFS=rw
fi
case "$EFIVARFS" in
'rw')
/sbin/mount -o rw -t efivarfs none /sys/firmware/efi/efivars
;;
'ro')
/sbin/mount -o ro -t efivarfs none /sys/firmware/efi/efivars
;;
esac
fi
fi
# If /run exists, mount a tmpfs on it (unless the
# initrd has already done so):
if [ -d /run ]; then
if ! /bin/grep -wq "tmpfs /run tmpfs" /proc/mounts ; then
/sbin/mount -v -n -t tmpfs tmpfs /run -o mode=0755,size=32M,nodev,nosuid,noexec
fi
fi
# limetech - lets mount debugfs
/sbin/mount -v -t debugfs none /sys/kernel/debug
# limetech - determine if the 'unraidlabel' kernel append parameter was
# provided to override which device is mounted for /boot (default: UNRAID)
UNRAIDLABEL="UNRAID"
UNRAIDROOT=
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
unraidlabel=*)
UNRAIDLABEL="${x#unraidlabel=}"
;;
root=*)
UNRAIDROOT="${x#root=}"
;;
esac
done
# limetech - poll for device with $UNRAIDLABEL present, with 30-sec timeout
# this serves to synchronize this script with USB subsystem
abort() {
read -p "$1 - press ENTER key to reboot ..."
echo
/sbin/reboot
}
find_device() {
# find which USB flash device/partition has the indicated label
local i
for i in {1..30} ; do
DEVICE=$(/sbin/blkid -L $UNRAIDLABEL)
[[ -z $DEVICE ]] && sleep 1 || return 0
done
return 1
}
echo -n "waiting up to 30 sec for device with label $UNRAIDLABEL to come online ... "
find_device && echo "found $DEVICE" || abort "not found"
echo "Checking $DEVICE ..."
/sbin/fsck.fat -a -w $DEVICE 2>/dev/null
/sbin/mount -v -t vfat -o auto,rw,flush,noatime,nodiratime,dmask=77,fmask=177,shortname=mixed $DEVICE /boot || abort "cannot mount $DEVICE"
# check initial files used to boot
bzcheck () {
local BZFILE=$1
if [[ -f /boot/config/skipbzcheck ]]; then
echo "Skipping $BZFILE checksum verification"
return
fi
echo "Verifying $BZFILE checksum ..."
[[ ! -f "/boot/$BZFILE" ]] && abort "$BZFILE not present"
local BZFILECHK="$BZFILE.sha256"
[[ ! -f "/boot/$BZFILECHK" ]] && abort "$BZFILECHK not present"
local SUM1=$(/bin/sha256sum /boot/$BZFILE)
local SUM2=$(/bin/cat /boot/$BZFILECHK)
[[ "${SUM1:0:63}" != "${SUM2:0:63}" ]] && abort "$BZFILE checksum error"
}
bzmount () {
local BZFILE=$1
local MNTDIR=$2
bzcheck $BZFILE
/bin/mkdir -p /$MNTDIR
/sbin/mount -v -r -t squashfs /boot/$BZFILE /$MNTDIR || abort "cannot mount $BZFILE"
# setup an overlayfs
/bin/mkdir -p /var/local/overlay/$MNTDIR
/bin/mkdir -p /var/local/overlay-work/$MNTDIR
/sbin/mount -v -t overlay overlay -o lowerdir=/$MNTDIR,upperdir=/var/local/overlay/$MNTDIR,workdir=/var/local/overlay-work/$MNTDIR /$MNTDIR
}
if [[ $UNRAIDROOT == "" ]]; then
bzcheck "bzimage"
bzcheck "bzroot"
bzcheck "bzroot-gui"
bzmount "bzmodules" "lib"
bzmount "bzfirmware" "usr"
# now that /usr is mounted make /etc/rc.d a symlink
/bin/rm -r /etc/rc.d
/bin/ln -s /usr/local/etc/rc.d /etc
# move /var/log to a tmpfs
/bin/mv /var/log/* /var/empty
/sbin/mount -t tmpfs -o size=128m,mode=0755 tmpfs /var/log
/bin/mv /var/empty/* /var/log
else
echo "Checking root filesystem"
/sbin/fsck -C -a $UNRAIDROOT
RETVAL=$?
[[ $RETVAL -ge 2 ]] && abort "fsck failed with return value $RETVAL"
# Remount the root filesystem in read-write mode
echo "Remounting $UNRAIDROOT with read-write enabled."
/sbin/mount -w -v -n -o remount /
RETVAL=$?
[[ $RETVAL -gt 0 ]] && abort "failed to remount $UNRAIDROOT r/w with return value $RETVAL"
fi
# invoke testing hook
if [[ -f /boot/config/rc.S.extra ]]; then
source /boot/config/rc.S.extra
fi
# and continue in separate script
source /etc/rc.d/rc.S.cont