diff --git a/prep_system.sh b/prep_system.sh index 4f4b660..4d3e1fa 100644 --- a/prep_system.sh +++ b/prep_system.sh @@ -3,8 +3,9 @@ TFTP_ROOT="/volume1/rpi/tftpboot/" ISCSI_TARGET_IP="192.168.1.5" ISCSI_TARGET_IQN="iqn.2000-01.com.synology:SynologyNAS.Target-11.b63ef49539c" ISCSI_INITIATOR_IQN="iqn.1993-08.org.debian:01:9174e3877a3" +ISCSI_DEVICE="/dev/sda" +ISCSI_ROOT_PARTITION="/dev/sda1" PI_SERIAL="6218cd17" - PI_HOSTNAME=$(hostname) PI_IP=$(ifconfig eth0 | awk '/inet /{ print $2;}') PI_MAC=$(ifconfig eth0 | awk '/ether/{ print $2;}' | tr ':' '-') @@ -12,8 +13,10 @@ 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_DIR="/nfs/$(hostname -s)-boot" NFS_IP=${ISCSI_TARGET_IP} NFS_ROOT_PATH="${TFTP_ROOT}${PI_SERIAL}" +ISCSI_ROOT_DIR="/iscsi/$(hostname -s)-iscsi" # Copy over to the TFTP server, via the NFS mount. mkdir -p /nfs/$(hostname -s)-boot @@ -30,39 +33,35 @@ update-initramfs -v -k "$(uname -r)" -c -b /nfs/$(hostname -s)-boot # everything in a very non-obvious way. cp cmdline.txt /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 +#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@\[pi4\]@[pi4]\ninitramfs initrd.img-$(uname -r) followkernel@" \ +# /nfs/$(hostname -s)-boot/config.txt #umount /nfs/$(hostname -s)-boot + +#Mount iSCSI sudo iscsiadm \ --mode discovery \ --type sendtargets \ - --portal 192.168.1.5 + --portal ${ISCSI_TARGET_IP} sudo iscsiadm \ --mode node \ - --targetname iqn.2000-01.com.synology:SynologyNAS.Target-11.b63ef49539c \ - --portal 192.168.1.5 \ + --targetname ${ISCSI_TARGET_IQN} \ + --portal ${ISCSI_TARGET_IP} \ --login -ISCSI_DEVICE="/dev/sda" sudo parted ${ISCSI_DEVICE} mklabel gpt sudo parted --align optimal ${ISCSI_DEVICE} mkpart primary btrfs 0% 100% -#!/bin/bash -ISCSI_ROOT_PARTITION="/dev/sda1" -ISCSI_ROOT_DIR="/iscsi/$(hostname -s)-iscsi" - # Create the btrfs Filesystem sudo mkfs.btrfs -f /${ISCSI_ROOT_PARTITION} -#ISCSI_ROOT_DIR="$(mktemp -d)" sudo mkdir -p ${ISCSI_ROOT_DIR} sudo mount "${ISCSI_ROOT_PARTITION}" ${ISCSI_ROOT_DIR} @@ -73,56 +72,42 @@ sudo mount "${ISCSI_ROOT_PARTITION}" ${ISCSI_ROOT_DIR} #sudo mount "${LOOP_DEVICE}p2" ${IMAGE_ROOT_DIR} # Begin the Copy -#sudo rsync -a --info=progress2 "${IMAGE_ROOT_DIR}/" ${ISCSI_ROOT_DIR} -sudo rsync -xa --progress --exclude /nfs --exclude /iscsi / ${ISCSI_ROOT_DIR} +sudo rsync -xa --info=progress2 --exclude /nfs --exclude /iscsi / ${ISCSI_ROOT_DIR} -# The generated image is no longer needed, so we can cleanup. -#sudo umount ${IMAGE_ROOT_DIR} -#sudo partx --delete -v ${LOOP_DEVICE} - -NFS_IP="192.168.1.5" -#NFS_ROOT_PATH="/nfs/$(hostname -s)-boot" -PI_SERIAL="6218cd17" -TFTP_ROOT="/volume1/rpi/tftpboot/" -ISCSI_ROOT_PARTITION="/dev/sda1" -ISCSI_ROOT_DIR="/iscsi/$(hostname -s)-iscsi" -ISCSI_TARGET_IQN="iqn.2000-01.com.synology:SynologyNAS.Target-11.b63ef49539c" # Update /boot to point to the NFS mount of the TFTP folder for the Pi. -NFS_ROOT_PATH="${TFTP_ROOT}${PI_SERIAL}" -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} / ext4 _netdev,noatime 0 1@" \ - ${ISCSI_ROOT_DIR}/etc/fstab +#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 -NFS_IP="192.168.1.5" -NFS_ROOT_PATH="/volume1/rpi/tftpboot/6218cd17" -NFS_DIR="/iscsi/$(hostname -s)-iscsi" -ISCSI_ROOT_PARTUUID="" - # 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 +#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} -#view raw 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 \ No newline at end of file +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} \ No newline at end of file