From b519001641b2dac6cff4c5c6523fb814f2249733 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 13 Jul 2021 00:13:39 -0400 Subject: [PATCH] root2 partitions, various improvements --- README | 8 + dsfull | 3 +- fai/config/distro-install-common/devbyid | 7 +- .../distro-install-common/libreboot_grub.cfg | 3 +- fai/config/files/boot/chboot/DEFAULT | 4 +- fai/config/hooks/partition.DEFAULT | 151 +++++++++++++----- fai/config/package_config/STANDARD | 2 + faiserver-setup | 7 +- wrt-setup-local | 17 +- 9 files changed, 157 insertions(+), 45 deletions(-) diff --git a/README b/README index 95eca1d..a1cb54d 100644 --- a/README +++ b/README @@ -180,6 +180,14 @@ reboot # Expected output in fai logs +On focal, +fai.log:updatebase.UBUNTU FAILED with exit code 1. +the real error is dpkg-reconfigure locales, seems to be related +to a workaround for < 20.04, relevant comment: +# in case the locales are already included inside the base file (Ubuntu) +in config/hooks/instsoft.DEBIAN + + For flidas, when installing systemd, this error happens, and it's a superflous upstream bug based on reading the post install script: diff --git a/dsfull b/dsfull index 91ab8ec..593e7d6 100755 --- a/dsfull +++ b/dsfull @@ -98,7 +98,8 @@ fi while [[ $(ser is-active btrbk.service) == active ]]; do sleep 5 done -btrbk-run -t $host +bbk -t $host archive +bbk -t $host #ssh $host /a/bin/distro-setup/distro-begin # this should be done instead of distro-begin, but # keeping it to 2 steps for now diff --git a/fai/config/distro-install-common/devbyid b/fai/config/distro-install-common/devbyid index e344389..056a83f 100755 --- a/fai/config/distro-install-common/devbyid +++ b/fai/config/distro-install-common/devbyid @@ -5,10 +5,11 @@ short_dev=$1 -# devices are identified by model+serial num, -# and wwn. model+serial gives me more info, so use that. +# devices are identified by model+serial num +# and for ssd/hdd: wwn, and for nvme: eui. +# model+serial gives me more info, so use that. shopt -s extglob -for id in /dev/disk/by-id/!(wwn*); do +for id in /dev/disk/by-id/!(nvme-eui*|wwn*); do [[ -e $id ]] || break # if we matched nothing if [[ $(readlink -f $id) == "$short_dev" ]]; then printf '%s\n' "$id" diff --git a/fai/config/distro-install-common/libreboot_grub.cfg b/fai/config/distro-install-common/libreboot_grub.cfg index 16fec9c..54cf468 100644 --- a/fai/config/distro-install-common/libreboot_grub.cfg +++ b/fai/config/distro-install-common/libreboot_grub.cfg @@ -28,7 +28,8 @@ function save_chosen { set default=/debianbuster_bootstrap # could use 0 here. set timeout=1 -for part in (ahci*5) (ata*5); do +# grub_extn +for part in (ahci*7) (ata*7); do envfile=$part/grubenv if [ -s $envfile ]; then load_env --file $envfile diff --git a/fai/config/files/boot/chboot/DEFAULT b/fai/config/files/boot/chboot/DEFAULT index 6354ed9..adfbe1c 100755 --- a/fai/config/files/boot/chboot/DEFAULT +++ b/fai/config/files/boot/chboot/DEFAULT @@ -127,8 +127,10 @@ done if [[ $(blockdev --getsize64 ${boot_disk}4) == 8388608 ]]; then # old partition scheme grub_dev=${boot_disk}4 -else +elif [[ $(blockdev --getsize64 ${boot_disk}5) == 8388608 ]]; then grub_dev=${boot_disk}5 +else + grub_dev=${boot_disk}7 fi e mount $grub_dev $mount_point diff --git a/fai/config/hooks/partition.DEFAULT b/fai/config/hooks/partition.DEFAULT index 534e1fa..0dc4c7d 100755 --- a/fai/config/hooks/partition.DEFAULT +++ b/fai/config/hooks/partition.DEFAULT @@ -26,16 +26,17 @@ fi # for calling outside of FAI: # fai-redep -# s +# # source /b/fai/fai-wrapper # - set any appropriate classes with: fai-setclass OPT1... which sets CLASS_OPT1=true... # or run eval-fai-classfile FILE. -# - Set a VOL_DISTROVER, eg: +# - Set a VOL_DISTROVER (if not doing mkroot2) eg: # fai-setclass VOL_NABIA -# - export luks_dir=/q/root/luks # # OPTIONS: # +# mkroot2: for running outside of fai and setting up the root2/boot2 luks and btrfs +# # environment variables: # # HOSTNAME: if frodo, we exclude 2 devices from the /boot array, which @@ -63,6 +64,19 @@ fi # raid10. # RAID1: forces raid1 filesystem. +mkroot2=false +case $1 in + mkroot2) + mkroot2=true + ;; + *) + echo "$0: error: unsupported arg: $1" >&2 + exit 1 + ;; +esac + + + if [[ $SPECIAL_DISK ]]; then export CLASS_REPARTITION=true fi @@ -104,18 +118,20 @@ fi # boot rootn=1 -swapn=2 -bootn=3 -efin=4 +root2n=2 +swapn=3 +bootn=4 +boot2n=5 +efin=6 # ext partition so grub can write persistent variables, # so it can do a one time boot. grub can't write to # btrfs or any cow fs because it's more # more complicated to do and they don't want to. -grub_extn=5 +grub_extn=7 # bios boot partition, # https://wiki.archlinux.org/index.php/GRUB -bios_grubn=6 -even_bign=7 +bios_grubn=8 +even_bign=9 lastn=$bios_grubn @@ -135,9 +151,11 @@ add-part() { # add partition suffix to $dev echo $d-part$part } -bootdev() { add-part $@ $bootn; } rootdev() { add-part $@ $rootn; } +root2dev() { add-part $@ $root2n; } swapdev() { add-part $@ $swapn; } +bootdev() { add-part $@ $bootn; } +boot2dev() { add-part $@ $boot2n; } efidev() { add-part $@ $efin; } grub_extdev() { add-part $@ $grub_extn; } bios_grubdev() { add-part $@ $bios_grubn; } @@ -146,8 +164,10 @@ even_bigdev() { add-part $@ $even_bign; } crypt-dev() { echo /dev/mapper/crypt_dev_${1##*/}; } crypt-name() { echo crypt_dev_${1##*/}; } root-cryptdev() { crypt-dev $(rootdev $@); } +root2-cryptdev() { crypt-dev $(root2dev $@); } swap-cryptdev() { crypt-dev $(swapdev $@); } root-cryptname() { crypt-name $(rootdev $@); } +root2-cryptname() { crypt-name $(root2dev $@); } swap-cryptname() { crypt-name $(swapdev $@); } dev-mib() { @@ -200,7 +220,7 @@ if (($(nproc) > 2)); then fi declare -A disk_excludes -if ! ifclass USE_MOUNTED; then +if ! $mkroot2 && ! ifclass USE_MOUNTED; then ## ignore disks that are mounted, eg when running from fai-cd while read -r l; do eval "$l" @@ -274,6 +294,7 @@ fi boot_space=0 first=true boot_devs=() +boot2_devs=() for dev in ${devs[@]}; do if ifclass frodo; then # I ran into a machine where the bios doesn't know about some disks, @@ -299,11 +320,15 @@ for dev in ${devs[@]}; do break fi done - $bad_disk || boot_devs+=($(bootdev)) + if ! $bad_disk; then + boot_devs+=($(bootdev)) + boot2_devs+=($(boot2dev)) + fi else boot_space=$(( boot_space + $(parted -m $dev unit MiB print | \ sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1)) boot_devs+=($(bootdev)) + boot2_devs+=($(boot2dev)) fi if $first && [[ $boot_devs ]]; then first_efi=$(efidev) @@ -335,17 +360,26 @@ if (( boot_space > 60000 )); then # becuase I keep a minimal debian install on it for # recovery needs and for doing pxe-kexec. boot_mib=10000 + root2_mib=200000 + boot2_mib=500 elif (( boot_space > 30000 )); then boot_mib=$(( 5000 + (boot_space - 30000) / 2 )) + root2_mib=100 + boot2_mib=100 else # Small vms don't have room for /boot recovery. With 3 kernels # installed, i'm using 132M on t8, so this seems like plenty of # room. note: rhel 8 recomments 1g for /boot. boot_mib=500 - # + root2_mib=100 + boot2_mib=100 fi case $raid_level in - 1*) boot_mib=$(( boot_mib * 2 )) ;; + 1*) + boot_mib=$(( boot_mib * 2 )) + boot2_mib=$(( boot2_mib * 2 )) + root2_mib=$(( root2_mib * 2 )) + ;; esac ### end calculate boot partition space @@ -374,6 +408,8 @@ if [[ ! $DISTRO ]]; then DISTRO=trisqueletiona elif ifclass VOL_NABIA; then DISTRO=trisquelnabia + elif $mkroot2; then + : else echo "PARTITIONER ERROR: no distro class/var set" >&2 exit 1 @@ -393,6 +429,13 @@ bpart() { # btrfs a partition if [[ ! $luks_dir ]]; then # see README for docs about how to create these luks_dir=$FAI/distro-install-common/luks + if [[ ! -d $luks_dir ]]; then + luks_dir=/q/root/luks + fi + if [[ ! -d $luks_dir ]]; then + echo "$0: error: no luks_dir found" >&2 + exit 1 + fi fi luks_file=$luks_dir/host-$HOSTNAME @@ -430,8 +473,33 @@ for dev in ${devs[@]}; do root_devs+=($(rootdev)) done shopt -s nullglob -if $partition; then +rm -f /mnt/root/root2-{fs,crypt}tab +if $mkroot2; then + if $partition; then + echo $0: error: found partition=true but have mkroot2 arg + exit 1 + fi + for dev in ${devs[@]}; do + luks_file=$luks_dir/host-amy + lukspw=$(cat $luks_dir/amy) + luks-setup $(root2dev) + cat >>/mnt/root/root2-crypttab <>/mnt/root/root2-fstab < /tmp/fai/fstab </tmp/fai/disk_var.sh < /tmp/fai/fstab <> /tmp/fai/fstab <>/tmp/fai/crypttab <> /tmp/fai/fstab </dev/null; then pkgs+=(nfs-kernel-server) else @@ -295,7 +295,10 @@ EOF fi rm -f /srv/fai/nfsroot/root/.ssh/known_hosts -key=$(ssh-keyscan localhost |& grep -o "ecdsa-sha2-nistp256.*") +if [[ $HOSTNAME == kd ]]; then + keyscan_arg="-p 8989" + fi +key=$(ssh-keyscan $keyscan_arg localhost |& grep -o "ecdsa-sha2-nistp256.*") for ip in faiserver $(ip addr show up| grep -w '^ *inet' | awk '{print $2}'| cut -d / -f 1 | grep -vF 127.0.0.1); do echo "$ip $key" >>/srv/fai/nfsroot/root/.ssh/known_hosts done diff --git a/wrt-setup-local b/wrt-setup-local index d900897..3388952 100755 --- a/wrt-setup-local +++ b/wrt-setup-local @@ -594,7 +594,7 @@ config rule option dest_port 22 config redirect - option name sshtp + option name sshkd option src wan option src_dport 2202 option dest_port 22 @@ -605,6 +605,20 @@ config rule option target ACCEPT option dest_port 2202 + +config redirect + option name sshkdalt + option src wan + option src_dport 8989 + option dest_port 8989 + option dest_ip $l.2 + option dest lan +config rule + option src wan + option target ACCEPT + option dest_port 8989 + + config redirect option name sshx2 option src wan @@ -1042,6 +1056,7 @@ dhcp-host=80:fa:5b:1c:6e:cf,set:amy,$l.8,amy # and copying the generated mac, so it should be randomish. dhcp-host=52:54:00:9c:ef:ad,set:demohost,$l.12,demohost dhcp-host=62:03:cb:a8:3e:a3,set:trp,$1.13,trp +#dhcp-host=62:03:cb:a8:3e:a3,set:onep9,$1.14,onep9 dhcp-host=00:1f:16:14:01:d8,set:x3,$l.18,x3 # BRN001BA98CA823 in dhcp logs dhcp-host=00:1b:a9:8c:a8:23,set:brother,$l.19,brother -- 2.30.2