2009-03-18 13:02:53 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2011-01-09 18:44:37 +01:00
|
|
|
################################################################################
|
|
|
|
|
# This file is part of OpenELEC - http://www.openelec.tv
|
2013-12-21 21:51:48 +01:00
|
|
|
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
|
2014-04-25 11:15:19 +02:00
|
|
|
# Copyright (C) 2010-2011 Roman Weber (roman@openelec.tv)
|
2012-03-03 13:43:37 +01:00
|
|
|
# Copyright (C) 2012 Yann Cézard (eesprit@free.fr)
|
2011-01-09 18:44:37 +01:00
|
|
|
#
|
2013-12-21 21:51:48 +01:00
|
|
|
# OpenELEC is free software: you can redistribute it and/or modify
|
2011-01-09 18:44:37 +01:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-12-21 21:51:48 +01:00
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
2011-01-09 18:44:37 +01:00
|
|
|
#
|
2013-12-21 21:51:48 +01:00
|
|
|
# OpenELEC is distributed in the hope that it will be useful,
|
2011-01-09 18:44:37 +01:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-12-21 21:51:48 +01:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-01-09 18:44:37 +01:00
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2013-12-21 21:51:48 +01:00
|
|
|
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-09 18:44:37 +01:00
|
|
|
################################################################################
|
|
|
|
|
|
2013-12-18 17:25:18 +01:00
|
|
|
# create directories
|
2016-12-04 13:23:45 -08:00
|
|
|
/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
|
2013-12-18 17:25:18 +01:00
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# mount all needed special filesystems
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/bin/busybox mount -t devtmpfs devtmpfs /dev
|
|
|
|
|
/usr/bin/busybox mount -t proc proc /proc
|
|
|
|
|
/usr/bin/busybox mount -t sysfs sysfs /sys
|
2009-03-18 13:02:53 +01:00
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
# common functions
|
|
|
|
|
. /functions
|
|
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# set needed variables
|
2016-12-04 13:23:45 -08:00
|
|
|
MODULE_DIR=/usr/lib/modules
|
2013-01-11 14:05:20 +01:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
UPDATE_ROOT=/storage/.update
|
|
|
|
|
UPDATE_DIR="$UPDATE_ROOT"
|
|
|
|
|
|
2013-01-11 14:05:20 +01:00
|
|
|
UPDATE_KERNEL="KERNEL"
|
|
|
|
|
UPDATE_SYSTEM="SYSTEM"
|
|
|
|
|
IMAGE_KERNEL="KERNEL"
|
|
|
|
|
IMAGE_SYSTEM="SYSTEM"
|
|
|
|
|
|
2013-03-17 17:20:25 +01:00
|
|
|
BOOT_STEP="start"
|
2013-01-11 14:05:20 +01:00
|
|
|
MD5_FAILED="0"
|
2014-06-07 00:35:20 +02:00
|
|
|
RUN_FSCK="yes"
|
|
|
|
|
RUN_FSCK_DISKS=""
|
2016-08-31 18:43:14 +01:00
|
|
|
SYSLINUX_DEFAULT=""
|
2017-10-10 11:31:49 +08:00
|
|
|
GRUB_DEFAULT=""
|
2013-01-11 14:05:20 +01:00
|
|
|
|
|
|
|
|
NBD_DEVS="0"
|
2013-03-05 12:49:50 +01:00
|
|
|
FLASH_FREE_MIN="5"
|
2013-01-11 14:05:20 +01:00
|
|
|
|
2014-07-25 07:28:13 +02:00
|
|
|
INSTALLED_MEMORY=`cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}'`
|
|
|
|
|
SYSTEM_TORAM_LIMIT=1024000
|
|
|
|
|
|
2015-04-05 18:41:40 +03:00
|
|
|
LIVE="no"
|
|
|
|
|
|
2017-07-10 05:14:41 +01:00
|
|
|
BREAK_TRIPPED="no"
|
|
|
|
|
|
2016-08-26 17:14:35 +01:00
|
|
|
# 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 :)"
|
|
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# hide kernel log messages on console
|
2010-12-11 15:02:03 +01:00
|
|
|
echo '1 4 1 7' > /proc/sys/kernel/printk
|
|
|
|
|
|
2015-06-17 10:46:11 +03:00
|
|
|
# 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
|
|
|
|
|
|
2014-12-17 05:05:20 +01:00
|
|
|
# run platform_init script if exists
|
|
|
|
|
if [ -f "./platform_init" ]; then
|
|
|
|
|
./platform_init
|
|
|
|
|
fi
|
|
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# clear screen and hide cursor
|
2013-05-25 19:03:12 +03:00
|
|
|
clear
|
2016-03-21 07:32:14 +00:00
|
|
|
hidecursor
|
2012-02-23 21:36:21 +01:00
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# parse command line arguments
|
2009-09-22 07:07:58 +02:00
|
|
|
for arg in $(cat /proc/cmdline); do
|
|
|
|
|
case $arg in
|
2012-05-04 07:17:07 +02:00
|
|
|
BOOT_IMAGE=*)
|
|
|
|
|
IMAGE_KERNEL="${arg#*=}"
|
|
|
|
|
;;
|
|
|
|
|
SYSTEM_IMAGE=*)
|
|
|
|
|
IMAGE_SYSTEM="${arg#*=}"
|
|
|
|
|
;;
|
2012-04-12 15:01:57 +02:00
|
|
|
boot=*)
|
|
|
|
|
boot="${arg#*=}"
|
2013-09-23 22:46:08 +03:00
|
|
|
case $boot in
|
2014-08-17 15:54:20 +02:00
|
|
|
ISCSI=*|NBD=*|NFS=*)
|
2013-09-23 22:46:08 +03:00
|
|
|
UPDATE_DISABLED=yes
|
2014-04-30 09:16:56 +02:00
|
|
|
FLASH_NETBOOT=yes
|
2013-09-23 22:46:08 +03:00
|
|
|
;;
|
2014-06-07 00:35:20 +02:00
|
|
|
/dev/*|LABEL=*|UUID=*)
|
|
|
|
|
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $boot"
|
|
|
|
|
;;
|
2013-09-23 22:46:08 +03:00
|
|
|
esac
|
2012-04-12 15:01:57 +02:00
|
|
|
;;
|
|
|
|
|
disk=*)
|
|
|
|
|
disk="${arg#*=}"
|
2013-10-18 19:43:12 +03:00
|
|
|
case $disk in
|
2014-08-17 15:54:20 +02:00
|
|
|
ISCSI=*|NBD=*|NFS=*)
|
2013-10-18 19:43:12 +03:00
|
|
|
STORAGE_NETBOOT=yes
|
|
|
|
|
;;
|
2014-06-07 00:35:20 +02:00
|
|
|
/dev/*|LABEL=*|UUID=*)
|
|
|
|
|
RUN_FSCK_DISKS="$RUN_FSCK_DISKS $disk"
|
|
|
|
|
;;
|
2013-10-18 19:43:12 +03:00
|
|
|
esac
|
2012-04-12 15:01:57 +02:00
|
|
|
;;
|
2014-04-25 11:15:19 +02:00
|
|
|
wol_mac=*)
|
|
|
|
|
wol_mac="${arg#*=}"
|
|
|
|
|
;;
|
|
|
|
|
wol_wait=*)
|
|
|
|
|
wol_wait="${arg#*=}"
|
|
|
|
|
;;
|
2013-08-18 19:41:24 +02:00
|
|
|
textmode)
|
2015-01-19 11:53:58 +02:00
|
|
|
INIT_UNIT="--unit=textmode.target"
|
2013-08-18 19:41:24 +02:00
|
|
|
;;
|
2013-08-04 14:33:02 +02:00
|
|
|
installer)
|
2015-01-19 11:53:58 +02:00
|
|
|
INIT_UNIT="--unit=installer.target"
|
2016-08-31 18:43:14 +01:00
|
|
|
SYSLINUX_DEFAULT="installer"
|
2013-08-04 14:33:02 +02:00
|
|
|
;;
|
2009-09-22 07:07:58 +02:00
|
|
|
debugging)
|
|
|
|
|
DEBUG=yes
|
|
|
|
|
;;
|
2011-12-22 20:38:15 +01:00
|
|
|
progress)
|
|
|
|
|
PROGRESS=yes
|
2013-08-04 14:33:02 +02:00
|
|
|
INIT_ARGS="$INIT_ARGS --show-status=1"
|
2011-12-22 20:38:15 +01:00
|
|
|
;;
|
2014-06-07 00:35:20 +02:00
|
|
|
nofsck)
|
|
|
|
|
RUN_FSCK=no
|
|
|
|
|
;;
|
2012-05-03 13:03:33 +02:00
|
|
|
nosplash)
|
|
|
|
|
SPLASH=no
|
|
|
|
|
;;
|
2014-07-25 07:28:13 +02:00
|
|
|
noram)
|
|
|
|
|
SYSTEM_TORAM=no
|
|
|
|
|
;;
|
2015-04-05 18:41:40 +03:00
|
|
|
live)
|
|
|
|
|
LIVE=yes
|
2016-08-31 18:43:14 +01:00
|
|
|
SYSLINUX_DEFAULT="live"
|
|
|
|
|
;;
|
|
|
|
|
portable)
|
|
|
|
|
SYSLINUX_DEFAULT="run"
|
2015-04-05 18:41:40 +03:00
|
|
|
;;
|
2017-10-10 11:31:49 +08:00
|
|
|
grub_live)
|
|
|
|
|
LIVE=yes
|
2017-10-12 08:40:08 +08:00
|
|
|
GRUB_DEFAULT="Live"
|
2017-10-10 11:31:49 +08:00
|
|
|
;;
|
|
|
|
|
grub_portable)
|
2017-10-12 08:40:08 +08:00
|
|
|
GRUB_DEFAULT="Run"
|
2017-10-10 11:31:49 +08:00
|
|
|
;;
|
2012-03-19 18:55:38 +01:00
|
|
|
overlay)
|
|
|
|
|
OVERLAY=yes
|
|
|
|
|
;;
|
2016-05-21 22:39:37 +01:00
|
|
|
setfbres=*)
|
|
|
|
|
SWITCH_FRAMEBUFFER="${arg#*=}"
|
|
|
|
|
SWITCH_FRAMEBUFFER="${SWITCH_FRAMEBUFFER//,/ }"
|
|
|
|
|
;;
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
break=*)
|
|
|
|
|
BREAK="${arg#*=}"
|
2011-04-05 01:21:26 +02:00
|
|
|
;;
|
2009-09-22 07:07:58 +02:00
|
|
|
esac
|
|
|
|
|
done
|
2009-03-18 13:02:53 +01:00
|
|
|
|
2012-03-20 17:55:48 +01:00
|
|
|
if test "$DEBUG" = "yes"; then
|
|
|
|
|
exec 3>&1
|
|
|
|
|
else
|
|
|
|
|
exec 3>/dev/null
|
|
|
|
|
fi
|
|
|
|
|
SILENT_OUT=3
|
|
|
|
|
|
2009-09-22 07:07:58 +02:00
|
|
|
progress() {
|
2011-12-22 20:38:15 +01:00
|
|
|
if test "$PROGRESS" = "yes"; then
|
2016-07-12 01:05:58 +01:00
|
|
|
echo "### $1 ###" >&2
|
2009-03-18 13:02:53 +01:00
|
|
|
fi
|
2009-09-22 07:07:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-03 09:20:04 +01:00
|
|
|
debug_msg() {
|
|
|
|
|
echo "$1" >&$SILENT_OUT
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-22 07:07:58 +02:00
|
|
|
debug_shell() {
|
2017-07-10 05:14:41 +01:00
|
|
|
echo "### Starting debugging shell for boot step: $BOOT_STEP... type exit to quit ###"
|
2012-02-23 21:36:21 +01:00
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
showcursor
|
2012-02-23 21:36:21 +01:00
|
|
|
|
2017-07-07 13:35:03 -07:00
|
|
|
setsid cttyhack sh
|
2009-09-22 07:07:58 +02:00
|
|
|
}
|
|
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
error() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Display fatal error message
|
|
|
|
|
# $1:action which caused error, $2:message
|
2017-08-09 16:08:31 +01:00
|
|
|
# Send debug_shell output to stderr, in case caller is redirecting/consuming stdout
|
|
|
|
|
# Return exitcode=1 so that called may detect when an error has occurred
|
2016-07-12 01:05:58 +01:00
|
|
|
echo "*** Error in $BOOT_STEP: $1: $2 ***" >&2
|
2017-08-09 16:08:31 +01:00
|
|
|
debug_shell >&2
|
|
|
|
|
return 1
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break_after() {
|
2017-07-10 05:14:41 +01:00
|
|
|
# Start debug shell after boot step $1, and all subsequent steps
|
|
|
|
|
if [ $BREAK_TRIPPED == yes ]; then
|
|
|
|
|
debug_shell
|
|
|
|
|
else
|
|
|
|
|
case $BREAK in
|
|
|
|
|
all|*$1*)
|
|
|
|
|
BREAK_TRIPPED=yes
|
|
|
|
|
debug_shell
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Mount handlers
|
|
|
|
|
# All handlers take the following parameters:
|
|
|
|
|
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
|
|
|
|
|
mount_common() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Common mount handler, handles block devices and filesystem images
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
MOUNT_OPTIONS="-o $3"
|
|
|
|
|
[ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS"
|
|
|
|
|
|
2012-05-02 07:35:30 +02:00
|
|
|
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
ERR_ENV=1
|
|
|
|
|
|
2013-05-25 19:03:12 +03:00
|
|
|
mount $MOUNT_OPTIONS $1 $2 >&$SILENT_OUT 2>&1
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
[ "$?" -eq "0" ] && ERR_ENV=0 && break
|
|
|
|
|
|
2013-05-25 19:03:12 +03:00
|
|
|
usleep 1000000
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
done
|
2017-08-09 16:08:31 +01:00
|
|
|
[ "$ERR_ENV" -eq "0" ] && return 0
|
|
|
|
|
error "mount_common" "Could not mount $1"
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-26 02:27:35 +02:00
|
|
|
get_iscsistart_options() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Convert kernel commandline ISCSI= options to iscsistart options
|
2012-03-26 02:27:35 +02:00
|
|
|
IFS_SAVE="$IFS"
|
|
|
|
|
IFS=,
|
|
|
|
|
|
|
|
|
|
for arg in $1; do
|
|
|
|
|
val="${arg#*=}"
|
|
|
|
|
case "$arg" in
|
|
|
|
|
iscsi_initiator=*)
|
|
|
|
|
option="-i"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_target_name=*)
|
|
|
|
|
option="-t"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_target_ip=*)
|
|
|
|
|
option="-a"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_target_port=*)
|
|
|
|
|
option="-p"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_target_group=*)
|
|
|
|
|
option="-g"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_username=*)
|
|
|
|
|
option="-u"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_password=*)
|
|
|
|
|
option="-w"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_in_username=*)
|
|
|
|
|
option="-U"
|
|
|
|
|
;;
|
|
|
|
|
iscsi_in_password=*)
|
|
|
|
|
option="-W"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
echo "$option $val"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
IFS="$IFS_SAVE"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mount_iscsi() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Mount iSCSI target
|
2012-03-26 02:27:35 +02:00
|
|
|
ISCSI_DEV="${1##*,}"
|
|
|
|
|
ISCSI_OPTIONS="${1%,*}"
|
|
|
|
|
|
2016-12-04 13:23:45 -08:00
|
|
|
if [ ! -f "/usr/sbin/iscsistart" ]; then
|
2012-03-26 02:27:35 +02:00
|
|
|
error "iscsistart" "iSCSI support not available"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$ISCSI_OPTIONS" = "auto" ]; then
|
|
|
|
|
progress "Network configuration based on iBFT"
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || \
|
2012-03-26 02:27:35 +02:00
|
|
|
error "iscsistart" "Unable to configure network"
|
|
|
|
|
progress "iSCSI auto connect based on iBFT"
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || \
|
2012-03-26 02:27:35 +02:00
|
|
|
error "iscsistart" "Unable to auto connect"
|
|
|
|
|
else
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || \
|
2012-03-26 02:27:35 +02:00
|
|
|
error "iscsistart" "Unable to connect to ISCSI target"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mount_common "$ISCSI_DEV" "$2" "$3" "$4"
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 17:51:26 +01:00
|
|
|
mount_nbd() {
|
|
|
|
|
# Mount NBD device
|
|
|
|
|
NBD_SERVER="${1%%:*}"
|
|
|
|
|
NBD_PORT="${1#*:}"
|
|
|
|
|
NBD_DEV="/dev/nbd$NBD_DEVS"
|
|
|
|
|
|
2013-05-25 19:03:12 +03:00
|
|
|
nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \
|
2012-03-19 17:51:26 +01:00
|
|
|
error "nbd-client" "Could not connect to NBD server $1"
|
|
|
|
|
|
|
|
|
|
mount_common "$NBD_DEV" "$2" "$3" "$4"
|
|
|
|
|
|
|
|
|
|
NBD_DEVS=$(( ${NBD_DEVS} + 1 ))
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 17:54:48 +01:00
|
|
|
mount_nfs() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Mount NFS export
|
2012-03-25 14:28:11 +02:00
|
|
|
NFS_EXPORT="${1%%,*}"
|
|
|
|
|
NFS_OPTIONS="${1#*,}"
|
2012-03-19 17:54:48 +01:00
|
|
|
|
2012-03-25 14:28:11 +02:00
|
|
|
[ "$NFS_OPTIONS" = "$1" ] && NFS_OPTIONS=
|
|
|
|
|
|
2014-03-05 15:59:40 +02:00
|
|
|
mount_common "$NFS_EXPORT" "$2" "$3,nolock,soft,timeo=3,retrans=2,rsize=32768,wsize=32768,$NFS_OPTIONS" "nfs"
|
2012-03-19 17:54:48 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-27 01:47:47 +01:00
|
|
|
mount_ubifs() {
|
|
|
|
|
mount_common "$1" "$2" "$3" "ubifs"
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-22 07:07:58 +02:00
|
|
|
mount_part() {
|
2013-11-02 16:11:09 +02:00
|
|
|
# Mount a local or network filesystem
|
|
|
|
|
# $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type]
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
progress "mount filesystem $1 ..."
|
2012-03-20 21:46:58 +01:00
|
|
|
|
|
|
|
|
MOUNT_TARGET="${1#*=}"
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
case $1 in
|
2015-02-27 01:47:47 +01:00
|
|
|
/dev/ubi*)
|
|
|
|
|
MOUNT_CMD="mount_ubifs"
|
|
|
|
|
MOUNT_TARGET="$1"
|
|
|
|
|
RUN_FSCK="no"
|
|
|
|
|
;;
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
LABEL=*|UUID=*|/*)
|
|
|
|
|
MOUNT_CMD="mount_common"
|
|
|
|
|
MOUNT_TARGET="$1"
|
|
|
|
|
;;
|
2012-03-26 02:27:35 +02:00
|
|
|
ISCSI=*)
|
|
|
|
|
MOUNT_CMD="mount_iscsi"
|
|
|
|
|
;;
|
2012-03-19 17:51:26 +01:00
|
|
|
NBD=*)
|
|
|
|
|
MOUNT_CMD="mount_nbd"
|
|
|
|
|
;;
|
2012-03-19 17:54:48 +01:00
|
|
|
NFS=*)
|
|
|
|
|
MOUNT_CMD="mount_nfs"
|
|
|
|
|
;;
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
*)
|
|
|
|
|
error "mount_part" "Unknown filesystem $1"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2016-08-26 17:14:35 +01:00
|
|
|
|
|
|
|
|
# Substitute unique identifier if available or remove placeholder
|
|
|
|
|
MOUNT_TARGET="${MOUNT_TARGET//@UID@/$MACHINE_UID}"
|
|
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
$MOUNT_CMD "$MOUNT_TARGET" "$2" "$3" "$4"
|
2009-09-22 07:07:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 01:05:58 +01:00
|
|
|
# mount the specified SYSTEM file and output arch from /etc/os-release
|
|
|
|
|
get_project_arch() {
|
2017-08-09 16:08:31 +01:00
|
|
|
mount_part "$1" "/sysroot" "ro,loop" || return
|
2016-07-12 01:05:58 +01:00
|
|
|
|
|
|
|
|
if [ -f /sysroot/etc/os-release ]; then
|
|
|
|
|
. /sysroot/etc/os-release
|
|
|
|
|
echo "${LIBREELEC_ARCH:-${OPENELEC_ARCH}}"
|
|
|
|
|
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() {
|
|
|
|
|
local result=1
|
|
|
|
|
|
|
|
|
|
if [ "${2}" = "${3}" ]; then
|
|
|
|
|
result=0
|
|
|
|
|
else
|
|
|
|
|
mount_part "$1" "/sysroot" "ro,loop"
|
|
|
|
|
|
|
|
|
|
if [ -f /sysroot/usr/share/bootloader/canupdate.sh ]; then
|
|
|
|
|
sh /sysroot/usr/share/bootloader/canupdate.sh "${2}" "${3}" && result=0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
umount /sysroot
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return ${result}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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}"
|
2017-08-09 16:08:31 +01:00
|
|
|
local old_project_arch new_project_arch
|
|
|
|
|
|
|
|
|
|
old_project_arch="$(get_project_arch "${old_system}")" || return
|
|
|
|
|
new_project_arch="$(get_project_arch "${new_system}")" || return
|
2016-07-12 01:05:58 +01:00
|
|
|
|
|
|
|
|
# If old or new project/arch isn't available then could be very old (pre-/etc/os-release) build - have to trust it
|
|
|
|
|
if [ -n "${old_project_arch}" -a -n "${new_project_arch}" ]; then
|
|
|
|
|
# If the old project/arch is not compatible with the new project/arch then abort...
|
|
|
|
|
if ! is_compatible "${new_system}" "${old_project_arch}" "${new_project_arch}"; then
|
|
|
|
|
echo ""
|
|
|
|
|
echo "ERROR: $(basename "${update_filename}") is not compatible with ${old_project_arch} hardware - update cancelled."
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Current system: ${old_project_arch}"
|
|
|
|
|
echo "Update system: ${new_project_arch}"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Create $UPDATE_ROOT/.nocompat to disable compatibility checks and risk a non-booting system."
|
|
|
|
|
echo ""
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 18:18:21 +02:00
|
|
|
update_file() {
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then
|
2013-11-02 16:11:09 +02:00
|
|
|
mount -o remount,rw /flash
|
2016-03-21 07:32:14 +00:00
|
|
|
|
|
|
|
|
StartProgress percent "Updating $1... " "$3" $(stat -t "$UPDATE_DIR/$2" | awk '{print $2}')
|
|
|
|
|
# use dd here with conv=fsync so that all writes are non-buffered
|
|
|
|
|
# ensuring accurate progress - take the sync hit during the
|
|
|
|
|
# transfer, rather than when flushing file buffers after the progress
|
|
|
|
|
# meter declares the transfer already complete
|
|
|
|
|
dd if=$UPDATE_DIR/$2 of=$3 bs=1M conv=fsync 2>/dev/null
|
|
|
|
|
StopProgress
|
|
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# loopback file needs writable /flash all the time
|
|
|
|
|
if [ "${disk%%=*}" != "FILE" ]; then
|
|
|
|
|
mount -o remount,ro /flash
|
|
|
|
|
fi
|
|
|
|
|
sync
|
2009-09-22 07:07:58 +02:00
|
|
|
fi
|
|
|
|
|
}
|
2009-09-28 14:10:32 +02:00
|
|
|
|
2015-05-28 18:18:21 +02:00
|
|
|
update_partition() {
|
2016-03-21 07:32:14 +00:00
|
|
|
local result
|
|
|
|
|
|
2015-05-28 18:18:21 +02:00
|
|
|
if [ -f "$UPDATE_DIR/$2" -a -b "$3" ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Updating $1... "
|
2017-07-09 21:44:49 +02:00
|
|
|
result="$(dd if="$UPDATE_DIR/$2" of="$3" 2>&1)"
|
2016-03-21 07:32:14 +00:00
|
|
|
StopProgress "done"
|
|
|
|
|
echo "${result}"
|
|
|
|
|
fi
|
2015-05-28 18:18:21 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-07 01:52:39 +02:00
|
|
|
update_bootloader() {
|
2016-03-21 07:32:14 +00:00
|
|
|
local result
|
|
|
|
|
|
2013-05-25 19:01:31 +03:00
|
|
|
export BOOT_ROOT="/flash"
|
|
|
|
|
export SYSTEM_ROOT="/sysroot"
|
2012-08-07 01:52:39 +02:00
|
|
|
|
2013-05-25 19:01:31 +03:00
|
|
|
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
|
2012-08-07 01:52:39 +02:00
|
|
|
|
2013-05-25 19:01:31 +03:00
|
|
|
if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Updating Bootloader... "
|
|
|
|
|
result="$(sh $SYSTEM_ROOT/usr/share/bootloader/update.sh 2>&1)"
|
|
|
|
|
sync
|
|
|
|
|
StopProgress "done"
|
|
|
|
|
[ -n "${result}" ] && echo "${result}"
|
2012-08-07 01:52:39 +02:00
|
|
|
fi
|
2013-05-25 19:01:31 +03:00
|
|
|
|
|
|
|
|
umount /sysroot
|
2012-08-07 01:52:39 +02:00
|
|
|
}
|
|
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
load_modules() {
|
|
|
|
|
progress "Loading kernel modules"
|
2012-03-20 21:46:58 +01:00
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
[ ! -f "/etc/modules" ] && return
|
|
|
|
|
for module in $(cat /etc/modules); do
|
|
|
|
|
progress "Loading kernel module $module"
|
2013-05-25 19:03:12 +03:00
|
|
|
insmod "$MODULE_DIR/$module.ko" || \
|
2012-05-15 00:12:38 +02:00
|
|
|
progress "... Failed to load kernel module $module, skipping"
|
2011-04-05 01:21:26 +02:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 13:03:33 +02:00
|
|
|
load_splash() {
|
2016-05-21 22:39:37 +01:00
|
|
|
local set_default_res=no
|
|
|
|
|
local vres
|
|
|
|
|
|
2013-09-30 03:23:11 +02:00
|
|
|
if [ ! "$SPLASH" = "no" ]; then
|
2014-02-22 14:47:17 +02:00
|
|
|
progress "Loading bootsplash"
|
|
|
|
|
|
2013-09-30 03:23:11 +02:00
|
|
|
# load uvesafb module if needed
|
|
|
|
|
if [ -f "$MODULE_DIR/uvesafb.ko" -a ! -e /dev/fb0 ]; then
|
|
|
|
|
progress "Loading kernel module uvesafb.ko"
|
2016-05-21 22:39:37 +01:00
|
|
|
insmod "$MODULE_DIR/uvesafb.ko" && \
|
|
|
|
|
set_default_res=yes || \
|
2013-11-02 16:11:09 +02:00
|
|
|
progress "... Failed to load kernel module uvesafb, skipping"
|
2013-09-30 03:23:11 +02:00
|
|
|
fi
|
2012-05-03 13:03:33 +02:00
|
|
|
|
2013-09-30 03:23:11 +02:00
|
|
|
if [ -e /dev/fb0 ]; then
|
2016-05-21 22:39:37 +01:00
|
|
|
# Set framebuffer to a custom resolution and/or fallback to default resolution (1024x768-32), if required.
|
|
|
|
|
if [ ! "$SWITCH_FRAMEBUFFER" = "no" ]; then
|
|
|
|
|
if [ "$SWITCH_FRAMEBUFFER" = "1080" ]; then
|
|
|
|
|
SWITCH_FRAMEBUFFER="1920 1080 1920 1080 32"
|
|
|
|
|
elif [ "$SWITCH_FRAMEBUFFER" = "720" ]; then
|
|
|
|
|
SWITCH_FRAMEBUFFER="1280 720 1280 720 32"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Try setting a custom framebuffer resolution
|
|
|
|
|
if [ ! "${SWITCH_FRAMEBUFFER:-yes}" = "yes" ]; then
|
|
|
|
|
fbset -g $SWITCH_FRAMEBUFFER 2>/dev/null && set_default_res=no
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Set a default resolution if required
|
|
|
|
|
if [ "$set_default_res" = "yes" ]; then
|
|
|
|
|
fbset -g 1024 768 1024 768 32
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2016-06-01 20:01:54 +01:00
|
|
|
# load splash
|
2016-06-03 09:20:04 +01:00
|
|
|
if [ -f /splash/splash.conf ]; then
|
2016-06-01 20:01:54 +01:00
|
|
|
. /splash/splash.conf
|
|
|
|
|
fi
|
|
|
|
|
|
2016-05-21 22:39:37 +01:00
|
|
|
# Select splash image based on current native resolution
|
|
|
|
|
if [ -z "$SPLASHIMAGE" ]; then
|
2016-06-03 09:20:04 +01:00
|
|
|
vres="$(fbset 2>/dev/null | awk '/geometry/ { print $3 }')"
|
|
|
|
|
|
|
|
|
|
if [ -f /flash/oemsplash.png -o -f /flash/oemsplash-1080.png ]; then
|
|
|
|
|
if [ -n "$vres" -a -f /flash/oemsplash-$vres.png ]; then
|
|
|
|
|
SPLASHIMAGE="/flash/oemsplash-$vres.png"
|
|
|
|
|
elif [ -f /flash/oemsplash-1080.png ]; then
|
|
|
|
|
SPLASHIMAGE="/flash/oemsplash-1080.png"
|
|
|
|
|
else
|
|
|
|
|
SPLASHIMAGE="/flash/oemsplash.png"
|
|
|
|
|
fi
|
2016-05-21 22:39:37 +01:00
|
|
|
else
|
2016-06-03 09:20:04 +01:00
|
|
|
if [ -n "$vres" -a -f /splash/splash-$vres.png ]; then
|
|
|
|
|
SPLASHIMAGE="/splash/splash-$vres.png"
|
|
|
|
|
else
|
|
|
|
|
SPLASHIMAGE="/splash/splash-1080.png"
|
|
|
|
|
fi
|
2016-05-21 22:39:37 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2016-06-03 09:20:04 +01:00
|
|
|
if [ -n "$SPLASHIMAGE" -a -f "$SPLASHIMAGE" ]; then
|
|
|
|
|
ply-image $SPLASHIMAGE > /dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
debug_msg "Framebuffer vertical res: $vres"
|
|
|
|
|
debug_msg "Framebuffer splash image: $SPLASHIMAGE"
|
2013-09-30 03:23:11 +02:00
|
|
|
fi
|
2012-05-03 13:03:33 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 17:10:42 +02:00
|
|
|
do_reboot() {
|
|
|
|
|
echo "System reboots now..."
|
|
|
|
|
|
|
|
|
|
# syncing filesystem
|
2016-03-21 07:32:14 +00:00
|
|
|
sync
|
2014-06-07 17:10:42 +02:00
|
|
|
|
|
|
|
|
# unmount filesystems
|
2016-12-04 13:23:45 -08:00
|
|
|
if /usr/bin/busybox mountpoint -q /flash ; then
|
|
|
|
|
/usr/bin/busybox umount /flash
|
2016-03-21 07:32:14 +00:00
|
|
|
fi
|
2014-06-07 17:10:42 +02:00
|
|
|
|
2016-12-04 13:23:45 -08:00
|
|
|
if /usr/bin/busybox mountpoint -q /storage ; then
|
|
|
|
|
/usr/bin/busybox umount /storage
|
2016-03-21 07:32:14 +00:00
|
|
|
fi
|
2014-06-07 17:10:42 +02:00
|
|
|
|
|
|
|
|
usleep 2000000
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/bin/busybox reboot
|
2014-06-07 17:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-08 13:48:46 +02:00
|
|
|
force_fsck() {
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Filesystem corruption has been detected!"
|
|
|
|
|
echo "To prevent an automatic repair attempt continuing,"
|
2015-02-08 13:48:46 +02:00
|
|
|
echo "press any key or power off your system within the next 120 seconds"
|
|
|
|
|
echo ""
|
|
|
|
|
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
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Repairing filesystem..."
|
2015-02-08 13:48:46 +02:00
|
|
|
echo ""
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/sbin/fsck -T -M -y $RUN_FSCK_DISKS
|
2015-02-08 13:48:46 +02:00
|
|
|
FSCK_RET="$?"
|
|
|
|
|
if [ "$(( $FSCK_RET & 8 ))" = 8 ] ; then
|
|
|
|
|
# fubar
|
|
|
|
|
echo "Forced fsck failed. Your system is broken beyond repair"
|
2016-04-13 17:20:22 +02:00
|
|
|
echo "Please re-install @DISTRONAME@"
|
2015-02-08 13:48:46 +02:00
|
|
|
echo ""
|
|
|
|
|
echo "Press enter to shutdown now"
|
|
|
|
|
echo ""
|
|
|
|
|
read fubar
|
|
|
|
|
poweroff
|
|
|
|
|
fi
|
|
|
|
|
do_reboot
|
|
|
|
|
else
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Shutting down..."
|
2015-02-08 13:48:46 +02:00
|
|
|
sleep 5
|
|
|
|
|
sync
|
|
|
|
|
poweroff
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-07 02:27:42 +02:00
|
|
|
check_disks() {
|
2014-06-07 00:35:20 +02:00
|
|
|
if [ "$RUN_FSCK" = "yes" -a -n "$RUN_FSCK_DISKS" ]; then
|
|
|
|
|
progress "Checking disk(s): $RUN_FSCK_DISKS"
|
2016-12-04 13:23:45 -08:00
|
|
|
/usr/sbin/fsck -T -M -p -a $RUN_FSCK_DISKS > /dev/null 2>&1
|
2016-03-21 07:32:14 +00:00
|
|
|
FSCK_RET="$?"
|
2013-10-07 02:27:42 +02:00
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
# FSCK_RET is the bit-wise OR of the exit codes for each filesystem that is checked.
|
|
|
|
|
if [ "$(( $FSCK_RET & 4 ))" = 4 ] ; then
|
|
|
|
|
# errors left
|
|
|
|
|
force_fsck
|
|
|
|
|
elif [ "$(( $FSCK_RET & 2 ))" = 2 ] ; then
|
|
|
|
|
# reboot needed
|
|
|
|
|
echo "Filesystem repaired, reboot needed..."
|
|
|
|
|
do_reboot
|
|
|
|
|
elif [ "$(( $FSCK_RET & 1 ))" = 1 ] ; then
|
|
|
|
|
# filesystem errors corrected
|
|
|
|
|
progress "Filesystem errors corrected , continuing..."
|
|
|
|
|
elif [ "$(( $FSCK_RET & 0 ))" = 0 ] ; then
|
|
|
|
|
# no errors found
|
|
|
|
|
progress "No filesystem errors found, continuing..."
|
|
|
|
|
fi
|
2013-10-07 02:27:42 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 09:16:56 +02:00
|
|
|
wakeonlan() {
|
|
|
|
|
if [ "$STORAGE_NETBOOT" = "yes" ]; then
|
|
|
|
|
wol_ip=${disk%:*}
|
|
|
|
|
wol_ip=${wol_ip#*=}
|
|
|
|
|
elif [ "$FLASH_NETBOOT" = "yes" ]; then
|
|
|
|
|
wol_ip=${boot%:*}
|
|
|
|
|
wol_ip=${wol_ip#*=}
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2014-06-07 00:38:33 +02:00
|
|
|
|
2014-04-30 09:16:56 +02:00
|
|
|
if [ -n "$wol_ip" -a -n "$wol_mac" -a -n "$wol_wait" ]; then
|
|
|
|
|
progress "Sending Magic Packet (WOL) if needed"
|
|
|
|
|
|
|
|
|
|
if ! ping -q -c 2 "$wol_ip" &>/dev/null; then
|
|
|
|
|
ether-wake "$wol_mac"
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "WOL magic packet sent to $wol_ip, waiting $wol_wait seconds... " $wol_wait "done"
|
2014-04-30 09:16:56 +02:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 18:28:28 +02:00
|
|
|
mount_flash() {
|
|
|
|
|
progress "Mounting flash"
|
2012-03-20 21:46:58 +01:00
|
|
|
|
2014-04-30 09:16:56 +02:00
|
|
|
wakeonlan
|
|
|
|
|
|
2012-06-19 07:48:40 +02:00
|
|
|
mount_part "$boot" "/flash" "ro,noatime"
|
2012-08-06 18:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-07 00:38:33 +02:00
|
|
|
mount_storage() {
|
2012-08-06 18:28:28 +02:00
|
|
|
progress "Mounting storage"
|
2012-03-19 18:55:38 +01:00
|
|
|
|
2015-04-05 18:41:40 +03:00
|
|
|
if [ "$LIVE" = "yes" ]; then
|
|
|
|
|
# mount tmpfs and exit early. disk=xx is not allowed in live mode
|
|
|
|
|
mount -t tmpfs none /storage
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2014-04-30 09:16:56 +02:00
|
|
|
wakeonlan
|
|
|
|
|
|
2012-03-20 21:46:58 +01:00
|
|
|
if [ -n "$disk" ]; then
|
|
|
|
|
if [ -n "$OVERLAY" ]; then
|
2013-05-25 19:03:12 +03:00
|
|
|
OVERLAY_DIR=`cat /sys/class/net/eth0/address | tr -d :`
|
2012-03-20 19:57:09 +01:00
|
|
|
|
2012-06-19 07:48:40 +02:00
|
|
|
mount_part "$disk" "/storage" "rw,noatime"
|
2012-03-20 21:46:58 +01:00
|
|
|
mkdir -p /storage/$OVERLAY_DIR
|
2013-05-25 19:03:12 +03:00
|
|
|
umount /storage
|
2012-03-20 21:46:58 +01:00
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# split $disk into $target,$options so we can append $OVERLAY_DIR
|
2012-03-20 21:46:58 +01:00
|
|
|
options="${disk#*,}"
|
|
|
|
|
target="${disk%%,*}"
|
|
|
|
|
if [ "$options" = "$disk" ]; then
|
|
|
|
|
disk="$target/$OVERLAY_DIR"
|
|
|
|
|
else
|
|
|
|
|
disk="$target/$OVERLAY_DIR,$options"
|
|
|
|
|
fi
|
2012-03-20 19:57:09 +01:00
|
|
|
fi
|
2012-06-19 07:48:40 +02:00
|
|
|
mount_part "$disk" "/storage" "rw,noatime"
|
2015-04-05 20:30:52 +03:00
|
|
|
else
|
|
|
|
|
# /storage should always be writable
|
|
|
|
|
mount -t tmpfs none /storage
|
2012-03-20 21:46:58 +01:00
|
|
|
fi
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
}
|
2011-05-09 12:00:24 +02:00
|
|
|
|
2016-08-31 18:43:14 +01:00
|
|
|
# Make last bootloader label (installer, live, run etc.) as the new default
|
2017-10-12 08:40:08 +08:00
|
|
|
update_bootmenu() {
|
2016-08-31 18:43:14 +01:00
|
|
|
local crnt_default
|
|
|
|
|
|
|
|
|
|
if [ -n "$SYSLINUX_DEFAULT" -a -f /flash/syslinux.cfg ]; then
|
|
|
|
|
if grep -q "^LABEL $SYSLINUX_DEFAULT\$" /flash/syslinux.cfg; then
|
|
|
|
|
crnt_default="$(awk '/^DEFAULT/ {print $2}' /flash/syslinux.cfg)"
|
|
|
|
|
if [ ! "$crnt_default" = "$SYSLINUX_DEFAULT" ]; then
|
|
|
|
|
progress "Updating /flash/syslinux.cfg [$crnt_default -> $SYSLINUX_DEFAULT]"
|
|
|
|
|
|
|
|
|
|
mount -o remount,rw /flash
|
|
|
|
|
sed -i "s/^DEFAULT .*/DEFAULT $SYSLINUX_DEFAULT/" /flash/syslinux.cfg
|
2016-09-28 18:21:10 +01:00
|
|
|
[ -f /flash/EFI/BOOT/syslinux.cfg ] && cp /flash/syslinux.cfg /flash/EFI/BOOT/syslinux.cfg
|
2016-08-31 18:43:14 +01:00
|
|
|
mount -o remount,ro /flash
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2017-10-10 11:31:49 +08:00
|
|
|
|
2017-10-12 08:40:08 +08:00
|
|
|
if [ -n "\"$GRUB_DEFAULT\"" -a -f /flash/grub.cfg ]; then
|
|
|
|
|
if grep -q "^menuentry \"$GRUB_DEFAULT\"" /flash/grub.cfg; then
|
2017-10-10 11:31:49 +08:00
|
|
|
crnt_default="$(awk '/^set default/ {print substr($2,9,19)}' /flash/grub.cfg)"
|
2017-10-12 08:40:08 +08:00
|
|
|
if [ ! "$crnt_default" = "\"$GRUB_DEFAULT\"" ]; then
|
|
|
|
|
progress "Updating /flash/grub.cfg [$crnt_default -> \"$GRUB_DEFAULT\"]"
|
2017-10-10 11:31:49 +08:00
|
|
|
|
|
|
|
|
mount -o remount,rw /flash
|
2017-10-12 08:40:08 +08:00
|
|
|
sed -i "s/^set default=.*/set default=\"$GRUB_DEFAULT\"/" /flash/grub.cfg
|
2017-10-10 11:31:49 +08:00
|
|
|
[ -f /flash/EFI/BOOT/grub.cfg ] && cp /flash/grub.cfg /flash/EFI/BOOT/grub.cfg
|
|
|
|
|
mount -o remount,ro /flash
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2016-08-31 18:43:14 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-05 17:55:10 +01:00
|
|
|
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"
|
|
|
|
|
echo "free space on /storage to complete the upgrade!"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Please free up space on your /storage partition"
|
|
|
|
|
echo "by deleting unecessary files, then try again."
|
|
|
|
|
echo ""
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
echo ""
|
|
|
|
|
echo "The $1 is corrupt/invalid!"
|
|
|
|
|
echo ""
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup() {
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Cleaning up... "
|
|
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ -d $UPDATE_ROOT/.tmp/mnt ]; then
|
|
|
|
|
if mountpoint -q $UPDATE_ROOT/.tmp/mnt ; then
|
|
|
|
|
# busybox umount deletes loop device automatically
|
|
|
|
|
umount $UPDATE_ROOT/.tmp/mnt
|
2016-03-20 21:36:53 +00:00
|
|
|
fi
|
2016-03-20 21:32:59 +00:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
[ -n $LOOP ] && losetup -d $LOOP &>/dev/null
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[ -f "$UPDATE_TAR" ] && rm -f "$UPDATE_TAR" &>/dev/null
|
|
|
|
|
[ -f "$UPDATE_IMG_GZ" ] && rm -f "$UPDATE_IMG_GZ" &>/dev/null
|
|
|
|
|
[ -f "$UPDATE_IMG" ] && rm -f "$UPDATE_IMG" &>/dev/null
|
|
|
|
|
|
|
|
|
|
rm -rf $UPDATE_ROOT/.tmp &>/dev/null
|
|
|
|
|
rm -rf $UPDATE_ROOT/[0-9a-zA-Z]* &>/dev/null
|
2016-07-12 01:05:58 +01:00
|
|
|
rm -f $UPDATE_ROOT/.nocheck $UPDATE_ROOT/.nocompat &>/dev/null
|
2016-03-21 07:32:14 +00:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
sync
|
2016-03-21 07:32:14 +00:00
|
|
|
|
|
|
|
|
StopProgress "done"
|
2016-03-18 10:11:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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`
|
|
|
|
|
UPDATE_IMG=`ls -1 "$UPDATE_DIR"/*.img 2>/dev/null | head -n 1`
|
|
|
|
|
|
|
|
|
|
if ! [ -f "$UPDATE_DIR/$UPDATE_KERNEL" -a -f "$UPDATE_DIR/$UPDATE_SYSTEM" ] &&
|
|
|
|
|
! [ -f "$UPDATE_TAR" -o -f "$UPDATE_IMG_GZ" -o -f "$UPDATE_IMG" ]; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$UPDATE_DISABLED" = "yes" ] ; then
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Updating is not supported on netboot"
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 10s... " 10 "NOW"
|
2016-03-18 10:11:21 +01:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-17 16:16:55 +01:00
|
|
|
if [ -d $UPDATE_DIR/.tmp ]; then
|
|
|
|
|
echo "Failed update detected - performing recovery."
|
|
|
|
|
echo ""
|
|
|
|
|
do_cleanup
|
|
|
|
|
StartProgress countdown "Normal startup in 10s... " 10 "NOW"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mkdir -p $UPDATE_DIR/.tmp &>/dev/null
|
|
|
|
|
sync
|
2016-03-18 10:11:21 +01:00
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "UPGRADE IN PROGRESS"
|
|
|
|
|
echo ""
|
2016-04-13 17:20:22 +02:00
|
|
|
echo "Please do not reboot or turn off your @DISTRONAME@ device!"
|
2016-03-21 07:32:14 +00:00
|
|
|
echo ""
|
|
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ -f "$UPDATE_TAR" ] ; then
|
2016-08-05 17:55:10 +01:00
|
|
|
TARRESULT="0"
|
|
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Found new .tar archive"
|
2016-07-12 01:05:58 +01:00
|
|
|
UPDATE_FILENAME="$UPDATE_TAR"
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Extracting contents of archive... "
|
2016-08-05 17:55:10 +01:00
|
|
|
tar -xf "$UPDATE_TAR" -C $UPDATE_DIR/.tmp 1>/dev/null 2>/tmp/tarresult.txt || TARRESULT="1"
|
|
|
|
|
|
|
|
|
|
if [ "${TARRESULT}" -eq "0" ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
mv $UPDATE_DIR/.tmp/*/target/* $UPDATE_DIR &>/dev/null
|
|
|
|
|
sync
|
|
|
|
|
StopProgress "done"
|
2016-08-05 17:55:10 +01:00
|
|
|
else
|
|
|
|
|
StopProgress "FAILED"
|
|
|
|
|
|
|
|
|
|
echo "Failed to extract contents of archive file!"
|
|
|
|
|
echo "tar result: '$(cat /tmp/tarresult.txt)'"
|
|
|
|
|
|
|
|
|
|
check_out_of_space "archive"
|
|
|
|
|
|
|
|
|
|
do_cleanup
|
|
|
|
|
StartProgress countdown "Normal startup in 30s... " 30 "NOW"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2016-03-18 10:11:21 +01:00
|
|
|
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"
|
2016-03-21 07:32:14 +00:00
|
|
|
GZRESULT="0"
|
2016-03-18 10:11:21 +01:00
|
|
|
|
|
|
|
|
if [ -f "$UPDATE_IMG_GZ" ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Found new compressed image file"
|
2016-07-12 01:05:58 +01:00
|
|
|
UPDATE_FILENAME="$UPDATE_IMG_GZ"
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Decompressing image file... "
|
|
|
|
|
gunzip -d -c "$UPDATE_IMG_GZ" 1>$IMG_FILE 2>/tmp/gzresult.txt || GZRESULT="1"
|
|
|
|
|
sync
|
|
|
|
|
[ "${GZRESULT}" -eq "0" ] && StopProgress "OK" || StopProgress "FAILED"
|
|
|
|
|
|
|
|
|
|
if [ "${GZRESULT}" -eq "1" ]; then
|
|
|
|
|
echo "Failed to decompress image file!"
|
|
|
|
|
echo "gunzip result: '$(cat /tmp/gzresult.txt)'"
|
2016-08-05 17:55:10 +01:00
|
|
|
|
|
|
|
|
check_out_of_space "compressed image"
|
|
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
do_cleanup
|
|
|
|
|
StartProgress countdown "Normal startup in 30s... " 30 "NOW"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2016-03-18 10:11:21 +01:00
|
|
|
else
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Found new image file"
|
2016-07-12 01:05:58 +01:00
|
|
|
UPDATE_FILENAME="$UPDATE_IMG"
|
2016-03-18 10:11:21 +01:00
|
|
|
mv "$UPDATE_IMG" $IMG_FILE
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
LOOP=$(losetup -f)
|
|
|
|
|
LOOP_NUM=$(echo $LOOP | sed 's|/dev/loop||')
|
2016-03-30 10:24:49 +02:00
|
|
|
mknod $LOOP b 7 $LOOP_NUM &>/dev/null
|
2016-03-18 10:11:21 +01:00
|
|
|
losetup $LOOP $IMG_FILE
|
|
|
|
|
|
|
|
|
|
# check for MBR partititon
|
2017-12-04 00:49:10 +00:00
|
|
|
OFFSET=$(fdisk -u -l $LOOP 2>/dev/null | awk '/^[ ]*Device/{part=1; next}; part{if ($2 == "*") {print $5} else {print $4} ; exit}')
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ -z "$OFFSET" ]; then
|
|
|
|
|
# check for GPT partititon
|
2016-03-21 07:32:14 +00:00
|
|
|
OFFSET=$(fdisk -u -l $LOOP 2>/dev/null | awk '/^Number/{part=1; next}; part{print $2; exit}')
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ -z "$OFFSET" ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Could not find a valid system partition in image file!"
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 10s... " 10 "NOW"
|
2013-11-02 16:02:19 +02:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
SECTOR_SIZE=$(cat /sys/devices/virtual/block/loop${LOOP_NUM}/queue/hw_sector_size)
|
|
|
|
|
losetup -d $LOOP
|
|
|
|
|
sync
|
2012-05-03 14:50:34 +03:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
OFFSET=$(($OFFSET * $SECTOR_SIZE))
|
2012-05-03 14:50:34 +03:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
# use losetup because busybox mount does not support the -o offset option
|
|
|
|
|
echo "Mounting system partition..."
|
|
|
|
|
losetup -o $OFFSET $LOOP $IMG_FILE
|
|
|
|
|
mount -o ro,loop $LOOP $UPDATE_DIR/.tmp/mnt
|
2012-05-03 14:50:34 +03:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
# don't make temporary files but instead copy
|
|
|
|
|
# directly from mountpoint to /flash
|
|
|
|
|
UPDATE_DIR=$UPDATE_ROOT/.tmp/mnt
|
2016-07-04 16:25:03 +02:00
|
|
|
if [ ! -b $IMAGE_KERNEL -o -z "@KERNEL_NAME@" ]; then
|
|
|
|
|
UPDATE_KERNEL=$(basename $IMAGE_KERNEL)
|
|
|
|
|
else
|
|
|
|
|
UPDATE_KERNEL="@KERNEL_NAME@"
|
|
|
|
|
fi
|
2016-07-12 01:05:58 +01:00
|
|
|
else
|
|
|
|
|
UPDATE_FILENAME="$UPDATE_DIR/$UPDATE_SYSTEM"
|
2016-03-18 10:11:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sync
|
2016-03-21 07:32:14 +00:00
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ ! -f "$UPDATE_DIR/$UPDATE_KERNEL" -o ! -f "$UPDATE_DIR/$UPDATE_SYSTEM" ] ; then
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Missing ${UPDATE_KERNEL} or ${UPDATE_SYSTEM}!"
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 10s... " 10 "NOW"
|
2016-03-18 10:11:21 +01:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# check md5 sums if .nocheck doesn't exist
|
2016-07-12 01:05:58 +01:00
|
|
|
if [ ! -f "$UPDATE_ROOT/.nocheck" ]; then
|
2016-03-18 10:11:21 +01:00
|
|
|
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
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Zero-sized .md5 file!"
|
2016-03-20 21:36:53 +00:00
|
|
|
MD5_FAILED="1"
|
|
|
|
|
else
|
2016-03-18 10:11:21 +01:00
|
|
|
sed "s#target/KERNEL#$UPDATE_DIR/$UPDATE_KERNEL#g" "$UPDATE_DIR/${UPDATE_KERNEL}.md5" >"$UPDATE_ROOT/${UPDATE_KERNEL}.check.md5"
|
|
|
|
|
sed "s#target#$UPDATE_DIR#g" "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" >"$UPDATE_ROOT/${UPDATE_SYSTEM}.check.md5"
|
|
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Checking ${UPDATE_KERNEL}.md5... "
|
|
|
|
|
if md5sum -sc "$UPDATE_ROOT/${UPDATE_KERNEL}.check.md5"; then
|
|
|
|
|
StopProgress "OK"
|
|
|
|
|
else
|
|
|
|
|
StopProgress "FAILED"
|
|
|
|
|
MD5_FAILED="1"
|
2016-08-05 17:55:10 +01:00
|
|
|
fi
|
2016-03-18 10:11:21 +01:00
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress spinner "Checking ${UPDATE_SYSTEM}.md5... "
|
|
|
|
|
if md5sum -sc "$UPDATE_ROOT/${UPDATE_SYSTEM}.check.md5"; then
|
|
|
|
|
StopProgress "OK"
|
|
|
|
|
else
|
|
|
|
|
StopProgress "FAILED"
|
|
|
|
|
MD5_FAILED="1"
|
|
|
|
|
fi
|
2013-03-05 12:49:50 +01:00
|
|
|
fi
|
2012-05-03 14:50:34 +03:00
|
|
|
else
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "Missing ${UPDATE_KERNEL}.md5 or ${UPDATE_SYSTEM}.md5!"
|
2016-03-18 10:11:21 +01:00
|
|
|
MD5_FAILED="1"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$MD5_FAILED" -eq "1" ]; then
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "md5 check failed!"
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 30s... " 30 "NOW"
|
2016-03-18 10:11:21 +01:00
|
|
|
return 0
|
2012-05-03 14:50:34 +03:00
|
|
|
fi
|
|
|
|
|
fi
|
2016-03-18 10:11:21 +01:00
|
|
|
|
2016-07-12 01:05:58 +01:00
|
|
|
# Verify that the new upgrade is compatible with the current system - this should avoid creating
|
|
|
|
|
# non-booting systems after (for example) an RPi tar is incorrectly applied to an RPi2 system.
|
|
|
|
|
if [ ! -f "$UPDATE_ROOT/.nocompat" ]; then
|
|
|
|
|
if ! check_is_compatible "$UPDATE_FILENAME" "/flash/$IMAGE_SYSTEM" "$UPDATE_DIR/$UPDATE_SYSTEM"; then
|
|
|
|
|
do_cleanup
|
|
|
|
|
StartProgress countdown "Normal startup in 60s... " 60 "NOW"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2016-03-18 10:11:21 +01:00
|
|
|
# get sizes
|
|
|
|
|
FLASH_FREE=$(df /flash/ | awk '/[0-9]%/{print $4}')
|
|
|
|
|
FLASH_FREE=$(( $FLASH_FREE * 1024 ))
|
|
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
# Disregard kernel size if it's a a block device, which is the case on Amlogic/WeTek devices
|
2016-03-18 10:11:21 +01:00
|
|
|
if [ ! -b $IMAGE_KERNEL ]; then
|
|
|
|
|
OLD_KERNEL=$(stat -t "/flash/$IMAGE_KERNEL" | awk '{print $2}')
|
2016-03-21 07:32:14 +00:00
|
|
|
else
|
|
|
|
|
OLD_KERNEL="0"
|
2016-03-18 10:11:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
OLD_SYSTEM=$(stat -t "/flash/$IMAGE_SYSTEM" | awk '{print $2}')
|
|
|
|
|
NEW_KERNEL=$(stat -t "$UPDATE_DIR/$UPDATE_KERNEL" | awk '{print $2}')
|
|
|
|
|
NEW_SYSTEM=$(stat -t "$UPDATE_DIR/$UPDATE_SYSTEM" | awk '{print $2}')
|
|
|
|
|
|
2016-07-12 01:05:58 +01:00
|
|
|
# old KERNEL+SYSTEM+free space - new KERNEL+SYSTEM must be higher than 5MB
|
2016-03-18 10:11:21 +01:00
|
|
|
# at least 5MB free after update
|
|
|
|
|
|
|
|
|
|
TMP_SIZE=$(($OLD_KERNEL+$OLD_SYSTEM+$FLASH_FREE-$NEW_KERNEL-$NEW_SYSTEM))
|
|
|
|
|
FLASH_FREE_MIN=$(($FLASH_FREE_MIN*1024*1024))
|
|
|
|
|
|
|
|
|
|
if [ $TMP_SIZE -ge $FLASH_FREE_MIN ]; then
|
|
|
|
|
echo "Checking size: OK"
|
|
|
|
|
else
|
|
|
|
|
echo "Checking size: FAILED"
|
2016-03-21 07:32:14 +00:00
|
|
|
echo ""
|
|
|
|
|
echo "Your System (FAT) partition is too small for this update,"
|
|
|
|
|
echo "and there is not enough space for the update to be installed!"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "You must re-install your system using the disk image of a"
|
|
|
|
|
echo "current release, or you must re-size your existing partitions"
|
|
|
|
|
echo "so that the System (FAT) partition is at least 512MB in size."
|
|
|
|
|
echo ""
|
2016-03-18 10:11:21 +01:00
|
|
|
do_cleanup
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 60s... " 60 "NOW"
|
2016-03-18 10:11:21 +01:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# all ok, update
|
|
|
|
|
if [ -b $IMAGE_KERNEL ]; then
|
|
|
|
|
update_partition "Kernel" "$UPDATE_KERNEL" "$IMAGE_KERNEL"
|
|
|
|
|
else
|
|
|
|
|
update_file "Kernel" "$UPDATE_KERNEL" "/flash/$IMAGE_KERNEL"
|
|
|
|
|
fi
|
|
|
|
|
update_file "System" "$UPDATE_SYSTEM" "/flash/$IMAGE_SYSTEM"
|
|
|
|
|
update_bootloader
|
|
|
|
|
do_cleanup
|
|
|
|
|
do_reboot
|
2011-04-05 01:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
prepare_sysroot() {
|
|
|
|
|
progress "Preparing system"
|
|
|
|
|
|
2014-07-25 07:28:13 +02:00
|
|
|
if [ "$SYSTEM_TORAM" = "no" -o "$INSTALLED_MEMORY" -lt "$SYSTEM_TORAM_LIMIT" ]; then
|
|
|
|
|
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
|
|
|
|
|
else
|
|
|
|
|
cp /flash/$IMAGE_SYSTEM /dev/$IMAGE_SYSTEM
|
|
|
|
|
mount_part "/dev/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
|
|
|
|
|
fi
|
|
|
|
|
|
2013-05-25 19:03:12 +03:00
|
|
|
mount --move /flash /sysroot/flash
|
2015-04-05 20:30:52 +03:00
|
|
|
mount --move /storage /sysroot/storage
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
|
2017-09-05 09:17:30 +02:00
|
|
|
if [ ! -d "/sysroot/usr/lib/kernel-overlays/base/lib/modules/$(uname -r)/" -a -f "/sysroot/usr/lib/systemd/systemd" ]; then
|
2014-11-23 19:06:08 +02:00
|
|
|
echo ""
|
2016-03-21 07:32:14 +00:00
|
|
|
echo "NEVER TOUCH boot= in extlinux.conf / cmdline.txt!"
|
|
|
|
|
echo "If you don't know what you are doing,"
|
|
|
|
|
echo "your installation is now broken."
|
2014-11-23 19:06:08 +02:00
|
|
|
echo ""
|
2016-03-21 07:32:14 +00:00
|
|
|
StartProgress countdown "Normal startup in 60s... " 60 "NOW"
|
2014-11-23 19:06:08 +02:00
|
|
|
fi
|
|
|
|
|
|
2016-03-21 07:32:14 +00:00
|
|
|
[ -f "/sysroot/usr/lib/systemd/systemd" ] || error "final_check" "Could not find systemd!"
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-09 00:04:01 +01:00
|
|
|
# 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
|
|
|
|
|
|
2013-03-17 17:20:25 +01:00
|
|
|
if [ "${boot%%=*}" = "FILE" ]; then
|
|
|
|
|
error "check arguments" "boot argument can't be FILE type..."
|
|
|
|
|
fi
|
|
|
|
|
|
2016-08-26 17:14:35 +01:00
|
|
|
debug_msg "Unique identifier for this client: ${MACHINE_UID:-NOT AVAILABLE}"
|
|
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# main boot sequence
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
for BOOT_STEP in \
|
|
|
|
|
load_modules \
|
2013-10-07 02:27:42 +02:00
|
|
|
check_disks \
|
2012-08-06 18:28:28 +02:00
|
|
|
mount_flash \
|
2017-10-12 08:40:08 +08:00
|
|
|
update_bootmenu \
|
2012-08-06 18:28:28 +02:00
|
|
|
load_splash \
|
|
|
|
|
mount_storage \
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
check_update \
|
|
|
|
|
prepare_sysroot; do
|
|
|
|
|
$BOOT_STEP
|
|
|
|
|
[ -n "$DEBUG" ] && break_after $BOOT_STEP
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
BOOT_STEP=final
|
2009-03-18 13:02:53 +01:00
|
|
|
|
2015-01-12 21:55:58 +02:00
|
|
|
# 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
|
|
|
|
|
echo "### BIG FAT WARNING" > /dev/kmsg
|
|
|
|
|
echo "### $i is removable. suspend/resume may not work" > /dev/kmsg
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
2013-11-02 16:11:09 +02:00
|
|
|
# move some special filesystems
|
2016-12-04 13:23:45 -08:00
|
|
|
/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
|
2010-05-17 13:11:40 +02:00
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# tell OE settings addon to disable updates
|
2013-09-23 21:56:54 +03:00
|
|
|
if [ "$UPDATE_DISABLED" = "yes" ] ; then
|
|
|
|
|
echo "" > /sysroot/dev/.update_disabled
|
|
|
|
|
fi
|
2013-11-02 16:11:09 +02:00
|
|
|
# swap can not be used over nfs.(see scripts/mount-swap)
|
2013-10-18 19:43:12 +03:00
|
|
|
if [ "$STORAGE_NETBOOT" = "yes" ] ; then
|
|
|
|
|
echo "" > /sysroot/dev/.storage_netboot
|
|
|
|
|
fi
|
2015-01-19 02:24:51 +02:00
|
|
|
|
|
|
|
|
if [ -f /sysroot/storage/.please_resize_me ] ; then
|
2015-01-19 20:09:22 +02:00
|
|
|
INIT_UNIT="--unit=fs-resize.target"
|
2015-01-19 02:24:51 +02:00
|
|
|
fi
|
2015-01-19 11:43:04 +02:00
|
|
|
|
|
|
|
|
BACKUP_FILE=`ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1`
|
|
|
|
|
if [ -f "$BACKUP_FILE" ] ; then
|
2015-01-19 11:53:58 +02:00
|
|
|
INIT_UNIT="--unit=backup-restore.target"
|
2015-01-19 11:43:04 +02:00
|
|
|
fi
|
2015-01-19 11:50:35 +02:00
|
|
|
|
|
|
|
|
if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ] ; then
|
2015-01-19 11:53:58 +02:00
|
|
|
INIT_UNIT="--unit=factory-reset.target"
|
2015-01-19 11:50:35 +02:00
|
|
|
fi
|
2016-03-21 07:32:14 +00:00
|
|
|
|
2013-11-02 16:11:09 +02:00
|
|
|
# switch to new sysroot and start real init
|
2016-12-04 13:23:45 -08:00
|
|
|
exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT
|
2009-11-06 15:29:05 +01:00
|
|
|
|
busybox-initramfs: reorganize init script in preparation for boot type handlers
Changes to kernel commandline parameters:
Remove legacy parameters, to be added back later if desired.
Add a new parameter: break=<all|step,step,...> which will cause a debugging
shell to be started after each or the specified boot steps.
Functions:
mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which
will support specifying kernel parameters like boot=TYPE=target and
disk=TYPE=target. This initial commit only has mount_default, which supports
LABEL=label and UUID=uuid, as well as block devices /dev/* and image files.
error: show more meaningful error messages, containing the boot step and action
which caused the error.
If not debugging, halt the system. This prevents the error from causing more
damage further on in the boot sequence. If debugging, start a debugging shell.
update: make sure the file to update already exists at the destination, to
prevent clobbering a rootfs mounted on /flash, which can be the case when
mounting a mtd or NBD device.
load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd
to enable mount of USB3 devices on boot.
Add a simple boot step sequencer, which allows for starting a debugging shell
after each step.
Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
2012-03-19 17:22:23 +01:00
|
|
|
error "switch_root" "Error in initramfs. Could not switch to new root"
|