Merge pull request #3302 from antonlacon/init-changes

busybox/init: cleanup
This commit is contained in:
MilhouseVH 2019-03-19 15:03:41 +00:00 committed by GitHub
commit fca5752af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,9 +20,6 @@
/usr/bin/busybox mount -t proc proc /proc /usr/bin/busybox mount -t proc proc /proc
/usr/bin/busybox mount -t sysfs sysfs /sys /usr/bin/busybox mount -t sysfs sysfs /sys
# common functions
. /functions
# set needed variables # set needed variables
MODULE_DIR=/usr/lib/modules MODULE_DIR=/usr/lib/modules
@ -55,123 +52,10 @@
MACHINE_UID="$(cat /proc/cpuinfo | awk '/^Serial/{s=$3; gsub ("^0*","",s); print s}')" 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 :)" [ -z "$MACHINE_UID" ] && MACHINE_UID="$(cat /sys/class/net/eth0/address 2>/dev/null | tr -d :)"
# hide kernel log messages on console # common functions
echo '1 4 1 7' > /proc/sys/kernel/printk . /functions
# 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
# script functions
progress() { progress() {
if test "$PROGRESS" = "yes"; then if test "$PROGRESS" = "yes"; then
echo "### $1 ###" >&2 echo "### $1 ###" >&2
@ -287,14 +171,11 @@
if [ "$ISCSI_OPTIONS" = "auto" ]; then if [ "$ISCSI_OPTIONS" = "auto" ]; then
progress "Network configuration based on iBFT" progress "Network configuration based on iBFT"
/usr/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || \ /usr/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to configure network"
error "iscsistart" "Unable to configure network"
progress "iSCSI auto connect based on iBFT" progress "iSCSI auto connect based on iBFT"
/usr/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || \ /usr/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to auto connect"
error "iscsistart" "Unable to auto connect"
else else
/usr/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || \ /usr/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || error "iscsistart" "Unable to connect to ISCSI target"
error "iscsistart" "Unable to connect to ISCSI target"
fi fi
mount_common "$ISCSI_DEV" "$2" "$3" "$4" mount_common "$ISCSI_DEV" "$2" "$3" "$4"
@ -306,8 +187,7 @@
NBD_PORT="${1#*:}" NBD_PORT="${1#*:}"
NBD_DEV="/dev/nbd$NBD_DEVS" NBD_DEV="/dev/nbd$NBD_DEVS"
nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \ nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || error "nbd-client" "Could not connect to NBD server $1"
error "nbd-client" "Could not connect to NBD server $1"
mount_common "$NBD_DEV" "$2" "$3" "$4" mount_common "$NBD_DEV" "$2" "$3" "$4"
@ -483,8 +363,7 @@
[ ! -f "/etc/modules" ] && return [ ! -f "/etc/modules" ] && return
for module in $(cat /etc/modules); do for module in $(cat /etc/modules); do
progress "Loading kernel module $module" progress "Loading kernel module $module"
insmod "$MODULE_DIR/$module.ko" || \ insmod "$MODULE_DIR/$module.ko" || progress "... Failed to load kernel module $module, skipping"
progress "... Failed to load kernel module $module, skipping"
done done
} }
@ -498,9 +377,7 @@
# load uvesafb module if needed # load uvesafb module if needed
if [ -f "$MODULE_DIR/uvesafb.ko" -a ! -e /dev/fb0 ]; then if [ -f "$MODULE_DIR/uvesafb.ko" -a ! -e /dev/fb0 ]; then
progress "Loading kernel module uvesafb.ko" progress "Loading kernel module uvesafb.ko"
insmod "$MODULE_DIR/uvesafb.ko" && \ insmod "$MODULE_DIR/uvesafb.ko" && set_default_res=yes || progress "... Failed to load kernel module uvesafb, skipping"
set_default_res=yes || \
progress "... Failed to load kernel module uvesafb, skipping"
fi fi
if [ -e /dev/fb0 ]; then if [ -e /dev/fb0 ]; then
@ -586,12 +463,12 @@
read -t120 -n1 read -t120 -n1
# The exit status is 0 if input is available # The exit status is 0 if input is available
# The exit status is greater than 128 if the timeout is exceeded # 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 "Repairing filesystem..."
echo "" echo ""
/usr/sbin/fsck -T -M -y $RUN_FSCK_DISKS /usr/sbin/fsck -T -M -y $RUN_FSCK_DISKS
FSCK_RET="$?" FSCK_RET=$?
if [ "$(( $FSCK_RET & 8 ))" = 8 ] ; then if [ $(( $FSCK_RET & 8 )) -eq 8 ]; then
# fubar # fubar
echo "Forced fsck failed. Your system is broken beyond repair" echo "Forced fsck failed. Your system is broken beyond repair"
echo "Please re-install @DISTRONAME@" echo "Please re-install @DISTRONAME@"
@ -614,20 +491,20 @@
if [ "$RUN_FSCK" = "yes" -a -n "$RUN_FSCK_DISKS" ]; then if [ "$RUN_FSCK" = "yes" -a -n "$RUN_FSCK_DISKS" ]; then
progress "Checking disk(s): $RUN_FSCK_DISKS" progress "Checking disk(s): $RUN_FSCK_DISKS"
/usr/sbin/fsck -T -M -p -a $RUN_FSCK_DISKS > /dev/null 2>&1 /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. # 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 # errors left
force_fsck force_fsck
elif [ "$(( $FSCK_RET & 2 ))" = 2 ] ; then elif [ $(( $FSCK_RET & 2 )) -eq 2 ]; then
# reboot needed # reboot needed
echo "Filesystem repaired, reboot needed..." echo "Filesystem repaired, reboot needed..."
do_reboot do_reboot
elif [ "$(( $FSCK_RET & 1 ))" = 1 ] ; then elif [ $(( $FSCK_RET & 1 )) -eq 1 ]; then
# filesystem errors corrected # filesystem errors corrected
progress "Filesystem errors corrected , continuing..." progress "Filesystem errors corrected , continuing..."
elif [ "$(( $FSCK_RET & 0 ))" = 0 ] ; then elif [ $(( $FSCK_RET & 0 )) -eq 0 ]; then
# no errors found # no errors found
progress "No filesystem errors found, continuing..." progress "No filesystem errors found, continuing..."
fi fi
@ -1048,6 +925,125 @@
[ -f "/sysroot/usr/lib/systemd/systemd" ] || error "final_check" "Could not find systemd!" [ -f "/sysroot/usr/lib/systemd/systemd" ] || error "final_check" "Could not find systemd!"
} }
# Do init tasks to bring up system
# 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 # 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 # 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 grep '^\(nameserver\|domain\) ' /proc/net/pnp | grep -v '^nameserver 0\.0\.0\.0$' > /etc/resolv.conf