busybox-initramfs: init: cosmetics

This commit is contained in:
Stefan Saraev 2013-11-02 16:11:09 +02:00
parent 5450520500
commit 1f14eb6a37

View File

@ -22,12 +22,12 @@
# http://www.gnu.org/copyleft/gpl.html # http://www.gnu.org/copyleft/gpl.html
################################################################################ ################################################################################
# mount all needed special filesystems # mount all needed special filesystems
/bin/busybox mount -t devtmpfs devtmpfs /dev /bin/busybox mount -t devtmpfs devtmpfs /dev
/bin/busybox mount -t proc proc /proc /bin/busybox mount -t proc proc /proc
/bin/busybox mount -t sysfs sysfs /sys /bin/busybox mount -t sysfs sysfs /sys
# set needed variables # set needed variables
MODULE_DIR=/lib/modules MODULE_DIR=/lib/modules
UPDATE_DIR=/storage/.update UPDATE_DIR=/storage/.update
@ -49,19 +49,19 @@
INSTALLED_MEMORY=`cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}'` INSTALLED_MEMORY=`cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}'`
SYSTEM_TORAM_LIMIT=1024000 SYSTEM_TORAM_LIMIT=1024000
# load any configuration # load any configuration
if [ -f "/etc/initramfs.conf" ]; then if [ -f "/etc/initramfs.conf" ]; then
. /etc/initramfs.conf . /etc/initramfs.conf
fi fi
# hide kernel log messages on console # hide kernel log messages on console
echo '1 4 1 7' > /proc/sys/kernel/printk echo '1 4 1 7' > /proc/sys/kernel/printk
# clear screen and hide cursor # clear screen and hide cursor
clear clear
echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink
# parse command line arguments # parse command line arguments
for arg in $(cat /proc/cmdline); do for arg in $(cat /proc/cmdline); do
case $arg in case $arg in
BOOT_IMAGE=*) BOOT_IMAGE=*)
@ -137,20 +137,20 @@
echo "### Starting debugging shell... type exit to quit ###" echo "### Starting debugging shell... type exit to quit ###"
# show cursor # show cursor
echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink
sh </dev/tty1 >/dev/tty1 2>&1 sh </dev/tty1 >/dev/tty1 2>&1
} }
error() { error() {
# Display fatal error message # Display fatal error message
# $1:action which caused error, $2:message # $1:action which caused error, $2:message
echo "*** Error in $BOOT_STEP: $1: $2 ***" echo "*** Error in $BOOT_STEP: $1: $2 ***"
debug_shell debug_shell
} }
break_after() { break_after() {
# Start debug shell after boot step $1 # Start debug shell after boot step $1
case $BREAK in case $BREAK in
all|*$1*) all|*$1*)
debug_shell debug_shell
@ -163,7 +163,7 @@
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type] # $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
mount_common() { mount_common() {
# Common mount handler, handles block devices and filesystem images # Common mount handler, handles block devices and filesystem images
MOUNT_OPTIONS="-o $3" MOUNT_OPTIONS="-o $3"
[ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS" [ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS"
@ -179,7 +179,7 @@
} }
mount_cifs() { mount_cifs() {
# Mount CIFS (Samba) share # Mount CIFS (Samba) share
CIFS_SHARE="${1%%,*}" CIFS_SHARE="${1%%,*}"
CIFS_OPTIONS="${1#*,}" CIFS_OPTIONS="${1#*,}"
[ "$CIFS_OPTIONS" = "$1" ] && CIFS_OPTIONS= [ "$CIFS_OPTIONS" = "$1" ] && CIFS_OPTIONS=
@ -188,7 +188,7 @@
} }
get_iscsistart_options() { get_iscsistart_options() {
# Convert kernel commandline ISCSI= options to iscsistart options # Convert kernel commandline ISCSI= options to iscsistart options
IFS_SAVE="$IFS" IFS_SAVE="$IFS"
IFS=, IFS=,
@ -230,7 +230,7 @@
} }
mount_iscsi() { mount_iscsi() {
# Mount iSCSI target # Mount iSCSI target
ISCSI_DEV="${1##*,}" ISCSI_DEV="${1##*,}"
ISCSI_OPTIONS="${1%,*}" ISCSI_OPTIONS="${1%,*}"
@ -268,7 +268,7 @@
} }
mount_nfs() { mount_nfs() {
# Mount NFS export # Mount NFS export
NFS_EXPORT="${1%%,*}" NFS_EXPORT="${1%%,*}"
NFS_OPTIONS="${1#*,}" NFS_OPTIONS="${1#*,}"
@ -278,8 +278,8 @@
} }
mount_part() { mount_part() {
# Mount a local or network filesystem # Mount a local or network filesystem
# $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type] # $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type]
progress "mount filesystem $1 ..." progress "mount filesystem $1 ..."
MOUNT_TARGET="${1#*=}" MOUNT_TARGET="${1#*=}"
@ -313,13 +313,13 @@
update() { update() {
if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then
echo "updating $1..." echo "updating $1..."
mount -o remount,rw /flash mount -o remount,rw /flash
mv $UPDATE_DIR/$2 $3 mv $UPDATE_DIR/$2 $3
# loopback file needs writable /flash all the time # loopback file needs writable /flash all the time
if [ "${disk%%=*}" != "FILE" ]; then if [ "${disk%%=*}" != "FILE" ]; then
mount -o remount,ro /flash mount -o remount,ro /flash
fi fi
sync sync
fi fi
} }
@ -331,8 +331,8 @@
if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then
echo "updating Bootloader..." echo "updating Bootloader..."
sh $SYSTEM_ROOT/usr/share/bootloader/update.sh sh $SYSTEM_ROOT/usr/share/bootloader/update.sh
sync sync
fi fi
umount /sysroot umount /sysroot
@ -375,8 +375,8 @@
# 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" || \
progress "... Failed to load kernel module uvesafb, skipping" progress "... Failed to load kernel module uvesafb, skipping"
# set framebuffer to a default resolution (1024x768-32) # set framebuffer to a default resolution (1024x768-32)
if [ ! "$SWITCH_FRAMEBUFFER" = "no" ]; then if [ ! "$SWITCH_FRAMEBUFFER" = "no" ]; then
@ -402,7 +402,7 @@
progress "Checking disks" progress "Checking disks"
if [ -x /bin/fsck_hfs ]; then if [ -x /bin/fsck_hfs ]; then
# deal with hfs partitions # deal with hfs partitions
hfsdiskprep hfsdiskprep
fi fi
} }
@ -473,7 +473,7 @@
mkdir -p /storage/$OVERLAY_DIR mkdir -p /storage/$OVERLAY_DIR
umount /storage umount /storage
# split $disk into $target,$options so we can append $OVERLAY_DIR # split $disk into $target,$options so we can append $OVERLAY_DIR
options="${disk#*,}" options="${disk#*,}"
target="${disk%%,*}" target="${disk%%,*}"
if [ "$options" = "$disk" ]; then if [ "$options" = "$disk" ]; then
@ -491,9 +491,9 @@
progress "Checking for updates" progress "Checking for updates"
# check for ATV1 mach-o-kernel # check for ATV1 mach-o-kernel
if [ -f "/flash/com.apple.Boot.plist" -a -f "/flash/boot.efi" ]; then if [ -f "/flash/com.apple.Boot.plist" -a -f "/flash/boot.efi" ]; then
UPDATE_KERNEL="MACH_KERNEL" UPDATE_KERNEL="MACH_KERNEL"
fi fi
UPDATE_TAR=`ls -1 "$UPDATE_DIR"/*.tar 2>/dev/null | head -n 1` UPDATE_TAR=`ls -1 "$UPDATE_DIR"/*.tar 2>/dev/null | head -n 1`
if [ -f "$UPDATE_DIR/$UPDATE_KERNEL" -a -f "$UPDATE_DIR/$UPDATE_SYSTEM" -o -f "$UPDATE_TAR" ] ; then if [ -f "$UPDATE_DIR/$UPDATE_KERNEL" -a -f "$UPDATE_DIR/$UPDATE_SYSTEM" -o -f "$UPDATE_TAR" ] ; then
@ -527,18 +527,20 @@
fi fi
# check md5 sums if .nocheck doesn't exist # check md5 sums if .nocheck doesn't exist
if [ "$MD5_NOCHECK" -eq "0" -a -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then if [ "$MD5_NOCHECK" -eq "0" ] ; then
sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_KERNEL}.md5" if [ -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then
sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_KERNEL}.md5"
sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_SYSTEM}.md5"
echo "Checking ${UPDATE_KERNEL}.md5..." echo "Checking ${UPDATE_KERNEL}.md5..."
md5sum -c "$UPDATE_DIR/${UPDATE_KERNEL}.md5" || MD5_FAILED="1" md5sum -c "$UPDATE_DIR/${UPDATE_KERNEL}.md5" || MD5_FAILED="1"
echo "Checking ${UPDATE_SYSTEM}.md5..." echo "Checking ${UPDATE_SYSTEM}.md5..."
md5sum -c "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" || MD5_FAILED="1" md5sum -c "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" || MD5_FAILED="1"
else else
echo "missing ${UPDATE_KERNEL}.md5 or ${UPDATE_SYSTEM}.md5..." echo "missing ${UPDATE_KERNEL}.md5 or ${UPDATE_SYSTEM}.md5..."
MD5_FAILED="1" MD5_FAILED="1"
fi
fi fi
# get sizes # get sizes
@ -615,7 +617,7 @@
error "check arguments" "boot argument can't be FILE type..." error "check arguments" "boot argument can't be FILE type..."
fi fi
# main boot sequence # main boot sequence
for BOOT_STEP in \ for BOOT_STEP in \
load_modules \ load_modules \
check_disks \ check_disks \
@ -630,20 +632,20 @@
BOOT_STEP=final BOOT_STEP=final
# move some special filesystems # move some special filesystems
/bin/busybox mount --move /dev /sysroot/dev /bin/busybox mount --move /dev /sysroot/dev
/bin/busybox mount --move /proc /sysroot/proc /bin/busybox mount --move /proc /sysroot/proc
/bin/busybox mount --move /sys /sysroot/sys /bin/busybox mount --move /sys /sysroot/sys
# tell OE settings addon to disable updates # tell OE settings addon to disable updates
if [ "$UPDATE_DISABLED" = "yes" ] ; then if [ "$UPDATE_DISABLED" = "yes" ] ; then
echo "" > /sysroot/dev/.update_disabled echo "" > /sysroot/dev/.update_disabled
fi fi
# swap can not be used over nfs.(see scripts/mount-swap) # swap can not be used over nfs.(see scripts/mount-swap)
if [ "$STORAGE_NETBOOT" = "yes" ] ; then if [ "$STORAGE_NETBOOT" = "yes" ] ; then
echo "" > /sysroot/dev/.storage_netboot echo "" > /sysroot/dev/.storage_netboot
fi fi
# switch to new sysroot and start real init # switch to new sysroot and start real init
exec /bin/busybox switch_root /sysroot /lib/systemd/systemd $INIT_ARGS exec /bin/busybox switch_root /sysroot /lib/systemd/systemd $INIT_ARGS
error "switch_root" "Error in initramfs. Could not switch to new root" error "switch_root" "Error in initramfs. Could not switch to new root"