From: Ian Kelling Date: Sat, 24 Aug 2024 04:03:53 +0000 (-0400) Subject: fixes and remove some old unused stuff X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=2a97e0ad1de05cb5a079e82330e02fb92d050ccf;p=automated-distro-installer fixes and remove some old unused stuff --- diff --git a/fai-redep b/fai-redep index d358d5f..b63cf1f 100755 --- a/fai-redep +++ b/fai-redep @@ -97,7 +97,7 @@ if ! ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then fi # these are gitignored. -rsync -atL /home/iank/.ssh/authorized_keys fai/config/files/root/.ssh/authorized_keys/STANDARD +cat /home/iank/.ssh/{home,work}.pub >fai/config/files/root/.ssh/authorized_keys/STANDARD # we hssh and ssh_filter_btrbk for the initial btrbk (alternatively, I could open up the # permissions in authorized_keys, but that just seems lazy) install --owner=iank --group=iank -d fai/config/files/usr/local/bin/hssh @@ -136,15 +136,15 @@ if [[ -e ${dirs[0]} ]]; then rsrv -rlpt --delete --relative ${dirs[@]} /fai/config/distro-install-common fi -. /a/bin/distro-setup/pkgs -tmpstr=$(/a/bin/buildscripts/emacs -p && /a/bin/distro-setup/distro-pkgs $distro) -declare -a pall -for p in $tmpstr; do - pall+=($p) -done - -printf "%s\n%s\n" "PACKAGES install" ${pall[*]} | \ - $faiserver_shell dd of=/srv/fai/config/package_config/DESKTOP status=none ||: # broken pipe - +# historical notes: once I tried installing all generic packages using +# the DESKTOP class, and populated the package list here, but it had +# some problem and figured it was easier to debug if we let fai just +# handle some basic initial things. +# I also tried speeding up an initial install by making basefile with +# lots of packages installed in a script called mk-basefile-big. Many +# packages fail to install by having debootstrap install extra +# packages. I tried instead to do a fai dirinstall (fancy chroot) to +# install packages, then turn that into a new basefile. It had some +# problem and once again, did not seem worth debugging. rsrv -rplt --include '/*.zst' --exclude '/**' --delete-excluded $BASEFILE_DIR/ /fai/config/basefiles/ diff --git a/fai-revm b/fai-revm index 6fb8650..c2d17e4 100755 --- a/fai-revm +++ b/fai-revm @@ -88,8 +88,8 @@ done # change this to test different disk counts. -disk_count=3 disk_count=1 +disk_count=3 rm -f /tmp/fai-revm-did-pxe diff --git a/fai/config/class/10-base-classes b/fai/config/class/10-base-classes index 6d0df6d..e4408b6 100755 --- a/fai/config/class/10-base-classes +++ b/fai/config/class/10-base-classes @@ -1,5 +1,5 @@ #! /bin/bash -_ + # do only execute if this is called on the client being installed. Do not use during fai-diskimage if [ X$FAI_ACTION = Xinstall -a $do_init_tasks -eq 0 ]; then exit 0 diff --git a/fai/config/hooks/partition.DEFAULT b/fai/config/hooks/partition.DEFAULT index c9c8c95..a616537 100755 --- a/fai/config/hooks/partition.DEFAULT +++ b/fai/config/hooks/partition.DEFAULT @@ -47,9 +47,14 @@ fi # the main root fs in /tmp/fai. Must run with env var, eg export DISTRO=trisquelaramo. # # Example use in a bootstrap distro: -# scp /a/bin/fai/fai/config/{distro-install-common/devbyid,hooks/partition.DEFAULT} root@HOST: +# scp /b/fai/fai-wrapper /a/bin/fai/fai/config/{distro-install-common/devbyid,hooks/partition.DEFAULT} root@HOST: # sl HOST -# export DISTRO=trisquelnabia; ./partition.DEFAULT mktab +# . fai-wrapper # ignore error that FAI is not set, it is not needed for SPECIAL_DISK purposes. +# fai-setclass FSF +# export SPECIAL_DISK=/dev/sde +# export DISTRO=trisquelecne # not actually used +# ./partition.DEFAULT +# # ## cryptsetup wont take within a pipeline # mapfile -t lines < <(awk '! /swap/ {print $2,$1}' /tmp/fai/crypttab ) # for l in "${lines[@]}"; do cryptsetup luksOpen $l; done @@ -464,7 +469,7 @@ hdds=() ssds=() # this excludes "usb". vda disk has empty tran (transport). This may need adjustment # for some new type we come across. cdrom has type "rom" -for disk in $(lsblk -ndo name,type,tran | awk '$3 ~ "^(sata|nvme|)$" && $2 == "disk" { print $1 }'); do +for disk in $(lsblk -ndo name,type,tran | awk '$3 ~ "^(sata|nvme|sas|)$" && $2 == "disk" { print $1 }'); do if [[ ${disk_excludes[$disk]} ]]; then continue fi @@ -751,9 +756,17 @@ else fi -# 1.5 x based on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-disk-partitioning-setup-x86.html#sect-custom-partitioning-x86 -swap_mib=$(( $(grep ^MemTotal: /proc/meminfo | \ - awk '{print $2}') * 3/(${#devs[@]} * 2 ) / 1024 )) +# +# for servers, 4gb min based on https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_storage_devices/getting-started-with-swap_managing-storage-devices#recommended-system-swap-space_getting-started-with-swap +# meh, i'll just do that * drives for machines with lots of ram. +mem_kb=$(awk '$1 == "MemTotal:" {print $2}' /proc/meminfo) +mem_gb=$(( mem_kb / 1024 / 1024 )) +if (( mem_gb < 64 )); then + # enable hibernate with 1.5x of ram, split per disk + swap_mib=$(( mem_gb * 3 / ${#devs[@]} )) +else + swap_mib=4096 +fi shopt -s nullglob ##### end variable setup @@ -769,7 +782,7 @@ elif $mktab; then exit 0 else mktab - if ! fsf; then + if ! fsf && [[ ! $SPECIAL_DISK ]]; then getluks fi fi diff --git a/fai/config/package_config/STANDARD b/fai/config/package_config/STANDARD index f70f19a..63b198f 100644 --- a/fai/config/package_config/STANDARD +++ b/fai/config/package_config/STANDARD @@ -66,6 +66,8 @@ cryptsetup-initramfs zstd # for detecting wireless iw +# for the fai partitioning script +parted dosfstools # iank, copied from DEBIAN so it goes into ubuntu too PACKAGES install GRUB_PC diff --git a/mk-basefile-big b/mk-basefile-big deleted file mode 100755 index 1a6b6a9..0000000 --- a/mk-basefile-big +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/bash -# Copyright (C) 2018 Ian Kelling - -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - -[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" - -set -e; . /usr/local/lib/bash-bear; set +e - -this_file="$(readlink -f -- "${BASH_SOURCE[0]}")" -readonly this_file this_dir="${this_file%/*}" -PATH="$this_dir:$PATH" # directory of this file - -usage() { - cat < /srv/fai/config/class/51-multi-boot - -rm -rf $t; mkdir -p $t - -# shellcheck disable=SC1007 # intentional -LANG= fai -N -u hostname_does_not_matter dirinstall $t - -# Turn a dirinstall into a basefile. taken from mk-basefile -chroot $t apt-get clean -rm -f $t/etc/hostname $t/etc/resolv.conf \ - $t/var/lib/apt/lists/*_* $t/usr/bin/qemu-*-static \ - $t/etc/udev/rules.d/70-persistent-net.rules -echo | dd of=$t/etc/machine-id -tar --one-file-system -C $t -cf - . | zstd -9 > /a/bin/fai-basefiles/basefiles/${distver^^}64BIG.tar.zst - - -cleanup -exit 0 diff --git a/myfai-chboot b/myfai-chboot index aa3c088..d0f1a2d 100755 --- a/myfai-chboot +++ b/myfai-chboot @@ -41,10 +41,19 @@ can change the fai flags in the grub config, for example in We could probably also set FAI_FLAGS the same way we set FAI_ACTION, but I haven't tried it. +Debugging notes: I had nfs communication problems due to misconfiguration, +tcpdump showed small packets, many size 4, but I couldn't figure out what +the hell they actually meant. -vv does nfs decoding, but output nothing +useful. This seems to generally output all nfs operations into syslog +with kernel: prepended "for module in nfsd rpc nlm; do s rpcdebug -m $module -s all; done" disable with "for module in nfsd rpc nlm; do s rpcdebug -m $module -c; done" +i read the nfstrace man page and tried running it, it seemed totally useless, +just outputing some statistics of valid commands. + HOSTNAME|IP|default Sets the host to enable it for. No argument disables pxe config for all hosts, but leaves nfs server alone. Use faiserver-disable to disable the - nfs server. + nfs server. Hostnames are simply converted to ip address + for nfs and pxe. -S sets FAI_ACTION=sysinfo, and remove fai flag reboot. Usefull for doing a system recovery. It reboots automatically anyways :( diff --git a/myfai-chboot-local b/myfai-chboot-local index 0bc1f63..f79d405 100755 --- a/myfai-chboot-local +++ b/myfai-chboot-local @@ -19,8 +19,6 @@ [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" -set -x - set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR @@ -83,41 +81,32 @@ done read -r host <<<"$@" readonly host - rm -f /srv/tftp/fai/pxelinux.cfg/* -if [[ ! $1 ]]; then +if [[ ! $host ]]; then echo "$0: clearing pxe config and exiting" exit 0 fi # somewhat duplicated in brc hostip() -case $host in - default) : ;; - [0-9:]) - hostip=$host - ;; - *) - hostip=$(getent ahostsv4 "$host" | awk '{ print $1 }' | head -n1) - ;; -esac - -if [[ $hostip ]]; then - - # assuming ipv4, or else we might need to deal with multiple addresses - # in an ipv4 + ipv6 network. - # - # t11 has via. presumably, older os had src - my_ip=$(ip -4 route get $hostip | head -n1 | sed -nr 's,^.*(src|via)\s+(\S+).*,\1,p' || [[ $? == 141 ]] ) + +nonip_regex='[^0-9:.]' +if [[ $host == default ]]; then + ip_arg=8.8.8.8 else - my_ip=$(ip -4 r show default | head -n1 | sed -r 's/.*(src|via) ([^ ]*).*/\1/' || [[ $? == 141 ]] ) + if [[ $host =~ $nonip_regex ]]; then + ip_arg="$(getent ahostsv4 "$host" | awk '{ print $1 }' | head -n1)" + else + ip_arg="$host" + fi fi -if [[ ! $my_ip || $my_ip =~ [[:space:]] ]]; then +my_ip=$(ip -r -j r get $ip_arg|jq -r '.[0].prefsrc' ) + +if [[ ! $my_ip || $my_ip =~ $nonip_regex ]]; then echo "$0: error: failed to get \$my_ip, got: $my_ip" exit 1 fi - if [[ $host == default ]]; then ip='*' elif [[ $host == [0-9]*.[0-9]*.[0-9]*.[0-9]* ]]; then @@ -125,7 +114,7 @@ elif [[ $host == [0-9]*.[0-9]*.[0-9]*.[0-9]* ]]; then else type -t host &>/dev/null || apt-get -y install dnsutils ip=$(host $host | sed -rn 's/^\S+ has address //p;T;q' ||:) - if [[ ! $ip || $ip =~ [[:space:]] ]]; then + if [[ ! $ip || $ip =~ $nonip_regex ]]; then echo "$0: error: failed to get \$ip, got: $ip" exit 1 fi @@ -168,7 +157,16 @@ fi # man page doesn't explain this, but this deletes & thus disables # all chboot systems. -m fai-chboot -iv $std_arg default # set it to default to get a val out of it next +# We want to set to default to get a val out of it next. +# If needing to debug, normal output from this command looks like this: +# Booting kernel vmlinuz-6.1.0-23-amd64 +# append initrd=initrd.img-6.1.0-23-amd64 ip=dhcp +# FAI_CONFIG_SRC=nfs://faiserver.b8.nz/srv/fai/config +# +# default has no IP in hex default +# Writing file /srv/tftp/fai/pxelinux.cfg/default for default +fai-chboot -iv default &>/dev/null + kernel=$(fai-chboot -L '^default$' | awk '{print $3}') default_k_args=$(fai-chboot -L '^default$' | \ sed -r "s/^(\S+\s+){3}(.*)/\2/")