diff options
-rwxr-xr-x | make-boot-image.sh | 171 |
1 files changed, 99 insertions, 72 deletions
diff --git a/make-boot-image.sh b/make-boot-image.sh index 470eeed..7b80a7e 100755 --- a/make-boot-image.sh +++ b/make-boot-image.sh @@ -1,5 +1,6 @@ #!/bin/bash -xe -PS4='+ ($LINENO) ' +PS4='+ ($LINENO) ' # To ease debugging +VERSION="1.0" # Config # ########## @@ -151,6 +152,10 @@ while more_work and i < 10: if name in ['EFI_STUB', 'EFI_VARS', 'DELL_RBU', 'USB_XHCI_HCD', 'IKCONFIG']: more_work = sset(sym) or more_work + # Support FUSE for ntfs-3g + if name in ['FUSE_FS']: + more_work = sset(sym) or more_work + # Support soft RAID (linux) and hard RAID (some cards) if name in ['DM_RAID', 'SCSI_LOWLEVEL', 'MEGARAID_SAS', 'MEGARAID_NEWGEN']: more_work = sset(sym) or more_work @@ -252,8 +257,12 @@ then ( mkchroot "$WORKDIR/initrd" dmidecode iftop iostat lshw lspci lsblk lsusb mpstat tcpdump # Console tools and manpages display mkchroot "$WORKDIR/initrd" setterm strace groff nroff troff grotty gtbl + # Filesystem tools + mkchroot "$WORKDIR/initrd" mkfs mke2fs /sbin/mkfs.ext* mkntfs mkfs.ntfs mkfs.fat mkexfatfs mkfs.exfat mkfs + mkchroot "$WORKDIR/initrd" ntfs-3g mount.ntfs mount.fuse mount.exfat-fuse mount.exfat + mkchroot "$WORKDIR/initrd" /sbin/ntfs* /bin/ntfs* # Disk tools - mkchroot "$WORKDIR/initrd" fdisk gdisk sfdisk sgdisk /sbin/mkfs* + mkchroot "$WORKDIR/initrd" fdisk gdisk sfdisk sgdisk # Cloning tools mkchroot "$WORKDIR/initrd" /usr/sbin/partclone* efibootmgr pigz udp-receiver # Some dyn-loaded libraries (ldd will not display them) @@ -275,6 +284,7 @@ fi if [ ! -d "$WORKDIR/initrd/usr/man" ] then mkdir -p "$WORKDIR"/initrd/usr/man/man{1,8} "$WORKDIR"/initrd/usr/share/groff/1.22.2/font "$WORKDIR/initrd/etc/groff/" cp -a /usr/share/man/man1/{iostat,mpstat,strace,udp-receiver}* "$WORKDIR/initrd/usr/man/man1/" + cp -a /usr/share/man/man8/{dmidecode,partclone,efibootmgr,ntfs,mkntfs,gdisk,iftop,tcpdump}* "$WORKDIR/initrd/usr/man/man8/" cp -a /usr/share/man/man8/{dmidecode,partclone,efibootmgr,gdisk,iftop,tcpdump}* "$WORKDIR/initrd/usr/man/man8/" cp -ra /usr/share/groff/1.22.2/font/devascii "$WORKDIR/initrd/usr/share/groff/1.22.2/font/" cp -ra /usr/share/groff/1.22.2/tmac "$WORKDIR/initrd/usr/share/groff/1.22.2/" @@ -304,6 +314,8 @@ then [ -f "$DLDIR/nic-firmware.deb" ] || $WGET -O "$DLDIR/nic-firmware.deb" "$NI find "$WORKDIR/initrd/lib/firmware/" \( -name 'ipw*' -o -name 'brcmfmac*' -o -name '*wifi*' \) -print0 | xargs -r0 rm -v fi +echo $VERSION > "$WORKDIR/initrd/etc/eficast_version" + cat > "$WORKDIR/initrd/etc/init.d/funcs" <<"EOF" # echo_color <foreground_color> <background_color> [prefix_string] <message> echo_color() { @@ -311,45 +323,26 @@ echo_color() { setterm --foreground "$1" --background "$2" [ $# -eq 4 ] && echo -n "$4" || echo -n "$3" setterm --foreground white --background black - echo + echo " (eficast v"$(cat /etc/eficast_version)")" } -rescue_shell() { - echo_color white red "Something went wrong. Dropping to a shell." - PS1='\h:\w# ' setsid cttyhack /bin/busybox sh +# if no args, print colored message, wait 1 minute and reboot +# if first arg is 'silent', just reboot +eficast_end() { + if [ "$1" -ne 'silent'] + then echo_color white green "----- EFICAST end of execution ------" + sleep 60 + fi sync umount /dev /sys /proc #umount /dev/pts /dev /sys /proc reboot -f } -mount_pseudofilesystems() { - # Mount pseudo-filesystems - mount -t proc none /proc || return $? - mount -t sysfs none /sys || return $? - mount -t devtmpfs -o size=1m none /dev || return $? - ln -s /proc/self/fd/2 /dev/stderr - #mkdir /dev/pts - #mount -t devpts none /dev/pts - return 0 -} - -tty_prog() { - tty=/dev/tty$1; shift - while true - do - echo "(re)spawning $* on $tty" >$tty - setsid sh -c "exec $* <$tty >$tty 2>&1" - sleep 2 - done -} - -network_up() { - ip -oneline link | grep DOWN | cut -d: -f2 | grep -v sit | while read iface - do - echo ip link set dev $iface up - ip link set dev $iface up - done +rescue_shell() { + echo_color white red "Something went wrong. Dropping to a shell." + PS1='\h:\w# ' /bin/busybox sh + eficast_end silent } machine_info() { @@ -371,7 +364,7 @@ machine_info() { network_conf() { ip -oneline link | grep LOWER_UP | cut -d: -f2 | grep -v sit | grep -v lo | while read iface do - udhcpc -b $iface + udhcpc -b $iface -t 15 done } @@ -381,21 +374,14 @@ network_show() { setterm -bold off } -nfs_check() { - [ -x /mnt/nfs/autorun.sh ] || return 1 - echo_color white green "----- NFS server ready ------" -} - nfs_autorun() { - # Run it in background, so busybox will see rcS ending and will allow others consoles to spawn - PS1='\h:\w#' exec setsid cttyhack /mnt/nfs/autorun.sh & -} - -# no args, print colored message, wait 1 minute and reboot -eficast_end() { - echo_color white green "----- EFICAST end of execution ------" - sleep 60 - reboot -f + if [ -x /mnt/nfs/autorun.sh ] + then echo_color white green "----- NFS server ready ------" + echo_color green black "autorun.sh script will run on tty1 now" + cd /mnt/nfs && ./autorun.sh + else + echo_color white red "----- NFS server NOT ready ------" + fi } EOF @@ -407,7 +393,7 @@ cat > "$WORKDIR/initrd/etc/inittab" <<"EOF" ::shutdown:/sbin/swapoff -a ::shutdown:/bin/umount -a -r ::restart:/sbin/init -tty1::respawn:/bin/autorun_once.sh +tty1::respawn:/bin/rc2_once.sh tty2::askfirst:/bin/sh tty3::askfirst:/bin/sh tty4::askfirst:/bin/sh @@ -415,37 +401,77 @@ EOF cat > "$WORKDIR/initrd/etc/init.d/rcS" <<"EOF" #!/bin/busybox sh -/bin/busybox sleep 3 # Let the kernel take his time to flood the console echo -e '\033[37;43m'----- rcS script started -----'\033[0m' # Hint for user about boot steps if its hangs -. /etc/init.d/funcs # Load helper functions -set -v # Trace execution -/bin/busybox --install -s || rescue_shell -mount_pseudofilesystems || rescue_shell +# Declare some funcs to have a tidy output with trace mode +rescue_shell() { + echo_color white red "Something went wrong. Dropping to a shell." + PS1='\h:\w# ' setsid cttyhack /bin/busybox sh + sync + umount /dev /sys /proc + #umount /dev/pts /dev /sys /proc + reboot -f +} + +mount_pseudofilesystems() { + # Mount pseudo-filesystems + mount -t proc none /proc || return $? + mount -t sysfs none /sys || return $? + mount -t devtmpfs -o size=1m none /dev || return $? + ln -s /proc/self/fd/2 /dev/stderr + #mkdir /dev/pts + #mount -t devpts none /dev/pts + return 0 +} + -# Allow using most of the RAM for rootfs -mount -o remount -o size=80% / +network_up() { + ip -oneline link | grep DOWN | cut -d: -f2 | grep -v sit | while read iface + do + echo ip link set dev $iface up + ip link set dev $iface up + done +} + +# Trace execution +set -v + +/bin/busybox --install -s||rescue_shell # Setup busybox symlinks for all applets +mount_pseudofilesystems || rescue_shell # Setup /dev, /proc, /sys and so + +loadkmap < /etc/keys.bmap # Load keyboard layout +setterm -blank 60 # screen sleep mode after 60 minutes -# Load keyboard layout and set screen sleep mode after 60 minutes -loadkmap < /etc/keys.bmap -setterm -blank 60 +mount -o remount -o size=80% / # Allow using most of RAM for rootfs -network_up -# Wait for physical link detection + STP + IPv6 DAD & Autoconf -sleep 15 +network_up # Bring net interfaces up (no config) + +sleep 5 # Wait for physical link detection + STP + IPv6 DAD & Autoconf + +set +v +echo -e '\033[32m/etc/init.d/rc2 script will run on tty1 now\033[0m' +echo -e '\033[37;43m----- rcS script ended -----\033[0m' # Hint for user about boot steps if its hangs +EOF +chmod +x "$WORKDIR/initrd/etc/init.d/rcS" + +cat > "$WORKDIR/initrd/etc/init.d/rc2" <<"EOF" +#!/bin/busybox sh +echo -e '\033[37;43m'----- rc2 script started -----'\033[0m' # Hint for user about boot steps if its hangs +. /etc/init.d/funcs # Load helper functions +set -v # Trace execution network_conf network_show machine_info mount -v -t nfs -o nolock 172.16.2.28:/masters /mnt/nfs || rescue_shell -nfs_check || rescue_shell +nfs_autorun || rescue_shell +eficast_end set +v -echo -e '\033[37;43m'----- rcS script ended -----'\033[0m' # Hint for user about boot steps if its hangs -echo_color green black "autorun.sh script will run on tty1 now" +echo -e '\033[37;43m'----- rc2 script ended -----'\033[0m' # Hint for user about boot steps if its hangs EOF -chmod +x "$WORKDIR/initrd/etc/init.d/rcS" +chmod +x "$WORKDIR/initrd/etc/init.d/rc2" cat > "$WORKDIR/initrd/usr/share/udhcpc/default.script" <<"EOF" #!/bin/sh @@ -472,15 +498,16 @@ esac EOF chmod +x "$WORKDIR/initrd/usr/share/udhcpc/default.script" -cat > "$WORKDIR/initrd/bin/autorun_once.sh" <<"EOF" +cat > "$WORKDIR/initrd/bin/rc2_once.sh" <<"EOF" #!/bin/busybox sh -if [ -f /run/autorun_once ] -then exec busybox sh -else touch /run/autorun_once - cd /mnt/nfs && ./autorun.sh +if [ -f /run/rc2_once ] +then source /etc/init.d/funcs + rescue_shell +else touch /run/rc2_once + /etc/init.d/rc2 fi EOF -chmod +x "$WORKDIR/initrd/bin/autorun_once.sh" +chmod +x "$WORKDIR/initrd/bin/rc2_once.sh" # XXX workaround, kernel makefile's cpio preseves everything and it is not so cool for us $ROOTCMD chown -R root: "$WORKDIR/initrd" |