From a60a6e65397ef38083292b276922282419ca32a6 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 10:51:14 -0300 Subject: [PATCH 01/83] PXE WIP --- .gitignore | 1 + pxe/.env.example | 4 +++ pxe/README.md | 3 ++ pxe/install-pxe.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 pxe/.env.example create mode 100644 pxe/README.md create mode 100755 pxe/install-pxe.sh diff --git a/.gitignore b/.gitignore index b9aa2fd..b3b940f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ iso settings.ini # ignore all possible snapshots in this dir *.json +pxe/.env diff --git a/pxe/.env.example b/pxe/.env.example new file mode 100644 index 0000000..7f9b806 --- /dev/null +++ b/pxe/.env.example @@ -0,0 +1,4 @@ +server_ip=192.168.1.2 +nfs_allowed_lan=192.168.1.0/24 +tftp_path='/srv/pxe-tftp' +nfs_path='/srv/pxe-images' diff --git a/pxe/README.md b/pxe/README.md new file mode 100644 index 0000000..f30acc4 --- /dev/null +++ b/pxe/README.md @@ -0,0 +1,3 @@ +Run `install-pxe.sh` + +inspired on https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh new file mode 100755 index 0000000..6839de8 --- /dev/null +++ b/pxe/install-pxe.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# Copyright (c) 2024 Pedro +# SPDX-License-Identifier: AGPL-3.0-or-later + +set -e +set -u +# DEBUG +set -x + +install_dependencies() { + apt update + apt install -y wget dnsmasq nfs-kernel-server +} + +backup_file() { + target="${1}" + ts="$(date +'%Y-%m-%d_%H-%M-%S')" + if [ -f "${target}" ]; then + cp -a "${target}" "${target}_bak_${ts}" + fi +} + +install_nfs() { + backup_file /etc/exports + cat /etc/exports < Date: Tue, 24 Sep 2024 10:57:01 -0300 Subject: [PATCH 02/83] bugfix env location --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 6839de8..7b703ef 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -57,9 +57,9 @@ END init_config() { if [ -f ./.env ]; then - . ./env + . ./.env else - echo 'WARNING: ./env does not exist, cannot read config from there' + echo 'WARNING: ./.env does not exist yet, cannot read config from there. You can take inspiration in file ./.env.example' fi VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" tftp_path="${tftp_path:-/srv/pxe-tftp}" -- 2.30.2 From 44be896bb258128279b4bbe865255bea827baed4 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 11:33:45 -0300 Subject: [PATCH 03/83] deploy-workbench: fixes: mkfs.vfat not found --- deploy-workbench.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index ffa4cdc..3ba88ee 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -405,7 +405,8 @@ install_requirements() { image_deps='debootstrap squashfs-tools xorriso - mtools' + mtools + dosfstools' # secureboot: # -> extra src https://wiki.debian.org/SecureBoot/ # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine -- 2.30.2 From f888eb39f987180fd92ccf44b81595bd9f624721 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:14:24 -0300 Subject: [PATCH 04/83] add dnsmasq config --- pxe/install-pxe.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 7b703ef..834d4f7 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -29,11 +29,14 @@ END } install_tftp() { - # TODO creo que se puede hacer un fichero de config específico - # podría ser algo como /etc/dnsmasq.conf.d/my-pxe-server ? - #backup_file /etc/dnsmasq.conf - cat /etc/exports < /etc/dnsmasq.d/pxe-tftp < Date: Tue, 24 Sep 2024 12:14:33 -0300 Subject: [PATCH 05/83] bugfix bad netboot config --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 834d4f7..61ac4bc 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -47,7 +47,7 @@ install_netboot() { cd "${tftp_path}" wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz tar xvf netboot.tar.gz - cat "${tftp_path}/pxelinux.cfg/default" < "${tftp_path}/pxelinux.cfg/default" < Date: Tue, 24 Sep 2024 12:20:24 -0300 Subject: [PATCH 06/83] pxe: improve installation msg --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 61ac4bc..7ac4dde 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -62,7 +62,7 @@ init_config() { if [ -f ./.env ]; then . ./.env else - echo 'WARNING: ./.env does not exist yet, cannot read config from there. You can take inspiration in file ./.env.example' + echo 'WARNING: .env does not exist yet, cannot read config from there. You can take inspiration with file .env.example' fi VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" tftp_path="${tftp_path:-/srv/pxe-tftp}" -- 2.30.2 From 748a2255eb959fac7cf8dc64d9bcd05f5f801cde Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:21:03 -0300 Subject: [PATCH 07/83] deploy workbench: bugfix copy of settings.ini --- deploy-workbench.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 3ba88ee..a49f092 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -199,7 +199,12 @@ create_persistence_partition() { mkdir -p "${tmp_rw_mount}" ${SUDO} mount "$(pwd)/${rw_img_path}" "${tmp_rw_mount}" ${SUDO} mkdir -p "${tmp_rw_mount}/settings" - ${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings/settings.ini" + if [ -f "settings.ini" ]; then + ${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings/settings.ini" + else + echo "ERROR: settings.ini does not exist yet, cannot read config from there. You can take inspiration with file settings.ini.example" + exit 1 + fi ${SUDO} umount "${tmp_rw_mount}" uuid="$(blkid "${rw_img_path}" | awk '{ print $3; }')" -- 2.30.2 From 887cf162c5a2abe8b0ef37d5c58a8aade52862a6 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:26:10 -0300 Subject: [PATCH 08/83] pxe: facilitate run --- pxe/install-pxe.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 7ac4dde..c94c6af 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -59,6 +59,10 @@ END } init_config() { + + # get where the script is + cd "$(dirname "${0}")" + if [ -f ./.env ]; then . ./.env else -- 2.30.2 From a7bc751ccd7ee3a57c991139ccbd008a86ca4a4f Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:27:11 -0300 Subject: [PATCH 09/83] pxe: bugfix wrong cat for nfs --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index c94c6af..dbe7bc2 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -23,7 +23,7 @@ backup_file() { install_nfs() { backup_file /etc/exports - cat /etc/exports < /etc/exports < Date: Tue, 24 Sep 2024 12:28:28 -0300 Subject: [PATCH 10/83] pxe: better msgs --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index dbe7bc2..77cef21 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -66,7 +66,7 @@ init_config() { if [ -f ./.env ]; then . ./.env else - echo 'WARNING: .env does not exist yet, cannot read config from there. You can take inspiration with file .env.example' + echo 'PXE: WARNING: .env does not exist yet, cannot read config from there. You can take inspiration with file .env.example' fi VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" tftp_path="${tftp_path:-/srv/pxe-tftp}" -- 2.30.2 From 8a5942a2878271a753258f3dacfa3ab54e5c6cbd Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:36:23 -0300 Subject: [PATCH 11/83] pxe: dnsmasq: fix tftp path --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 77cef21..52c7f4f 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -36,7 +36,7 @@ dhcp-range=${nfs_allowed_lan%/*},proxy dhcp-boot=pxelinux.0 pxe-service=x86PC,"Network Boot",pxelinux enable-tftp -tftp-root=/srv/tftp +tftp-root=${tftp_path} END } -- 2.30.2 From 0e153cec68e10a4182fbe22b71b8255f18151859 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 12:36:30 -0300 Subject: [PATCH 12/83] pxe: clarify when pxe is finished --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 52c7f4f..add1c98 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -80,6 +80,7 @@ main() { install_netboot install_tftp install_nfs + echo "PXE: Installation finished" } main "${@}" -- 2.30.2 From e4fb74c59cdc136d5113d69502edf1602ff1dcc5 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 13:03:28 -0300 Subject: [PATCH 13/83] pxe: create dir for nfs --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index add1c98..5b6a2e7 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -26,6 +26,7 @@ install_nfs() { cat > /etc/exports < Date: Tue, 24 Sep 2024 13:03:35 -0300 Subject: [PATCH 14/83] pxe: fix path of linux and initrd --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 5b6a2e7..5770bc0 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -52,8 +52,8 @@ install_netboot() { default wb label wb - KERNEL vmlinuz - INITRD initd.img + KERNEL debian-installer/amd64/linux + INITRD debian-installer/amd64/initd.gz APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae END fi -- 2.30.2 From 0d8dd533edf16acedf17e723ea459db34e233d76 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 13:41:39 -0300 Subject: [PATCH 15/83] pxe: try fixing kernel and initrd --- pxe/install-pxe.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 5770bc0..c8448f4 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -48,12 +48,14 @@ install_netboot() { cd "${tftp_path}" wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz tar xvf netboot.tar.gz + cp debian-installer/amd64/linux . + cp debian-installer/amd64/initrd.gz . cat > "${tftp_path}/pxelinux.cfg/default" < Date: Tue, 24 Sep 2024 13:44:05 -0300 Subject: [PATCH 16/83] pxe: add FORCE for netboot --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index c8448f4..91983d3 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -43,7 +43,7 @@ END install_netboot() { # if you want to refresh install, remove or move dir - if [ ! -d "${tftp_path}" ]; then + if [ ! -d "${tftp_path}" ] || [ "${FORCE}" ]; then mkdir -p "${tftp_path}" cd "${tftp_path}" wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz -- 2.30.2 From f51f38d677bf4d6ac5642bed7e07cf8f4d9a6b81 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 24 Sep 2024 22:56:47 -0300 Subject: [PATCH 17/83] pxe: probably last details --- pxe/install-pxe.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 91983d3..8b1ff2e 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -26,11 +26,13 @@ install_nfs() { cat > /etc/exports < /etc/dnsmasq.d/pxe-tftp < "${tftp_path}/pxelinux.cfg/default" < Date: Wed, 25 Sep 2024 09:39:41 -0300 Subject: [PATCH 18/83] pxe: bugfix FORCE env var --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 8b1ff2e..117ac4e 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -59,7 +59,7 @@ extract_live_parts_for_tftp() { install_netboot() { # if you want to refresh install, remove or move dir - if [ ! -d "${tftp_path}" ] || [ "${FORCE}" ]; then + if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then mkdir -p "${tftp_path}" cd "${tftp_path}" if [ -f /tmp/live.iso ]; then -- 2.30.2 From 3113a3f9c2b640238ed99470c183bdad163aafed Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 09:43:11 -0300 Subject: [PATCH 19/83] pxe: fix logic on tftp live parts --- pxe/install-pxe.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 117ac4e..0e5f631 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -44,13 +44,14 @@ END } extract_live_parts_for_tftp() { + if [ ! -f /tmp/live.iso ]; then # src https://www.debian.org/CD/faq/#newest - DEBIAN_VERSION="$(wget https://www.debian.org/CD/ -O- \ - | grep -o '[0-9.]*' \ - | grep -o '[0-9.]*')" - url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${DEBIAN_VERSION}-amd64-standard.iso" - wget "${url}" -O /tmp/live.iso - + DEBIAN_VERSION="$(wget https://www.debian.org/CD/ -O- \ + | grep -o '[0-9.]*' \ + | grep -o '[0-9.]*')" + url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${DEBIAN_VERSION}-amd64-standard.iso" + wget "${url}" -O /tmp/live.iso + fi mount -o loop live.iso /mnt/ cp /mnt/live/vmlinuz "${tftp_path}/vmlinuz-live" cp /mnt/live/initrd.img "${tftp_path}/initrd-live.img" @@ -62,9 +63,7 @@ install_netboot() { if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then mkdir -p "${tftp_path}" cd "${tftp_path}" - if [ -f /tmp/live.iso ]; then - extract_live_parts_for_tftp - fi + extract_live_parts_for_tftp cat > "${tftp_path}/pxelinux.cfg/default" < Date: Wed, 25 Sep 2024 09:50:13 -0300 Subject: [PATCH 20/83] pxe: path live iso --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 0e5f631..7c831ca 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -52,7 +52,7 @@ extract_live_parts_for_tftp() { url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${DEBIAN_VERSION}-amd64-standard.iso" wget "${url}" -O /tmp/live.iso fi - mount -o loop live.iso /mnt/ + mount -o loop /tmp/live.iso /mnt/ cp /mnt/live/vmlinuz "${tftp_path}/vmlinuz-live" cp /mnt/live/initrd.img "${tftp_path}/initrd-live.img" umount /mnt -- 2.30.2 From 5aae459ca4116fbc74a47563392ed9b4dfd2d3e5 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 09:52:26 -0300 Subject: [PATCH 21/83] pxe: fix wrong cp --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 7c831ca..59ae7e6 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -53,8 +53,8 @@ extract_live_parts_for_tftp() { wget "${url}" -O /tmp/live.iso fi mount -o loop /tmp/live.iso /mnt/ - cp /mnt/live/vmlinuz "${tftp_path}/vmlinuz-live" - cp /mnt/live/initrd.img "${tftp_path}/initrd-live.img" + cp /mnt/live/vmlinuz "${tftp_path}/" + cp /mnt/live/initrd.img "${tftp_path}/" umount /mnt } -- 2.30.2 From 13b17dbcf70c98471e910248ffa3367d6b6ac34c Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 09:54:16 -0300 Subject: [PATCH 22/83] pxe: fix wrong paths TFTP/PXE --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 59ae7e6..332ba55 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -69,8 +69,8 @@ install_netboot() { default wb label wb - KERNEL linux - INITRD initrd.gz + KERNEL vmlinuz + INITRD initrd.img APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae END fi -- 2.30.2 From e3dfe94955c1d2463e5b249f58e8916ff5ac7a6e Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:08:36 -0300 Subject: [PATCH 23/83] deploy-workbench: protect shell vars --- deploy-workbench.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index a49f092..283d0f5 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -34,12 +34,12 @@ END create_iso() { # Copy kernel and initramfs - vmlinuz="$(ls -1v ${ISO_PATH}/chroot/boot/vmlinuz-* | tail -n 1)" - initrd="$(ls -1v ${ISO_PATH}/chroot/boot/initrd.img-* | tail -n 1)" - ${SUDO} cp ${vmlinuz} ${ISO_PATH}/staging/live/vmlinuz - ${SUDO} cp ${initrd} ${ISO_PATH}/staging/live/initrd + vmlinuz="$(ls -1v "${ISO_PATH}"/chroot/boot/vmlinuz-* | tail -n 1)" + initrd="$(ls -1v "${ISO_PATH}"/chroot/boot/initrd.img-* | tail -n 1)" + ${SUDO} cp ${vmlinuz} "${ISO_PATH}"/staging/live/vmlinuz + ${SUDO} cp ${initrd} "${ISO_PATH}"/staging/live/initrd # Creating ISO - iso_path="${ISO_PATH}/${iso_name}.iso" + iso_path=""${ISO_PATH}"/${iso_name}.iso" # 0x14 is FAT16 Hidden FAT16 <32, this is the only format detected in windows10 automatically when using a persistent volume of 10 MB ${SUDO} xorrisofs \ @@ -59,7 +59,7 @@ create_iso() { -e /EFI/boot/efiboot.img \ -no-emul-boot \ -isohybrid-gpt-basdat \ - -append_partition 2 0xef ${ISO_PATH}/staging/EFI/boot/efiboot.img \ + -append_partition 2 0xef "${ISO_PATH}"/staging/EFI/boot/efiboot.img \ -append_partition 3 0x14 "${rw_img_path}" \ "${ISO_PATH}/staging" @@ -138,7 +138,7 @@ EOF ${SUDO} grub-mkstandalone \ --format=x86_64-efi \ - --output=${ISO_PATH}/tmp/bootx64.efi \ + --output="${ISO_PATH}"/tmp/bootx64.efi \ --locales="" \ --fonts="" \ "boot/grub/grub.cfg=${ISO_PATH}/tmp/grub-standalone.cfg" @@ -149,10 +149,10 @@ EOF # grubx64 looks for a file in /EFI/debian/grub.cfg -> src src https://unix.stackexchange.com/questions/648089/uefi-grub-not-finding-config-file ${SUDO} cp /usr/lib/shim/shimx64.efi.signed /tmp/bootx64.efi ${SUDO} cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed /tmp/grubx64.efi - ${SUDO} cp ${ISO_PATH}/tmp/grub-standalone.cfg ${ISO_PATH}/staging/EFI/debian/grub.cfg + ${SUDO} cp "${ISO_PATH}/tmp/grub-standalone.cfg" "${ISO_PATH}/staging/EFI/debian/grub.cfg" ( - cd ${ISO_PATH}/staging/EFI/boot + cd "${ISO_PATH}/staging/EFI/boot" ${SUDO} dd if=/dev/zero of=efiboot.img bs=1M count=20 ${SUDO} mkfs.vfat efiboot.img ${SUDO} mmd -i efiboot.img efi efi/boot @@ -178,8 +178,8 @@ compress_chroot_dir() { # why squashfs -> https://unix.stackexchange.com/questions/163190/why-do-liveusbs-use-squashfs-and-similar-file-systems # noappend option needed to avoid this situation -> https://unix.stackexchange.com/questions/80447/merging-preexisting-source-folders-in-mksquashfs ${SUDO} mksquashfs \ - ${ISO_PATH}/chroot \ - ${ISO_PATH}/staging/live/filesystem.squashfs \ + "${ISO_PATH}/chroot" \ + "${ISO_PATH}/staging/live/filesystem.squashfs" \ ${DEBUG_SQUASHFS_ARGS:-} \ -noappend -e boot } @@ -429,17 +429,17 @@ install_requirements() { # thanks https://willhaley.com/blog/custom-debian-live-environment/ create_base_dirs() { - mkdir -p ${ISO_PATH} - mkdir -p ${ISO_PATH}/staging/EFI/boot - mkdir -p ${ISO_PATH}/staging/boot/grub/x86_64-efi - mkdir -p ${ISO_PATH}/staging/isolinux - mkdir -p ${ISO_PATH}/staging/live - mkdir -p ${ISO_PATH}/tmp + mkdir -p "${ISO_PATH}" + mkdir -p "${ISO_PATH}/staging/EFI/boot" + mkdir -p "${ISO_PATH}/staging/boot/grub/x86_64-efi" + mkdir -p "${ISO_PATH}/staging/isolinux" + mkdir -p "${ISO_PATH}/staging/live" + mkdir -p "${ISO_PATH}/tmp" # usb name - ${SUDO} touch ${ISO_PATH}/staging/${iso_name} + ${SUDO} touch "${ISO_PATH}/staging/${iso_name}" # for uefi secure boot grub config file - mkdir -p ${ISO_PATH}/staging/EFI/debian + mkdir -p "${ISO_PATH}/staging/EFI/debian" } # this function is used both in shell and chroot -- 2.30.2 From b8ffd19b6abeaa6193a43eb733f6f9eeb01731f7 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:08:55 -0300 Subject: [PATCH 24/83] deploy-workbench: add nfs as dependency --- deploy-workbench.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 283d0f5..ac90f74 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -411,7 +411,8 @@ install_requirements() { squashfs-tools xorriso mtools - dosfstools' + dosfstools + nfs-common' # secureboot: # -> extra src https://wiki.debian.org/SecureBoot/ # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine -- 2.30.2 From 71dffb30744a1c756a7a7c304c578c830705e263 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:10:43 -0300 Subject: [PATCH 25/83] pxe: prepare more the nfs part --- pxe/.env.example | 3 ++- pxe/install-pxe.sh | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pxe/.env.example b/pxe/.env.example index 7f9b806..04a6817 100644 --- a/pxe/.env.example +++ b/pxe/.env.example @@ -1,4 +1,5 @@ server_ip=192.168.1.2 nfs_allowed_lan=192.168.1.0/24 tftp_path='/srv/pxe-tftp' -nfs_path='/srv/pxe-images' +nfs_images_path='/srv/pxe-images' +nfs_wbdata_path='/srv/workbench-data' diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 332ba55..deb8ea9 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -24,10 +24,21 @@ backup_file() { install_nfs() { backup_file /etc/exports cat > /etc/exports < Date: Wed, 25 Sep 2024 11:11:21 -0300 Subject: [PATCH 26/83] pxe: add comment --- pxe/install-pxe.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index deb8ea9..86df3c8 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -55,6 +55,8 @@ END } extract_live_parts_for_tftp() { + # this is slow, so it is not enforced, reboot or remove the + # file to redownload the live iso if [ ! -f /tmp/live.iso ]; then # src https://www.debian.org/CD/faq/#newest DEBIAN_VERSION="$(wget https://www.debian.org/CD/ -O- \ -- 2.30.2 From 37975fc2366cd65006a6e5f259c7c072bca93e5c Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:12:01 -0300 Subject: [PATCH 27/83] pxe: update README --- pxe/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pxe/README.md b/pxe/README.md index f30acc4..9b468da 100644 --- a/pxe/README.md +++ b/pxe/README.md @@ -1,3 +1,9 @@ Run `install-pxe.sh` -inspired on https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md +## Resources + +- I originally inspired on this article https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md +- https://github.com/eReuse/workbench-live/blob/feature/pxe/docs/PXE-setup.md +- https://wiki.debian.org/PXEBootInstall +- https://wiki.debian.org/DebianInstaller/NetbootFirmware +- [In this presentation](https://people.debian.org/~andi/LiveNetboot.pdf), page 12 recommends [4.6 Building a netboot image](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#236) [4.7 Webbooting](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#275) -- 2.30.2 From e6a3ffd0609000b593433c82c9782a79096ae9d2 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:15:44 -0300 Subject: [PATCH 28/83] no, nfs common is not needed --- deploy-workbench.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index ac90f74..283d0f5 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -411,8 +411,7 @@ install_requirements() { squashfs-tools xorriso mtools - dosfstools - nfs-common' + dosfstools' # secureboot: # -> extra src https://wiki.debian.org/SecureBoot/ # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine -- 2.30.2 From 47ea66f013013fafecdb691f78ef0e9d587def92 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:51:07 -0300 Subject: [PATCH 29/83] workbench-script: attempt to write to snapshot dir --- .gitignore | 2 +- snapshots/README.md | 3 +++ workbench-script.py | 31 +++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 snapshots/README.md diff --git a/.gitignore b/.gitignore index b3b940f..ee8601d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ iso settings.ini -# ignore all possible snapshots in this dir +# ignore all possible snapshots in this repo *.json pxe/.env diff --git a/snapshots/README.md b/snapshots/README.md new file mode 100644 index 0000000..7b90349 --- /dev/null +++ b/snapshots/README.md @@ -0,0 +1,3 @@ +This is the path by default used by workbench-script + +You can change it in the configuration diff --git a/workbench-script.py b/workbench-script.py index df5c744..628b805 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -249,15 +249,30 @@ def gen_snapshot(all_disks): def save_snapshot_in_disk(snapshot, path): - filename = "{}/{}_{}.json".format( - path, - datetime.now().strftime("%Y%m%d-%H_%M_%S"), - snapshot['uuid'] - ) - print(f"workbench: INFO: Snapshot written in path '{filename}'") - with open(filename, "w") as f: - f.write(json.dumps(snapshot)) + snapshot_path = os.path.join(path, 'snapshots') + filename = "{}/{}_{}.json".format( + snapshot_path, + datetime.now().strftime("%Y%m%d-%H_%M_%S"), + snapshot['uuid']) + + try: + if not os.path.exists(snapshot_path): + os.makedirs(snapshot_path) + print(f"workbench: INFO: Created snapshots directory at '{snapshot_path}'") + + with open(filename, "w") as f: + f.write(json.dumps(snapshot)) + print(f"workbench: INFO: Snapshot written in path '{filename}'") + except Exception as e: + print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") + fallback_filename = "{}/{}_{}.json".format( + path, + datetime.now().strftime("%Y%m%d-%H_%M_%S"), + snapshot['uuid']) + with open(fallback_filename, "w") as f: + f.write(json.dumps(snapshot)) + print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") # TODO sanitize url, if url is like this, it fails # url = 'http://127.0.0.1:8000/api/snapshot/' -- 2.30.2 From 23f1bc77171e887645d3583af0e47c6da4589c53 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 11:52:46 -0300 Subject: [PATCH 30/83] change nfs persistency strategy it is easier than you thought --- pxe/.env.example | 3 +-- pxe/install-pxe.sh | 18 ++++++++---------- pxe/settings.ini.example | 6 ++++++ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 pxe/settings.ini.example diff --git a/pxe/.env.example b/pxe/.env.example index 04a6817..8f80779 100644 --- a/pxe/.env.example +++ b/pxe/.env.example @@ -1,5 +1,4 @@ server_ip=192.168.1.2 nfs_allowed_lan=192.168.1.0/24 tftp_path='/srv/pxe-tftp' -nfs_images_path='/srv/pxe-images' -nfs_wbdata_path='/srv/workbench-data' +nfs_path='/srv/pxe-nfs' diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 86df3c8..22c422f 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -24,16 +24,15 @@ backup_file() { install_nfs() { backup_file /etc/exports cat > /etc/exports < Date: Wed, 25 Sep 2024 11:59:26 -0300 Subject: [PATCH 31/83] pxe: fix wrong path --- pxe/settings.ini.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/settings.ini.example b/pxe/settings.ini.example index 5812222..d46c541 100644 --- a/pxe/settings.ini.example +++ b/pxe/settings.ini.example @@ -1,6 +1,6 @@ [settings] url = http://127.0.0.1:8000/api/snapshot/ token = '1234' -path = /srv/pxe-nfs/snapshots +path = /srv/pxe-nfs # device = your_device_name # # erase = basic -- 2.30.2 From e80c58c16f4cb63f36dba28606002cabc740e7da Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:02:30 -0300 Subject: [PATCH 32/83] pxe: bugfix wrong symlink --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 22c422f..51c4c7c 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -32,7 +32,7 @@ END if [ ! -f "${nfs_path}/settings.ini" ]; then if [ -f "settings.ini" ]; then - ln -sv "${nfs_path}/settings.ini" "settings.ini" + ln -sv "$(pwd)/settings.ini"" ${nfs_path}/settings.ini" else echo "ERROR: ../settings.ini does not exist yet, cannot read config from there. You can take inspiration with file ../settings.ini.example" exit 1 -- 2.30.2 From 06f1b2231f64ad86e92546f12326f9b59a99ba6e Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:39:47 -0300 Subject: [PATCH 33/83] pxe: simplify a lot the extraction of live parts --- pxe/install-pxe.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 51c4c7c..e60050c 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -32,7 +32,7 @@ END if [ ! -f "${nfs_path}/settings.ini" ]; then if [ -f "settings.ini" ]; then - ln -sv "$(pwd)/settings.ini"" ${nfs_path}/settings.ini" + ln -sfv "$(pwd)/settings.ini"" ${nfs_path}/settings.ini" else echo "ERROR: ../settings.ini does not exist yet, cannot read config from there. You can take inspiration with file ../settings.ini.example" exit 1 @@ -54,20 +54,9 @@ END } extract_live_parts_for_tftp() { - # this is slow, so it is not enforced, reboot or remove the - # file to redownload the live iso - if [ ! -f /tmp/live.iso ]; then - # src https://www.debian.org/CD/faq/#newest - DEBIAN_VERSION="$(wget https://www.debian.org/CD/ -O- \ - | grep -o '[0-9.]*' \ - | grep -o '[0-9.]*')" - url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${DEBIAN_VERSION}-amd64-standard.iso" - wget "${url}" -O /tmp/live.iso - fi - mount -o loop /tmp/live.iso /mnt/ - cp /mnt/live/vmlinuz "${tftp_path}/" - cp /mnt/live/initrd.img "${tftp_path}/" - umount /mnt + ln -sfv "$(pwd)/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" + ln -sfv "$(pwd)/../iso/staging/live/vmlinuz" "${tftp_path}/" + ln -sfv "$(pwd)/../iso/staging/live/initrd.img" "${tftp_path}/" } install_netboot() { -- 2.30.2 From f09e9306dff42b95fd6f3733eb76c312ade21563 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:41:49 -0300 Subject: [PATCH 34/83] pxe: fix symlinks live --- pxe/install-pxe.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index e60050c..4349476 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -54,9 +54,9 @@ END } extract_live_parts_for_tftp() { - ln -sfv "$(pwd)/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" - ln -sfv "$(pwd)/../iso/staging/live/vmlinuz" "${tftp_path}/" - ln -sfv "$(pwd)/../iso/staging/live/initrd.img" "${tftp_path}/" + ln -sfv "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" + ln -sfv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" + ln -sfv "${PXE_DIR}/../iso/staging/live/initrd.img" "${tftp_path}/" } install_netboot() { @@ -80,6 +80,7 @@ END init_config() { # get where the script is cd "$(dirname "${0}")" + PXE_DIR="$(pwd)" if [ -f ./.env ]; then . ./.env -- 2.30.2 From 9243f55b373a50cff49f9dafe42c5e419126c296 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:50:31 -0300 Subject: [PATCH 35/83] pxe: fix initrd location --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 4349476..d09924d 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -56,7 +56,7 @@ END extract_live_parts_for_tftp() { ln -sfv "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" ln -sfv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" - ln -sfv "${PXE_DIR}/../iso/staging/live/initrd.img" "${tftp_path}/" + ln -sfv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" } install_netboot() { -- 2.30.2 From 5bf01202dc83c099fb6410576ed6e8895847acab Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:51:47 -0300 Subject: [PATCH 36/83] pxe: add missing directory --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index d09924d..8626227 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -62,7 +62,7 @@ extract_live_parts_for_tftp() { install_netboot() { # if you want to refresh install, remove or move dir if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then - mkdir -p "${tftp_path}" + mkdir -p "${tftp_path}/pxelinux.cfg" cd "${tftp_path}" extract_live_parts_for_tftp -- 2.30.2 From 7bc3e4b69d10343299df57a4122f10e0dbb3385c Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 12:55:37 -0300 Subject: [PATCH 37/83] pxe: recover netboot stuff yes, finally this is needed too --- pxe/install-pxe.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 8626227..f20de40 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -64,6 +64,11 @@ install_netboot() { if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then mkdir -p "${tftp_path}/pxelinux.cfg" cd "${tftp_path}" + if [ -f "${tftp_path}/netboot.tar.gz" ]; then + wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz + tar xvf netboot.tar.gz + rm -rf "${tftp_path}/pxelinux.cfg" + fi extract_live_parts_for_tftp cat > "${tftp_path}/pxelinux.cfg/default" < Date: Wed, 25 Sep 2024 12:57:52 -0300 Subject: [PATCH 38/83] pxe: fix netboot conditional --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index f20de40..df8a321 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -64,7 +64,7 @@ install_netboot() { if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then mkdir -p "${tftp_path}/pxelinux.cfg" cd "${tftp_path}" - if [ -f "${tftp_path}/netboot.tar.gz" ]; then + if [ ! -f "${tftp_path}/netboot.tar.gz" ]; then wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz tar xvf netboot.tar.gz rm -rf "${tftp_path}/pxelinux.cfg" -- 2.30.2 From 95ae7b41446e5c01449d1c96abc691e8cb6e2d60 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:00:15 -0300 Subject: [PATCH 39/83] pxe: bugfix to continue --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index df8a321..d125dbc 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -66,7 +66,7 @@ install_netboot() { cd "${tftp_path}" if [ ! -f "${tftp_path}/netboot.tar.gz" ]; then wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz - tar xvf netboot.tar.gz + tar xvf netboot.tar.gz || true rm -rf "${tftp_path}/pxelinux.cfg" fi extract_live_parts_for_tftp -- 2.30.2 From 5447aea9e2b9d3092dd32d08a00a768cdf7d95b7 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:02:18 -0300 Subject: [PATCH 40/83] pxe: fix directory pxelinux --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index d125dbc..bbdeb3f 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -68,6 +68,7 @@ install_netboot() { wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz tar xvf netboot.tar.gz || true rm -rf "${tftp_path}/pxelinux.cfg" + mkdir -p "${tftp_path}/pxelinux.cfg" fi extract_live_parts_for_tftp -- 2.30.2 From 5aa938f195f3ba02eddd0266ed28b054132d9a6f Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:05:12 -0300 Subject: [PATCH 41/83] pxe: change symlink to cp --- pxe/install-pxe.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index bbdeb3f..1af225a 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -54,9 +54,9 @@ END } extract_live_parts_for_tftp() { - ln -sfv "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" - ln -sfv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" - ln -sfv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" + cp -v "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" + cp -v "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" + cp -v "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" } install_netboot() { -- 2.30.2 From f0b5b91ccd08310d4ebd454f95c93fe5bda1a913 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:07:43 -0300 Subject: [PATCH 42/83] pxe: force cp --- pxe/install-pxe.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 1af225a..82ed2c0 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -54,9 +54,9 @@ END } extract_live_parts_for_tftp() { - cp -v "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" - cp -v "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" - cp -v "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" + cp -fv "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" + cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" + cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" } install_netboot() { -- 2.30.2 From 8d54a4c157c0d857db9d7159001be4406f176af3 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:09:13 -0300 Subject: [PATCH 43/83] pxe: see if squashfs can be a symlink --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 82ed2c0..1f79104 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -54,9 +54,9 @@ END } extract_live_parts_for_tftp() { - cp -fv "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" + ln -sfv "${nfs_path}/live/" "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" } install_netboot() { -- 2.30.2 From d2431bead7ca1f24a090bc54111498f5c9e968f0 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:12:20 -0300 Subject: [PATCH 44/83] pxe: come back to the previous directory --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 1f79104..d312279 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -80,6 +80,7 @@ label wb INITRD initrd.img APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae END + cd - fi } -- 2.30.2 From 9e96ae52d041809c5a8acc34b7b1d7af8a41137d Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:15:55 -0300 Subject: [PATCH 45/83] pxe: change initrd location in tftp --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index d312279..cea532c 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -77,7 +77,7 @@ default wb label wb KERNEL vmlinuz - INITRD initrd.img + INITRD initrd APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae END cd - -- 2.30.2 From a70179223a8c79b60097c10d05e06a095e74279d Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:37:22 -0300 Subject: [PATCH 46/83] pxe: rsync to copy squashfs --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index cea532c..ac06d7b 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -10,7 +10,7 @@ set -x install_dependencies() { apt update - apt install -y wget dnsmasq nfs-kernel-server + apt install -y wget dnsmasq nfs-kernel-server rsync } backup_file() { @@ -56,7 +56,7 @@ END extract_live_parts_for_tftp() { cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" - ln -sfv "${nfs_path}/live/" "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" + rsync -av "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" } install_netboot() { -- 2.30.2 From 4fcdcc895596b12fd4e2851020fd2cf27cdb46df Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:40:00 -0300 Subject: [PATCH 47/83] deploy-workbench: detect nfs env --- deploy-workbench.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 283d0f5..7111840 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -269,7 +269,13 @@ stty -echo # Do not show what we type in terminal so it does not meddle with our dmesg -n 1 # Do not report *useless* system messages to the terminal # clearly specify the right working directory, used in the python script as os.getcwd() cd /mnt -pipenv run python /opt/workbench/workbench-script.py --config "/mnt/settings/settings.ini" +# detect pxe env +if [ -d /run/live/medium ]; then + config_path='/run/live/medium/settings.ini' +else + config_path='/mnt/settings.ini' +fi +pipenv run python /opt/workbench/workbench-script.py --config "\${config_path}" stty echo END #TODO add some useful commands -- 2.30.2 From b99c729125257d43fe2ad012916a8193103e3e8b Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:40:57 -0300 Subject: [PATCH 48/83] pxe: simplify with cp --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index ac06d7b..8d7bf2d 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -32,7 +32,7 @@ END if [ ! -f "${nfs_path}/settings.ini" ]; then if [ -f "settings.ini" ]; then - ln -sfv "$(pwd)/settings.ini"" ${nfs_path}/settings.ini" + cp settings.ini "${nfs_path}/settings.ini" else echo "ERROR: ../settings.ini does not exist yet, cannot read config from there. You can take inspiration with file ../settings.ini.example" exit 1 -- 2.30.2 From 51af4d3a9b68f3a3fe2be0c8cbb4af826524c1ed Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 13:45:54 -0300 Subject: [PATCH 49/83] pxe: simplify and avoid error --- pxe/install-pxe.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 8d7bf2d..5169e6a 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -53,12 +53,6 @@ tftp-root=${tftp_path} END } -extract_live_parts_for_tftp() { - cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" - cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" - rsync -av "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" -} - install_netboot() { # if you want to refresh install, remove or move dir if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then @@ -70,7 +64,10 @@ install_netboot() { rm -rf "${tftp_path}/pxelinux.cfg" mkdir -p "${tftp_path}/pxelinux.cfg" fi - extract_live_parts_for_tftp + + cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" + cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/" + rsync -av "${PXE_DIR}/../iso/staging/live/filesystem.squashfs" "${nfs_path}/live/" cat > "${tftp_path}/pxelinux.cfg/default" < Date: Wed, 25 Sep 2024 13:47:43 -0300 Subject: [PATCH 50/83] pxe: more useful warning error --- pxe/install-pxe.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 5169e6a..ed94e07 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -34,7 +34,7 @@ END if [ -f "settings.ini" ]; then cp settings.ini "${nfs_path}/settings.ini" else - echo "ERROR: ../settings.ini does not exist yet, cannot read config from there. You can take inspiration with file ../settings.ini.example" + echo "ERROR: $(pwd)/settings.ini does not exist yet, cannot read config from there. You can take inspiration with file $(pwd)/settings.ini.example" exit 1 fi fi @@ -89,7 +89,7 @@ init_config() { if [ -f ./.env ]; then . ./.env else - echo 'PXE: WARNING: .env does not exist yet, cannot read config from there. You can take inspiration with file .env.example' + echo "PXE: WARNING: $(pwd)/.env does not exist yet, cannot read config from there. You can take inspiration with file $(pwd)/.env.example" fi VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" tftp_path="${tftp_path:-/srv/pxe-tftp}" -- 2.30.2 From 66a744d108413e94e046d70a30508d9000a44b47 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 17:59:34 -0300 Subject: [PATCH 51/83] pxe: fix wrong default path --- pxe/settings.ini.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/settings.ini.example b/pxe/settings.ini.example index d46c541..3ad5c4a 100644 --- a/pxe/settings.ini.example +++ b/pxe/settings.ini.example @@ -1,6 +1,6 @@ [settings] url = http://127.0.0.1:8000/api/snapshot/ token = '1234' -path = /srv/pxe-nfs +path = /run/live/medium # device = your_device_name # # erase = basic -- 2.30.2 From d2c06b760fc60bc4123f838ef0f16dac1badbbce Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 17:59:57 -0300 Subject: [PATCH 52/83] pxe: move README to spanish --- pxe/README-es.md | 9 +++++++++ pxe/README.md | 10 +++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 pxe/README-es.md diff --git a/pxe/README-es.md b/pxe/README-es.md new file mode 100644 index 0000000..a49cf8b --- /dev/null +++ b/pxe/README-es.md @@ -0,0 +1,9 @@ +Ejecuta `./install-pxe.sh` + +## Recursos + +- Originalmente inspirado en este artículo https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md +- https://github.com/eReuse/workbench-live/blob/feature/pxe/docs/PXE-setup.md +- https://wiki.debian.org/PXEBootInstall +- https://wiki.debian.org/DebianInstaller/NetbootFirmware +- [In this presentation](https://people.debian.org/~andi/LiveNetboot.pdf), recomienda página 12 [4.6 Building a netboot image](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#236) [4.7 Webbooting](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#275) diff --git a/pxe/README.md b/pxe/README.md index 9b468da..9f75404 100644 --- a/pxe/README.md +++ b/pxe/README.md @@ -1,9 +1,5 @@ -Run `install-pxe.sh` +# pxe -## Resources +- [Español](./README-es.md) +- [English](./README-en.md) -- I originally inspired on this article https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md -- https://github.com/eReuse/workbench-live/blob/feature/pxe/docs/PXE-setup.md -- https://wiki.debian.org/PXEBootInstall -- https://wiki.debian.org/DebianInstaller/NetbootFirmware -- [In this presentation](https://people.debian.org/~andi/LiveNetboot.pdf), page 12 recommends [4.6 Building a netboot image](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#236) [4.7 Webbooting](https://live-team.pages.debian.net/live-manual/html/live-manual/the-basics.en.html#275) -- 2.30.2 From 52e99064c621c34c6a05a1e3f637fe1023e2906e Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 18:07:43 -0300 Subject: [PATCH 53/83] workbench-script: remove ntplib - it was not being used - let's delegate this to Operating System --- workbench-script.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index 628b805..1fdec4e 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -7,7 +7,6 @@ import hashlib import argparse import configparser -import ntplib import requests @@ -287,12 +286,6 @@ def send_snapshot_to_devicehub(snapshot, token, url): except: print(f"workbench: ERROR: Snapshot not remotely sent. URL '{url}' is unreachable. Do you have internet? Is your server up & running?") -@logs -def sync_time(): - # is neccessary? - ntplib.NTPClient() - response = client.request('pool.ntp.org') - def load_config(config_file="settings.ini"): """ Tries to load configuration from a config file. -- 2.30.2 From ecb9b1649b2d7f9f4798681af89cc74afbc8bccd Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 25 Sep 2024 20:16:03 -0300 Subject: [PATCH 54/83] pxe: do the trick for rw snapshots dir --- deploy-workbench.sh | 4 ++++ pxe/install-pxe.sh | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 7111840..3313e9e 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -272,6 +272,10 @@ cd /mnt # detect pxe env if [ -d /run/live/medium ]; then config_path='/run/live/medium/settings.ini' + # debian live nfs path is readonly, do a trick + # to make snapshots subdir readwrite + nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" + mount \${nfs_host}:/snapshots /run/live/medium/snapshots else config_path='/mnt/settings.ini' fi diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index ed94e07..96ac03d 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -23,9 +23,20 @@ backup_file() { install_nfs() { backup_file /etc/exports + + # debian live nfs path is readonly, do a trick + # to make snapshots subdir readwrite + if grep -q "/snapshots" /proc/mounts; then + mount --bind "${nfs_path}/snapshots" "/snapshots" + fi + cat > /etc/exports < Date: Thu, 26 Sep 2024 08:49:38 -0300 Subject: [PATCH 55/83] improve docs --- README-es.md | 6 ++++++ pxe/README-es.md | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README-es.md b/README-es.md index a648bb5..b1b4255 100644 --- a/README-es.md +++ b/README-es.md @@ -54,3 +54,9 @@ OPCIONES ## Enfoque workbench-script trata de ser simple y minimalista, una función principal y funciones de soporte la lectura de las diferentes funcionalidades. + +## Generar ISO para el USB + +Para generar la iso y preparar un usb que arranque con workbench necesitas generarte una workbench de este, con tu configuración específica + +Ejecuta `./deploy-workbench.sh` diff --git a/pxe/README-es.md b/pxe/README-es.md index a49cf8b..7b6d7de 100644 --- a/pxe/README-es.md +++ b/pxe/README-es.md @@ -1,7 +1,25 @@ -Ejecuta `./install-pxe.sh` +# workbench via PXE + +## Introducción + +Permite arrancar workbench a través de la red en vez de por USB. Utiliza la misma imagen generada por el script [deploy-workbench.sh](../deploy-workbench.sh), pero en el formato compatible con el arranque por red en vez de la iso. + +Ejecuta el siguiente script en un servidor debian estable que estará dedicado a la gestión del pxe server + +``` +./install-pxe.sh +``` + +Este servidor aporta un servicio de arranque por red tipo PXE, y no hace colisión con un servidor DHCP existente. + +## Funcionamiento + +El servidor PXE ofrece a la máquina que arranca un *debian live* a través de [NFS](https://es.wikipedia.org/wiki/Network_File_System). Una vez arrancado, ejecuta el `workbench-script.py` con la configuración remota del servidor PXE. Cuando ha terminado, también guarda en el mismo servidor PXE el snapshot resultante. También lo puede guardar en devicehub si se especifica en la variable `url` de la configuración `settings.ini`. ## Recursos +El servicio PXE + - Originalmente inspirado en este artículo https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md - https://github.com/eReuse/workbench-live/blob/feature/pxe/docs/PXE-setup.md - https://wiki.debian.org/PXEBootInstall -- 2.30.2 From da026ad0c3ce6b1ec3523dc3f472137ec06c1cdd Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 08:49:53 -0300 Subject: [PATCH 56/83] workbench-script: warn when not root --- workbench-script.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/workbench-script.py b/workbench-script.py index 1fdec4e..e4001a5 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -227,6 +227,8 @@ def smartctl(all_disks, disk=None): ## End Command Functions ## +# TODO permitir selección +# TODO permitir que vaya más rápido def get_data(all_disks): lshw = 'sudo lshw -json' hwinfo = 'sudo hwinfo --reallyall' @@ -341,6 +343,11 @@ def main(): config = load_config(config_file) + # TODO show warning if non root, means data is not complete + # if annotate as potentially invalid snapshot (pending the new API to be done) + if os.geteuid() != 0: + print("workbench: WARNING: This script must be run as root. Collected data will be incomplete or unusable") + all_disks = get_disks() snapshot = gen_snapshot(all_disks) -- 2.30.2 From 21942f26afd7568090658f47696c85808034b06d Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 08:50:05 -0300 Subject: [PATCH 57/83] settings.ini: move to using domain --- settings.ini.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini.example b/settings.ini.example index 35fb89b..81dac5e 100644 --- a/settings.ini.example +++ b/settings.ini.example @@ -1,5 +1,5 @@ [settings] -url = http://127.0.0.1:8000/api/snapshot/ +url = http://localhost:8000/api/snapshot/ token = '1234' # path = /path/to/save # device = your_device_name -- 2.30.2 From e4b844713ed01ae87d095811b4226a4fe553780d Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 08:57:13 -0300 Subject: [PATCH 58/83] pxe settings.ini: migrate to localhost domain --- pxe/settings.ini.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/settings.ini.example b/pxe/settings.ini.example index 3ad5c4a..5e9eac0 100644 --- a/pxe/settings.ini.example +++ b/pxe/settings.ini.example @@ -1,5 +1,5 @@ [settings] -url = http://127.0.0.1:8000/api/snapshot/ +url = http://localhost:8000/api/snapshot/ token = '1234' path = /run/live/medium # device = your_device_name -- 2.30.2 From 9de317adbf92e4763bb4b3a61ef4ecd0f2ab58ee Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 09:00:36 -0300 Subject: [PATCH 59/83] pxe: fix snapshot nfs logic --- pxe/install-pxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 96ac03d..811240d 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -26,7 +26,7 @@ install_nfs() { # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite - if grep -q "/snapshots" /proc/mounts; then + if ! grep -q "/snapshots" /proc/mounts; then mount --bind "${nfs_path}/snapshots" "/snapshots" fi -- 2.30.2 From 80edd9e7488015b62d3e3913377f83e19e566ef8 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 09:01:04 -0300 Subject: [PATCH 60/83] add empty readme in english --- pxe/README-en.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 pxe/README-en.md diff --git a/pxe/README-en.md b/pxe/README-en.md new file mode 100644 index 0000000..1333ed7 --- /dev/null +++ b/pxe/README-en.md @@ -0,0 +1 @@ +TODO -- 2.30.2 From b380450bd42f514c2a165b408cf5b22c46daf329 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 09:01:52 -0300 Subject: [PATCH 61/83] pxe: snapshot nfs dir, ensure exists --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 811240d..96eb135 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -27,6 +27,7 @@ install_nfs() { # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite if ! grep -q "/snapshots" /proc/mounts; then + mkdir -p "/snapshots" mount --bind "${nfs_path}/snapshots" "/snapshots" fi -- 2.30.2 From 19957c608d993ed81ba8a6772aa71d447a140a0c Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 11:24:38 -0300 Subject: [PATCH 62/83] pxe: add try-exception for writing fallback path --- workbench-script.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index e4001a5..be482be 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -266,14 +266,17 @@ def save_snapshot_in_disk(snapshot, path): f.write(json.dumps(snapshot)) print(f"workbench: INFO: Snapshot written in path '{filename}'") except Exception as e: - print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") - fallback_filename = "{}/{}_{}.json".format( - path, - datetime.now().strftime("%Y%m%d-%H_%M_%S"), - snapshot['uuid']) + try: + print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") + fallback_filename = "{}/{}_{}.json".format( + path, + datetime.now().strftime("%Y%m%d-%H_%M_%S"), + snapshot['uuid']) with open(fallback_filename, "w") as f: f.write(json.dumps(snapshot)) - print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") + print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") + except Exception as e: + print(f"workbench: ERROR: Failed to write in fallback path: {fallback_error}. Could not save snapshot locally.") # TODO sanitize url, if url is like this, it fails # url = 'http://127.0.0.1:8000/api/snapshot/' -- 2.30.2 From 6ffa9a9304f4ef1de14e32275dfdcad9904d490c Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 11:26:24 -0300 Subject: [PATCH 63/83] deploy-workbench: no debug mode when script ended --- deploy-workbench.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 3313e9e..d81665e 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -281,6 +281,8 @@ else fi pipenv run python /opt/workbench/workbench-script.py --config "\${config_path}" stty echo + +set +x END #TODO add some useful commands cat > "${ISO_PATH}/chroot/root/.bash_history" < Date: Thu, 26 Sep 2024 12:04:05 -0300 Subject: [PATCH 64/83] pxe: bugfix wrong try --- workbench-script.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index be482be..dba27e6 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -272,9 +272,9 @@ def save_snapshot_in_disk(snapshot, path): path, datetime.now().strftime("%Y%m%d-%H_%M_%S"), snapshot['uuid']) - with open(fallback_filename, "w") as f: - f.write(json.dumps(snapshot)) - print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") + with open(fallback_filename, "w") as f: + f.write(json.dumps(snapshot)) + print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") except Exception as e: print(f"workbench: ERROR: Failed to write in fallback path: {fallback_error}. Could not save snapshot locally.") -- 2.30.2 From 103f2f8e79295dbbd897c721b21bac526f4646e3 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 12:17:12 -0300 Subject: [PATCH 65/83] workbench-script: improve autostart script --- deploy-workbench.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index d81665e..428afa4 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -263,26 +263,33 @@ prepare_app() { # startup script execution cat > "${ISO_PATH}/chroot/root/.profile" < "${ISO_PATH}/chroot/root/.bash_history" < Date: Thu, 26 Sep 2024 12:17:52 -0300 Subject: [PATCH 66/83] bugfix wrong try/except --- workbench-script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workbench-script.py b/workbench-script.py index dba27e6..28f391d 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -276,7 +276,7 @@ def save_snapshot_in_disk(snapshot, path): f.write(json.dumps(snapshot)) print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") except Exception as e: - print(f"workbench: ERROR: Failed to write in fallback path: {fallback_error}. Could not save snapshot locally.") + print(f"workbench: ERROR: Failed to write in fallback path: {fallback_filename}. Could not save snapshot locally.") # TODO sanitize url, if url is like this, it fails # url = 'http://127.0.0.1:8000/api/snapshot/' -- 2.30.2 From 2fd0d2fdb9dd123662e34caa7937047ac34b6904 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 12:18:17 -0300 Subject: [PATCH 67/83] pxe: add ref to dhcp proxy --- pxe/install-pxe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 96eb135..8ca21cf 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -57,6 +57,7 @@ install_tftp() { # from https://wiki.debian.org/PXEBootInstall#Simple_way_-_using_Dnsmasq cat > /etc/dnsmasq.d/pxe-tftp < Date: Thu, 26 Sep 2024 12:21:24 -0300 Subject: [PATCH 68/83] pxe: we know the server host, is in the config --- deploy-workbench.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 428afa4..58c37ca 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -279,8 +279,7 @@ if [ -d /run/live/medium ]; then mount --bind /run/live/medium /mnt # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite - nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" - mount \${nfs_host}:/snapshots /run/live/medium/snapshots + mount ${server_ip}:/snapshots /run/live/medium/snapshots else fi # clearly specify the right working directory, used in the python script as os.getcwd() -- 2.30.2 From 7d16cb8bd48329214a98f2e614888e0a6a76fc03 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 12:28:03 -0300 Subject: [PATCH 69/83] pxe: fix autostart script --- deploy-workbench.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 58c37ca..5723220 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -264,7 +264,7 @@ prepare_app() { # startup script execution cat > "${ISO_PATH}/chroot/root/.profile" < Date: Thu, 26 Sep 2024 13:24:09 -0300 Subject: [PATCH 70/83] Revert "pxe: we know the server host, is in the config" This reverts commit 5399d544ee4bec1e427686155d629c118d2a70f1. --- deploy-workbench.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 5723220..9b736f4 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -279,7 +279,8 @@ if [ -d /run/live/medium ]; then mount --bind /run/live/medium /mnt # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite - mount ${server_ip}:/snapshots /run/live/medium/snapshots + nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" + mount \${nfs_host}:/snapshots /run/live/medium/snapshots fi # clearly specify the right working directory, used in the python script as os.getcwd() cd /mnt -- 2.30.2 From b2e82e7bb95accc4851d8a838aed66db1a3c2081 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 13:46:56 -0300 Subject: [PATCH 71/83] pxe: trying to fix autostart script --- deploy-workbench.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 9b736f4..21dc3d9 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -263,15 +263,15 @@ prepare_app() { # startup script execution cat > "${ISO_PATH}/chroot/root/.profile" < Date: Thu, 26 Sep 2024 13:56:26 -0300 Subject: [PATCH 72/83] pxe: improve autostart --- deploy-workbench.sh | 3 +-- workbench-script.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 21dc3d9..b0e1a86 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -264,7 +264,6 @@ prepare_app() { # startup script execution cat > "${ISO_PATH}/chroot/root/.profile" < Date: Thu, 26 Sep 2024 13:57:32 -0300 Subject: [PATCH 73/83] pxe: add nfs-common --- deploy-workbench.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index b0e1a86..c267d32 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -428,7 +428,8 @@ install_requirements() { squashfs-tools xorriso mtools - dosfstools' + dosfstools + nfs-common' # secureboot: # -> extra src https://wiki.debian.org/SecureBoot/ # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine -- 2.30.2 From abfe9a5ceb9abe2e4fa5de48eb9090d5274f2648 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 26 Sep 2024 19:41:16 -0300 Subject: [PATCH 74/83] pxe: improve autostart script --- deploy-workbench.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index c267d32..1cf319d 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -263,16 +263,16 @@ prepare_app() { # startup script execution cat > "${ISO_PATH}/chroot/root/.profile" < "${ISO_PATH}/chroot/root/.bash_history" < Date: Thu, 26 Sep 2024 19:41:38 -0300 Subject: [PATCH 75/83] pxe: improve error msgs in wb-script --- workbench-script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index 80b1c1d..f4b01a6 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -267,7 +267,7 @@ def save_snapshot_in_disk(snapshot, path): print(f"workbench: INFO: Snapshot written in path '{filename}'") except Exception as e: try: - print(f"workbench: WARNING: Failed to write in snapshots directory: {e}. Attempting to save in actual path.") + print(f"workbench: WARNING: Attempting to save in actual path. Reason: Failed to write in snapshots directory:\n {e}.") fallback_filename = "{}/{}_{}.json".format( path, datetime.now().strftime("%Y%m%d-%H_%M_%S"), @@ -276,7 +276,7 @@ def save_snapshot_in_disk(snapshot, path): f.write(json.dumps(snapshot)) print(f"workbench: INFO: Snapshot written in fallback path '{fallback_filename}'") except Exception as e: - print(f"workbench: ERROR: Failed to write in fallback path: {e}. Could not save snapshot locally.") + print(f"workbench: ERROR: Could not save snapshot locally. Reason: Failed to write in fallback path:\n {e}") # TODO sanitize url, if url is like this, it fails # url = 'http://127.0.0.1:8000/api/snapshot/' -- 2.30.2 From f617526c349b488f49ae10c98e947efd699bbbc6 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 09:17:48 -0300 Subject: [PATCH 76/83] workbench-script: improve err msg for HTTP POST --- workbench-script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index f4b01a6..743a505 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -288,8 +288,8 @@ def send_snapshot_to_devicehub(snapshot, token, url): try: requests.post(url, data=json.dumps(snapshot), headers=headers) print(f"workbench: INFO: Snapshot sent to '{url}'") - except: - print(f"workbench: ERROR: Snapshot not remotely sent. URL '{url}' is unreachable. Do you have internet? Is your server up & running?") + except Exception as e: + print(f"workbench: ERROR: Snapshot not remotely sent. URL '{url}' is unreachable. Do you have internet? Is your server up & running?\n {e}") def load_config(config_file="settings.ini"): """ -- 2.30.2 From 97b8de7fd3919cf47f69d43fc2891d8cdc96b663 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 09:28:16 -0300 Subject: [PATCH 77/83] pxe: nfs-common dep was in the wrong place --- deploy-workbench.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 1cf319d..2e29ff9 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -303,7 +303,7 @@ apt-get install -y --no-install-recommends \ python3 python3-dev python3-pip pipenv \ dmidecode smartmontools hwinfo pciutils lshw < /dev/null # Install python requirements using apt instead of pip - #python3-dateutils python3-decouple python3-colorlog + #python3-dateutils python3-decouple python3-colorlog nfs-common # Install lshw B02.19 utility using backports (DEPRECATED in Debian 12) #apt install -y -t ${VERSION_CODENAME}-backports lshw < /dev/null @@ -427,8 +427,7 @@ install_requirements() { squashfs-tools xorriso mtools - dosfstools - nfs-common' + dosfstools' # secureboot: # -> extra src https://wiki.debian.org/SecureBoot/ # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine -- 2.30.2 From 2e57351e1a4243c1965c0aa5318fb6dbe26f3d45 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 09:28:38 -0300 Subject: [PATCH 78/83] pxe: ensure systemd is aware of mounts --- deploy-workbench.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 2e29ff9..02d4601 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -280,6 +280,8 @@ if [ -d /run/live/medium ]; then # to make snapshots subdir readwrite nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" mount \${nfs_host}:/snapshots /run/live/medium/snapshots + # reload mounts on systemd + systemctl daemon-reload fi # clearly specify the right working directory, used in the python script as os.getcwd() cd /mnt -- 2.30.2 From bd52916b06d302eca2268e1678d00d45b3960d7d Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 09:34:41 -0300 Subject: [PATCH 79/83] pxe: finally this is the thing for nfs cleanup old deps --- deploy-workbench.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 02d4601..b14ed73 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -303,9 +303,7 @@ echo 'Install requirements' apt-get install -y --no-install-recommends \ sudo \ python3 python3-dev python3-pip pipenv \ - dmidecode smartmontools hwinfo pciutils lshw < /dev/null - # Install python requirements using apt instead of pip - #python3-dateutils python3-decouple python3-colorlog nfs-common + dmidecode smartmontools hwinfo pciutils lshw nfs-common < /dev/null # Install lshw B02.19 utility using backports (DEPRECATED in Debian 12) #apt install -y -t ${VERSION_CODENAME}-backports lshw < /dev/null -- 2.30.2 From 2df34e4b2363301fc99e723b835b00c30cef3312 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 17:27:12 -0300 Subject: [PATCH 80/83] pxe: a lot of improvements --- deploy-workbench.sh | 8 ++-- pxe/Makefile | 2 + pxe/README-es.md | 28 ++++++++++++++ pxe/install-pxe.sh | 82 +++++++++++++++++++++++++++++++--------- pxe/settings.ini.example | 2 +- 5 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 pxe/Makefile diff --git a/deploy-workbench.sh b/deploy-workbench.sh index b14ed73..a0e4d79 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -198,9 +198,9 @@ create_persistence_partition() { ${SUDO} umount -f -l "${tmp_rw_mount}" >/dev/null 2>&1 || true mkdir -p "${tmp_rw_mount}" ${SUDO} mount "$(pwd)/${rw_img_path}" "${tmp_rw_mount}" - ${SUDO} mkdir -p "${tmp_rw_mount}/settings" + ${SUDO} mkdir -p "${tmp_rw_mount}" if [ -f "settings.ini" ]; then - ${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings/settings.ini" + ${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings.ini" else echo "ERROR: settings.ini does not exist yet, cannot read config from there. You can take inspiration with file settings.ini.example" exit 1 @@ -274,11 +274,11 @@ stty -echo # Do not show what we type in terminal so it does not meddle with our dmesg -n 1 # Do not report *useless* system messages to the terminal # detect pxe env -if [ -d /run/live/medium ]; then +nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" +if [ "\${nfs_host}" ]; then mount --bind /run/live/medium /mnt # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite - nfs_host="\$(df -hT | grep nfs | cut -f1 -d: | head -n1)" mount \${nfs_host}:/snapshots /run/live/medium/snapshots # reload mounts on systemd systemctl daemon-reload diff --git a/pxe/Makefile b/pxe/Makefile new file mode 100644 index 0000000..edf648f --- /dev/null +++ b/pxe/Makefile @@ -0,0 +1,2 @@ +test_pxe: + qemu-system-x86_64 -m 1G -boot n -netdev user,id=mynet0,tftp=/srv/pxe-tftp,bootfile=pxelinux.0 -device e1000,netdev=mynet0 diff --git a/pxe/README-es.md b/pxe/README-es.md index 7b6d7de..c1cda36 100644 --- a/pxe/README-es.md +++ b/pxe/README-es.md @@ -16,6 +16,34 @@ Este servidor aporta un servicio de arranque por red tipo PXE, y no hace colisi El servidor PXE ofrece a la máquina que arranca un *debian live* a través de [NFS](https://es.wikipedia.org/wiki/Network_File_System). Una vez arrancado, ejecuta el `workbench-script.py` con la configuración remota del servidor PXE. Cuando ha terminado, también guarda en el mismo servidor PXE el snapshot resultante. También lo puede guardar en devicehub si se especifica en la variable `url` de la configuración `settings.ini`. +## Probarlo todo en localhost + +Preparar configuración de `.env` tal como: + +``` +server_ip=10.0.2.2 +nfs_allowed_lan=10.0.2.0/24 +tftp_path='/srv/pxe-tftp' +nfs_path='/srv/pxe-nfs' +``` + +Red y host 10.0.2.2? Esta es la forma en que el programa *qemu* hace red en localhost, 10.0.2.2 es la dirección de localhost que saliendo de qemu es traducida como 127.0.0.1 + +Desplegar servidores TFTP y NFS en el mismo ordenador, para permitir nfs inseguro: + +``` +DEBUG=true ./install-pxe.sh +``` + +Los directorios inseguros contienen configuración y snapshots de workbench, nada importante supongo. Aún así, `DEBUG=true` no se recomienda para un entorno de producción para evitar sorpresas. + + +Y para terminar, probar el cliente PXE con el siguiente comando: + +``` +make test_pxe +``` + ## Recursos El servicio PXE diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 8ca21cf..17f153c 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -8,21 +8,46 @@ set -u # DEBUG set -x +detect_user() { + userid="$(id -u)" + # detect non root user without sudo + if [ ! "${userid}" = 0 ] && id ${USER} | grep -qv sudo; then + echo "ERROR: this script needs root or sudo permissions (current user is not part of sudo group)" + exit 1 + # detect user with sudo or already on sudo src https://serverfault.com/questions/568627/can-a-program-tell-it-is-being-run-under-sudo/568628#568628 + elif [ ! "${userid}" = 0 ] || [ -n "${SUDO_USER}" ]; then + SUDO='sudo' + # jump to current dir where the script is so relative links work + cd "$(dirname "${0}")" + # working directory to build the iso + ISO_PATH="iso" + # detect pure root + elif [ "${userid}" = 0 ]; then + SUDO='' + ISO_PATH="/opt/workbench" + fi +} + install_dependencies() { - apt update - apt install -y wget dnsmasq nfs-kernel-server rsync + ${SUDO} apt update + ${SUDO} apt install -y wget dnsmasq nfs-kernel-server rsync syslinux } backup_file() { target="${1}" ts="$(date +'%Y-%m-%d_%H-%M-%S')" + if [ -f "${target}" ]; then - cp -a "${target}" "${target}_bak_${ts}" + if ! grep -q 'we should do a backup' "${target}"; then + ${SUDO} cp -a "${target}" "${target}-bak_${ts}" + fi fi } install_nfs() { - backup_file /etc/exports + # append live directory, which is expected by the debian live env + mkdir -p "${nfs_path}/live" + mkdir -p "${nfs_path}/snapshots" # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite @@ -31,16 +56,21 @@ install_nfs() { mount --bind "${nfs_path}/snapshots" "/snapshots" fi - cat > /etc/exports < /etc/dnsmasq.d/pxe-tftp < "${tftp_path}/pxelinux.cfg/default" < Date: Fri, 27 Sep 2024 18:02:19 -0300 Subject: [PATCH 81/83] pxe: more sudo cmds to fix --- pxe/install-pxe.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 17f153c..08b53d9 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -46,14 +46,14 @@ backup_file() { install_nfs() { # append live directory, which is expected by the debian live env - mkdir -p "${nfs_path}/live" - mkdir -p "${nfs_path}/snapshots" + ${SUDO} mkdir -p "${nfs_path}/live" + ${SUDO} mkdir -p "${nfs_path}/snapshots" # debian live nfs path is readonly, do a trick # to make snapshots subdir readwrite if ! grep -q "/snapshots" /proc/mounts; then - mkdir -p "/snapshots" - mount --bind "${nfs_path}/snapshots" "/snapshots" + ${SUDO} mkdir -p "/snapshots" + ${SUDO} mount --bind "${nfs_path}/snapshots" "/snapshots" fi backup_file /etc/exports @@ -74,7 +74,7 @@ END if [ ! -f "${nfs_path}/settings.ini" ]; then if [ -f "settings.ini" ]; then - cp settings.ini "${nfs_path}/settings.ini" + ${SUDO} cp settings.ini "${nfs_path}/settings.ini" else echo "ERROR: $(pwd)/settings.ini does not exist yet, cannot read config from there. You can take inspiration with file $(pwd)/settings.ini.example" exit 1 @@ -100,13 +100,13 @@ END install_netboot() { # if you want to refresh install, remove or move dir if [ ! -d "${tftp_path}" ] || [ "${FORCE:-}" ]; then - mkdir -p "${tftp_path}/pxelinux.cfg" - cd "${tftp_path}" + ${SUDO} mkdir -p "${tftp_path}/pxelinux.cfg" if [ ! -f "${tftp_path}/netboot.tar.gz" ]; then - wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz - tar xvf netboot.tar.gz || true - rm -rf "${tftp_path}/pxelinux.cfg" - mkdir -p "${tftp_path}/pxelinux.cfg" + url="http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz" + ${SUDO} wget -P "${tftp_path}" "${url}" + ${SUDO} tar xvf "${tftp_path}/netboot.tar.gz" -C "${tftp_path}" + ${SUDO} rm -rf "${tftp_path}/pxelinux.cfg" + ${SUDO} mkdir -p "${tftp_path}/pxelinux.cfg" fi ${SUDO} cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/" -- 2.30.2 From d2e5b1f824931e098e51c0568d3ac3d6ce94d574 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 27 Sep 2024 18:02:37 -0300 Subject: [PATCH 82/83] pxe: allow personalization of boot menus --- pxe/install-pxe.sh | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 08b53d9..ee2fdd9 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.sh @@ -114,24 +114,10 @@ install_netboot() { ${SUDO} cp /usr/lib/syslinux/memdisk "${tftp_path}/" ${SUDO} cp /usr/lib/syslinux/modules/bios/* "${tftp_path}/" - ${SUDO} tee "${tftp_path}/pxelinux.cfg/default" < Date: Fri, 27 Sep 2024 18:03:04 -0300 Subject: [PATCH 83/83] pxe: more on customize pxe menus, give example --- .gitignore | 1 - pxe/.gitignore | 2 ++ pxe/pxe-menu.cfg.example | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 pxe/.gitignore create mode 100644 pxe/pxe-menu.cfg.example diff --git a/.gitignore b/.gitignore index ee8601d..69029b0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ iso settings.ini # ignore all possible snapshots in this repo *.json -pxe/.env diff --git a/pxe/.gitignore b/pxe/.gitignore new file mode 100644 index 0000000..9f6d6c8 --- /dev/null +++ b/pxe/.gitignore @@ -0,0 +1,2 @@ +.env +pxe-menu.cfg diff --git a/pxe/pxe-menu.cfg.example b/pxe/pxe-menu.cfg.example new file mode 100644 index 0000000..f702f1f --- /dev/null +++ b/pxe/pxe-menu.cfg.example @@ -0,0 +1,12 @@ +DEFAULT menu.c32 +PROMPT 0 +TIMEOUT 50 +ONTIMEOUT wb + +MENU TITLE PXE Boot Menu + +LABEL wb + MENU LABEL Boot Workbench + KERNEL vmlinuz + INITRD initrd + APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae -- 2.30.2