diff options
-rwxr-xr-x | make-boot-image.sh | 359 |
1 files changed, 181 insertions, 178 deletions
diff --git a/make-boot-image.sh b/make-boot-image.sh index c96d14c..81cae09 100755 --- a/make-boot-image.sh +++ b/make-boot-image.sh @@ -1,34 +1,65 @@ #!/bin/bash -xe PS4='+ ($LINENO) ' # To ease debugging -VERSION="1.1-emac" +VERSION="1.2-emac-alpha1" # Config # ########## -WORKDIR=./work # Must not be with "nodev" mount option - # sudo rm -r this folder if you want to re-run everything + # Failures happens if $WORKDIR has "nodev" mount option +WORKDIR=./work # sudo rm -r this folder if you want to re-run everything DLDIR=./downloads OUTDIR=./out #OUTUSB=/dev/sdb # If enabled, it could wreck everything there ! LEGACY=n # make USB bootable key compatible with non UEFI-BIOS -DEVEL_MODE=n # Adds debugging tools in the generated image -INCLUDE_TCPDUMP=n # tcpdump costs few Mb with libcrypto +DEVEL_MODE=y # Adds debugging tools in the generated image +INCLUDE_TCPDUMP=y # tcpdump costs few Mb with libcrypto +INCLUDE_PERF=n # perf costs few Mb with libpython2.7 and so ROOTCMD=sudo WGET="wget" # "wget --no-check-certificate" could help but is a security concern -# You probably need to tweak version numbers if you have an HTTP 404 - Not found error -KERNEL_TARBALL_URL=https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.17.tar.xz -KCONFIGLIB_MAIN_URL=https://raw.githubusercontent.com/ulfalizer/Kconfiglib/v10.36.0/kconfiglib.py + +# Should be customized with your NFS server IP address or options +NFS_MOUNT_CMDLINE="mount -v -t nfs -o nolock 172.16.2.28:/masters /mnt/nfs" + +# You probably need to tweak version numbers in following URLs if you have an HTTP 404 - Not found error +KERNEL_TARBALL_URL=https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.2.9.tar.xz +KERNEL_TARBALL_URL=https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.xz +KERNEL_TARBALL_URL=https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.18.140.tar.xz +KERNEL_TARBALL_URL=https://cdn.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.xz +# KConfigLib allows to create kernel .config in a programmatic manner, in a somewhat portable way +# Main project URL is https://github.com/ulfalizer/Kconfiglib +KCONFIGLIB_MAIN_URL=https://raw.githubusercontent.com/ulfalizer/Kconfiglib/v12.13.0/kconfiglib.py KCONFIGLIB_PATCH_URL=https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch -NIC_FIRMWARE_URL=http://fr.archive.ubuntu.com/ubuntu/pool/main/l/linux-firmware/linux-firmware_1.173.5_all.deb -BUSYBOX_BIN_URL=https://busybox.net/downloads/binaries/1.26.2-defconfig-multiarch/busybox-x86_64 +NIC_FIRMWARE_URL=http://fr.archive.ubuntu.com/ubuntu/pool/main/l/linux-firmware/linux-firmware_1.178.4_all.deb +BUSYBOX_BIN_URL=https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64 PCI_IDS_URL=https://pci-ids.ucw.cz/v2.2/pci.ids USB_IDS_URL=https://usb-ids.gowdy.us/usb.ids +# Free space checking to not let everything go wrong +ROOT_MIN_AVAIL_MIO=256 +WORKDIR_MIN_AVAIL_MIO=2048 +DLDIR_MIN_AVAIL_MIO=512 +OUTDIR_MIN_AVAIL_MIO=64 + # Utilities # ############# +function check_free_space +{ + limit_mio=$1 + path="$2" + LANG=C df "$path" | tail -1 | ( + set +x + read dev total used avail percent mp + avail=${avail:--1024} + avail_mio=$(($avail/1024)) + if [ "$avail_mio" -lt "$limit_mio" ] + then echo "$mp ($dev) should have more free space $avail_mio Mio < $limit_mio Mio)" + exit 2 + fi + ) +} + function add_initrd_script { - ( echo "#!/bin/busybox sh" ; cat ) > "$WORKDIR/initrd/$1" - chmod +x "$WORKDIR/initrd/$1" + [ "$WORKDIR/initrd/$1" -nt "$0" ] || ( echo "#!/bin/busybox sh" ; cat ) > "$WORKDIR/initrd/$1" && chmod +x "$WORKDIR/initrd/$1" } # From https://landley.net/writing/rootfs-programming.html @@ -78,9 +109,13 @@ EOT exit 1 fi -mkdir -p "$WORKDIR" "$DLDIR" "$OUTDIR" umask 0022 # Needed for embeding initrd without "sudo make" in kernel dir +[ -d "$WORKDIR" ] || mkdir -p "$WORKDIR" && check_free_space $WORKDIR_MIN_AVAIL_MIO "$WORKDIR" +[ -d "$DLDIR" ] || mkdir -p "$DLDIR" && check_free_space $DLDIR_MIN_AVAIL_MIO "$DLDIR" +[ -d "$OUTDIR" ] || mkdir -p "$OUTDIR" && check_free_space $OUTDIR_MIN_AVAIL_MIO "$OUTDIR" + + # When using sudo with password auth, ask and cache pass first $ROOTCMD true @@ -90,14 +125,16 @@ then $ROOTCMD apt-get update fi if [ ! -e "$WORKDIR/apt-install-done" ] -then # Dependencies of this script (assuming default debian install or live) +then check_free_space $ROOT_MIN_AVAIL_MIO / + + # Dependencies of this script (assuming default debian install or live) $ROOTCMD apt-get install wget libncurses5-dev coreutils [ "x$LEGACY" == "xy" ] && $ROOTCMD apt-get install mbr syslinux # Dependencies for kernel building - $ROOTCMD apt-get install build-essential flex bison + $ROOTCMD apt-get install build-essential flex bison libelf-dev # Dependencies for kernel tools - [ "x$DEVEL_MODE" == "xy" ] && $ROOTCMD apt-get install libelf-dev libunwind-dev \ + [ "x$DEVEL_MODE" == "xy" ] && $ROOTCMD apt-get install libunwind-dev \ libdw-dev libaudit-dev libssl-dev libslang2-dev libnuma-dev \ systemtap-sdt-dev python-dev binutils-dev libiberty-dev libbabeltrace-ctf-dev # Optionnally qemu to run the result for santity checking @@ -128,9 +165,8 @@ then [ -s "$DLDIR/kconfiglib.py" ] || $WGET -O "$DLDIR/kconfiglib.py" "$KCONFIGLIB_MAIN_URL" [ -s "$DLDIR/makefile.patch" ] || $WGET -O "$DLDIR/makefile.patch" "$KCONFIGLIB_PATCH_URL" mkdir -p "$WORKDIR/kernel/scripts/Kconfiglib" - patch -t -p1 -d "$WORKDIR/kernel" < "$DLDIR/makefile.patch" && \ - cp "$DLDIR/kconfiglib.py" "$WORKDIR/kernel/scripts/Kconfiglib/kconfiglib.py" patch -t -p1 -d "$WORKDIR/kernel" < "$DLDIR/makefile.patch" + cp "$DLDIR/kconfiglib.py" "$WORKDIR/kernel/scripts/Kconfiglib/kconfiglib.py" fi cat >"$WORKDIR/kernel/scripts/Kconfiglib/customize.py" <<"EOT" @@ -193,21 +229,23 @@ while more_work and i < passes: more_work = sset(sym, '../initrd/') or more_work # Make kernel directly loadable by EFI, add USB3, Dell flash - if sym.name in ['EFI_STUB', 'EARLY_PRINTK_EFI', 'EFI_VARS', 'DELL_RBU', 'USB_XHCI_HCD', 'IKCONFIG']: + if sym.name in ['EFI_STUB', 'EARLY_PRINTK_EFI']: more_work = sset(sym) or more_work + if sym.name in ['EFI_VARS', 'DELL_RBU', 'USB_XHCI_HCD', 'IKCONFIG']: + more_work = sset(sym, 1) or more_work # Support FUSE, soft RAID (linux) and hard RAID (some cards) - if sym.name in ['FUSE_FS', 'DM_RAID', 'SCSI_LOWLEVEL', 'MEGARAID_SAS', 'MEGARAID_NEWGEN']: + if sym.name in ['FUSE_FS', 'DM_RAID', 'MEGARAID_SAS']: + more_work = sset(sym, 1) or more_work + if sym.name in ['SCSI_LOWLEVEL', 'MEGARAID_NEWGEN']: more_work = sset(sym) or more_work # If --debug passed as arg, make kernel aware of virtual drivers (used for testing eficast on qemu/kvm) - if debug and sym.name in ['VIRTIO_PCI', 'VIRTIO_MMIO', 'VIRTIO_NET', 'VIRTIO_BLK', 'SCSI_LOWLEVEL', 'SCSI_VIRTIO']: - more_work = sset(sym) or more_work + if debug and sym.name in ['VIRTIO_PCI', 'VIRTIO_MMIO', 'VIRTIO_NET', 'VIRTIO_BLK', 'SCSI_VIRTIO']: + more_work = sset(sym, 1) or more_work # Disable thing that are unneeded or annoying for the purpose of disk cloning - # FIXME Need NFS v3 client - if sym.name in [ 'HAMRADIO', 'HIBERNATION', 'LOGO', 'NETFILTER', # 'KEYS', 'NETWORK_FILESYSTEMS', - 'PCCARD', 'RFKILL', 'SECURITY', 'SOUND', 'SUSPEND', 'VIRTUALIZATION', 'WIRELESS', 'WLAN']: + if sym.name in [ 'HAMRADIO', 'HIBERNATION', 'LOGO', 'NETFILTER', 'PCCARD', 'RFKILL', 'SECURITY', 'SOUND', 'SUSPEND', 'VIRTUALIZATION', 'WIRELESS', 'WLAN']: more_work = sset(sym, 0) or more_work # Compress everything with XZ if available (slower, smaller) @@ -224,43 +262,39 @@ while more_work and i < passes: # Build all available net/ethernet drivers if True in [ ('drivers/net/ethernet' in node.filename) for node in sym.nodes ]: - more_work = sset(sym) or more_work - - # Try to get everything in kernel, not as a module (1=='m') - if sym.tri_value == 1 and sym.assignable and 2 in sym.assignable: - more_work = sset(sym) or more_work + if 1 in sym.assignable: + more_work = sset(sym, 1) or more_work + else: + more_work = sset(sym) or more_work # Write .config even if some symbols are unset -res = kconf.write_config(standard_config_filename()) +print(kconf.write_config(standard_config_filename())) if i == passes: print('ERROR : can\'t set some of kernel config symbols after %i passes'%passes) - res = 1 -sys.exit(res) - + sys.exit(1) +sys.exit(0) EOT chmod +x "$WORKDIR/kernel/scripts/Kconfiglib/customize.py" # Kernel prepare + make tools # ############################### -( - cd "$WORKDIR/kernel" - if [ ! -s .config ] - then make defconfig - if [ "x$DEVEL_MODE" == "xy" ] - then extra="SCRIPT_ARG=--debug" - else extra="" - fi - make scriptconfig SCRIPT=scripts/Kconfiglib/customize.py $extra +if [ ! -s "$WORKDIR/kernel/.config" ] +then pushd "$WORKDIR/kernel" + make defconfig + if [ "x$DEVEL_MODE" == "xy" ] + then extra="SCRIPT_ARG=--debug" + else extra="" fi -) + make scriptconfig SCRIPT=scripts/Kconfiglib/customize.py $extra || ( mv .config .config-broken; exit 3 ) + popd +fi -if [ "x$DEVEL_MODE" == "xy" -a ! -s "$WORKDIR/kernel/tools/perf/perf" ] -then ( - cd "$WORKDIR/kernel" - # Workaround : linux-3.16.57 (and others?) have make tools/perf broken, ignore it - make tools/perf || true - ) +if [ "x$INCLUDE_PERF" == "xy" -a ! -s "$WORKDIR/kernel/tools/perf/perf" ] +then pushd "$WORKDIR/kernel" + # Workaround : linux-3.16.57 (and others?) have make tools/perf break in some cases, ignore it + make tools/perf || true + popd fi # Initial Ram Disk building (embed in kernel) # @@ -277,26 +311,23 @@ then mkdir -p "$WORKDIR/initrd/"{bin,dev,etc/rc.d,mnt/nfs,root,proc,root,sbin,sy echo 'root:x:0:' > "$WORKDIR/initrd/etc/group" fi -# XXX workaround, kernel makefile's cpio preseves everything and it is not so cool for us +# XXX workaround, kernel makefile's cpio preseves everything. Consider using fakeroot $ROOTCMD chown -R $USER: "$WORKDIR/initrd" -if [ ! -s "$WORKDIR/initrd/bin/busybox" ] -then [ -s "$DLDIR/busybox" ] || $WGET -O "$DLDIR/busybox" "$BUSYBOX_BIN_URL" - cp "$DLDIR/busybox" "$WORKDIR/initrd/bin/busybox" - chmod +x "$WORKDIR/initrd/bin/busybox" -fi -if [ ! -L "$WORKDIR/initrd/init" ] -then ln -s /bin/busybox "$WORKDIR/initrd/init" -fi +[ -s "$DLDIR/busybox" ] || $WGET -O "$DLDIR/busybox" "$BUSYBOX_BIN_URL" +cp "$DLDIR/busybox" "$WORKDIR/initrd/bin/busybox" +chmod 0755 "$WORKDIR/initrd/bin/busybox" +ln -sf /bin/busybox "$WORKDIR/initrd/init" + +cp -a /etc/localtime "$WORKDIR/initrd/etc/" if [ ! -s "$WORKDIR/initrd/etc/keys.bmap" ] then - # FIXME fails on Debian 9 and 10 $ROOTCMD dumpkeys | $ROOTCMD loadkeys -ub > "$WORKDIR/initrd/etc/keys.bmap" - cp -a /etc/localtime "$WORKDIR/initrd/etc/" fi -if [ ! -s "$WORKDIR/initrd/usr/share/figlet/standard" ] + +if [ ! -s "$WORKDIR/initrd/usr/bin/rsync" ] then ( set +x PATH="$WORKDIR/kernel/tools/perf:/usr/sbin:/usr/bin:/sbin:/bin" @@ -321,47 +352,41 @@ then ( then # tcpdump costs few Mb with libcrypto mkchroot "$WORKDIR/initrd" tcpdump fi + ) +fi # Some needed data files +if [ ! -s "$WORKDIR/initrd/usr/share/figlet/standard.flf" ] +then cp -ra /lib/terminfo "$WORKDIR"/initrd/lib/ mkdir -p "$WORKDIR"/initrd/usr/lib/locale "$WORKDIR"/initrd/usr/share/figlet cp -ra /usr/lib/locale/C.UTF-8 "$WORKDIR"/initrd/usr/lib/locale/ - cp -a /usr/share/figlet/{standard,mono12}* "$WORKDIR"/initrd/usr/share/figlet/ - ) + cp -a /usr/share/figlet/{mono12,standard}* "$WORKDIR"/initrd/usr/share/figlet/ fi -if [ "x$DEVEL_MODE" == "xy" ] +# Perf tool : skip copy and deps if compilation has failed or was skipped +p="$WORKDIR/kernel/tools/perf/perf" +if [ -s "$p" ] then ( - # Perf tool - p="$WORKDIR/kernel/tools/perf/perf" cp -a "$p" "$WORKDIR/initrd/sbin/" set +x mkchroot "$WORKDIR/initrd" $(ldd "$p" | egrep -o '/.* ') ) fi -if [ ! -f "$WORKDIR/initrd/usr/share/groff/current/man.local" ] +if [ ! -f "$WORKDIR/initrd/etc/groff/man.local" ] then mkdir -p "$WORKDIR"/initrd/usr/man/man{1,6,8} "$WORKDIR"/initrd/usr/share/groff/current/font mkdir -p "$WORKDIR"/initrd/etc/groff/ - cp -a /usr/share/man/man1/{beep,iostat,lshw,mpstat,setterm,bc,pv,strace,tmux,pigz}* "$WORKDIR"/initrd/usr/man/man1/ - cp -a /usr/share/man/man6/figlet* "$WORKDIR"/initrd/usr/man/man6/ - cp -a /usr/share/man/man8/{dmidecode,iftop,lspci,lsblk,lsusb,partclone,efibootmgr,mkfs}* "$WORKDIR"/initrd/usr/man/man8/ - cp -a /usr/share/man/man8/{ntfs,mkntfs,mkexfatfs,mount.ntfs,mount.fuse,mount.exfat-fuse}* "$WORKDIR"/initrd/usr/man/man8/ - cp -a /usr/share/man/man8/{mount.exfat,fdisk,gdisk,sfdisk,sgdisk,tcpdump,mii-tool,ethtool}* "$WORKDIR"/initrd/usr/man/man8/ + cp -a /usr/share/man/man1/{beep,iostat,lshw,mpstat,setterm,bc,pv,strace,tmux,pigz}* "$WORKDIR/initrd/usr/man/man1/" + cp -a /usr/share/man/man6/figlet* "$WORKDIR/initrd/usr/man/man6/" + cp -a /usr/share/man/man8/{dmidecode,iftop,lspci,lsblk,lsusb,partclone,efibootmgr,mkfs}* "$WORKDIR/initrd/usr/man/man8/" + cp -a /usr/share/man/man8/{ntfs,mkntfs,mkexfatfs,mount.ntfs,mount.fuse,mount.exfat-fuse}* "$WORKDIR/initrd/usr/man/man8/" + cp -a /usr/share/man/man8/{mount.exfat,fdisk,gdisk,sfdisk,sgdisk,tcpdump,mii-tool,ethtool}* "$WORKDIR/initrd/usr/man/man8/" - cp -ra /usr/share/groff/current/font/devascii "$WORKDIR"/initrd/usr/share/groff/current/font/ - cp -ra /usr/share/groff/current/tmac "$WORKDIR"/initrd/usr/share/groff/current/ - cp -a /etc/groff/man.local "$WORKDIR"/initrd/etc/groff/ -fi - -p="$WORKDIR/kernel/tools/perf/perf" -if [ "x$KERNEL_TOOLS" == "xy" -a ! -s "$p" ] -then ( - cp -a "$p" "$WORKDIR/initrd/sbin/" - set +x - mkchroot "$WORKDIR/initrd" $(ldd "$p" | egrep -o '/.* ') - ) + cp -ra /usr/share/groff/current/font/devascii "$WORKDIR/initrd/usr/share/groff/current/font/" + cp -ra /usr/share/groff/current/tmac "$WORKDIR/initrd/usr/share/groff/current/" + cp -a /etc/groff/man.local "$WORKDIR/initrd/etc/groff/" fi if [ ! -s "$WORKDIR/initrd/usr/share/misc/pci.ids" ] @@ -450,51 +475,6 @@ network_show() { setterm -bold off } -autorun_cleanup() { - if [ -f /run/rescue ] - then rm /run/rescue - echo_color green black "function autorun() is exiting. Spawn rescue_shell now" - rescue_shell - fi -} - -autorun() { - trap autorun_cleanup INT TERM EXIT - echo_color green black "$1-autorun.sh script will run on now" - read -t10 -p 'Ctrl+C to have a shell, Enter to skip wait time...' - - case $1 in - initrd) echo -ne "\e]2;initrd-autorun.sh\007" # Term title (tmux) - message initrd autorun - source /etc/rc.d/initrd-autorun.sh - ;; - nfs) source nfs-mount - if [ $? -ne 0 ] - then echo_color white red "----- NFS server : not mounted ------" - echo_color green black "Check for failure above. Exiting rescue shell will retry everything" - false; cleanup - fi - if ! [ -x /mnt/nfs/nfs-autorun.sh ] - then echo_color white red "----- NFS server : missing script ------" - echo_color green black "Check nfs-autorun.sh : should be present, readable and executable" - ls -l /mnt/nfs - false; cleanup - fi - echo_color white green "----- NFS server ready ------" - message nfs autorun - echo -ne "\e]2;nfs-autorun.sh\007" # Term title (tmux) - cd /mnt/nfs - # don't use source here, exit in inner script will skip cleanup routine (and rescue_shell) - ./nfs-autorun.sh - ;; - *) echo "Usage : $0 (nfs|initrd)" - false;; - esac - res=$? - [ $res -eq 0 ] || touch /run/rescue - echo_color green black "function autorun() return code : $res" -} - notes() { echo 'print "n=CCDEEFFGAABB\na=nsnbnnsnbnbn\n(\n"; for (d=21;d<109;d++) { scale=20; f=440*e((d-69)/12*l(2)); fr=f+0.5; scale=0; fr=fr/1; o=d/12-1; t=d%12; @@ -550,7 +530,7 @@ echo -e '\e[32m/etc/rc.d/rcS script will run on /dev/console now\e[0m' echo -e '\e[37;43m'----- rcS script started -----'\e[0m' # Hint for user about boot steps if its hangs # Declare some funcs to have a tidy output with trace mode -# note : rc.d/funcs rescue_shell is slighly different the environnement is ready to go +# note : rc.d/funcs has a rescue_shell() that is slighly different (the environment is not fully intialized here) rescue_shell() { busybox echo -e '\e[37;41m'Something went wrong. Dropping to a shell.'\e[0m' busybox beep @@ -570,14 +550,15 @@ mount_pseudofilesystems() { return 0 } +# FIXME : mod loading does not work. See https://github.com/slashbeast/mdev-like-a-boss/blob/master/mdev.init ? coldplugging() { echo 4 > /proc/sys/kernel/printk - for d in /sys/bus/*/devices/* - do - cd $d - [ -r driver ] || echo add > uevent - done - sleep 3 + mdev -s +# for d in /sys/bus/*/devices/* +# do +# [ -d "$d" ] && cd "$d" && [ -r driver ] || echo add > uevent +# done +# sleep 3 cut -f4 /proc/sys/kernel/printk > /proc/sys/kernel/printk } @@ -608,6 +589,7 @@ set -v /bin/busybox --install -s||rescue_shell # Setup busybox symlinks for all applets mount_pseudofilesystems || rescue_shell # Setup /dev, /proc, /sys and so klogd; syslogd # Start logging in /var/log/messages +touch /dev/mdev.seq ; mdev -d # hotplug deamon via kernel netlink mount -o remount -o size=80% / # Allow using most of RAM for rootfs coldplugging # Load modules for cold-plugged peripherials network_up # Bring net interfaces up (no config) @@ -618,35 +600,59 @@ set +v echo -e '\e[32m/etc/rc.d/rc2-or-rescue script will run on /dev/tty1 now\e[0m' echo -e '\e[37;43m----- rcS script ended -----\e[0m' EOF +add_initrd_script "/etc/rc.d/rc2-or-rescue" <<"EOF" +. /etc/rc.d/funcs # Load helper functions +if [ -f /run/rescue ] +then rm /run/rescue + echo_color red black "/etc/rc.d/rc2 dead. Spawning rescue_shell on /dev/tty1 now" + rescue_shell +else touch /run/rescue + echo_color green black "/etc/rc.d/rc2 script will run on /dev/tty1 now" + /etc/rc.d/rc2 +fi +EOF add_initrd_script "/etc/rc.d/rc2" <<"EOF" echo -e '\e[37;43m'----- rc2 script started -----'\e[0m' # Hint for user about boot steps if its hangs . /etc/rc.d/funcs # Load helper functions setterm -blank 60 # screen sleep mode after 60 minutes set -v # Trace execution - network_conf network_show machine_info - -#touch /run/nosound -autorun nfs && eficast_end -#autorun initrd && eficast_end +/etc/rc.d/initrd-autorun.sh && eficast_end set +v echo -e '\e[37;43m'----- rc2 script ended -----'\e[0m' # Hint for user about boot steps if its hangs EOF add_initrd_script "/etc/rc.d/initrd-autorun.sh" <<"EOF" -read -t60 -p 'Dummy script. Ctrl+C to have a shell, Enter to skip wait time...' -EOF -add_initrd_script "/etc/rc.d/rc2-or-rescue" <<"EOF" +echo -ne "\e]2;$0\007" # Term title (tmux) . /etc/rc.d/funcs # Load helper functions -if [ -f /run/rescue ] -then rm /run/rescue - echo_color green black "/etc/rc.d/rc2 dead. Spawn rescue_shell run on /dev/tty1 now" - rescue_shell -else touch /run/rescue - echo_color green black "/etc/rc.d/rc2 script will run on /dev/tty1 now" - /etc/rc.d/rc2 +read -t10 -p 'Ctrl+C to have a shell, Enter to skip wait time...' +echo +mount | grep -q /mnt/nfs && umount /mnt/nfs +busybox sh -v /etc/rc.d/nfs-mount +if [ $? -ne 0 ] +then echo_color white red "----- NFS server : not mounted ------" + echo_color green black "Check for failure above. Exiting rescue shell will retry everything" + exit 1 +fi +if ! [ -x /mnt/nfs/nfs-autorun.sh ] +then echo_color white red "----- NFS server : missing script ------" + echo_color green black "/mnt/nfs/nfs-autorun.sh : should be present, readable and executable" + echo ls -l /mnt/nfs + ls -l /mnt/nfs + exit 2 fi +echo_color white green "----- NFS server ready ------" +message nfs autorun +echo -ne "\e]2;nfs-autorun.sh\007" # Term title (tmux) +cd /mnt/nfs +# don't use source here, exit in inner script will skip cleanup routine (and rescue_shell) +./nfs-autorun.sh +echo -e '\e[37;43m'----- initrd-autorun.sh script ended -----'\e[0m' # Hint for user about boot steps if its hangs +} +EOF +add_initrd_script "/etc/rc.d/nfs-mount" <<EOF +$NFS_MOUNT_CMDLINE EOF add_initrd_script "/sbin/hotplug" <<"EOF" # Be verbose for PCI cards, be silent for the rest (many many things), log everything @@ -658,22 +664,16 @@ then if [ -n "$PCI_ID" ] then echo "$0: PCI_ID==$PCI_ID, starting 'modprobe $MODALIAS'" else echo -e "\e[37;43m$0: PCI_ID==$PCI_ID, no MODALIAS found\e[0m" fi - modprobe -v $MODALIAS 2>&1 | busybox awk -vT="$0: DEVPATH=$DEVPATH PCI_ID==$PCI_ID " '{print T $0 }' | tee -a /var/log/hotplug-pci.log + /sbin/modprobe -v $MODALIAS 2>&1 | /bin/busybox awk -vT="$0: DEVPATH=$DEVPATH PCI_ID==$PCI_ID " '{ print T $0 }' | /bin/busybox tee -a /var/log/hotplug-pci.log else if [ -n "$MODALIAS" ] - then modprobe -v $MODALIAS 2>&1 | busybox awk -vT="$0: DEVPATH=$DEVPATH MODALIAS==$MODALIAS " '{print T $0 }' >> /var/log/hotplug-non-pci.log + then /sbin/modprobe -v $MODALIAS 2>&1 | /bin/busybox awk -vT="$0: DEVPATH=$DEVPATH MODALIAS==$MODALIAS " '{ print T $0 }' >> /var/log/hotplug-non-pci.log else echo "$0: DEVPATH=$DEVPATH no MODALIAS found" >> /var/log/hotplug-non-pci.log fi fi else echo "$0: DEVPATH=$DEVPATH : no support for '$ACTION'" >> /var/log/hotplug-unsupported.log fi > /dev/console 2>&1 EOF -add_initrd_script "/bin/nfs-mount" <<"EOF" -echo -ne "\e]2;$0\007" # Term title (tmux) -mount | grep -q /mnt/nfs && umount /mnt/nfs -set -v # Trace execution -mount -v -t nfs -o nolock 172.16.2.28:/masters /mnt/nfs -EOF add_initrd_script "/bin/iftop-watch" <<"EOF" echo -ne "\e]2;$*\007" # Term title (tmux) iftop -nNl @@ -748,22 +748,21 @@ EOF # Kernel build (with embed initramfs) # ####################################### -( - cd "$WORKDIR/kernel" - nproc=$(nproc --all) - nproc=${nproc:-4} - # This make will produce a kernel with embed initrd without modules - make -j $((nproc+1)) - # This will complete the inird tree with modules - INSTALL_MOD_PATH=../initrd/ make modules_install - # XXX workaround, kernel makefile s cpio preseves everything and it is not so cool for us - $ROOTCMD chown -R root: ../initrd - # XXX Workaround : some kernel version forget to update embed initramfs in certain cases - [ -f usr/initramfs_data.cpio.gz ] && rm usr/initramfs_data.cpio.gz - $ROOTCMD chmod -R go+rX ../initrd/lib/modules - # This produce the final image - make -) +pushd "$WORKDIR/kernel" +nproc=$(nproc --all) +nproc=${nproc:-4} +# This make will produce a kernel with embed initrd without modules +make -j $((nproc+1)) +# This will complete the inird tree with modules +INSTALL_MOD_PATH=../initrd/ make modules_install +# XXX workaround, kernel makefile cpio preseves everything +$ROOTCMD chown -R root: ../initrd +# XXX Workaround : some kernel releases forget to update embed initramfs in certain cases +[ -f usr/initramfs_data.cpio.gz ] && rm usr/initramfs_data.cpio.gz +$ROOTCMD chmod -R go+rX ../initrd/lib/modules +# This produce the final image +make +popd # Copy / run result EFI file # ############################## @@ -796,10 +795,14 @@ prompt 1 EOT else $ROOTCMD mount "${OUTUSB}1" "$WORKDIR/mountpoint" fi - [ -d "$WORKDIR/mountpoint/BOOT/EFI" ] || $ROOTCMD mkdir -p "$WORKDIR/mountpoint/EFI/BOOT" + $ROOTCMD mkdir -p "$WORKDIR/mountpoint/EFI/BOOT" $ROOTCMD cp "$OUTDIR/BOOTX64.EFI" "$WORKDIR/mountpoint/EFI/BOOT" $ROOTCMD umount "$WORKDIR/mountpoint" fi -[ "x$DEVEL_MODE" == "xy" ] && qemu-system-x86_64 -M q35 -m 256 -kernel "$OUTDIR/BOOTX64.EFI" -enable-kvm -serial stdio -append "console=ttyAMA0 console=ttyS0" +if [ "x$DEVEL_MODE" == "xy" ] +then qemu-system-x86_64 -M q35 -m 256 -kernel "$OUTDIR/BOOTX64.EFI" -enable-kvm -serial stdio -append "console=ttyAMA0 console=ttyS0" +fi + +echo "$0 successful end of execution" |