slitaz-boot-scripts rev 276 4.6
log from any boot console
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jan 24 11:30:41 2012 +0100 (2012-01-24) |
parents | 6208c17a9e42 |
children | a6d3a3585e91 |
files | etc/init.d/rcS init |
line diff
1.1 --- a/etc/init.d/rcS Tue Jun 14 21:13:21 2011 +0200 1.2 +++ b/etc/init.d/rcS Tue Jan 24 11:30:41 2012 +0100 1.3 @@ -10,9 +10,11 @@ 1.4 1.5 # Set TZ and boot time. 1.6 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)" 1.7 -bootdate=`date +%s` 1.8 +[ -n "$bootdate" ] || bootdate=`date +%s` 1.9 1.10 -if [ "$1" != "logged" ]; then # logged 1.11 +case "$1" in 1.12 + 1.13 +readonly) 1.14 1.15 # Graphical boot start. 1.16 if [ "$FBSPLASH" == "yes" ]; then 1.17 @@ -32,26 +34,6 @@ 1.18 1.19 [ "$FBSPLASH" == "yes" ] && echo "10" > /etc/fbsplash/fifo 1.20 1.21 -# Parse cmdline args for earlier boot options. All other boot options 1.22 -# are in /etc/init./bootopts.sh. 1.23 -echo -n "Searching for early boot options..." 1.24 -for opt in `cat /proc/cmdline` 1.25 -do 1.26 - case $opt in 1.27 - fastbootx|fbx) 1.28 - export FAST_BOOT_X="yes" ;; 1.29 - cdrom=*) 1.30 - export CDROM=${opt#cdrom=} ;; 1.31 - modprobe=*) 1.32 - export MODPROBE="yes" ;; 1.33 - config=*) 1.34 - export CONFIG=${opt#config=} ;; 1.35 - *) 1.36 - continue ;; 1.37 - esac 1.38 -done 1.39 -status 1.40 - 1.41 [ "$FBSPLASH" == "yes" ] && echo "20" > /etc/fbsplash/fifo 1.42 1.43 # Before mounting filesystems we check fs specified in the file 1.44 @@ -68,6 +50,9 @@ 1.45 # Remount rootfs rw. 1.46 echo "Remounting rootfs read/write..." 1.47 /bin/mount -o remount,rw / 1.48 +;; 1.49 + 1.50 +readwrite) 1.51 1.52 # Trigger Udev and handle hotplug events 1.53 if [ "$UDEV" = "yes" ]; then 1.54 @@ -89,10 +74,29 @@ 1.55 1.56 # Store boot messages to log files. 1.57 /bin/dmesg > /var/log/dmesg.log & 1.58 -conspy -d | sed 's/ *$//;/^$/d;/^Processi\|^.witchi/,$!d' > /var/log/boot.log 1.59 -script -a -q -c '/etc/init.d/rcS logged' /var/log/boot.log 1.60 +;; 1.61 1.62 -else # logged 1.63 +logged) 1.64 + 1.65 +# Parse cmdline args for earlier boot options. All other boot options 1.66 +# are in /etc/init./bootopts.sh. 1.67 +echo -n "Searching for early boot options..." 1.68 +for opt in `cat /proc/cmdline` 1.69 +do 1.70 + case $opt in 1.71 + fastbootx|fbx) 1.72 + export FAST_BOOT_X="yes" ;; 1.73 + cdrom=*) 1.74 + export CDROM=${opt#cdrom=} ;; 1.75 + modprobe=*) 1.76 + export MODPROBE="yes" ;; 1.77 + config=*) 1.78 + export CONFIG=${opt#config=} ;; 1.79 + *) 1.80 + continue ;; 1.81 + esac 1.82 +done 1.83 +status 1.84 1.85 # Clean up the system. 1.86 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then 1.87 @@ -280,5 +284,19 @@ 1.88 echo $time > /var/log/boot-time 1.89 echo "SliTaz boot time: ${time}s" 1.90 [ "$FBSPLASH" == "yes" ] && echo "exit" > /etc/fbsplash/fifo 1.91 +;; 1.92 1.93 -fi # logged 1.94 +*) 1.95 +if [ ! -s /dev/shm/boot.log ]; then 1.96 + mount -t devpts devpts /dev/pts 1.97 + mount -t tmpfs tmpfs /dev/shm 1.98 +fi 1.99 +script -aqc '/etc/init.d/rcS readonly' /dev/shm/boot.log 1.100 +mv -f /dev/shm/boot.log /boot.log 1.101 +umount /dev/shm 1.102 +script -aqc '/etc/init.d/rcS readwrite' /boot.log 1.103 +mv -f /boot.log /var/log/boot.log 1.104 +script -aqc '/etc/init.d/rcS logged' /var/log/boot.log 1.105 +;; 1.106 + 1.107 +esac
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/init Tue Jan 24 11:30:41 2012 +0100 2.3 @@ -0,0 +1,180 @@ 2.4 +#!/bin/sh 2.5 + 2.6 +launch_init() 2.7 +{ 2.8 + [ -d /proc/sys ] && umount /proc 2.9 + echo -e "\\033[70G[ \\033[1;32mOK\\033[0;39m ]" 2.10 + cat > /dev/shm/init <<EOT 2.11 +mount --move /dev/pts /mnt/dev/pts 2.12 +mount --move /dev/shm /mnt/dev/shm 2.13 +exec /sbin/switch_root mnt /sbin/init 2.14 +EOT 2.15 + exit 2.16 +} 2.17 + 2.18 +failed() 2.19 +{ 2.20 + umount /proc 2.21 + echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]" 2.22 +} 2.23 + 2.24 +try_init() 2.25 +{ 2.26 + if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then 2.27 + modprobe dm-mod 2.28 + modprobe dm-crypt 2.29 + modprobe aes-i586 2.30 + root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.31 + dev=${root#/dev/} 2.32 + dmlabel=crypto-$dev 2.33 + if cryptsetup isLuks $root 2> /dev/null; then 2.34 + cryptsetup luksOpen $root $dmlabel 2.35 + else 2.36 + read -s -t 60 -p "Pass phrase : " passphrase 2.37 + key=$(echo $passphrase | hashalot -x -n 32 sha512) 2.38 + blocks=$(cat $(find /sys/block | grep /$dev/size)) 2.39 + echo 0 $blocks crypt aes-plain $key 0 $root 0 | \ 2.40 + dmsetup create $dmlabel 2.41 + fi 2.42 + mount /dev/mapper/$dmlabel /mnt 2.43 + fi 2.44 + if [ -d /mnt/etc ]; then 2.45 + umount /sys 2.46 + [ -n "$1" ] && for i in $@ ; do 2.47 + cp -a $i /mnt$(dirname $i) 2.48 + done 2.49 + mount /mnt -o remount,ro 2.50 + launch_init 2.51 + fi 2.52 + failed 2.53 +} 2.54 + 2.55 +mount_mapper() 2.56 +{ 2.57 + mount $root /mnt 2.58 + try_init /dev/mapper $@ 2.59 +} 2.60 + 2.61 +lvmsetup() 2.62 +{ 2.63 + grep -q lvmroot= /proc/cmdline || return 1 2.64 + modprobe dm-mod 2.65 + vgscan --ignorelockingfailure 2.66 + vgchange -ay --ignorelockingfailure 2.67 + root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.68 + return 0 2.69 +} 2.70 + 2.71 +load_raid() 2.72 +{ 2.73 +while read line; do 2.74 + case "$line" in 2.75 + *raid10*) modprobe raid10 ;; 2.76 + *raid0*) modprobe raid0 ;; 2.77 + *raid1*) modprobe raid1 ;; 2.78 + *raid[456]*) modprobe raid456 ;; 2.79 + esac 2.80 +done 2.81 +} 2.82 + 2.83 +if [ "$1" != "logged" ]; then 2.84 + mount -t devpts devpts /dev/pts 2.85 + mount -t tmpfs tmpfs /dev/shm 2.86 + script -qc '/init logged' /dev/shm/boot.log 2.87 + . /dev/shm/init 2.88 +else 2.89 +mount -t proc proc /proc 2.90 +mount -t sysfs sysfs /sys 2.91 +echo -n "Switching / to " 2.92 +if grep -q dmraid= /proc/cmdline; then 2.93 + root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.94 + echo -n "dmraid $root..." 2.95 + dmraid -s | grep ^type | awk '{ print $3 }' | load_raid 2.96 + case "$root" in 2.97 + /dev/*);; 2.98 + *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};; 2.99 + esac 2.100 + dmraid -ay 2.101 + lvmsetup 2.102 + mount_mapper 2.103 +fi 2.104 +if grep -q softraid= /proc/cmdline; then 2.105 + root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.106 + echo -n "softraid $root..." 2.107 + mdadm --examine --scan --config=partitions > /etc/mdadm.conf 2.108 + grep -qs " $root " /etc/mdadm.conf || 2.109 + root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf) 2.110 + grep level=raid /etc/mdadm.conf | load_raid 2.111 + for i in 1 2 3 4 5 6 7 8 9; do 2.112 + sleep $i 2.113 + mdadm --assemble --scan 2.114 + grep -qs ': active' /proc/mdstat && break 2.115 + done 2.116 + lvmsetup 2.117 + mount_mapper /etc/mdadm.conf 2.118 +fi 2.119 +if lvmsetup; then 2.120 + echo -n "lvm $root..." 2.121 + mount_mapper 2.122 +fi 2.123 +if grep -q mount= /proc/cmdline; then 2.124 + root="$(sed 's/.*mount=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.125 + dev=$(blkid | grep $root | sed 's/:.*//;q') 2.126 + echo -n "Mounting $dev ($root) ..." 2.127 + if ! mount $dev /mnt; then 2.128 + if echo $dev | grep -q "/dev/sd"; then 2.129 + delay=`cat /sys/module/usb_storage/parameters/delay_use` 2.130 + delay=$((1+$delay)) 2.131 + echo -n "sleep for $delay seconds..." 2.132 + sleep $delay 2.133 + fi 2.134 + mount $dev /mnt 2.135 + fi 2.136 + grep -q posixovl /proc/cmdline && mount.posixovl /mnt 2.137 +fi 2.138 +if grep -q loopfs= /proc/cmdline; then 2.139 + loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.140 + echo -n "loop $loopfs..." 2.141 + losetup /dev/loop0 /mnt/$loopfs 2.142 + mount /dev/loop0 /mnt 2> /dev/null 2.143 +fi 2.144 +if grep -q bindfs= /proc/cmdline; then 2.145 + bind="$(sed 's/.*bindfs=\([^ ]*\).*/\1/' < /proc/cmdline)" 2.146 + mount --bind /mnt/${bind%,*} /mnt/${bind%,*}/${bind#*,} 2.147 +fi 2.148 +grep -q cryptoroot= /proc/cmdline && try_init 2.149 +umount /sys 2.150 +if grep -q subroot= /proc/cmdline; then 2.151 + subroot="/$(sed 's/.*subroot=\([^ ]*\).*/\1/' < /proc/cmdline)" && 2.152 + if [ -s /usr/share/boot/busybox-static ]; then 2.153 + mv /usr/share/boot/busybox-static . 2.154 + /busybox-static rm -rf /etc /lib /*bin /usr /var 2.155 + echo "exec /busybox-static chroot /mnt$subroot /sbin/init" > /dev/shm/init 2.156 + else 2.157 + echo "exec chroot /mnt$subroot /sbin/init" > /dev/shm/init 2.158 + fi 2.159 +fi 2.160 +echo -n "tmpfs..." 2.161 +size="$(grep rootfssize= < /proc/cmdline | \ 2.162 + sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')" 2.163 +free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }') 2.164 +umount /proc 2.165 +[ -n "$size" ] || size="-o size=90%" 2.166 +echo "exec /sbin/init" > /dev/shm/init 2.167 +if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then 2.168 + echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]" 2.169 + exit 2.170 +fi 2.171 +for i in $(ls -a /); do 2.172 + case "$i" in 2.173 + .|..) ;; 2.174 + mnt) mkdir /mnt/mnt;; 2.175 + *) if ! cp -a /$i /mnt 2> /dev/null; then 2.176 + failed 2.177 + umount /mnt 2.178 + exit 2.179 + fi;; 2.180 + esac 2.181 +done 2.182 +launch_init 2.183 +fi