mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-28 05:06:43 +00:00
Merge pull request #3302 from antonlacon/init-changes
busybox/init: cleanup
This commit is contained in:
commit
fca5752af1
@ -6,191 +6,75 @@
|
||||
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
|
||||
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
|
||||
|
||||
# create directories
|
||||
/usr/bin/busybox mkdir -p /dev
|
||||
/usr/bin/busybox mkdir -p /proc
|
||||
/usr/bin/busybox mkdir -p /sys
|
||||
/usr/bin/busybox mkdir -p /tmp
|
||||
/usr/bin/busybox mkdir -p /flash
|
||||
/usr/bin/busybox mkdir -p /sysroot
|
||||
/usr/bin/busybox mkdir -p /storage
|
||||
# create directories
|
||||
/usr/bin/busybox mkdir -p /dev
|
||||
/usr/bin/busybox mkdir -p /proc
|
||||
/usr/bin/busybox mkdir -p /sys
|
||||
/usr/bin/busybox mkdir -p /tmp
|
||||
/usr/bin/busybox mkdir -p /flash
|
||||
/usr/bin/busybox mkdir -p /sysroot
|
||||
/usr/bin/busybox mkdir -p /storage
|
||||
|
||||
# mount all needed special filesystems
|
||||
/usr/bin/busybox mount -t devtmpfs devtmpfs /dev
|
||||
/usr/bin/busybox mount -t proc proc /proc
|
||||
/usr/bin/busybox mount -t sysfs sysfs /sys
|
||||
# mount all needed special filesystems
|
||||
/usr/bin/busybox mount -t devtmpfs devtmpfs /dev
|
||||
/usr/bin/busybox mount -t proc proc /proc
|
||||
/usr/bin/busybox mount -t sysfs sysfs /sys
|
||||
|
||||
# common functions
|
||||
. /functions
|
||||
# set needed variables
|
||||
MODULE_DIR=/usr/lib/modules
|
||||
|
||||
# set needed variables
|
||||
MODULE_DIR=/usr/lib/modules
|
||||
UPDATE_ROOT=/storage/.update
|
||||
UPDATE_DIR="$UPDATE_ROOT"
|
||||
|
||||
UPDATE_ROOT=/storage/.update
|
||||
UPDATE_DIR="$UPDATE_ROOT"
|
||||
UPDATE_KERNEL="KERNEL"
|
||||
UPDATE_SYSTEM="SYSTEM"
|
||||
IMAGE_KERNEL="@KERNEL_NAME@"
|
||||
IMAGE_SYSTEM="SYSTEM"
|
||||
|
||||
UPDATE_KERNEL="KERNEL"
|
||||
UPDATE_SYSTEM="SYSTEM"
|
||||
IMAGE_KERNEL="@KERNEL_NAME@"
|
||||
IMAGE_SYSTEM="SYSTEM"
|
||||
BOOT_STEP="start"
|
||||
MD5_FAILED="0"
|
||||
RUN_FSCK="yes"
|
||||
RUN_FSCK_DISKS=""
|
||||
SYSLINUX_DEFAULT=""
|
||||
GRUB_DEFAULT=""
|
||||
|
||||
BOOT_STEP="start"
|
||||
MD5_FAILED="0"
|
||||
RUN_FSCK="yes"
|
||||
RUN_FSCK_DISKS=""
|
||||
SYSLINUX_DEFAULT=""
|
||||
GRUB_DEFAULT=""
|
||||
NBD_DEVS="0"
|
||||
FLASH_FREE_MIN="5"
|
||||
|
||||
NBD_DEVS="0"
|
||||
FLASH_FREE_MIN="5"
|
||||
INSTALLED_MEMORY=$(cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}')
|
||||
SYSTEM_TORAM_LIMIT=1024000
|
||||
|
||||
INSTALLED_MEMORY=$(cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}')
|
||||
SYSTEM_TORAM_LIMIT=1024000
|
||||
LIVE="no"
|
||||
|
||||
LIVE="no"
|
||||
BREAK_TRIPPED="no"
|
||||
|
||||
BREAK_TRIPPED="no"
|
||||
# Get a serial number if present (eg. RPi) otherwise use MAC address from eth0
|
||||
MACHINE_UID="$(cat /proc/cpuinfo | awk '/^Serial/{s=$3; gsub ("^0*","",s); print s}')"
|
||||
[ -z "$MACHINE_UID" ] && MACHINE_UID="$(cat /sys/class/net/eth0/address 2>/dev/null | tr -d :)"
|
||||
|
||||
# Get a serial number if present (eg. RPi) otherwise use MAC address from eth0
|
||||
MACHINE_UID="$(cat /proc/cpuinfo | awk '/^Serial/{s=$3; gsub ("^0*","",s); print s}')"
|
||||
[ -z "$MACHINE_UID" ] && MACHINE_UID="$(cat /sys/class/net/eth0/address 2>/dev/null | tr -d :)"
|
||||
# common functions
|
||||
. /functions
|
||||
|
||||
# hide kernel log messages on console
|
||||
echo '1 4 1 7' > /proc/sys/kernel/printk
|
||||
|
||||
# set ondemand up_threshold
|
||||
if [ -e /sys/devices/system/cpu/cpufreq/ondemand/up_threshold ] ; then
|
||||
echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
|
||||
fi
|
||||
|
||||
# run platform_init script if exists
|
||||
if [ -f "./platform_init" ]; then
|
||||
./platform_init
|
||||
fi
|
||||
|
||||
# clear screen and hide cursor
|
||||
clear
|
||||
hidecursor
|
||||
|
||||
# parse command line arguments
|
||||
for arg in $(cat /proc/cmdline); do
|
||||
case $arg in
|
||||
BOOT_IMAGE=*)
|
||||
IMAGE_KERNEL="${arg#*=}"
|
||||
[ "${IMAGE_KERNEL:0:1}" = "/" ] && IMAGE_KERNEL="${IMAGE_KERNEL:1}"
|
||||
;;
|
||||
SYSTEM_IMAGE=*)
|
||||
IMAGE_SYSTEM="${arg#*=}"
|
||||
[ "${IMAGE_SYSTEM:0:1}" = "/" ] && IMAGE_SYSTEM="${IMAGE_SYSTEM:1}"
|
||||
;;
|
||||
boot=*)
|
||||
boot="${arg#*=}"
|
||||
case $boot in
|
||||
ISCSI=*|NBD=*|NFS=*)
|
||||
UPDATE_DISABLED=yes
|
||||
FLASH_NETBOOT=yes
|
||||
;;
|
||||
/dev/*|LABEL=*|UUID=*)
|
||||
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $boot"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
disk=*)
|
||||
disk="${arg#*=}"
|
||||
case $disk in
|
||||
ISCSI=*|NBD=*|NFS=*)
|
||||
STORAGE_NETBOOT=yes
|
||||
;;
|
||||
/dev/*|LABEL=*|UUID=*)
|
||||
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $disk"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
wol_mac=*)
|
||||
wol_mac="${arg#*=}"
|
||||
;;
|
||||
wol_wait=*)
|
||||
wol_wait="${arg#*=}"
|
||||
;;
|
||||
textmode)
|
||||
INIT_UNIT="--unit=textmode.target"
|
||||
;;
|
||||
installer)
|
||||
INIT_UNIT="--unit=installer.target"
|
||||
SYSLINUX_DEFAULT="installer"
|
||||
;;
|
||||
debugging)
|
||||
DEBUG=yes
|
||||
;;
|
||||
progress)
|
||||
PROGRESS=yes
|
||||
INIT_ARGS="$INIT_ARGS --show-status=1"
|
||||
;;
|
||||
nofsck)
|
||||
RUN_FSCK=no
|
||||
;;
|
||||
nosplash)
|
||||
SPLASH=no
|
||||
;;
|
||||
noram)
|
||||
SYSTEM_TORAM=no
|
||||
;;
|
||||
ramlimit=*)
|
||||
SYSTEM_TORAM_LIMIT="${arg#*=}"
|
||||
;;
|
||||
live)
|
||||
LIVE=yes
|
||||
SYSLINUX_DEFAULT="live"
|
||||
;;
|
||||
portable)
|
||||
SYSLINUX_DEFAULT="run"
|
||||
;;
|
||||
grub_live)
|
||||
LIVE=yes
|
||||
GRUB_DEFAULT="Live"
|
||||
;;
|
||||
grub_portable)
|
||||
GRUB_DEFAULT="Run"
|
||||
;;
|
||||
overlay)
|
||||
OVERLAY=yes
|
||||
;;
|
||||
setfbres=*)
|
||||
SWITCH_FRAMEBUFFER="${arg#*=}"
|
||||
SWITCH_FRAMEBUFFER="${SWITCH_FRAMEBUFFER//,/ }"
|
||||
;;
|
||||
break=*)
|
||||
BREAK="${arg#*=}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test "$DEBUG" = "yes"; then
|
||||
exec 3>&1
|
||||
else
|
||||
exec 3>/dev/null
|
||||
fi
|
||||
SILENT_OUT=3
|
||||
|
||||
progress() {
|
||||
# script functions
|
||||
progress() {
|
||||
if test "$PROGRESS" = "yes"; then
|
||||
echo "### $1 ###" >&2
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
debug_msg() {
|
||||
debug_msg() {
|
||||
echo "$1" >&$SILENT_OUT
|
||||
}
|
||||
}
|
||||
|
||||
debug_shell() {
|
||||
debug_shell() {
|
||||
echo "### Starting debugging shell for boot step: $BOOT_STEP... type exit to quit ###"
|
||||
|
||||
showcursor
|
||||
|
||||
setsid cttyhack sh
|
||||
}
|
||||
}
|
||||
|
||||
error() {
|
||||
error() {
|
||||
# Display fatal error message
|
||||
# $1:action which caused error, $2:message
|
||||
# Send debug_shell output to stderr, in case caller is redirecting/consuming stdout
|
||||
@ -198,9 +82,9 @@
|
||||
echo "*** Error in $BOOT_STEP: $1: $2 ***" >&2
|
||||
debug_shell >&2
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
break_after() {
|
||||
break_after() {
|
||||
# Start debug shell after boot step $1, and all subsequent steps
|
||||
if [ $BREAK_TRIPPED == yes ]; then
|
||||
debug_shell
|
||||
@ -212,12 +96,12 @@
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
# Mount handlers
|
||||
# All handlers take the following parameters:
|
||||
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
|
||||
mount_common() {
|
||||
# Mount handlers
|
||||
# All handlers take the following parameters:
|
||||
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
|
||||
mount_common() {
|
||||
# Common mount handler, handles block devices and filesystem images
|
||||
MOUNT_OPTIONS="-o $3"
|
||||
[ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS"
|
||||
@ -232,9 +116,9 @@
|
||||
done
|
||||
[ "$ERR_ENV" -eq "0" ] && return 0
|
||||
error "mount_common" "Could not mount $1"
|
||||
}
|
||||
}
|
||||
|
||||
get_iscsistart_options() {
|
||||
get_iscsistart_options() {
|
||||
# Convert kernel commandline ISCSI= options to iscsistart options
|
||||
IFS_SAVE="$IFS"
|
||||
IFS=,
|
||||
@ -274,9 +158,9 @@
|
||||
done
|
||||
|
||||
IFS="$IFS_SAVE"
|
||||
}
|
||||
}
|
||||
|
||||
mount_iscsi() {
|
||||
mount_iscsi() {
|
||||
# Mount iSCSI target
|
||||
ISCSI_DEV="${1##*,}"
|
||||
ISCSI_OPTIONS="${1%,*}"
|
||||
@ -287,34 +171,30 @@
|
||||
|
||||
if [ "$ISCSI_OPTIONS" = "auto" ]; then
|
||||
progress "Network configuration based on iBFT"
|
||||
/usr/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || \
|
||||
error "iscsistart" "Unable to configure network"
|
||||
/usr/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to configure network"
|
||||
progress "iSCSI auto connect based on iBFT"
|
||||
/usr/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || \
|
||||
error "iscsistart" "Unable to auto connect"
|
||||
/usr/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to auto connect"
|
||||
else
|
||||
/usr/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || \
|
||||
error "iscsistart" "Unable to connect to ISCSI target"
|
||||
/usr/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to connect to ISCSI target"
|
||||
fi
|
||||
|
||||
mount_common "$ISCSI_DEV" "$2" "$3" "$4"
|
||||
}
|
||||
}
|
||||
|
||||
mount_nbd() {
|
||||
# Mount NBD device
|
||||
mount_nbd() {
|
||||
# Mount NBD device
|
||||
NBD_SERVER="${1%%:*}"
|
||||
NBD_PORT="${1#*:}"
|
||||
NBD_DEV="/dev/nbd$NBD_DEVS"
|
||||
|
||||
nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \
|
||||
error "nbd-client" "Could not connect to NBD server $1"
|
||||
nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || error "nbd-client" "Could not connect to NBD server $1"
|
||||
|
||||
mount_common "$NBD_DEV" "$2" "$3" "$4"
|
||||
|
||||
NBD_DEVS=$(( NBD_DEVS + 1 ))
|
||||
}
|
||||
}
|
||||
|
||||
mount_nfs() {
|
||||
mount_nfs() {
|
||||
# Mount NFS export
|
||||
NFS_EXPORT="${1%%,*}"
|
||||
NFS_OPTIONS="${1#*,}"
|
||||
@ -322,13 +202,13 @@
|
||||
[ "$NFS_OPTIONS" = "$1" ] && NFS_OPTIONS=
|
||||
|
||||
mount_common "$NFS_EXPORT" "$2" "$3,nolock,soft,timeo=3,retrans=2,rsize=32768,wsize=32768,$NFS_OPTIONS" "nfs"
|
||||
}
|
||||
}
|
||||
|
||||
mount_ubifs() {
|
||||
mount_ubifs() {
|
||||
mount_common "$1" "$2" "$3" "ubifs"
|
||||
}
|
||||
}
|
||||
|
||||
mount_part() {
|
||||
mount_part() {
|
||||
# Mount a local or network filesystem
|
||||
# $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type]
|
||||
progress "mount filesystem $1 ..."
|
||||
@ -362,10 +242,10 @@
|
||||
MOUNT_TARGET="${MOUNT_TARGET//@UID@/$MACHINE_UID}"
|
||||
|
||||
$MOUNT_CMD "$MOUNT_TARGET" "$2" "$3" "$4"
|
||||
}
|
||||
}
|
||||
|
||||
# mount the specified SYSTEM file and output arch from /etc/os-release
|
||||
get_project_arch() {
|
||||
# mount the specified SYSTEM file and output arch from /etc/os-release
|
||||
get_project_arch() {
|
||||
mount_part "$1" "/sysroot" "ro,loop" || return
|
||||
|
||||
if [ -f /sysroot/etc/os-release ]; then
|
||||
@ -374,13 +254,13 @@
|
||||
fi
|
||||
|
||||
umount /sysroot
|
||||
}
|
||||
}
|
||||
|
||||
# If the project/arch of current matches the upgrade, then it is considered compatible.
|
||||
# Otherwise, mount the upgrade SYSTEM partition and, if canupdate.sh is available,
|
||||
# call the script to determine if the current upgrade file can be applied on to the
|
||||
# current system - 0 means it is compatible, non-zero that it is not compatible.
|
||||
is_compatible() {
|
||||
# If the project/arch of current matches the upgrade, then it is considered compatible.
|
||||
# Otherwise, mount the upgrade SYSTEM partition and, if canupdate.sh is available,
|
||||
# call the script to determine if the current upgrade file can be applied on to the
|
||||
# current system - 0 means it is compatible, non-zero that it is not compatible.
|
||||
is_compatible() {
|
||||
local result=1
|
||||
|
||||
if [ "${2}" = "${3}" ]; then
|
||||
@ -396,10 +276,10 @@
|
||||
fi
|
||||
|
||||
return ${result}
|
||||
}
|
||||
}
|
||||
|
||||
# determine if the new SYSTEM file is compatible with the current SYSTEM file
|
||||
check_is_compatible() {
|
||||
# determine if the new SYSTEM file is compatible with the current SYSTEM file
|
||||
check_is_compatible() {
|
||||
local update_filename="${1}"
|
||||
local old_system="${2}"
|
||||
local new_system="${3}"
|
||||
@ -425,9 +305,9 @@
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
update_file() {
|
||||
update_file() {
|
||||
if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then
|
||||
mount -o remount,rw /flash
|
||||
|
||||
@ -445,9 +325,9 @@
|
||||
fi
|
||||
sync
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
update_partition() {
|
||||
update_partition() {
|
||||
local result
|
||||
|
||||
if [ -f "$UPDATE_DIR/$2" -a -b "$3" ]; then
|
||||
@ -456,9 +336,9 @@
|
||||
StopProgress "done"
|
||||
echo "${result}"
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
update_bootloader() {
|
||||
update_bootloader() {
|
||||
local result
|
||||
|
||||
export BOOT_ROOT="/flash"
|
||||
@ -475,20 +355,19 @@
|
||||
fi
|
||||
|
||||
umount /sysroot
|
||||
}
|
||||
}
|
||||
|
||||
load_modules() {
|
||||
load_modules() {
|
||||
progress "Loading kernel modules"
|
||||
|
||||
[ ! -f "/etc/modules" ] && return
|
||||
for module in $(cat /etc/modules); do
|
||||
progress "Loading kernel module $module"
|
||||
insmod "$MODULE_DIR/$module.ko" || \
|
||||
progress "... Failed to load kernel module $module, skipping"
|
||||
insmod "$MODULE_DIR/$module.ko" || progress "... Failed to load kernel module $module, skipping"
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
load_splash() {
|
||||
load_splash() {
|
||||
local set_default_res=no
|
||||
local vres
|
||||
|
||||
@ -498,9 +377,7 @@
|
||||
# load uvesafb module if needed
|
||||
if [ -f "$MODULE_DIR/uvesafb.ko" -a ! -e /dev/fb0 ]; then
|
||||
progress "Loading kernel module uvesafb.ko"
|
||||
insmod "$MODULE_DIR/uvesafb.ko" && \
|
||||
set_default_res=yes || \
|
||||
progress "... Failed to load kernel module uvesafb, skipping"
|
||||
insmod "$MODULE_DIR/uvesafb.ko" && set_default_res=yes || progress "... Failed to load kernel module uvesafb, skipping"
|
||||
fi
|
||||
|
||||
if [ -e /dev/fb0 ]; then
|
||||
@ -557,9 +434,9 @@
|
||||
debug_msg "Framebuffer splash image: $SPLASHIMAGE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
do_reboot() {
|
||||
do_reboot() {
|
||||
echo "System reboots now..."
|
||||
|
||||
# syncing filesystem
|
||||
@ -576,9 +453,9 @@
|
||||
|
||||
usleep 2000000
|
||||
/usr/bin/busybox reboot
|
||||
}
|
||||
}
|
||||
|
||||
force_fsck() {
|
||||
force_fsck() {
|
||||
echo "Filesystem corruption has been detected!"
|
||||
echo "To prevent an automatic repair attempt continuing,"
|
||||
echo "press any key or power off your system within the next 120 seconds"
|
||||
@ -586,12 +463,12 @@
|
||||
read -t120 -n1
|
||||
# The exit status is 0 if input is available
|
||||
# The exit status is greater than 128 if the timeout is exceeded
|
||||
if [ "$?" -ne "0" -o "$?" -gt "128" ] ; then
|
||||
if [ $? -ne 0 -o $? -gt 128 ]; then
|
||||
echo "Repairing filesystem..."
|
||||
echo ""
|
||||
/usr/sbin/fsck -T -M -y $RUN_FSCK_DISKS
|
||||
FSCK_RET="$?"
|
||||
if [ "$(( $FSCK_RET & 8 ))" = 8 ] ; then
|
||||
FSCK_RET=$?
|
||||
if [ $(( $FSCK_RET & 8 )) -eq 8 ]; then
|
||||
# fubar
|
||||
echo "Forced fsck failed. Your system is broken beyond repair"
|
||||
echo "Please re-install @DISTRONAME@"
|
||||
@ -608,33 +485,33 @@
|
||||
sync
|
||||
poweroff
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
check_disks() {
|
||||
check_disks() {
|
||||
if [ "$RUN_FSCK" = "yes" -a -n "$RUN_FSCK_DISKS" ]; then
|
||||
progress "Checking disk(s): $RUN_FSCK_DISKS"
|
||||
/usr/sbin/fsck -T -M -p -a $RUN_FSCK_DISKS > /dev/null 2>&1
|
||||
FSCK_RET="$?"
|
||||
FSCK_RET=$?
|
||||
|
||||
# FSCK_RET is the bit-wise OR of the exit codes for each filesystem that is checked.
|
||||
if [ "$(( $FSCK_RET & 4 ))" = 4 ] ; then
|
||||
if [ $(( $FSCK_RET & 4 )) -eq 4 ]; then
|
||||
# errors left
|
||||
force_fsck
|
||||
elif [ "$(( $FSCK_RET & 2 ))" = 2 ] ; then
|
||||
elif [ $(( $FSCK_RET & 2 )) -eq 2 ]; then
|
||||
# reboot needed
|
||||
echo "Filesystem repaired, reboot needed..."
|
||||
do_reboot
|
||||
elif [ "$(( $FSCK_RET & 1 ))" = 1 ] ; then
|
||||
elif [ $(( $FSCK_RET & 1 )) -eq 1 ]; then
|
||||
# filesystem errors corrected
|
||||
progress "Filesystem errors corrected , continuing..."
|
||||
elif [ "$(( $FSCK_RET & 0 ))" = 0 ] ; then
|
||||
elif [ $(( $FSCK_RET & 0 )) -eq 0 ]; then
|
||||
# no errors found
|
||||
progress "No filesystem errors found, continuing..."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
wakeonlan() {
|
||||
wakeonlan() {
|
||||
if [ "$STORAGE_NETBOOT" = "yes" ]; then
|
||||
wol_ip=${disk%:*}
|
||||
wol_ip=${wol_ip#*=}
|
||||
@ -653,21 +530,21 @@
|
||||
StartProgress countdown "WOL magic packet sent to $wol_ip, waiting $wol_wait seconds... " $wol_wait "done"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
mount_flash() {
|
||||
mount_flash() {
|
||||
progress "Mounting flash"
|
||||
|
||||
wakeonlan
|
||||
|
||||
mount_part "$boot" "/flash" "ro,noatime"
|
||||
|
||||
if [ -f /flash/post-flash.sh ] ; then
|
||||
if [ -f /flash/post-flash.sh ]; then
|
||||
. /flash/post-flash.sh
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
mount_storage() {
|
||||
mount_storage() {
|
||||
progress "Mounting storage"
|
||||
|
||||
if [ "$LIVE" = "yes" ]; then
|
||||
@ -696,7 +573,7 @@
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f /flash/mount-storage.sh ] ; then
|
||||
if [ -f /flash/mount-storage.sh ]; then
|
||||
. /flash/mount-storage.sh
|
||||
else
|
||||
mount_part "$disk" "/storage" "rw,noatime"
|
||||
@ -705,10 +582,10 @@
|
||||
# /storage should always be writable
|
||||
mount -t tmpfs none /storage
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
# Make last bootloader label (installer, live, run etc.) as the new default
|
||||
update_bootmenu() {
|
||||
# Make last bootloader label (installer, live, run etc.) as the new default
|
||||
update_bootmenu() {
|
||||
local crnt_default
|
||||
|
||||
if [ -n "$SYSLINUX_DEFAULT" -a -f /flash/syslinux.cfg ]; then
|
||||
@ -738,9 +615,9 @@
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
check_out_of_space() {
|
||||
check_out_of_space() {
|
||||
if [ "$(df /storage | awk '/[0-9]%/{print $4}')" -eq "0" ]; then
|
||||
echo ""
|
||||
echo "The $1 is corrupt, or there is not enough"
|
||||
@ -756,9 +633,9 @@
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
do_cleanup() {
|
||||
do_cleanup() {
|
||||
StartProgress spinner "Cleaning up... "
|
||||
|
||||
if [ -d $UPDATE_ROOT/.tmp/mnt ]; then
|
||||
@ -781,9 +658,9 @@
|
||||
sync
|
||||
|
||||
StopProgress "done"
|
||||
}
|
||||
}
|
||||
|
||||
check_update() {
|
||||
check_update() {
|
||||
progress "Checking for updates"
|
||||
UPDATE_TAR=$(ls -1 "$UPDATE_DIR"/*.tar 2>/dev/null | head -n 1)
|
||||
UPDATE_IMG_GZ=$(ls -1 "$UPDATE_DIR"/*.img.gz 2>/dev/null | head -n 1)
|
||||
@ -794,7 +671,7 @@
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$UPDATE_DISABLED" = "yes" ] ; then
|
||||
if [ "$UPDATE_DISABLED" = "yes" ]; then
|
||||
echo "Updating is not supported on netboot"
|
||||
do_cleanup
|
||||
StartProgress countdown "Normal startup in 10s... " 10 "NOW"
|
||||
@ -817,7 +694,7 @@
|
||||
echo "Please do not reboot or turn off your @DISTRONAME@ device!"
|
||||
echo ""
|
||||
|
||||
if [ -f "$UPDATE_TAR" ] ; then
|
||||
if [ -f "$UPDATE_TAR" ]; then
|
||||
TARRESULT="0"
|
||||
|
||||
echo "Found new .tar archive"
|
||||
@ -841,7 +718,7 @@
|
||||
StartProgress countdown "Normal startup in 30s... " 30 "NOW"
|
||||
return 0
|
||||
fi
|
||||
elif [ -f "$UPDATE_IMG_GZ" -o -f "$UPDATE_IMG" ] ; then
|
||||
elif [ -f "$UPDATE_IMG_GZ" -o -f "$UPDATE_IMG" ]; then
|
||||
mkdir -p $UPDATE_DIR/.tmp/mnt &>/dev/null
|
||||
IMG_FILE="$UPDATE_DIR/.tmp/update.img"
|
||||
GZRESULT="0"
|
||||
@ -916,7 +793,7 @@
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -f "$UPDATE_DIR/$UPDATE_KERNEL" -o ! -f "$UPDATE_DIR/$UPDATE_SYSTEM" ] ; then
|
||||
if [ ! -f "$UPDATE_DIR/$UPDATE_KERNEL" -o ! -f "$UPDATE_DIR/$UPDATE_SYSTEM" ]; then
|
||||
echo "Missing (source) ${UPDATE_KERNEL} or ${UPDATE_SYSTEM}!"
|
||||
do_cleanup
|
||||
StartProgress countdown "Normal startup in 30s... " 30 "NOW"
|
||||
@ -925,9 +802,9 @@
|
||||
|
||||
# check md5 sums if .nocheck doesn't exist
|
||||
if [ ! -f "$UPDATE_ROOT/.nocheck" ]; then
|
||||
if [ -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then
|
||||
if [ -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ]; then
|
||||
# *.md5 size-check
|
||||
if [ ! -s "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -o ! -s "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then
|
||||
if [ ! -s "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -o ! -s "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ]; then
|
||||
echo "Zero-sized .md5 file!"
|
||||
MD5_FAILED="1"
|
||||
else
|
||||
@ -1021,9 +898,9 @@
|
||||
update_bootloader
|
||||
do_cleanup
|
||||
do_reboot
|
||||
}
|
||||
}
|
||||
|
||||
prepare_sysroot() {
|
||||
prepare_sysroot() {
|
||||
progress "Preparing system"
|
||||
|
||||
if [ "$SYSTEM_TORAM" = "no" -o "$INSTALLED_MEMORY" -lt "$SYSTEM_TORAM_LIMIT" ]; then
|
||||
@ -1046,20 +923,139 @@
|
||||
fi
|
||||
|
||||
[ -f "/sysroot/usr/lib/systemd/systemd" ] || error "final_check" "Could not find systemd!"
|
||||
}
|
||||
}
|
||||
|
||||
# If the network is up (due to the use of the "ip" kernel parameter) and a DNS
|
||||
# server is known, allow the libc resolver to use it
|
||||
grep '^\(nameserver\|domain\) ' /proc/net/pnp | grep -v '^nameserver 0\.0\.0\.0$' > /etc/resolv.conf
|
||||
# Do init tasks to bring up system
|
||||
|
||||
if [ "${boot%%=*}" = "FILE" ]; then
|
||||
# hide kernel log messages on console
|
||||
echo '1 4 1 7' > /proc/sys/kernel/printk
|
||||
|
||||
# set ondemand up_threshold
|
||||
if [ -e /sys/devices/system/cpu/cpufreq/ondemand/up_threshold ]; then
|
||||
echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
|
||||
fi
|
||||
|
||||
# run platform_init script if exists
|
||||
if [ -f "./platform_init" ]; then
|
||||
./platform_init
|
||||
fi
|
||||
|
||||
# clear screen and hide cursor
|
||||
clear
|
||||
hidecursor
|
||||
|
||||
# parse command line arguments
|
||||
for arg in $(cat /proc/cmdline); do
|
||||
case $arg in
|
||||
BOOT_IMAGE=*)
|
||||
IMAGE_KERNEL="${arg#*=}"
|
||||
[ "${IMAGE_KERNEL:0:1}" = "/" ] && IMAGE_KERNEL="${IMAGE_KERNEL:1}"
|
||||
;;
|
||||
SYSTEM_IMAGE=*)
|
||||
IMAGE_SYSTEM="${arg#*=}"
|
||||
[ "${IMAGE_SYSTEM:0:1}" = "/" ] && IMAGE_SYSTEM="${IMAGE_SYSTEM:1}"
|
||||
;;
|
||||
boot=*)
|
||||
boot="${arg#*=}"
|
||||
case $boot in
|
||||
ISCSI=*|NBD=*|NFS=*)
|
||||
UPDATE_DISABLED=yes
|
||||
FLASH_NETBOOT=yes
|
||||
;;
|
||||
/dev/*|LABEL=*|UUID=*)
|
||||
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $boot"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
disk=*)
|
||||
disk="${arg#*=}"
|
||||
case $disk in
|
||||
ISCSI=*|NBD=*|NFS=*)
|
||||
STORAGE_NETBOOT=yes
|
||||
;;
|
||||
/dev/*|LABEL=*|UUID=*)
|
||||
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $disk"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
wol_mac=*)
|
||||
wol_mac="${arg#*=}"
|
||||
;;
|
||||
wol_wait=*)
|
||||
wol_wait="${arg#*=}"
|
||||
;;
|
||||
textmode)
|
||||
INIT_UNIT="--unit=textmode.target"
|
||||
;;
|
||||
installer)
|
||||
INIT_UNIT="--unit=installer.target"
|
||||
SYSLINUX_DEFAULT="installer"
|
||||
;;
|
||||
debugging)
|
||||
DEBUG=yes
|
||||
;;
|
||||
progress)
|
||||
PROGRESS=yes
|
||||
INIT_ARGS="$INIT_ARGS --show-status=1"
|
||||
;;
|
||||
nofsck)
|
||||
RUN_FSCK=no
|
||||
;;
|
||||
nosplash)
|
||||
SPLASH=no
|
||||
;;
|
||||
noram)
|
||||
SYSTEM_TORAM=no
|
||||
;;
|
||||
ramlimit=*)
|
||||
SYSTEM_TORAM_LIMIT="${arg#*=}"
|
||||
;;
|
||||
live)
|
||||
LIVE=yes
|
||||
SYSLINUX_DEFAULT="live"
|
||||
;;
|
||||
portable)
|
||||
SYSLINUX_DEFAULT="run"
|
||||
;;
|
||||
grub_live)
|
||||
LIVE=yes
|
||||
GRUB_DEFAULT="Live"
|
||||
;;
|
||||
grub_portable)
|
||||
GRUB_DEFAULT="Run"
|
||||
;;
|
||||
overlay)
|
||||
OVERLAY=yes
|
||||
;;
|
||||
setfbres=*)
|
||||
SWITCH_FRAMEBUFFER="${arg#*=}"
|
||||
SWITCH_FRAMEBUFFER="${SWITCH_FRAMEBUFFER//,/ }"
|
||||
;;
|
||||
break=*)
|
||||
BREAK="${arg#*=}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test "$DEBUG" = "yes"; then
|
||||
exec 3>&1
|
||||
else
|
||||
exec 3>/dev/null
|
||||
fi
|
||||
SILENT_OUT=3
|
||||
|
||||
# If the network is up (due to the use of the "ip" kernel parameter) and a DNS
|
||||
# server is known, allow the libc resolver to use it
|
||||
grep '^\(nameserver\|domain\) ' /proc/net/pnp | grep -v '^nameserver 0\.0\.0\.0$' > /etc/resolv.conf
|
||||
|
||||
if [ "${boot%%=*}" = "FILE" ]; then
|
||||
error "check arguments" "boot argument can't be FILE type..."
|
||||
fi
|
||||
fi
|
||||
|
||||
debug_msg "Unique identifier for this client: ${MACHINE_UID:-NOT AVAILABLE}"
|
||||
debug_msg "Unique identifier for this client: ${MACHINE_UID:-NOT AVAILABLE}"
|
||||
|
||||
# main boot sequence
|
||||
for BOOT_STEP in \
|
||||
# main boot sequence
|
||||
for BOOT_STEP in \
|
||||
load_modules \
|
||||
check_disks \
|
||||
mount_flash \
|
||||
@ -1070,58 +1066,58 @@
|
||||
prepare_sysroot; do
|
||||
$BOOT_STEP
|
||||
[ -n "$DEBUG" ] && break_after $BOOT_STEP
|
||||
done
|
||||
done
|
||||
|
||||
BOOT_STEP=final
|
||||
BOOT_STEP=final
|
||||
|
||||
# log if booting from usb / removable storage
|
||||
STORAGE=$(cat /proc/mounts | grep " /sysroot/storage " | awk '{print $1}' | awk -F '/' '{print $3}')
|
||||
FLASH=$(cat /proc/mounts | grep " /sysroot/flash " | awk '{print $1}' | awk -F '/' '{print $3}')
|
||||
for i in $STORAGE $FLASH ; do
|
||||
if [ -n "$i" ] ; then
|
||||
# log if booting from usb / removable storage
|
||||
STORAGE=$(cat /proc/mounts | grep " /sysroot/storage " | awk '{print $1}' | awk -F '/' '{print $3}')
|
||||
FLASH=$(cat /proc/mounts | grep " /sysroot/flash " | awk '{print $1}' | awk -F '/' '{print $3}')
|
||||
for i in $STORAGE $FLASH ; do
|
||||
if [ -n "$i" ]; then
|
||||
removable="/sys/class/block/*/$i/../removable"
|
||||
if [ -e $removable ] ; then
|
||||
if [ "$(cat $removable 2>/dev/null)" = "1" ] ; then
|
||||
if [ -e $removable ]; then
|
||||
if [ "$(cat $removable 2>/dev/null)" = "1" ]; then
|
||||
echo "### BIG FAT WARNING" > /dev/kmsg
|
||||
echo "### $i is removable. suspend/resume may not work" > /dev/kmsg
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# move some special filesystems
|
||||
/usr/bin/busybox mount --move /dev /sysroot/dev
|
||||
/usr/bin/busybox mount --move /proc /sysroot/proc
|
||||
/usr/bin/busybox mount --move /sys /sysroot/sys
|
||||
/usr/bin/busybox rm -fr /tmp
|
||||
done
|
||||
# move some special filesystems
|
||||
/usr/bin/busybox mount --move /dev /sysroot/dev
|
||||
/usr/bin/busybox mount --move /proc /sysroot/proc
|
||||
/usr/bin/busybox mount --move /sys /sysroot/sys
|
||||
/usr/bin/busybox rm -fr /tmp
|
||||
|
||||
# tell OE settings addon to disable updates
|
||||
if [ "$UPDATE_DISABLED" = "yes" ] ; then
|
||||
# tell OE settings addon to disable updates
|
||||
if [ "$UPDATE_DISABLED" = "yes" ]; then
|
||||
echo "" > /sysroot/dev/.update_disabled
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FLASH_NETBOOT" = "yes" ] ; then
|
||||
if [ "$FLASH_NETBOOT" = "yes" ]; then
|
||||
echo "" > /sysroot/dev/.flash_netboot
|
||||
fi
|
||||
fi
|
||||
|
||||
# swap can not be used over nfs.(see scripts/mount-swap)
|
||||
if [ "$STORAGE_NETBOOT" = "yes" ] ; then
|
||||
# swap can not be used over nfs.(see scripts/mount-swap)
|
||||
if [ "$STORAGE_NETBOOT" = "yes" ]; then
|
||||
echo "" > /sysroot/dev/.storage_netboot
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f /sysroot/storage/.please_resize_me ] ; then
|
||||
if [ -f /sysroot/storage/.please_resize_me ]; then
|
||||
INIT_UNIT="--unit=fs-resize.target"
|
||||
fi
|
||||
fi
|
||||
|
||||
BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1)
|
||||
if [ -f "$BACKUP_FILE" ] ; then
|
||||
BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1)
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
INIT_UNIT="--unit=backup-restore.target"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ] ; then
|
||||
if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then
|
||||
INIT_UNIT="--unit=factory-reset.target"
|
||||
fi
|
||||
fi
|
||||
|
||||
# switch to new sysroot and start real init
|
||||
exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT
|
||||
# switch to new sysroot and start real init
|
||||
exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT
|
||||
|
||||
error "switch_root" "Error in initramfs. Could not switch to new root"
|
||||
error "switch_root" "Error in initramfs. Could not switch to new root"
|
||||
|
Loading…
x
Reference in New Issue
Block a user