Update 'prep_system.sh'
This commit is contained in:
+84
-57
@@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
PI_SERIAL="6218cd17"
|
||||
ISCSI_TARGET_IQN="iqn.2000-01.com.synology:SynologyNAS.Target-11.b63ef49539c"
|
||||
ISCSI_INITIATOR_IQN="iqn.1993-08.org.debian:01:9174e3877a3"
|
||||
|
||||
ISCSI_TARGET_IQN="iqn.2000-01.com.synology:SynologyNAS.Target-13.b63ef49539c"
|
||||
ISCSI_TARGET_IP="192.168.1.5"
|
||||
|
||||
PI_SERIAL="$(vcgencmd otp_dump | grep 28: | sed s/.*://g)"
|
||||
ISCSI_INITIATOR_IQN="$(tail -1 /etc/iscsi/initiatorname.iscsi | grep InitiatorName | cut -d '=' -f 2 | tr -d '"')"
|
||||
ISCSI_DEVICE="/dev/sda"
|
||||
ISCSI_ROOT_PARTITION="/dev/sda1"
|
||||
ISCSI_TARGET_IP="192.168.1.5"
|
||||
TFTP_ROOT="/volume1/rpi/tftpboot/"
|
||||
PI_HOSTNAME=$(hostname)
|
||||
PI_IP=$(ifconfig eth0 | awk '/inet /{ print $2;}')
|
||||
@@ -19,11 +19,47 @@ NFS_DIR="/nfs/$(hostname -s)-boot"
|
||||
NFS_IP=${ISCSI_TARGET_IP}
|
||||
NFS_ROOT_PATH="${TFTP_ROOT}${PI_SERIAL}"
|
||||
ISCSI_ROOT_DIR="/iscsi/$(hostname -s)-iscsi"
|
||||
#ISCSI_ROOT_UUID=$(sudo blkid | grep ${ISCSI_ROOT_PARTITION} | tr ' ' '\n' | grep -w UUID | cut -d '=' -f 2 | tr -d '"')
|
||||
#ISCSI_ROOT_PARTUUID=$(sudo blkid | grep ${ISCSI_ROOT_PARTITION} | tr ' ' '\n' | grep PARTUUID | cut -d '=' -f 2 | tr -d '"')
|
||||
|
||||
#Make sure ISCSI Initiator IQN is set
|
||||
sudo iscsiadm \
|
||||
--mode discovery \
|
||||
--type sendtargets \
|
||||
--portal ${ISCSI_TARGET_IP}
|
||||
|
||||
#Install Required Software
|
||||
apt -y install net-tools nfs-common open-iscsi
|
||||
|
||||
#Install libraspberrypi-lib if not installed
|
||||
LIBRASPBERRYPI_BIN_INSTALLED=$(apt-cache policy libraspberrypi-bin | grep 'Installed' | cut -d ':' -f 2)
|
||||
LIBRASPBERRYPI_BIN_IS_INSTALLED=" (none)"
|
||||
|
||||
if [ "${LIBRASPBERRYPI_BIN_INSTALLED}" = "${LIBRASPBERRYPI_BIN_IS_INSTALLED}" ]
|
||||
then
|
||||
apt -y install libraspberrypi-bin
|
||||
echo "ISCSI_INITIATOR_IQN=${ISCSI_INITIATOR_IQN}"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Please re-run the script after rebooting"
|
||||
echo ""
|
||||
read -p "Press any key to reboot ..."
|
||||
reboot now
|
||||
else
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Make sure the ISCSI and NFS targets are set op on the server"
|
||||
echo ""
|
||||
echo "ISCSI_INITIATOR_IQN=${ISCSI_INITIATOR_IQN}"
|
||||
read -p "PI_SERIAL=${PI_SERIAL}"
|
||||
fi
|
||||
|
||||
# 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
|
||||
rsync --info=progress2 -a --delete /boot/ /nfs/$(hostname -s)-boot
|
||||
|
||||
update-initramfs -v -k "$(uname -r)" -c -b /nfs/$(hostname -s)-boot
|
||||
|
||||
@@ -33,83 +69,74 @@ update-initramfs -v -k "$(uname -r)" -c -b /nfs/$(hostname -s)-boot
|
||||
# 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.
|
||||
cp cmdline.txt /nfs/$(hostname -s)-boot/cmdline.txt
|
||||
|
||||
touch /nfs/$(hostname -s)-boot/cmdline.txt
|
||||
cp config.txt /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
|
||||
sed -i -r -e \
|
||||
"s/$/ net.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 rootfstype=btrfs elevator=deadline rootwait fixrtc ip=dhcp root=UUID=${ISCSI_ROOT_UUID}$ISCSI_INITIATOR=${ISCSI_INITIATOR_IQ>
|
||||
/nfs/$(hostname -s)-boot/cmdline.txt
|
||||
|
||||
#umount /nfs/$(hostname -s)-boot
|
||||
|
||||
|
||||
#Mount iSCSI
|
||||
sudo iscsiadm \
|
||||
--mode discovery \
|
||||
--type sendtargets \
|
||||
--portal ${ISCSI_TARGET_IP}
|
||||
#Mount ISCSI
|
||||
#sudo iscsiadm \
|
||||
sudo iscsiadm \
|
||||
--mode node \
|
||||
--targetname ${ISCSI_TARGET_IQN} \
|
||||
--portal ${ISCSI_TARGET_IP} \
|
||||
--login
|
||||
|
||||
#read -p "Pausing after iscsiadm"
|
||||
# Sleep otherwise it errors
|
||||
sleep 5
|
||||
|
||||
# Partition the ISCSI Device
|
||||
sudo parted ${ISCSI_DEVICE} mklabel gpt
|
||||
sleep 5
|
||||
sudo parted --align optimal ${ISCSI_DEVICE} mkpart primary btrfs 0% 100%
|
||||
sleep 5
|
||||
|
||||
# Create the btrfs Filesystem
|
||||
sudo mkfs.btrfs -f /${ISCSI_ROOT_PARTITION}
|
||||
yes | sudo mkfs.btrfs -f /${ISCSI_ROOT_PARTITION}
|
||||
sleep 5
|
||||
sudo mkdir -p ${ISCSI_ROOT_DIR}
|
||||
sudo mount "${ISCSI_ROOT_PARTITION}" ${ISCSI_ROOT_DIR}
|
||||
|
||||
# Mount the Root Partion in the Generated Image
|
||||
#CREATION_OUTPUT=$(sudo partx --add -v output-arm-image/image)
|
||||
#LOOP_DEVICE=$(echo ${CREATION_OUTPUT} | sed -E 's@.*(/dev/loop[0-9]+).*@\1@')
|
||||
#IMAGE_ROOT_DIR="$(mktemp -d)"
|
||||
#sudo mount "${LOOP_DEVICE}p2" ${IMAGE_ROOT_DIR}
|
||||
|
||||
# Begin the Copy
|
||||
# Copy the root filesystem
|
||||
sudo rsync -xa --info=progress2 --exclude /nfs --exclude /iscsi / ${ISCSI_ROOT_DIR}
|
||||
|
||||
|
||||
# Update /boot to point to the NFS mount of the TFTP folder for the Pi.
|
||||
#sudo sed -i -r -E \
|
||||
# "s@.*/boot +.*@${NFS_IP}:${NFS_ROOT_PATH} /boot nfs defaults,proto=tcp 0 0@" \
|
||||
# ${ISCSI_ROOT_DIR}/etc/fstab
|
||||
sudo sed -i -r -E \
|
||||
"s@.*/boot +.*@${NFS_IP}:${NFS_ROOT_PATH} /boot nfs defaults,proto=tcp 0 0@" \
|
||||
${ISCSI_ROOT_DIR}/etc/fstab
|
||||
|
||||
# Update / to point to the iSCSI drive.
|
||||
ISCSI_ROOT_PARTUUID=$(sudo blkid | grep ${ISCSI_ROOT_PARTITION} | tr ' ' '\n' | grep PARTUUID | cut -d '=' -f 2 | tr -d '"')
|
||||
#sudo sed -i -r -E \
|
||||
# "s@.*/ +.*@PARTUUID=${ISCSI_ROOT_PARTUUID} / btrfs _netdev,noatime 0 1@" \
|
||||
# ${ISCSI_ROOT_DIR}/etc/fstab
|
||||
|
||||
# The connection to the iSCSI device is no longer needed, so clean it up.
|
||||
#sudo umount ${ISCSI_ROOT_DIR}
|
||||
#sudo iscsiadm --m node -T ${ISCSI_TARGET_IQN} --portal ${ISCSI_TARGET_IP}:3260 -u
|
||||
#sudo iscsiadm -m node -o delete -T ${ISCSI_TARGET_IQN} --portal ${ISCSI_TARGET_IP}:3260
|
||||
|
||||
# Mount the NFS Folder
|
||||
#NFS_DIR="$(mktemp -d)"
|
||||
#sudo mount ${NFS_IP}:${NFS_ROOT_PATH} ${NFS_DIR}
|
||||
|
||||
# Update the PARTUUID
|
||||
#sudo sed -i -r -E \
|
||||
# "s@(.*root=PARTUUID=)[A-Za-z0-9-]+(.*)@\1${ISCSI_ROOT_PARTUUID}\2@" \
|
||||
# ${NFS_DIR}/cmdline.txt
|
||||
|
||||
# Unmount the NFS Folder
|
||||
#sudo umount ${NFS_DIR}
|
||||
sudo sed -i -r -E \
|
||||
"s@.*/ +.*@PARTUUID=${ISCSI_ROOT_PARTUUID} / btrfs _netdev,noatime 0 1@" \
|
||||
${ISCSI_ROOT_DIR}/etc/fstab
|
||||
|
||||
# Create links in /boot
|
||||
ln /nfs/$(hostname -s)-boot/firmware/bcm2711-rpi-4-b.dtb /nfs/$(hostname -s)-boot/bcm2711-rpi-4-b.dtb
|
||||
ln /nfs/$(hostname -s)-boot/firmware/start4.elf /nfs/$(hostname -s)-boot/start4.elf
|
||||
ln /nfs/$(hostname -s)-boot/firmware/fixup4.dat /nfs/$(hostname -s)-boot/fixup4.dat
|
||||
|
||||
printf ISCSI UUID=
|
||||
printf ISCSI PARTUUID=${ISCSI_ROOT_PARTUUID}
|
||||
printf ISCSI TARGET IQN=${ISCSI_TARGET_IQN}
|
||||
printf ISCSI INITIATOR IQN=${ISCSI_INITIATOR_IQN}
|
||||
ISCSI_ROOT_UUID=$(sudo blkid | grep ${ISCSI_ROOT_PARTITION} | tr ' ' '\n' | grep -w UUID | cut -d '=' -f 2 | tr -d '"')
|
||||
ISCSI_ROOT_PARTUUID=$(sudo blkid | grep ${ISCSI_ROOT_PARTITION} | tr ' ' '\n' | grep PARTUUID | cut -d '=' -f 2 | tr -d '"')
|
||||
echo "ISCSI UUID=${ISCSI_ROOT_UUID}"
|
||||
echo "ISCSI PARTUUID=${ISCSI_ROOT_PARTUUID}"
|
||||
echo "ISCSI TARGET IQN=${ISCSI_TARGET_IQN}"
|
||||
echo "ISCSI INITIATOR IQN=${ISCSI_INITIATOR_IQN}"
|
||||
read -p "Installation Is Complete. Please remove the SD card and reboot."
|
||||
|
||||
# The connection to the iSCSI device is no longer needed, so clean it up.
|
||||
sudo umount ${ISCSI_ROOT_DIR}
|
||||
sudo iscsiadm --m node -T ${ISCSI_TARGET_IQN} --portal ${ISCSI_TARGET_IP}:3260 -u
|
||||
sudo iscsiadm -m node -o delete -T ${ISCSI_TARGET_IQN} --portal ${ISCSI_TARGET_IP}:3260
|
||||
sudo rm -rf ${ISCSI_ROOT_DIR}
|
||||
|
||||
# The connection to the NFS device is no longer needed, so clean it up
|
||||
sudo umount ${NFS_DIR}
|
||||
rm -rf ${NFS_DIR}
|
||||
|
||||
# Shutdown
|
||||
sudo shutdown now
|
||||
Reference in New Issue
Block a user