From 527f50b38e4a94a771215131cafe016a97ba83cd Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 12 Jun 2018 22:39:41 -0400 Subject: [PATCH] various fixes, make settable basefile dir --- README | 4 +- fai-redep | 5 +- fai-revm | 10 +++- fai/config/basefiles/mk-basefile | 1 - faiserver-setup | 7 ++- grub.cfg.autodiscover | 87 ++++++++++++++++++++++++++++++++ myfai-chboot | 3 -- myfai-chboot-local | 9 ++-- mymk-basefile | 53 +++++++++++++++++++ 9 files changed, 161 insertions(+), 18 deletions(-) create mode 100644 grub.cfg.autodiscover create mode 100755 mymk-basefile diff --git a/README b/README index e81a467..0333064 100644 --- a/README +++ b/README @@ -70,9 +70,10 @@ All scripts meant to be used directly are listed here: # Scripts to setup the environment for the install +sudo fai-cd grub.cfg.autodiscover -f -A $BASEFILE_DIR/autodiscover.iso # create autodiscover cd +mymk-basefile # Create basefiles for various distros arch-pxe # Setup arch pxe boot server from an arch base image fai-redep # Deploy fai configuration to host "faiserver" -faiserver-revm # using pxe & preseed, create a vm which is a fai server faiserver-uninstall # uninstall fai-server faiserver-setup # install fai-server on the current machine myfai-chboot # setup fai tftp and nfs. useful for doing pxe-kexec @@ -82,6 +83,7 @@ wrt-setup # setup my router in general: dhcp, dns, etc. # Script to do a distro install +faiserver-revm # using pxe & preseed, create a vm which is a fai server dsfull # install & post-install a new fai distro arch-init-remote # install arch after it's been booted into it's setup env fai-kexec # Kexec this or a remote machine using host faiserver diff --git a/fai-redep b/fai-redep index 5306d97..3e1263d 100755 --- a/fai-redep +++ b/fai-redep @@ -41,7 +41,7 @@ distro=$2 # use it, so look it up just to avoid the warning spam. faiserver_host=$(chost $host) || faiserver_host=$host -rsync -rlp --delete --relative --exclude /fai/config/basefiles/ fai/config root@$faiserver_host:/srv +rsync -rlpt --delete --relative --exclude /fai/config/basefiles/ fai/config root@$faiserver_host:/srv scp -q ~/.ssh/home.pub \ @@ -62,10 +62,9 @@ pall+=($(/a/bin/buildscripts/emacs -p; /a/bin/distro-setup/distro-pkgs $distro)) ssh root@$faiserver_host dd of=/srv/fai/config/package_config/DESKTOP 2>/dev/null ||: # broken pipe -rsync -rplt --delete /a/bin/fai-basefiles/basefiles root@$faiserver_host:/srv/fai/config +rsync -rplt --delete $BASEFILE_DIR/*.gz root@$faiserver_host:/srv/fai/config/basefiles/ ssh root@$faiserver_host bash <<'EOF' set -eE -o pipefail -set -x # make it the root because pxe-kexec only looks there. # It wouldn't be too hard to change if we needed. # We could also just dump things in /srv/tftp, but fai diff --git a/fai-revm b/fai-revm index 30f5419..7933377 100755 --- a/fai-revm +++ b/fai-revm @@ -101,7 +101,13 @@ else sleep 2 else fai-monitor& - boot_arg="--cdrom /a/bin/fai-basefiles/autodiscover.iso" + if [[ $BASEFILE_DIR ]]; then + BASEFILE_DIR=/tmp + fi + if [[ ! -e $BASEFILE_DIR/autodiscover.iso ]]; then + fai-cd grub.cfg.autodiscover -f -A $BASEFILE_DIR/autodiscover.iso + fi + boot_arg="--cdrom $BASEFILE_DIR/autodiscover.iso" e fai-redep e myfai-chboot default fi @@ -158,7 +164,7 @@ while ! timeout -s 9 10 ssh -oBatchMode=yes root@$name /bin/true; do e sleep 5 done unset _errcatch_cleanup -e pxe-server +e ./pxe-server $dhcp_arg if is_arch_revm; then ./arch-init-remote $name fi diff --git a/fai/config/basefiles/mk-basefile b/fai/config/basefiles/mk-basefile index ccfd367..8f2bd4a 100755 --- a/fai/config/basefiles/mk-basefile +++ b/fai/config/basefiles/mk-basefile @@ -1,5 +1,4 @@ #! /bin/bash -set -x # mk-basefile, create basefiles for some distributions # # Thomas Lange, Uni Koeln, 2011-2017 diff --git a/faiserver-setup b/faiserver-setup index 28e71e3..b9fe68f 100755 --- a/faiserver-setup +++ b/faiserver-setup @@ -30,8 +30,7 @@ that using a hostname does not work. Separate from running this, faiserver needs to be setup in dns to point to whatever host this is run on. -For running on arm, it expects Ian's fai-basefiles repository at -/a/bin/fai-basefiles +It expects $BASEFILE_DIR/STRETCH64.tar.gz to exist. EOF exit $1 @@ -186,7 +185,7 @@ fi if armhf; then cd /srv/fai rm -rf nfsroot - tar Jxf /a/bin/fai-basefiles/basefiles/STRETCH64.tar.xz + tar Jxf $BASEFILE_DIR/STRETCH64.tar.xz # background: Can't build the nfsroot on my arm system now. First, # fai-make-nfsroot won't work out of the box. One idea to make it work # is by installing qemu-user-static, then copying qemu-x86_64-static @@ -242,7 +241,7 @@ EOF else # not armhf # note, this copies the -B arg to # /srv/fai/nfsroot/var/tmp/base.tar.xz - e fai-setup -evf -B /a/bin/fai-basefiles/basefiles/STRETCH64.tar.gz + e fai-setup -evf -B $BASEFILE_DIR/STRETCH64.tar.gz # fai-setup expert mode avoids writing to /var/log/fai/variables # at least config_src is needed for autodiscover $sed '/^FAI_CONFIGDIR|^FAI_CONFIG_SRC|^LOGUSER/d' /var/log/fai/variables diff --git a/grub.cfg.autodiscover b/grub.cfg.autodiscover new file mode 100644 index 0000000..b1516bb --- /dev/null +++ b/grub.cfg.autodiscover @@ -0,0 +1,87 @@ +## grub2 configuration +set default="FAI server via dns" +set timeout=2 +set resolution=1024x768 + +if loadfont /boot/grub/unicode.pf2 ; then + insmod png + set gfxmode=640x480 + insmod gfxterm + insmod vbe + terminal_output gfxterm +fi + +if background_image /boot/grub/fai.png ; then + set color_normal=black/black + set color_highlight=red/black + set menu_color_normal=black/black + set menu_color_highlight=black/yellow +else + set menu_color_normal=white/black + set menu_color_highlight=black/yellow +fi + +# make sure we can access partitions +insmod part_msdos +insmod part_gpt + +if [ ${iso_path} ] ; then + set loopback="findiso=${iso_path}" +fi + +menuentry "" --unrestricted { + set gfxpayload=$resolution +} +menuentry " +------------------------------------------------------+" --unrestricted { + set gfxpayload=$resolution +} + +menuentry " | Fully Automatic Installation |" --unrestricted { + set gfxpayload=$resolution + +} +menuentry " | _VERSIONSTRING_ |" --unrestricted { + set gfxpayload=$resolution + +} +menuentry " | (c) Thomas Lange lange@debian.org |" --unrestricted { + set gfxpayload=$resolution +} +menuentry " +------------------------------------------------------+" --unrestricted { + set gfxpayload=$resolution +} +} +menuentry "" --unrestricted { + set gfxpayload=$resolution +} + +menuentry "Autodiscover the FAI server" { + set gfxpayload=$resolution + linux /boot/vmlinuz FAI_FLAGS="menu,verbose,createvt" fai.discover aufs rootovl root=/dev/nfs ip=dhcp quiet + initrd /boot/initrd.img +} + +# ian: Added this from fai +# note, we could replace faiserver with an ip if we didn't want to mess with dns. +# args are copied from myfai-chboot-local +menuentry "FAI server via dns" { + set gfxpayload=$resolution + linux /boot/vmlinuz FAI_FLAGS=verbose,sshd,createvt,reboot FAI_CONFIG_SRC=nfs://faiserver/srv/fai/config root=/dev/nfs rw nfsroot=faiserver:/srv/fai/nfsroot,vers=3,nolock aufs rootovl ip=dhcp FAI_FLAGS=verbose,sshd,createvt,reboot + initrd /boot/initrd.img +} + + +menuentry "Boot OS of first partition on first disk" --unrestricted { + if [ -d (cd) ]; then + chainloader (hd0)+1 + fi + + if [ "$root" = "hd1" ]; then + chainloader (hd0)+1 + fi + + if [ "$root" = "hd0" ]; then + set root=(hd1) + chainloader (hd1)+1 + fi +} diff --git a/myfai-chboot b/myfai-chboot index 0d036b9..cbba8b5 100755 --- a/myfai-chboot +++ b/myfai-chboot @@ -29,9 +29,6 @@ to disable the nfs server. EOF exit $1 } -if [[ ! $1 ]]; then - usage 1 -fi case $1 in -h|--help) usage ;; esac diff --git a/myfai-chboot-local b/myfai-chboot-local index 49ee6f6..f46c32d 100755 --- a/myfai-chboot-local +++ b/myfai-chboot-local @@ -35,6 +35,11 @@ e() { host=$1 +rm -f /srv/tftp/fai/pxelinux.cfg/* +if [[ ! $1 ]]; then + exit 0 +fi + # assuming ipv4, or else we might need to deal with multiple addresses # in an ipv4 + ipv6 network. my_ip=$(ip -4 route get 8.8.8.8 | sed -nr 's,^.*src\s+(\S+).*,\1,p') @@ -88,10 +93,6 @@ else EOF fi -rm -f /srv/tftp/fai/pxelinux.cfg/* -if [[ ! $1 ]]; then - exit 0 -fi # man page doesn't explain this, but this deletes & thus disables diff --git a/mymk-basefile b/mymk-basefile new file mode 100755 index 0000000..2a7f453 --- /dev/null +++ b/mymk-basefile @@ -0,0 +1,53 @@ +#!/bin/bash + +x="$(readlink -f "$BASH_SOURCE")"; source "${x%/*}/bash-trace" +script_dir="${x%/*}" + +usage() { + cat <