#!/bin/sh #============================================================================== # LiveCD/USB/HD init script # (C) 2009-2016 Paul Banham # Inspired by the work of Klaus Knopper # # License: GPLv3 or later #============================================================================== # SUFFIX NOTE: _MP absolute mountpoint # _NAME filename with no path # _PATH relative path but no filename # _FILE relative path with filename # _FULL absolute mountpoint and path and filename # _DIR varies # # CUSTOMIZATION: # Customize to your distro using /etc/initrd-release. Add further # customization if needed with scripts at /live/custom/$DISTRO/[1-9].sh. # These scripts are run at the respective breakpoints. So 1.sh is run # at breakpoint 1 and so on. The script 0.sh is run before we read the # boot parameters. You can use this to set defaults that can be # over-ridden by boot parameters. Use 1.sh to override boot parameters # that you don't want users to be able to adjust. ME="initrd init" VERSION="7.60.13" VERSION_DATE="Thu Nov 24 11:38:28 MST 2016" DEVELOPER="BitJam" BUG_REPORT_URL="liveboot@mxlinux.org" # This are all times in seconds, not attempts BOOT_RETRY=15 FRUGAL_RETRY=10 PERSIST_RETRY=10 FAILSAFE_BOOT_RETRY=30 DISABLE_SERVICES_OPTS="(c[0-9]+(\.[0-9]*)?|c\.[0-9]+|[DLMPSXacdgklmnNrsvwx])+" RW_MODE="ro" #DISTRO_NAME="Linux" PRINTK=0 LIVE_DIR="/live" FINAL_DIR="/live" LIVE_BIN="/bin" AUFS_DIR="aufs" EXTRA_FILES="deb xtra xtra.tgz state" MIN_SYS_RAM=80 MIN_AUFS_RAM=80 LOG_DIR="/var/log/live" LOG_FILE="$LOG_DIR/initrd.log" MY_LOG=/init.log VID_DIR="/etc/live/version" VID_FILE="$VID_DIR/linuxfs.ver" MAKE_OLD="rootfs xtra deb xtra.tgz linuxfs.md5" MOD_DIR="/lib/modules/$(uname -r)" FROM_TYPE="usb,cd" FROM_TYPE_ALL="usb,cd,hd" FRUGAL_FILES="linuxfs vmlinuz vmlinuz1 initrd.gz xtra xtra.tgz" FRUGAL_FILES="$FRUGAL_FILES ../boot ../efi ../EFI ../cdrom.ico ../version" MAX_MOUNT_CNT=30 RETRY_DELAY=50 # in hundredths of a second VERBOSE=5 DO_COLDPLUG=true COLDPLUG_DELAY= USER_UID=1000 USER_GID=1000 DO_DEB=true PLUG_LOOP_DELAY=50 # In 100ths of a second # Note: adding "crc32c-generic" works around a bug in the kernel: # https://github.com/manjaro/packages-core/issues/8 LOAD_FIRST="usb-common usbcore ehci-hcd fusbh200-hcd fotg210-hcd battery aufs overlay crc32c-generic mmc-block" VID_NAME=VID LINUXFS_NAME=linuxfs BLACK_LIST= BLACK_LIST_FILE=/etc/modprobe.d/initrd.conf KMS_VIDEO_MODULES="ast,bochs-drm,cirrus,emgd,gma500_gfx,i915,mgag200,nouveau,qxl,radeon,udl,vmwgfx" DEFAULT_SQFILE=/antiX/linuxfs DEFAULT_ISO_FILE=/antiX/antiX.iso LIVE_X64_LD_PATH="/lib:/lib/x86_64-linux-gnu:/usr/lib" LIVE_386_LD_PATH="/lib:/lib/i386-linux-gnu:/usr/lib" MKFS_FREE_MARGIN=10 rootfs_SIZE_PARAM="min_size=250 mid_size=100 max_size=2000 factor=50" homefs_SIZE_PARAM="min_size=10 mid_size=100 max_size=4000 factor=25" MKFS_SIZES="250 375 500 750 1000 1500 2000 2500 3000 4000" BIGGER_SIZES="5000 6000" SMALLER_SIZES="10 100 175" LIVE_SCRIPTS="live-L10n live-init" LAST_BP_TIME=0 NO_PLINK="" DEFAULT_UNIONFS="overlay" OPTIONS_ENTRIES="toram|from=usb|password|nousb2" LAZYTIME="" set_live_dirs() { local dir=$1 FRUGAL_MP="$dir/frugal" BOOT_MP="$dir/boot-dev" ISO_DEV_MP="$dir/iso-dev" ISO_FILE_MP="$dir/iso-file" TORAM_MP="$dir/to-ram" AUFS_RAM_MP="$dir/aufs-ram" AUFS_MP="$dir/$AUFS_DIR" ROOTFS_MP="$dir/persist-root" PERSIST_MP="$dir/persist-dev" SQFS_MP="$dir/linux" # where the linuxfs file gets *mounted* WRAP_FILE_MP="$dir/wrapper" OUTPUT_DIR="$dir/config" LOCALE_DIR="$dir/locale" CUSTOM_DIR="$dir/custom" DISABLED_USB_FILE="$OUTPUT_DIR/usb-disabled" } hbar="======================================================================" tbar="----------------------------------------------------------------------" main_wrapper() { local black blue green cyan red purple brown lt_gray dk_gray lt_blue local lt_green lt_cyan lt_red magenta yellow white rev_red local cheat_co cmd_co dev_co err_co from_co to_co head_co local hi_co mp_co m_co nc_co num_co ok_co bold_co PATH=$LIVE_BIN HOME=/ TERM=linux PWD=/ set_live_dirs $LIVE_DIR mkdir -p $OUTPUT_DIR # Don't allow interrupts to ruin our day # HUP INT QUIT SEGV TERM trap "" 1 2 3 11 15 umask 022 system_mount local time_0=$(cut -d" " -f22 /proc/$$/stat) make_nodes /dev read_distro_release /etc/initrd-release : ${DISTRO_BUG_REPORT_URL:=$BUG_REPORT_URL} : ${DISTRO_NAME:=antiX} : ${DISTRO_PRETTY_NAME:=antiX-16 (generic)} custom_code 0 'before reading boot codes' clear_env read_cmdline_params select_breakpoints FREE_MEM=$(mem_info MemFree) set_colors "$NO_COLOR" "$LOW_COLOR" read_xlat init $LANG # disable console screen blanking printf "\e[9;0]\e[14;0]" echo "$PRINTK" > /proc/sys/kernel/printk SCREEN_WIDTH=$(stty size 2>/dev/null | cut -d" " -f2) [ -z "${FINAL_DIR##/*}" ] || FINAL_DIR="/$FINAL_DIR" NEW_ROOT=$AUFS_MP if [ "$NO_ERR_LOG" ]; then main_core else # Evaluate redirects RIGHT TO LEFT: # # stdout 1 -------. .---> while, sed, tee ---> screen (stdout) # \ / # stderr 2 ---. `--- / -------------------------> screen (stderr) # \ / # 17 `------' main_core 17>&1 1>&2 2>&17 | while read line; do echo "$line" \ | sed -e "s/^/${yellow}Error: $red/" -e "s/$/$nc_co/" | tee -a $MY_LOG; done fi read LAST_BP_TIME < /LAST_BP_TIME start_hotplug # Nota Bene: when error log is enabled, main_core() runs in a subshell # so it cannot affect our variables. # Need to run persist-password outside of our error catching breakpoint 8 "before running live init.d scripts" breakpoint b8 "Bash shell before running live init.d scripts" # Try running live-usb-save first so it can restore an xorg.conf machine-state file confile remasterable && LIVE_SCRIPTS="live-usb-save $LIVE_SCRIPTS" confile hwclock && LIVE_SCRIPTS="$LIVE_SCRIPTS live-hwclock" confile persist-root force-passwd && LIVE_SCRIPTS="$LIVE_SCRIPTS persist-password" confile save-persist && LIVE_SCRIPTS="$LIVE_SCRIPTS persist-autosave" # Do this after the above so the changes aren't saved until after a "real" persist-save confile systemd || LIVE_SCRIPTS="$LIVE_SCRIPTS live-disable-services" confile toram-eject && LIVE_SCRIPTS="$LIVE_SCRIPTS live-toram-eject" confile bootsave && LIVE_SCRIPTS="$LIVE_SCRIPTS live-bootsave" confile deb-install && LIVE_SCRIPTS="$LIVE_SCRIPTS live-deb-install" unset CMDLINE PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin run_init_scripts $NEW_ROOT $LIVE_SCRIPTS PATH=$LIVE_BIN test -r /late-umount.sh && . /late-umount.sh sync late_umount $PERSIST_DEVICE late_umount $SQFILE_DEV if [ -z "$DISABLE_STORE" ]; then if detect_old_persist_scripts $NEW_ROOT; then warn "%s disabled due to outdated persistence scripts and libs" "$(pqw LiveUSB-Storage)" else confile remasterable && run_init_scripts $NEW_ROOT live-usb-storage local dir new_dir for dir in config bin; do local new_dir=$NEW_ROOT/etc/live/$dir mkdir -p $new_dir mount --bind /live/aufs/live/$dir $new_dir done chmod 700 $NEW_ROOT/live fi fi local f rm_list for f in $NEW_ROOT/live/menus/*; do case $f in *tz.*) continue;; esac rm_list="$rm_list $f" done rm -f $rm_list dmesg > $NEW_ROOT/live/config/dmesg.out breakpoint bash "Bash shell right before starting init" breakpoint b9 "Bash shell right before starting init" breakpoint 9 "right before starting init" stop_hotplug local time_1=$(get_time) local dt=$((time_1 - time_0)) vmsg 6 vmsg 5 "The %s program took %s seconds" "$ME" $(nq $(get_seconds $dt)) vmsg 6 $hbar write_log_files $MY_LOG $NEW_ROOT/$LOG_FILE MY_LOG=$NEW_ROOT/$LOG_FILE.color #free -m >> $MY_LOG echo 3 > /proc/sys/vm/drop_caches vmsg 6 'drop caches' #free -m >> $MY_LOG if find_init_prog INIT_PROG $NEW_ROOT; then vmsg 4 'Run %s instead of %s' $white$INIT_PROG$m_co $white/sbin/init$m_co vmsg 5 "${hi_co}%s" 'Please exit shells normally to allow for a clean unmount' CHROOT_BIN=$FINAL_DIR/bin chroot $NEW_ROOT $CHROOT_BIN/setsid $CHROOT_BIN/cttyhack $INIT_PROG breakpoint i "after init= chroot" MY_LOG=/dev/null safe_shutdown poweroff ask else : ${INIT_COMMAND:=/sbin/init} test -x $NEW_ROOT$INIT_COMMAND || INIT_COMMAND=/sbin/init vmsg 6 "Start %s process" $(pq $INIT_COMMAND) exec $LIVE_BIN/switch_root -c /dev/console $NEW_ROOT $INIT_COMMAND "$@" fi } main_core() { [ "$NO_CLEAR" ] || printf "\e[1J" # Clear and reset screen vmsg 6 "=== initrd bootstrap ==================================================" vmsg 6 '%s started at %s seconds' "$ME" $(nq $(get_seconds $time_0)) mkdir -p $MOD_DIR depmod &>/dev/null blacklist_modules $BLACK_LIST breakpoint 1 "before welcome" # These ones must be loaded before the others # Add a cheap black-lister if [ ${#BLACK_LIST} -gt 0 ]; then local bl_regex=${BLACK_LIST#,} bl_regex=${bl_regex%,} bl_regex=${bl_regex//,/|} echo $LOAD_FIRST | tr " " "\n" | egrep -v "^($bl_regex)$" | xargs modprobe -q -a 2>/dev/null else echo $LOAD_FIRST | xargs modprobe -q -a 2>/dev/null fi start_hotplug do_welcome "$DISTRO_PRETTY_NAME" "$VERSION" "$VERSION_DATE" show_bootcodes "$(live_param_filter $UNKNOWN_BOOTCODES)" show_integer_errors "$INTEGER_ERRORS" show_disable_errors "$DISABLE_SERVICES" "$DS_PARAM" breakpoint 2 "before coldplug" check_unionfs coldplug_delay coldplug_modules # local orig_fb_name # read orig_fb_name 2>/dev/null /dev/null /live/config/proc-cmdline clean_xlat : ${SQFILE_FILE:=$DEFAULT_SQFILE} : ${SQFILE_NAME:=${SQFILE_FILE##*/}} [ -z "${SQFILE_FILE##*/*}" ] && : ${BOOT_DIR:=${SQFILE_FILE%/*}} [ "$SQFILE_EXT" ] && SQFILE_NAME="$SQFILE_NAME.$SQFILE_EXT" SQFILE_FILE="$BOOT_DIR/$SQFILE_NAME" SQFILE_FILE=${SQFILE_FILE#/} # Wait and only do this in the find_files() loop so the usb report # will always work #[ "$NO_EHCI" ] && disable_hcd ehci breakpoint 3 "before looking for linuxfs file" RW_MODE=ro if [ "$FRUGAL_ID" ]; then find_frugal_file "$FRUGAL_ID" || frugal_error $? else find_linuxfs_file fi mount -o remount,rw $BOOT_MP &>/dev/null dir_has_param "$BOOT_MP" rw && REMASTERABLE=true [ "$DID_ISO" ] && REMASTERABLE= case $BOOT_FSTYPE in iso9660|udf) REMASTERABLE= ;; esac BOOT_UUID=$(device_uuid $SQFILE_DEV) [ "$BOOT_UUID" ] && vmsg 6 "boot device uuid: $BOOT_UUID" breakpoint 4 "after mounting boot device" mount -o remount,rw $SQFILE_DEV 2>/dev/null dir_has_param "$SQFILE_MP" rw || REMASTERABLE= [ "$REMASTERABLE" ] && do_remaster "$SQFILE_FULL" mount_linuxfs "$SQFS_MP" "$SQFILE_FULL" "$WRAP_FILE_MP" if [ "$LOAD_ALL_MODULES" ]; then debug_cmd find /sys/devices -name uevent -exec sed -n 's/^MODALIAS=//p' '{}' + 2>/dev/null | sort -u debug_cmd lsmod fi prep_ld_path RW_MODE=rw # FIXME: this makes debugging persist_makefs simpler #[ "$PERSIST_FILES" ] && mount -o remount,rw $SQFILE_DEV mount -o remount,rw $SQFILE_DEV #breakpoint 4 "after mounting linuxfs file" prepare_persistence mount_persist_device "$PERSIST_FILES" "$FROM_PERSIST" list_modules # Check for ehci warning dmesg | grep 'Warning.*ehci' >&2 breakpoint 5 "after mounting persistence device" fsck_boot_dev "$SQFILE_DEV" "$SQFILE_MP" ORIG_SQFILE_MP=$SQFILE_MP ORIG_SQFILE_DIR=$SQFILE_PATH ORIG_SQFILE_FULL=$ORIG_SQFILE_DIR/$SQFILE_NAME test -d $SQFILE_MP/$SQFILE_PATH/deb || DO_DEB= # Check md5 of files in directory containing linuxfs file # 'fromiso' causes us to check md5sums in two places [ "$CHECK_MD5" ] && check_md5 $SQFILE_DIR [ "$TO_RAM" ] && copy_to_ram "$SQFILE_FULL" $TORAM_MP check_kernel_version $SQFS_MP mount -o remount,rw $SQFILE_DEV 2>/dev/null fsck_persist_dev "$PERSIST_FILES" "$PERSIST_DEVICE" "$PERSIST_MP" [ "$WANT_ROOTFS" ] && remaster_rootfs "$PERSIST_MP" "$PERSIST_FULL_PATH" mount_aufs_ram "$AUFS_RAM_MP" "$MIN_AUFS_RAM" "$FREE_MEM" mount_and_copy_rootfs [ "$STATIC_ROOT" ] && log_cmd umount $AUFS_RAM_MP mount_unionfs "$AUFS_MP" "$SQFS_MP" "$AUFS_RAM_MP" "$ROOTFS_MP" SYSTEM_D= local sbin_init=$(readlink $NEW_ROOT/sbin/init) if [ -n "$sbin_init" -a -z "${sbin_init##*systemd}" ]; then SYSTEM_D=true touch /live/config/systemd msg "Detected %s init system" $(cq systemd) fi breakpoint 6 "after mounting aufs" rm -f $NEW_ROOT$BLACK_LIST_FILE [ -e $BLACK_LIST_FILE ] && cp $BLACK_LIST_FILE $NEW_ROOT$BLACK_LIST_FILE [ "$WANT_HOMEFS" ] \ && mount_homefs $PERSIST_FULL_PATH/homefs $NEW_ROOT/home "$WANT_HOMEFS" "$NEED_HOMEFS" [ "$DB_PLUS" ] && local plus_t1=$(get_time) [ "$DO_XTRA" ] && copy_xtra $DEFAULT_DIR [ "$DO_XTRA" ] && delete_files $DEFAULT_DIR [ "$DO_AUTO_LOGIN" ] && auto_login "$AUTO_LOGIN_PROG" "$AUTO_LOGIN_TERMS" "$NEW_ROOT" [ "$DO_FANCY" ] && fancy_prompt "$FANCY_PROMPT" "$NEW_ROOT" if [ "$DB_PLUS" ]; then local plus_t2=$(get_time) local delta=$(get_seconds $((plus_t2 - plus_t1))) vmsg 8 "$green@${cyan} Extras took$hi_co $delta${cyan} seconds" fi [ ! -e /$NEW_ROOT/etc/issue -o -n "$FORCE_ISSUE" ] && cp /issue $NEW_ROOT/etc/issue # FIXME: do this after copy_xtra for easy testing (for now) (????) PROC_CMDLINE=$(cat /live/config/proc-cmdline) [ "$DO_MENUS" ] && do_late_menus echo "$PROC_CMDLINE" > /live/config/proc-cmdline [ "$NO_NEW_OUTPUT" ] || write_output_files $OUTPUT_DIR [ "$NO_OLD_OUTPUT" ] || old_write_output_files $OUTPUT_DIR update_store_file "$NO_STORE" "$DO_STORE" mkdir -p $NEW_ROOT/etc/live echo $FINAL_DIR > $NEW_ROOT/etc/live/live-dir # FIXME: since we are using the real persist-save we can do these either # before or after we run the init scripts! But we lose some of the variables # when not run inside of main_core(). #sync #late_umount $PERSIST_DEVICE #late_umount $SQFILE_DEV stop_hotplug breakpoint 7 "before prepare switch_root" prepare_switch_root $NEW_ROOT $LIVE_DIR $FINAL_DIR write_ntfs_pids $FINAL_DIR/aufs/run/sendsigs.omit.d/initrd-ntfs-3g echo $LAST_BP_TIME > /LAST_BP_TIME cat< late-umount.sh PERSIST_DEVICE="$PERSIST_DEVICE" SQFILE_DEV="$SQFILE_DEV" HOMEFS_DEV="$HOMEFS_DEV" ROOTFS_DEV="$ROOTFS_DEV" LINUXFS_DEV="$LINUXFS_DEV" Late_Umount } #------------------------------------------------------------------------------ # Getting started #------------------------------------------------------------------------------ system_mount() { dir=$1 mkdir -p $dir/proc $dir/sys $dir/dev mount -t proc proc $dir/proc mount -t sysfs sys $dir/sys mount -t devtmpfs devtmpfs $dir/dev mkdir -p $dir/dev/pts mount -t devpts devpts $dir/dev/pts } make_nodes() { local dir=$1 mkdir -p $dir [ -e $dir/console ] || mknod $dir/console c 5 1 [ -e $dir/null ] || mknod $dir/null c 1 3 [ -e $dir/tty0 ] || mknod $dir/tty0 c 4 0 } read_distro_release() { local file=$1 #sed -r -n 's/^\s*([A-Z0-9_]+=)/DISTRO_\1/p' $file >> $MY_LOG eval $(sed -r -n 's/^\s*([A-Z0-9_]+=)/DISTRO_\1/p' $file) } clear_env() { local ev # unset almost all env variables for ev in $(printenv | sed 's/=.*//'); do case $ev in HOME|PATH|PWD|TERM) continue;; esac unset $ev done } read_late_cmdline_params() { #vmsg 6 "read_late_cmdline_params: $*" local param value cmdline=${1:-$(cat /proc/cmdline)} for param in $cmdline; do value=${param#*=} case $param in frugal) set_frugal ;; frugal=*) set_frugal $value ;; hwclock=*|hwc=*) DO_HWCLOCK=true ;; from=*) FROM_TYPE=$value ; ALWAYS_SCAN=true ;; persist=*|p=*) PERSIST=$PERSIST,$value ;; persist) PERSIST=$PERSIST,root,home ;; lang=*) LANG=$value ;; md5|checkmd5) CHECK_MD5=true ;; checkfs) FORCE_FSCK=true ;; nousb2|noehci) NO_EHCI=true ;; private|private=*) FORCE_PASSWD=true ;; toram) TO_RAM=true ;; # Convenience short cuts from our menus persist_all) PERSIST='root!,home' ;; persist_root) PERSIST='root!' ;; persist_static) PERSIST='root!,home,static' ;; persist_home) PERSIST='home!' ;; frugal_persist) set_frugal 'root!,home' ;; frugal_root) set_frugal 'root!' ;; frugal_static) set_frugal 'root!,home,static' ;; frugal_home) set_frugal 'home!' ;; frugal_only) set_frugal ;; nostore) NO_STORE=true ;; dostore) DO_STORE=true ;; esac done } set_frugal() { : ${FRUGAL_ID:=label=$DISTRO_NAME-Frugal} [ "$NO_LABEL_FRUGAL" ] || LABEL_FRUGAL=true PERSIST=$1 } #------------------------------------------------------------------------------ # Function read_cmdline_params # # Gather all boot codes #------------------------------------------------------------------------------ read_cmdline_params() { local param value cmdline=${1:-$(cat /proc/cmdline)} for param in $cmdline; do value=${param#*=} case $param in aufs) WANT_UNIONFS=aufs ;; overlayfs) WANT_UNIONFS=overlay ;; menus) DO_MENUS=${MENUS_LIST:-ltopfs} ;; menus=*) DO_MENUS=$DO_MENUS$value ;; rootdelay=*|delay=*) small_int COLDPLUG_DELAY $param ;; old-conf) NO_NEW_OUTPUT=true ;; new-conf) NO_OLD_OUTPUT=true ;; splash) SPLASH_PARAM=v ;; splash=*) SPLASH_PARAM=$value ;; poweroff) poweroff -f -n ;; reboot) reboot -f -n ;; bootdir=*|bdir=*) BOOT_DIR=$value ;; bootlabel=*|blabel=*|blab=*) BOOT_ID=label=$value ;; bootuuid=*|buuid=*) BOOT_ID=uuid=$value ;; bootdev=*|bdev=*) BOOT_ID=name=$value ;; try=*|retry=*) small_int CMD_RETRY $param ;; persistdir=*|pdir=*) PERSIST_PATH=${value#/} ;; persistlabel=*|plabel=*|plab=*) PERSIST_ID=label=$value ; SET_PERSIST=true ;; persistuuid=*|puuid=*) PERSIST_ID=uuid=$value ; SET_PERSIST=true ;; persistdev=*|pdev=*) PERSIST_ID=name=$value ; SET_PERSIST=true ;; btry=*) small_int CMD_BOOT_RETRY $param ;; ftry=*) small_int CMD_FRUGAL_RETRY $param ;; ptry=*) small_int CMD_PERSIST_RETRY $param ;; fneed=*) FRUGAL_NEEDED=$value ;; fforce) FORCE_FRUGAL=true ;; flab=*) FRUGAL_ID=label=$value ; NO_LABEL_FRUGAL=true ;; fdev=*) FRUGAL_ID=name=$value ; NO_LABEL_FRUGAL=true ;; fuuid=*) FRUGAL_ID=uuid=$value ; NO_LABEL_FRUGAL=true ;; iso=*|fromiso=*) ISO_FILE=${value/#} ;; iso|fromiso) FROM_ISO=true ;; sqext=*) SQFILE_EXT=$value ;; sqname=*) SQFILE_NAME=${value#/} ;; sq=*) SQFILE_FILE=$value ;; verbose=*|verb=*|v=*) small_int VERBOSE $param ;; bp=*) BREAK_POINTS=$BREAK_POINTS,$value ;; pk=*) PRINTK=$value ;; hico|highcolor) LOW_COLOR= ;; loco|lowcolor) LOW_COLOR=true ;; noco|nocolor) NO_COLOR=true ;; noxtra) DO_XTRA= ;; doxtra) DO_XTRA=true ;; fdb+|db+) DO_AUTO_LOGIN=true; DO_FANCY=true; DB_PLUS=true ;; db++) ;; fancyprompt|fprompt) DO_FANCY=true ;; autologin|alogin) DO_AUTO_LOGIN=true ;; nodeb) DO_DEB= ;; #toram-eject) TO_RAM=true ; TO_RAM_EJECT=true ;; noremaster) NO_REMASTER=true ;; rollback) ROLLBACK=true ;; lang=*) LANG=$value ;; noclear) NO_CLEAR=true ;; gfxsave=*) GFX_SAVE=$value ; BOOT_SAVE=true ;; save|gfxsave) GFX_SAVE=both ; BOOT_SAVE=true ;; bootsave) BOOT_SAVE=true ;; nocheckfs) DO_FSCK= ;; failsafe) MODULE_LIST=all BLACK_LIST=$BLACK_LIST,VIDEO BOOT_RETRY=$FAILSAFE_BOOT_RETRY FROM_TYPE=all ;; load=*) MODULE_LIST=$MODULE_LIST,$value ;; bl=*|blacklist=*) BLACK_LIST=$BLACK_LIST,$value ;; nocoldplug) DO_COLDPLUG= ;; nohotplug) FORCE_COLDPLUG_LOOP=true ;; traceload) TRACE_LOAD=true ;; autoload|aload) FULL_AUTOLOAD=true ;; init=*) INIT_PROG=$value ;; noerrlog) NO_ERR_LOG=true ;; noerr=*) NO_ERROR=$value ;; # Not used here see live-init vtblank=*) small_int VT_BLANK $param ;; livedir=*|ldir=*) FINAL_DIR=$value ;; pw|passwd|pw=*|passwd=*) FORCE_PASSWD=true ;; bootchart) INIT_COMMAND=/sbin/bootchartd ; BOOT_CHART=true ;; noplink) NO_PLINK=,noplink ;; plink) NO_PLINK= ;; fatuid=*) any_int USER_UID $param ;; fatgid=*) any_int USER_GID $param ;; disable=*|nosysv=*) DISABLE_SERVICES="$DISABLE_SERVICES$value" ; DS_PARAM=$param ;; disablestore) DISABLE_STORE=true ;; nolazy) LAZYTIME= ;; lazytime) LAZYTIME=,lazytime ;; issue) FORCE_ISSUE=true ;; #----- These get interpreted late but we don't want them to be unknown hwclock=*|hwc=*) ;; frugal) ;; frugal=*) ;; from=*) ;; persist=*|p=*) ;; persist) ;; lang=*) ;; md5|checkmd5) ;; checkfs) ;; nousb2|noehci) ;; private|private=*) ;; toram) ;; # Convenience short cuts from our menus persist_all) ;; persist_root) ;; persist_static) ;; persist_home) ;; frugal_persist) ;; frugal_root) ;; frugal_static) ;; frugal_home) ;; frugal_only) ;; nostore) ;; dostore) ;; #----- Some known codes ------------------------- [sS1-6]|BOOT_IMAGE=*);; video.*);; # Most kernel codes from version 3.8 (plus additions) acpi_force_table_verification|acpi_no_auto_serialize|acpica_no_return_repair);; forcepae|systemd.*);; acpi=*|acpi_rsdp=*|acpi_apic_instance=*|acpi_backlight=*);; acpi.debug_layer=*|acpi.debug_level=*|acpi_irq_balance);; acpi_irq_nobalance|acpi_irq_isa=*|acpi_irq_pci=*|acpi_no_auto_ssdt);; acpi_os_name=*|acpi_osi=*|acpi_pm_good|acpi_sci=*|acpi_serialize);; acpi_skip_timer_override|acpi_sleep=*|acpi_use_timer_override);; acpi_enforce_resources=*|add_efi_memmap|agp=*|ALSA|alignment=*);; align_va_addr=*|amd_iommu=*|amd_iommu_dump=*|amijoy.map=*);; analog.map=*|apc=*|apic=*|autoconf=*|show_lapic=*|apm=*|arcrimi=*);; ataflop=*|atarimouse=*|atkbd.extra=*|atkbd.reset=*|atkbd.set=*);; atkbd.scroll=*|atkbd.softraw=*|atkbd.softrepeat=*|baycom_epp=*);; baycom_par=*|baycom_ser_fdx=*|baycom_ser_hdx=*|boot_delay=*);; bootmem_debug|bttv.card=*|bttv.radio=*|bttv.pll=*|bttv.tuner=*);; bulk_remove=*|c101=*|cachesize=*|ccw_timeout_log|cgroup_disable=*);; checkreqprot|cio_ignore=*|clock=*|clocksource=*|clearcpuid=*|cma=*);; cmo_free_hint=*|coherent_pool=*|code_bytes|com20020=*|com90io=*);; com90xx=*|condev=*|conmode=*|console=*|consoleblank=*);; coredump_filter=*|cpuidle.off=*|cpcihp_generic=*|crashkernel=*);; cs89x0_dma=*|cs89x0_media=*|dasd=*|db9.dev[23]=*|ddebug_query=*|debug);; debug_locks_verbose=*|debug_objects|no_debug_objects);; debug_guardpage_minorder=*|debugpat|decnet.addr=*);; default_hugepagesz=*|dhash_entries=*|digi=*|digiepca=*|disable=*);; disable_ddw|disable_ipv6=*|disable_mtrr_cleanup|disable_mtrr_trim);; disable_timer_pin_1|dma_debug=*|dma_debug_entries=*);; dma_debug_driver=*|drm_kms_helper.edid_firmware=*|dscc4.setup=*);; dyndbg|dyndbg=*|module.dyndbg|module.dyndbg=*|earlycon=*);; earlyprintk=*|ekgdboc=*|edd=*|eisa_irq_edge=*|elanfreq=*|elevator=*);; elfcorehdr=*|enable_mtrr_cleanup|enable_timer_pin_1|enforcing);; erst_disable|ether=*|evm=*|failslab=*|fail_page_alloc=*);; fail_make_request=*|floppy=*|force_pal_cache_flush|ftrace=*);; ftrace_dump_on_oops|ftrace_dump_on_oops=*|ftrace_filter=*);; ftrace_notrace=*|ftrace_graph_filter=*|gamecon.map[23]=*|gamma=*);; gart_fix_e820=*|gcov_persist=*|gpt|grcan.enable0=*|grcan.enable1=*);; grcan.select=*|grcan.txsize=*|grcan.rxsize=*|hashdist=*|hcl=*|hd=*);; hest_disable|highmem=*|highres=*|hisax=*|hlt|hpet=*|hugepages=*);; hugepagesz=*|hvc_iucv=*|hvc_iucv_allow=*|keep_bootcon|i2c_bus=*);; i8042.debug|i8042.direct|i8042.dumbkbd|i8042.noaux|i8042.nokbd);; i8042.noloop|i8042.nomux|i8042.nopnp|i8042.notimeout|i8042.reset);; i8042.unlock|i810=*|i8k.ignore_dmi|i8k.force|i8k.power_status);; i8k.restricted|i915.invert_brightness=*|icn=*|ide-core.nodma=*);; ide-pci-generic.all-generic-ide|idle=*|ignore_loglevel);; ihash_entries=*|ima_appraise=*|ima_appraise_tcb|ima_audit=*);; ima_hash=*|ima_tcb|init=*|initcall_debug|initrd=*|inport.irq=*);; intel_iommu=*|intel_idle.max_cstate=*|intremap=*|iomem=*|iommu=*);; io7=*|io_delay=*|ip=*|ip2=*|irqfixup|irqpoll|isapnp=*|isolcpus=*);; iucv=*|js=*|keepinitrd|kernelcore=*|kgdbdbgp=*|kgdboc=*|kgdbwait);; kmac=*|kmemleak=*|kstack=*|kvm.ignore_msrs=*|kvm.mmu_audit=*);; kvm-amd.nested=*|kvm-amd.npt=*|kvm-intel.ept=*);; kvm-intel.emulate_invalid_guest_state=*|kvm-intel.flexpriority=*);; kvm-intel.nested=*|kvm-intel.unrestricted_guest=*|kvm-intel.vpid=*);; l2cr=*|l3cr=*|lapic|lapic=*|lapic_timer_c2_ok|libata.dma=*);; libata.ignore_hpa=*|libata.noacpi|libata.force=*|memblock=*);; load_ramdisk=*|lockd.nlm_grace_period=*|lockd.nlm_tcpport=*);; lockd.nlm_timeout=*|lockd.nlm_udpport=*|logibm.irq=*|loglevel=*);; log_buf_len=*|logo.nologo|lp=*|lpj=*|ltpc=*|machvec=*|machtype=*);; max_addr=*|maxcpus=*|max_loop=*|mce|mce=*|md=*);; mdacon=*|mem=*|memchunk=*|memmap=*|memory_corruption_check=*);; memory_corruption_check_size=*|memory_corruption_check_period=*);; memtest=*|meye.*=*|mfgpt_irq=*|mfgptfix|mga=*|min_addr=*|mini2440=*);; mminit_loglevel=*|module.sig_enforce|mousedev.tap_time=*);; mousedev.xres=*|mousedev.yres=*|movablecore=*|MTD_Partition=*);; MTD_Region=*|mtdparts=*|multitce=*|onenand.bdry=*|mtdset=*);; mtouchusb.raw_coordinates=*|mtrr_chunk_size=*|mtrr_gran_size=*);; mtrr_spare_reg_nr=*|n2=*|netdev=*|nf_conntrack.acct=*|nfsaddrs=*);; nfsroot=*|nfsrootdebug|nfs.callback_tcpport=*|nfs.cache_getent=*);; nfs.cache_getent_timeout=*|nfs.idmap_cache_timeout=*);; nfs.enable_ino64=*|nfs.max_session_slots=*);; nfs.nfs4_disable_idmapping=*|nfs.nfs4_unique_id=*);; nfs.send_implementation_id|nfsd.nfs4_disable_idmapping=*);; objlayoutdriver.osd_login_prog=*|nmi_debug=*|nmi_watchdog=*);; netpoll.carrier_timeout=*|no387|no_console_suspend|noaliencache);; noalign|noapic|noautogroup|nobats|nocache|noclflush|nodelayacct);; nodisconnect|nodsp|noefi|noexec|nosmap|nosmep|noexec32|nofpu|nofxsr);; noxsave|eagerfpu=*|nohlt|no-hlt|no_file_caps|nohalt|nohz=*|noiotrap);; noirqdebug|no_timer_check|noisapnp|noinitrd|nointremap|nointroute);; nojitter|no-kvmclock|no-kvmapf|no-steal-acc|nolapic|nolapic_timer);; noltlbs|nomca|nomce|nomfgpt|nonmi_ipi|nomodule|nopat|norandmaps);; noreplace-paravirt|noreplace-smp|noresidual|nordrand|noresume);; no-scroll|nosbagart|nosep|nosmp|nosoftlockup|nosync|notsc|nousb);; nowatchdog|nowb|nox2apic|cpu0_hotplug|nptcg=*|nr_cpus=*|nr_uarts=*);; numa_balancing=*|numa_zonelist_order=*|ohci1394_dma=*);; olpc_ec_timeout=*|omap_mux=*|oprofile.timer=*|oprofile.cpu_type=*);; oops=*|OSS|panic=*|parkbd.port=*|parkbd.mode=*|parport=*);; parport_init_mode=*|pause_on_oops=*|pcbit=*|pcd.|pci=*|pcie_aspm=*);; pcie_hp=*|pcie_ports=*|pcie_pme=*|pcmv=*|pd.|pdcchassis=*);; percpu_alloc=*|pf.|pg.|pirq=*|plip=*|pmtmr=*|pnp.debug=*|pnpacpi=*);; pnpbios=*|pnp_reserve_irq=*|pnp_reserve_dma=*|pnp_reserve_io=*);; pnp_reserve_mem=*|ports=*|print-fatal-signals=*);; printk.always_kmsg_dump=*|printk.time=*|processor.max_cstate=*);; processor.nocst|profile=*|prompt_ramdisk=*|psmouse.proto=*);; psmouse.rate=*|psmouse.resetafter=*|psmouse.resolution=*);; psmouse.smartscroll=*|pstore.backend=*|pt.|pty.legacy_count=*|quiet);; r128=*|raid=*|ramdisk_blocksize=*|ramdisk_size=*|rcu_nocbs=*);; rcu_nocb_poll|rcutree.blimit=*|rcutree.fanout_leaf=*);; rcutree.qhimark=*|rcutree.qlowmark=*|rcutree.rcu_cpu_stall_suppress=*);; rcutree.rcu_cpu_stall_timeout=*|rcutree.jiffies_till_first_fqs=*);; rcutree.jiffies_till_next_fqs=*|rcutorture.fqs_duration=*);; rcutorture.fqs_holdoff=*|rcutorture.fqs_stutter=*);; rcutorture.irqreader=*|rcutorture.n_barrier_cbs=*);; rcutorture.nfakewriters=*|rcutorture.nreaders=*);; rcutorture.onoff_holdoff=*|rcutorture.onoff_interval=*);; rcutorture.shuffle_interval=*|rcutorture.shutdown_secs=*);; rcutorture.stall_cpu=*|rcutorture.stall_cpu_holdoff=*);; rcutorture.stat_interval=*|rcutorture.stutter=*);; rcutorture.test_boost=*|rcutorture.test_boost_duration=*);; rcutorture.test_boost_interval=*|rcutorture.test_no_idle_hz=*);; rcutorture.torture_type=*|rcutorture.verbose=*|rdinit=*|reboot=*);; relax_domain_level=*|reserve=*|reservetop=*|reservelow=*);; reset_devices|resume=*|resume_offset=*|resumedelay=*|resumewait);; hibernate=*|retain_initrd|rhash_entries=*|riscom8=*|ro|root=*);; rootdelay=*|rootflags=*|rootfstype=*|rootwait|rw|S|sa1100ir|sbni=*);; sched_debug|skew_tick=*|security=*|selinux=*|apparmor=*|serialnumber);; shapers=*|show_msr=*|simeth=*|simscsi=*|slram=*|slab_max_order=*);; slub_debug|slub_debug=*|slub_max_order=*|slub_min_objects=*);; slub_min_order=*|slub_nomerge|smart2=*|smsc-ircc2.nopnp);; smsc-ircc2.ircc_cfg=*|smsc-ircc2.ircc_sir=*|smsc-ircc2.ircc_fir=*);; smsc-ircc2.ircc_irq=*|smsc-ircc2.ircc_dma=*);; smsc-ircc2.ircc_transceiver=*|softlockup_panic=*|sonypi.*=*);; specialix=*|spia_io_base=*|spia_fio_base=*|spia_pedr=*|spia_peddr=*);; stacktrace|stacktrace_filter=*|sti=*|sti_font=*|stifb=*);; sunrpc.min_resvport=*|sunrpc.max_resvport=*|sunrpc.pool_mode=*);; sunrpc.tcp_slot_table_entries=*|sunrpc.udp_slot_table_entries=*);; swapaccount|swapaccount=*|swiotlb=*|switches=*|sysfs.deprecated=*);; sysrq_always_enabled|tdfx=*|test_suspend=*|thash_entries=*);; thermal.act=*|thermal.crt=*|thermal.nocrt=*|thermal.off=*);; thermal.psv=*|thermal.tzp=*|threadirqs|topology=*|tp720=*);; tpm_suspend_pcr=*|trace_buf_size=*|trace_event=*|trace_options=*);; transparent_hugepage=*|tsc=*|turbografx.map[23]=*|udbg-immortal);; uhash_entries=*|uhci-hcd.ignore_oc=*|unknown_nmi_panic);; usbcore.authorized_default=*|usbcore.autosuspend=*);; usbcore.usbfs_snoop=*|usbcore.blinkenlights=*);; usbcore.old_scheme_first=*|usbcore.usbfs_memory_mb=*);; usbcore.use_both_schemes=*|usbcore.initial_descriptor_timeout=*);; usbhid.mousepoll=*|usb-storage.delay_use=*|usb-storage.quirks=*);; user_debug=*|userpte=*|vdso=*|vdso32=*|vector=*|video=*);; virtio_mmio.device=*|vga=*|vmalloc=*|vmhalt=*|vmpanic=*|vmpoff=*);; vsyscall=*|vt.cur_default=*|vt.default_blu=*|vt.default_grn=*);; vt.default_red=*|vt.default_utf8=*|vt.global_cursor_default=*);; watchdog|x2apic_phys|x86_mrst_timer=*|xd=*|xd_geo=*|xen_emul_unplug=*);; xirc2ps_cs=*);; drm.*|i915.*) ;; nomodeset|*.modeset=*);; nosplash|splash=*|fbcon=*);; #------------------------------------------------------------------------ # NOTE: see /live/custom/$DISTRO_NAME/0.sh for distro specific boot codes #------------------------------------------------------------------------ *) UNKNOWN_BOOTCODES="$UNKNOWN_BOOTCODES $param" esac done BOOT_RETRY=${CMD_RETRY:-$BOOT_RETRY} FRUGAL_RETRY=${CMD_RETRY:-$FRUGAL_RETRY} PERSIST_RETRY=${CMD_RETRY:-$PERSIST_RETRY} BOOT_RETRY=${CMD_BOOT_RETRY:-$BOOT_RETRY} FRUGAL_RETRY=${CMD_FRUGAL_RETRY:-$FRUGAL_RETRY} PERSIST_RETRY=${CMD_PERSIST_RETRY:-$PERSIST_RETRY} if [ "$DISABLE_STORE" ]; then USER_UID=0 USER_GID=0 fi } small_int() { local var=$1 val=${2#*=} name=${2%%=*} param=$2 case $val in "") return ;; [0-9]|[0-9][0-9]) eval $var=\$val; return ;; esac INTEGER_ERRORS="$INTEGER_ERRORS $param" } any_int() { local var=$1 val=${2#*=} name=${2%%=*} param=$2 if echo $val | egrep -q "^[0-9]+$"; then eval $var=\$val return fi INTEGER_ERRORS="$INTEGER_ERRORS $param" } coldplug_delay() { [ "$COLDPLUG_DELAY" ] || return msg "Waiting %s seconds for buses to settle ..." $(nq $COLDPLUG_DELAY) sleep $COLDPLUG_DELAY } start_coldplug_loop() { coldplug-loop $PLUG_LOOP_DELAY &>/dev/null 17>/dev/null & COLDPLUG_LOOP_PID=$! vmsg 6 'Coldplug loop pid: %s' $(nq $COLDPLUG_LOOP_PID) echo $COLDPLUG_LOOP_PID > /COLDPLUG_LOOP_PID } start_hotplug() { local trace_load=$1 targ=/proc/sys/kernel/hotplug # Set up file for recording sequence of kernel events sent to mdev echo > /dev/mdev.seq if [ ! -e $targ -o -n "$FORCE_COLDPLUG_LOOP" ]; then start_coldplug_loop return fi if [ "$trace_load" ]; then echo $LIVE_BIN/mdev-trace | tee $targ &>/dev/null else echo $LIVE_BIN/mdev-hotplug | tee $targ &>/dev/null fi } stop_hotplug() { local targ=/proc/sys/kernel/hotplug test -e $targ && echo | tee $targ &>/dev/null test -r /COLDPLUG_LOOP_PID || return read COLDPLUG_LOOP_PID < /COLDPLUG_LOOP_PID vmsg 6 'kill coldplug loop pid: %s' $(nq $COLDPLUG_LOOP_PID) rm /COLDPLUG_LOOP_PID kill -9 $COLDPLUG_LOOP_PID } old_stop_hotplug() { local targ=/proc/sys/kernel/hotplug test -e $targ && echo | tee $targ &>/dev/null } list_modules() { local mod list cnt=0 list=$( echo $(lsmod | grep "^[a-z]" | cut -d" " -f1) | sort) cnt=$(echo $list | wc -w) # loaded modules(s) vmsg 6 'Loaded %s module(s)' $(nq $cnt) [ "$list" ] && vmsg 7 "$white$list" [ "$ERR_MODULES" ] || return local ecnt=$(echo "$ERR_MODULES" | wc -w) vmsg 6 '%s module(s) failed to load' $(nq $ecnt) vmsg 7 "$white$ERR_MODULES" } select_breakpoints() { case $BREAK_POINTS in *\?*|*ask*) echo echo "${m_co}Remaining ${hi_co}$ME$m_co breakpoints:$nc_co" echo sed -rn 's/^\s*breakpoint ([1-9a-z])\> */ \1) /p' $0 | sed "s/['\"]//g" | sort echo echo "${m_co}Use \"a\" to set most breakpoints$nc_co" echo "${m_co}Use \"A\" to set all breakpoints$nc_co" echo "${m_co}Use \"bash\" to enter a Bash shell before system starts$nc_co" echo printf "${ok_co}%s$m_co: $nc_co" "Enter breakpoint(s) separated by commas" setsid cttyhack > /dev/null read BREAK_POINTS;; esac } mem_info() { local info amt kb while read info amt kb; do [ ! "$info" = "$1:" ] && continue echo $((amt / 1024)) return done /issue if lspci -n | grep -iq " 80ee:beef"; then vmsg 7 'VirtualBox detected' touch /live/config/virtualbox fi local bat_stat=$(battery-status | sed "s/:/:$hi_co/" ) [ -n "$DB_PLUS" -a -n "$bat_stat" ] && msg %s "$bat_stat" # Get total ramsize, and available real ram in MB. We need this later. local total_mem=$(mem_info MemTotal) local used_mem=$((total_mem - FREE_MEM)) vmsg 8 "$white $(busybox | head -n 1)" [ -x /bin/ntfs-3g ] && vmsg 8 "$white $(ntfs-3g --version 2>&1)" vmsg 6 "%25s: $white%s" 'initrd version' "$version" vmsg 6 "%25s: $white%s" 'initrd built' "$v_date" # Print meminfo. local mem_format="${m_co}%s: $num_co%5d${m_co} M" vmsg 8 "$mem_format" ' Total Memory' $total_mem # vmsg 6 "$mem_format" ' Free Memory' $FREE_MEM vmsg 8 "$mem_format" ' Used Memory' $used_mem local cpu_format="%s:$white %s" vmsg 5 "$cpu_format" ' Linux kernel' "$(uname -r)" vmsg 8 "$cpu_format" ' Screen width' "$SCREEN_WIDTH" vmsg 8 "$cpu_format" ' Kernel arch' "$(uname -m)" local product_name board_vendor id_dir=/sys/class/dmi/id read product_name 2>/dev/null < $id_dir/product_name read board_vendor 2>/dev/null < $id_dir/board_vendor vmsg 8 "$cpu_format" ' Hardware' "$board_vendor $product_name" # vmsg 6 "$cpu_format" ' CPU' "$(cpu_param 'model name' unknown)" # vmsg 6 "$cpu_format" ' Cores' "$num_co$(cpu_param 'cpu cores' 1)" # vmsg 6 "$cpu_format" ' Cache' "$(cpu_param 'cache size' unknown)" } show_bootcodes() { local unknown=$1 vmsg 5 "%s:" "Current boot codes" vmsg 5 " $white $(cat /proc/cmdline)" [ -n "$unknown" -a -n "$CHECK_BOOTCODES" ] || return vmsg 4 vmsg 4 "$warn_co%s:" "Possibly unknown or misspelled boot codes" vmsg 4 "(%s)" "don't take this too seriously" local code for code in $unknown; do vmsg 4 "$hi_co $code" done vmsg 4 } show_integer_errors() { local param name value params=$1 # Only small integer values are allowed for . Will ignore for param in $params; do name=${param%%=*} value=${param#*=} warn 'Only small integer values are allowed for %s. Will ignore %s' \ $(pqw $name) $(pqw $param) done } show_disable_errors() { local codes=$1 ds_param=$2 [ -n "$codes" ] || return local bad=$(echo "$codes" | sed -r "s/$DISABLE_SERVICES_OPTS//g") [ -n "$bad" ] || return #. Unknown options in . Unknown options(s): warn "Unknown option(s) in %s. Unknown option(s): %s" "$(pqw $ds_param)" "$(pqw $bad)" } cpu_param() { local result=$(grep "^$1" /proc/cpuinfo | head -n 1 | sed 's/.*\t: //') [ "$result" ] || result=$2 echo "$result" } disable_hcd() { local type=$1 local dir=/sys/bus/pci/drivers/${type}_hcd local symlink kmsg=/dev/kmsg test -d $dir || return for symlink in $(find $dir -name "0*" | sed 's=.*/=='); do echo $symlink >> $DISABLED_USB_FILE.$type msg 'disable %s bus: %s' $(nq $type) $(pq $symlink) [ -e $kmsg ] && echo "initrd disabled $type: $symlink" >> $kmsg echo $symlink > $dir/unbind done } set_fbcondecor() { local boot_param=$1 orig_name=$2 param verbose theme=default #vmsg 5 "set_fbcondecor('$1' '$2')" [ "$orig_name" ] || return [ "$boot_param" ] || return #vmsg 5 "Got boot param: $param" local prog=/bin/fbcondecor_ctl.static test -x $prog || return #vmsg 5 "found $prog" local new_name read new_name 2>/dev/null /dev/null $prog -t $theme -c setpic 2>/dev/null $prog -c on 2>/dev/null } blacklist_modules() { local black_list=$1 [ "$black_list" ] || return black_list=$(echo $black_list | sed -r "s/(VIDEO|KMS)/$KMS_VIDEO_MODULES/"); mkdir -p /etc/modprobe.d/ echo $black_list | sed 's/,/\n/g' | sed -r 's/^([a-z])/blacklist \1/' >> $BLACK_LIST_FILE } load_kernel_modules() { local list=$1 file=$2 # if [ -r $file ]; then # vmsg 7 'Load modules from file %s' "$(fq $file)" # grep -v "^\s*#" $file | sed 's/\s*#.*//' | xargs modprobe -a -q -b # fi coldplug_modules 5 for module in ${list//,/ }; do case $module in all) load_all_modules ;; *) modprobe -q $module || warn "Could not load module %s" $(pqw $module);; esac done } load_all_modules() { local subdir=$1 msg "Loading all modules" debug_cmd lsmod debug_cmd lspci LOAD_ALL_MODULES=true find $MOD_DIR/$subdir -name "*.ko" | sed -e 's=.*/==' -e 's/\.ko$//' \ | xargs modprobe -q -a -b 2>/dev/null } debug_cmd() { echo "==== $*" >> $MY_LOG "$@" >> $MY_LOG echo "==============================" >> $MY_LOG } coldplug_modules() { local verb=$1 [ "$verb" ] && vmsg $verb "Loading hardware specific modules ..." #find /sys/devices -name uevent -exec sed -n 's/^MODALIAS=//p' '{}' + 2>/dev/null \ # | sort -u | xargs modprobe -a -q -b #return #find /sys/devices -name modalias -exec cat '{}' + 2>/dev/null | sort -u \ # | xargs modprobe -a -q -b 2>/dev/null find /sys/devices -name modalias -print0 | xargs -0 sort -u \ | xargs modprobe -a -q -b 2>/dev/null return # local alias_file alias # find /sys/devices -name modalias | while read alias_file; do # alias=$(cat $alias_file 2>/dev/null) # modprobe -q -b $alias 2>/dev/null # done } #============================================================================== # Find the squashfs file #============================================================================== #------------------------------------------------------------------------------ # Function: is_usb_or_removable #------------------------------------------------------------------------------ is_usb_or_removable() { local drive=$(get_drive $1) local dir=/sys/block/$drive flag read flag 2>/dev/null < $dir/removable [ "$flag" = 1 ] && return 0 local devpath=$(readlink -f $dir/device) [ "$devpath" ] || return 1 echo $devpath | grep -q /usb return $? } is_removable() { local drive=$(get_drive $1) local dir=/sys/block/$drive flag read flag 2>/dev/null < $dir/removable [ "$flag" = 1 ] return $? } #------------------------------------------------------------------------------ # Function: get_drive #------------------------------------------------------------------------------ get_drive() { local drive part=${1##*/} case $part in mmcblk*) echo ${part%p[0-9]} ;; *) drive=${part%[0-9]} ; echo ${drive%[0-9]} ;; esac } #------------------------------------------------------------------------------ # Function: from_filter # # Filter and order devices in list according to types listed in $FROM_TYPE. # Output goes into FILTERED_LIST so we can give error messages from within. # Return true if there is at least one item in the FILTERED_LIST otherwise # return false. Error out if there is an invalid from= type. # # See LINUX ALLOCATED DEVICES for device numbers # https://www.kernel.org/doc/Documentation/devices.txt # # 3 block First MFM, RLL and IDE hard disk/CD-ROM interface hda, hdb # 8 block SCSI disk devices (0-15) sda, sdb, ... sdp # 22 block Second IDE hard disk/CD-ROM interface hdc, hdd # 179 block MMC block devices mmcblk0, mmcblk1, ... mmcblk7 #------------------------------------------------------------------------------ from_filter() { FILTERED_LIST= local from_type invalid_scan case ,$FROM_TYPE, in *,all,*) from_type=$FROM_TYPE_ALL;; *) from_type=$FROM_TYPE;; esac # First segregate devices by type local dev cd_devs hd_devs usb_devs mmc_devs for dev; do [ -b "$dev" ] || continue case $(stat -c %t $dev) in b) cd_devs="$cd_devs $dev" ;; b3) mmc_devs="$mmc_devs $dev" if is_removable $dev; then usb_devs="$usb_devs $dev" else hd_devs="$hd_devs $dev" fi ;; 3|8|22|103) if is_usb_or_removable $dev; then usb_devs="$usb_devs $dev" else hd_devs="$hd_devs $dev" fi ;; esac done local type for type in ${from_type//,/ }; do case $type in cd) FILTERED_LIST="$FILTERED_LIST$cd_devs" cd_devs= ;; usb) FILTERED_LIST="$FILTERED_LIST$usb_devs" usb_devs= ;; hd) FILTERED_LIST="$FILTERED_LIST$hd_devs" hd_devs= ;; mmc) FILTERED_LIST="$FILTERED_LIST$mmc_devs" mmc_devs= ;; "") ;; *) invalid_scan="$invalid_scan $type";; esac done # Invalid value(s) [ "$invalid_scan" ] \ && _fatal "$(printf 'Invalid %s values(s) %s' "$(pqh from=)" "$(pqh $invalid_scan)")" \ "$(printf 'Valid values are %s' "$(cq cd hd mmc usb all)")" [ "$FILTERED_LIST" ] return $? } find_boot_file() { local ret find_files boot "$@" ret=$? local file=$1 case $ret in 10) fatal "No %s devices found" block ;; 20) fatal "No %s devices found" $(pqh $FROM_TYPE) ;; 30) _fatal "" \ "$(printf "The %s parameter is blocking device %s" \ $(pqh from=$FROM_TYPE) "$(pqh $DEVICE_LIST)")" \ "$(printf "Even though device %s has %s" "$(pqh $DEVICE_LIST)" "$(pqh $device_id)")" \ "$(printf "Remove the %s boot parameter to allow that device to be scanned" \ $(cq $FROM_TYPE))" ;; 40) fatal "Device found but could not find %s file on device" $(pqh $file) ;; esac return $ret } #------------------------------------------------------------------------------ # Function: find_files