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
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
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
# 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
# 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 <<EOF
+usage: ${0##*/} [-h|--help]
+Deploy fai configuration to host "faiserver"
+EOF
+ exit $1
+}
+case $1 in
+ -h|--help) usage ;;
+esac
# i use faiserver as a dns alias, but ssh key is associated with
# STABLE, STRETCH64, XENIAL64, BELANOS64
# the distro subvol name, we can add as many of these as we want:
# VOL_STABLE, VOL_STABLE_BOOTSTRAP, VOL_STRETCH, VOL_XENIAL, VOL_BELANOS
+# Using VOL_STABLE_BOOTSTRAP sets up the install to act like a pxe rom if
+# grub sets a specific var.
# and the class which defines the apt sources files we want,
# STABLE_FREE, STABLE_NONFREE, TESTING_FREE, TESTING_NONFREE,
# XENIAL_FREE (no XENIAL_NONFREE setup yet), BELANOS, STABLE_LINODE.
fi
fi
-# use a list of classes for our demo machine
echo "FAIBASE"
-#echo "PARTITION_PROMPT"
+echo "PARTITION_PROMPT"
#echo REPARTITION
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+
+usage() {
+ cat <<EOF
+Usage: ${0##*/} [OPTION]
+If grub var set, act like pxe rom and pxe-kexec to faiserver
+
+-f|--force do kexec if we can reach faiserver
+-h|--help Print help and exit.
+
+Note: Uses GNU getopt options parsing style
+EOF
+ exit $1
+}
+
+
+
# Keep it short so we don't delay too much wnen we don't have networking.
# In practice, on my home network, on an x200, it took 15 seconds, so
# give it an extra 10 seconds, which seems fairly short as I write this.
m() { printf "%s\n" "$*"; "$@"; }
-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/
- 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 ||:
- 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
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
#!/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
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
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
sleep 1
$ROOTCMD apt-get update
-fcopy -riB /etc/ssh
chroot $FAI_ROOT bash <<'EOF'
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
# 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 "$@"; "$@"; }
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 <<EOF
+usage: ${0##*/} [-h|--help] [hostname|ip|default]...
-Sets up tftp pxe config. No argument disables for all hosts.
+Sets up tftp pxe config on host "faiserver". Argument sets the host to
+enable it for, "default" is for all hosts. No argument disables for all
+hosts.
EOF
exit $1
}
-cd "${BASH_SOURCE%/*}" # directory of the script
+
+case $1 in
+ -h|--help) usage ;;
+esac
+
host=$(chost faiserver)
ssh root@$host bash -s "$@" <myfai-chboot-local
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+case $1 in
+ -h|--help)
+ echo "see help from myfai-chboot"
+ exit 0
+ ;;
+esac
+
[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@"
e() { echo "$@"; "$@"; }
-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
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