From: Ian Kelling Date: Sun, 22 Jan 2017 01:39:34 +0000 (-0800) Subject: fixes mostly for bootstrap vol, better docs X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=83828fe2683227f4d8ecb2343eff28439741b490;p=automated-distro-installer fixes mostly for bootstrap vol, better docs --- diff --git a/README b/README index 10d52fe..5e09791 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ Multi-boot/distro btrfs provisioning -Some things are specific to my home network. Uses pxe or pxe-kexec (on -libreboot, I have not addded a pxe rom. I use a minimal debian stable -subvolume which acts like a pxe rom). I use this for bare metal and vms, -and two scripts which can run post boot so I use them on vps distributed -image as well. +Some things are specific to my home network, and uses files with secrets +that are not in this repo. Uses pxe or pxe-kexec (on libreboot, I have +not added a pxe rom, I use a minimal debian stable subvolume which acts +like a pxe rom). I use this for bare metal and vms, and two scripts +which can run post boot so I use them on vps distributed image as well. Features people may find useful: installs encrypted trisquel belanos, , debian jessie, debian stretch, ubuntu 16.04, and arch (havne't done @@ -52,6 +52,7 @@ install-chboot # reinstall chboot to /boot subvols, for when it changes dsfull # install & setup a new fai distro (if data partition already synced) eboot # reboot without automatic disk decryption fai-kexec # kexec to fai tftp server that pxe would normally point to +fai-redep # Deploy fai configuration to host "faiserver" fai-revm # test fai on a fresh vm fai-wrapper # Evaluate and use fai classes outside of fai. faiserver-revm # create a vm which is a fai server using pxe & preseed file diff --git a/arch-init b/arch-init index 37fa90b..aa26ffd 100755 --- a/arch-init +++ b/arch-init @@ -18,7 +18,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -cd $(dirname $(readlink -f "$BASH_SOURCE")) +x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} export HOSTNAME="$1" mirror=$2 diff --git a/fai-kexec b/fai-kexec index 5e10ac2..dbf003b 100755 --- a/fai-kexec +++ b/fai-kexec @@ -14,11 +14,28 @@ # limitations under the License. -# kexec to fai tftp server that pxe would normally point to - set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +usage() { + cat <<'EOF' +usage: $0 [-h|--help] [SERVER] +kexec to SERVER (faiserver by default), pxe boot from it's tftp server + +This does what pxe would do, but skipping boot sequence up to and +including the pxe dhcp. + +EOF + exit $1 +} + +case $1 in + -h|--help) usage ;; +esac + + + if [[ $1 ]]; then prefix="ssh root@$1" fi diff --git a/fai-redep b/fai-redep index b035ef5..b8fabac 100755 --- a/fai-redep +++ b/fai-redep @@ -16,13 +16,23 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. set -x -# Deploy fai configuration to faiserver, -# then start a virtual machine to test the config. + set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -cd $(dirname $(readlink -f "$BASH_SOURCE")) +x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} + +usage() { + cat <&2' ERR + + +usage() { + cat < deadline )); then - echo "fai-check: hit $NETWORK_TIMOUT_SECS s tftp server timeout" - return 0 - fi - sleep 1 - done - m pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||: - else - return 0 - fi +try-kexec() { + deadline=$(( `date +%s` + NETWORK_TIMOUT_SECS )) + while ! nc -zu faiserver 69; do + if (( `date +%s` > deadline )); then + echo "fai-check: hit $NETWORK_TIMOUT_SECS s tftp server timeout" + return 0 + fi + sleep 1 + done + m pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||: } +case $1 in + -f|--force) + try-kexec + exit + ;; +esac + first=true for dev in $(btrfs fi show / | sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \ |sort); do @@ -46,7 +59,18 @@ for dev in $(btrfs fi show / | sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \ set +x fi first=false - check-fai + # we could just as well check if last_boot != /debianstable_boostrap + # the intent with this one is just a little clearer. + if [[ $did_fai_check == true ]]; then + grub-editenv /mnt/grubenv set did_fai_check=os_true + # our service does not wait for network-online.target, + # because it will wait for too long when we don't have a network + # connection. So, we wait for 10 seconds. + # ref: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ + try-kexec + else + return 0 + fi else # we make sure there is only 1 grubenv, # so grub can just find the first one, in whatever order diff --git a/fai/config/hooks/instsoft.DEFAULT b/fai/config/hooks/instsoft.DEFAULT index 36c0caf..6d7f4c0 100755 --- a/fai/config/hooks/instsoft.DEFAULT +++ b/fai/config/hooks/instsoft.DEFAULT @@ -1,7 +1,7 @@ #!/bin/bash # exit for any vm which is not our test vm -if ifclass VM && ! ifclass demohost || ifclass STABLE_BOOTSTRAP; then +if ifclass VM && ! ifclass demohost || ifclass VOL_STABLE_BOOTSTRAP; then exit 0 fi diff --git a/fai/config/scripts/GRUB_PC/11-ian b/fai/config/scripts/GRUB_PC/11-ian index 6a55e44..0a3bbdb 100755 --- a/fai/config/scripts/GRUB_PC/11-ian +++ b/fai/config/scripts/GRUB_PC/11-ian @@ -30,13 +30,6 @@ EOFOUTER fcopy -riB /boot # this is also done by FABASE/10-misc by default. fcopy -riB /root -if ifclass STABLE_BOOTSTRAP; then - fcopy -ri /etc/systemd/system - chroot $FAI_ROOT bash <<'EOFOUTER' -systemctl enable fai_check.service -EOFOUTER - exit 0 -fi src=$FAI/distro-install-common/shadow @@ -51,9 +44,20 @@ src=$FAI/distro-install-common/p/c/machine_specific/$HOSTNAME/filesystem/etc/ssh dst=/target/etc/ssh if [[ -e $src && -e $dst ]]; then # outside of fai context, we skip this - cp -rT $src + cp -rT $src $dst fi +fcopy -riB /etc/ssh + +if ifclass VOL_STABLE_BOOTSTRAP; then + fcopy -ri /etc/systemd/system + chroot $FAI_ROOT bash <<'EOFOUTER' +systemctl enable fai_check.service +EOFOUTER + exit 0 +fi + + $FAI/distro-install-common/end # these get copied in an earlier stage by fai, but leaving it here since @@ -65,7 +69,6 @@ fcopy -riB /etc/apt sleep 1 $ROOTCMD apt-get update -fcopy -riB /etc/ssh chroot $FAI_ROOT bash <<'EOF' set -eE -o pipefail diff --git a/faiserver-revm b/faiserver-revm index 7842723..a0a0bb8 100755 --- a/faiserver-revm +++ b/faiserver-revm @@ -10,7 +10,7 @@ set -eE -o pipefail cleanup() { :; } trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -cd "${BASH_SOURCE%/*}" +x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} cleanup() { pxe-server :; } ./debian-pxe-preseed -i 192.168.1.1 -u ian -g vda diff --git a/install-chboot b/install-chboot index 838c0ae..d066101 100755 --- a/install-chboot +++ b/install-chboot @@ -24,7 +24,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR # in case there is an issue booting and it is needed. # Run this when chboot changes. -cd "${BASH_SOURCE%/*}" +x=$(readlink -f "$BASH_SOURCE"); cd ${x%/*} e() { echo "$@"; "$@"; } diff --git a/myfai-chboot b/myfai-chboot index 1abead8..310969e 100755 --- a/myfai-chboot +++ b/myfai-chboot @@ -3,17 +3,24 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR +x=$(readlink -f "$BASH_SOURCE"); cd ${x%/*} usage() { - cat <<'EOF' -usage $0 [hostname|ip|default]... + cat <&2' ERR +case $1 in + -h|--help) + echo "see help from myfai-chboot" + exit 0 + ;; +esac + [[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@" e() { echo "$@"; "$@"; } diff --git a/pxe-server b/pxe-server index e59854a..9e74eeb 100755 --- a/pxe-server +++ b/pxe-server @@ -45,12 +45,14 @@ ln -s tftpboot -r Don't redeploy fai config. For example, if there is a different host that is mid-install. --a Wait for 2 dhcp acks, then disable the pxe server after a delay. - First ack is for pxe boot, 2nd ack is for os boot. Sometimes - on debian, there is a 3rd one shortly after the 2nd. I can't remember - exactly why this caused a problem, but I'm hoping the sleep - will take care of it. --w Initially setup pxe, then wait like -a. + +-a Don't setup pxe, just Wait for 2 dhcp acks, then disable the pxe + server after a delay. First ack is for pxe boot, 2nd ack is + for os boot. Sometimes on debian, there is a 3rd one shortly + after the 2nd. I can't remember exactly why this caused a + problem, but I'm hoping the sleep will take care of it. + +-w Setup pxe, then wait like -a. -h|--help Print help and exit diff --git a/wrt-setup-remote b/wrt-setup-remote index 57e2c59..f2948b0 100755 --- a/wrt-setup-remote +++ b/wrt-setup-remote @@ -21,7 +21,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -cd "${BASH_SOURCE%/*}" +x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} h=root@192.168.1.1 scp /a/bin/fai/wrt-setup /a/bin/cedit/cedit $h:/usr/bin