summaryrefslogtreecommitdiff
path: root/make-boot-image.sh
diff options
context:
space:
mode:
Diffstat (limited to 'make-boot-image.sh')
-rwxr-xr-xmake-boot-image.sh97
1 files changed, 49 insertions, 48 deletions
diff --git a/make-boot-image.sh b/make-boot-image.sh
index d55a088..d16c9a0 100755
--- a/make-boot-image.sh
+++ b/make-boot-image.sh
@@ -22,6 +22,12 @@ USB_IDS_URL=https://usb-ids.gowdy.us/usb.ids
# Utilities #
#############
+function add_initrd_script
+{
+ ( echo "#!/bin/busybox sh" ; cat ) > "$WORKDIR/initrd/$1"
+ chmod +x "$WORKDIR/initrd/$1"
+}
+
# From https://landley.net/writing/rootfs-programming.html
# Its first argument is the new directory, and the rest of its arguments are executables to copy.
function mkchroot
@@ -84,7 +90,7 @@ then $ROOTCMD apt-get update
[ "x$DEVEL_MODE" = "xy" ] && $ROOTCMD apt-get install qemu-system-x86
# Dependencies to put into the initrd
$ROOTCMD apt-get install dmidecode pciutils usbutils lshw sysstat iftop strace tmux \
- ntfs-3g e2fsprogs partclone util-linux udpcast gdisk efibootmgr tcpdump pigz
+ ntfs-3g e2fsprogs partclone util-linux udpcast gdisk efibootmgr tcpdump pigz pv
# util-linux : fdisk, sfdisk, lsblk, setterm
> "$WORKDIR/apt-done"
fi
@@ -256,7 +262,7 @@ then (
# Diagnostic tools
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 tmux
+ mkchroot "$WORKDIR/initrd" setterm strace groff nroff troff grotty gtbl tmux pv
# 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
@@ -381,6 +387,7 @@ nfs_autorun() {
}
EOF
+# XXX Useful ?
cat > "$WORKDIR/initrd/etc/inittab" <<"EOF"
# Custom init scripts
::sysinit:/etc/init.d/rcS
@@ -394,9 +401,7 @@ tty2::askfirst:/bin/sh
tty3::askfirst:/bin/sh
tty4::askfirst:/bin/sh
EOF
-
-cat > "$WORKDIR/initrd/etc/init.d/rcS" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/etc/init.d/rcS" <<"EOF"
echo -e '\033[37;43m'----- rcS script started -----'\033[0m' # Hint for user about boot steps if its hangs
# Declare some funcs to have a tidy output with trace mode
@@ -405,7 +410,7 @@ 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
}
@@ -414,6 +419,8 @@ mount_pseudofilesystems() {
mount -t proc none /proc || return $?
mount -t sysfs none /sys || return $?
mount -t devtmpfs -o size=1m none /dev || return $?
+ mkdir /dev/pts || return $?
+ mount -t devpts none /dev/pts || return $?
ln -s /proc/self/fd/2 /dev/stderr
return 0
}
@@ -433,6 +440,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
+export TERM=linux
loadkmap < /etc/keys.bmap # Load keyboard layout
setterm -blank 60 # screen sleep mode after 60 minutes
@@ -446,10 +454,7 @@ 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
+add_initrd_script "/etc/init.d/rc2" <<"EOF"
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
@@ -465,9 +470,7 @@ eficast_end
set +v
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/rc2"
-
-cat > "$WORKDIR/initrd/usr/share/udhcpc/default.script" <<"EOF"
+add_initrd_script "/usr/share/udhcpc/default.script" <<"EOF"
#!/bin/sh
case $1 in
bound)
@@ -489,10 +492,7 @@ case $1 in
leasefail | nak) echo "configuration failed: $1: $message" >&2 ;;
esac
EOF
-chmod +x "$WORKDIR/initrd/usr/share/udhcpc/default.script"
-
-cat > "$WORKDIR/initrd/bin/rc2_once.sh" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/bin/rc2_once.sh" <<"EOF"
if [ -f /run/rc2_once ]
then source /etc/init.d/funcs
rescue_shell
@@ -500,32 +500,28 @@ else touch /run/rc2_once
/etc/init.d/rc2
fi
EOF
-chmod +x "$WORKDIR/initrd/bin/rc2_once.sh"
-
-cat > "$WORKDIR/initrd/bin/autorun.sh" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/bin/autorun.sh" <<"EOF"
# Helper script to have retries handy
cd /mnt/nfs
./autorun.sh
EOF
-chmod +x "$WORKDIR/initrd/bin/autorun.sh"
-
-cat > "$WORKDIR/initrd/etc/profile" <<"EOF"
-# tmux on qemu need this (problems with carriage return)
-stty sane
-EOF
-
-chmod +x "$WORKDIR/initrd/bin/autorun.sh"
-cat > "$WORKDIR/initrd/bin/restore-script" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/bin/restore-script" <<"EOF"
# Dummy restore script for testing the tmux inegration
-pigz -dc testimg.partclone.gz | partclone.restore -o /dev/vg_data/lv_dst
+pigz -dc testimg.partclone.gz | partclone.restore -o /dev/sda1
+sleep 60
EOF
-chmod +x "$WORKDIR/initrd/bin/restore-script"
-
-cat > "$WORKDIR/initrd/bin/pigz-watch" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/bin/iftop-watch" <<"EOF"
+printf '\033]2;'"$*"'\033\\' # Term title (tmux)
+iftop -nNl
+EOF
+add_initrd_script "/bin/iostat-watch" <<"EOF"
+# Emulates watch command with iostat (filtered info, minimal height)
+printf '\033]2;'"$*"'\033\\' # Term title (tmux)
+iostat -cdmz 1 | awk '$1=="avg-cpu:" { system("clear"); } length($0) > 0 { print $0; }'
+EOF
+add_initrd_script "/bin/pigz-watch" <<"EOF"
# Emulate watch command using pipeview (pv) for a running pigz
+printf '\033]2;'"$*"'\033\\' # Term title (tmux)
while true
do
pid=$(pidof -s pigz)
@@ -533,25 +529,30 @@ do
sleep 1
done
EOF
-chmod +x "$WORKDIR/initrd/bin/pigz-watch"
-
-cat > "$WORKDIR/initrd/bin/toilet-center" <<"EOF"
-#!/bin/busybox sh
+add_initrd_script "/bin/pstree-watch" <<"EOF"
+printf '\033]2;'"$*"'\033\\' # Term title (tmux)
+watch -t pstree -p
+EOF
+add_initrd_script "/bin/tmux-wrap" <<"EOF"
+tmux new-session -d "if $* ; then tmux kill-server; else tmux select-pane -P bg=red; rescue_shell ; fi" \; \
+ set-window-option status off \; \
+ split-window -t %0 -l1 pigz-watch \; \
+ split-window -t %0 -l5 iftop-watch \; \
+ split-window -t %0 -l6 iostat-watch \; \
+ split-window -h -p30 pstree-watch \; \
+ select-pane -t:.0 \; \
+ attach
+EOF
+#XXX Unused ?
+add_initrd_script "/bin/toilet-center" <<"EOF"
# Output some center ASCII-art text, one line per argument
+printf '\033]2;'"$*"'\033\\' # Term title (tmux)
while [ -n "$1" ]
do
echo $1 | toilet -t -f mono12 | awk "{ for (i=0;i<($(tput cols)-length(\$0))/2;i++) printf \" \"; print }"
shift
done
EOF
-chmod +x "$WORKDIR/initrd/bin/toilet-center"
-
-cat > "$WORKDIR/initrd/bin/iostat-watch" <<"EOF"
-#!/bin/busybox sh
-# Emulates watch command with iostat (filtered info, minimal height)
-iostat -cdmz 1 | awk '$1=="avg-cpu:" { system("clear"); } length($0) > 0 { print $0; }'
-EOF
-chmod +x "$WORKDIR/initrd/bin/iostat-watch"
# XXX workaround, kernel makefile's cpio preseves everything and it is not so cool for us
$ROOTCMD chown -R root: "$WORKDIR/initrd"