diff --git a/1.initramfs-and-tftp-setup.sh b/1.initramfs-and-tftp-setup.sh new file mode 100644 index 0000000..87c30e5 --- /dev/null +++ b/1.initramfs-and-tftp-setup.sh @@ -0,0 +1,42 @@ +#!/bin/bash +TFTP_ROOT="/volume1/rpi/tftpboot/" +ISCSI_TARGET_IP="192.168.1.5" +ISCSI_TARGET_IQN="iqn.2000-01.com.synology:SynologyNAS.default-target.b63ef49539c" +ISCSI_INITIATOR_IQN="iqn.1993-08.org.debian:01:ab91dbfb8224" +PI_SERIAL="3079dde4" + +PI_HOSTNAME=$(hostname) +PI_IP=$(ifconfig eth0 | awk '/inet /{ print $2;}') +PI_MAC=$(ifconfig eth0 | awk '/ether/{ print $2;}' | tr ':' '-') +PI_NETMASK=$(ifconfig eth0 | awk '/netmask/{ print $4;}') +#ISCSI_INITIATOR_IQN=$(cat /etc/iscsi/iscsi.initramfs | grep 'ISCSI_INITIATOR=' | cut -d '=' -f 2) +#ISCSI_TARGET_IP=$(cat /etc/iscsi/iscsi.initramfs | grep 'ISCSI_TARGET_IP=' | cut -d '=' -f 2) +#ISCSI_TARGET_IQN=$(cat /etc/iscsi/iscsi.initramfs | grep 'ISCSI_TARGET=' | cut -d '=' -f 2) +NFS_IP=${ISCSI_TARGET_IP} +NFS_ROOT_PATH="${TFTP_ROOT}${PI_SERIAL}" + +# Copy over to the TFTP server, via the NFS mount. +mkdir -p /nfs/$(hostname -s)-boot +mount ${NFS_IP}:${NFS_ROOT_PATH} /nfs/$(hostname -s)-boot +rsync -a --delete /boot/ /nfs/$(hostname -s)-boot + +update-initramfs -v -k "$(uname -r)" -c -b /nfs/$(hostname -s)-boot + +# Update the cmdline.txt file that the pi boots with +# https://www.raspberrypi.org/documentation/configuration/cmdline-txt.md +# ip= docs can be found at +# https://git.kernel.org/pub/scm/libs/klibc/klibc.git/tree/usr/kinit/ipconfig/README.ipconfig +# However, don't put anything after static in the line below, because it completely breaks +# everything in a very non-obvious way. +touch /nfs/$(hostname -s)-boot/cmdline.txt +touch /nfs/$(hostname -s)-boot/config.txt +sed -i -r -e \ + "s/$/ ip=${PI_IP}:::${PI_NETMASK}:${PI_HOSTNAME}:eth0:static ISCSI_INITIATOR=${ISCSI_INITIATOR_IQN} ISCSI_TARGET_NAME=${ISCSI_TARGET_IQN} ISCSI_TARGET_IP=${ISCSI_TARGET_IP} rw/g" \ + /nfs/$(hostname -s)-boot/cmdline.txt + +# Update /boot/config.txt to use our new initramfs. +sed -i -r -e \ + "s@\[pi4\]@[pi4]\ninitramfs initrd.img-$(uname -r) followkernel@" \ + /nfs/$(hostname -s)-boot/config.txt + +umount /nfs/$(hostname -s)-boot \ No newline at end of file