From: Ian Kelling Date: Tue, 7 Feb 2017 00:21:31 +0000 (-0800) Subject: Merge branch 'upstream' X-Git-Url: https://iankelling.org/git/?p=automated-distro-installer;a=commitdiff_plain;h=7f77555b3d92709034fe41919358053c650c71e1;hp=-c Merge branch 'upstream' merges upstream example config 5.3.4~bpo8+1 --- 7f77555b3d92709034fe41919358053c650c71e1 diff --combined fai-revm index 97b6338,0000000..cc494cc mode 100755,000000..100755 --- a/fai-revm +++ b/fai-revm @@@ -1,138 -1,0 +1,139 @@@ +#!/bin/bash -l +# Copyright (C) 2016 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. + + + +cleanup() { :; } +set -eE -o pipefail +trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR +script_dir=$(dirname $(readlink -f "$BASH_SOURCE")) + +e() { echo "$*"; "$@"; } + + +usage() { + cat < 1 should be the only +# important things to test. +disk_count=1 + + +if [[ $script_dir == /a/bin/* ]]; then + # Copy our script elsewhere so we can develop it + # and save it at the same time it's running + rm -rf /tmp/faifreeze + mkdir -p /a/tmp + cp -ar /a/bin/fai /tmp/faifreeze + exec /tmp/faifreeze/${BASH_SOURCE##*/} "$@" +fi + +cd $script_dir + +is_arch_revm() { + [[ ${0##*/} == arch-revm ]] +} + +cleanup() { ./pxe-server; } +if is_arch_revm; then + ./pxe-server demohost arch + sleep 2 + # via osinfo-query os. guessing arch is closest to latest fedora. + variant=fedora22 +else + ./pxe-server demohost fai + sleep 2 + # I don't think these variants actually make a diff for us, but I + # use the appropriate one when trying a new distro just in case. + variant=ubuntu14.04 + #variant=ubuntu16.04 + #variant=debian8 +fi + +name=demohost + +e s virshrm $name ||: + + +disk_arg=() +for ((i=1; i <= disk_count; i++)); do + f=/var/lib/libvirt/images/${name}$i + disk_arg+=("--disk path=$f") + if $new_disk || [[ ! -e $f ]]; then + s rm -f $f + e s qemu-img create -o preallocation=metadata -f qcow2 $f 20G + fi +done + +if [[ $SSH_CLIENT ]]; then + console_arg=--noautoconsole +fi + +# --cpu host: this causes mkfs.btrfs to fail with a stack trace which began +# something like: +# init_module+0x108/0x1000 [raid6_pq] +# +# uniq is to stop gtk-warning spam +e s virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \ + ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \ + --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq & + +if [[ $SSH_CLIENT ]]; then + fg +fi + +sleep 30 +while ! timeout -s 9 10 ssh root@$name /bin/true; do + e sleep 5 ++ khfix root@$name ||: +done +cleanup() { :; } +e pxe-server +if is_arch_revm; then + ./arch-init-remote $name +fi diff --combined fai/config/basefiles/mk-basefile index a61010a,6d6cfca..15fbf76 --- a/fai/config/basefiles/mk-basefile +++ b/fai/config/basefiles/mk-basefile @@@ -2,11 -2,8 +2,8 @@@ # mk-basefile, create basefiles for some distributions # - # Thomas Lange, Uni Koeln, 2011-2015 + # Thomas Lange, Uni Koeln, 2011-2016 # based on the Makefile implementation of Michael Goetze - # - # Usage example: fai-mk-basefile -J SQUEEZE64 - # This will create a SQUEEZE64.tar.xz basefile. # Supported distributions (each i386/amd64): # Debian GNU/Linux @@@ -20,20 -17,17 +17,18 @@@ # Define your local mirros here # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf -MIRROR_DEBIAN=http://httpredir.debian.org/debian/ +MIRROR_DEBIAN=http://http.us.debian.org/debian - #MIRROR_DEBIAN=http://localmirror/debian/ MIRROR_UBUNTU=http://mirror.netcologne.de/ubuntu/ +MIRROR_TRISQUEL=http://mirror.fsf.org/trisquel/ MIRROR_CENTOS=http://mirror.netcologne.de/ - #MIRROR_CENTOS=http://localmirror - #MIRROR_SLC=http://localmirror EXCLUDE_SQUEEZE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data - EXCLUDE_WHEEZY=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data - EXCLUDE_JESSIE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data + EXCLUDE_WHEEZY=info,tasksel,tasksel-data + EXCLUDE_JESSIE=tasksel,tasksel-data + EXCLUDE_STRETCH=tasksel,tasksel-data - +EXCLUDE_BELENOS=dhcp3-client,dhcp3-common,info EXCLUDE_TRUSTY=dhcp3-client,dhcp3-common,info - EXCLUDE_XENIAL=isc-dhcp-client,isc-dhcp-common,udhcpc,dibbler-client,dhcpcd5,info,tasksel,tasksel-data + EXCLUDE_XENIAL=tasksel,tasksel-data INCLUDE_DEBIAN=aptitude @@@ -126,7 -120,7 +121,7 @@@ cleanup-rinse() tarit() { - tar --xattrs --selinux --acl --one-file-system -C $xtmp -cf - . | $zip > $target.$ext + tar $attributes --one-file-system -C $xtmp -cf - . | $zip > $target.$ext } @@@ -160,80 -154,30 +155,30 @@@ slc() } - squeeze() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_SQUEEZE} squeeze $xtmp ${MIRROR_DEBIAN} - cleanup-deb - tarit - } + debgeneric() { - wheezy() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_WHEEZY} wheezy $xtmp ${MIRROR_DEBIAN} - cleanup-deb - tarit - } - - jessie() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} jessie $xtmp ${MIRROR_DEBIAN} - cleanup-deb - tarit - } - - stretch() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} stretch $xtmp ${MIRROR_DEBIAN} - cleanup-deb - tarit - } - - trusty() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_TRUSTY} --include=${INCLUDE_DEBIAN} trusty $xtmp ${MIRROR_UBUNTU} - cleanup-deb - tarit - } - - xenial() { - - local arch=$1 - - check - debootstrap --arch $arch --exclude=${EXCLUDE_XENIAL} --include=${INCLUDE_DEBIAN} xenial $xtmp ${MIRROR_UBUNTU} - cleanup-deb - tarit - } + local DIST=$1 + shift + local mirror=$1 + if [[ $DIST =~ 64 ]]; then + arch=amd64 + else + arch=i386 + fi - belenos() { - ln -sf gutsy /usr/share/debootstrap/scripts/belenos - local arch=$1 + DIST=${DIST%%??} + dist=${DIST,,} + local exc="EXCLUDE_$DIST" check - debootstrap --arch $arch --exclude=${EXCLUDE_BELENOS} --include=${INCLUDE_DEBIAN} belenos $xtmp ${MIRROR_TRISQUEL} + debootstrap --arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror cleanup-deb tarit } - unknown() { + prtdists() { - echo "Unknown distribution. Aborting." echo "Available: CENTOS5_32 CENTOS5_64 @@@ -247,27 -191,56 +192,56 @@@ SQUEEZE32 SQUEEZE64 WHEEZY32 WHEEZY64 JESSIE32 JESSIE64 + STRETCH32 STRETCH64 " - exit 99 } + usage() { + + cat <$error?$?:$error))' ERR # save maximum error code - if ! ifclass STABLE; then - + newnicnames() { + + # determine predictable network names only for stretch and above + + [ $do_init_tasks -eq 0 ] && return + + ver=$($ROOTCMD dpkg-query --showformat='${Version}' --show udev) + if dpkg --compare-versions $ver lt 220-7; then + return + fi + + [ -z $NIC1 ] && return + + fields="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH" + for field in $fields; do + name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E: $field=(.+)/\1/p") + if [[ $name ]]; then + NIC1=$name + break + fi + done + if ifclass VM; then - # older distro still uses eth0 - if ifclass BELENOS64; then - NIC1=eth0 - else - # For a vm, we only get ID_NET_NAME_MAC from below, - # but when it reboots, it uses ID_NET_NAME_SLOT. - NIC1=ens3 - fi - else - # get persistent interface name. Note, these class conditions - # will need to get modified for new oses. testing vm doesn't use - # it right now, but other vms do I'm sure. - for field in ID_NET_NAME_FROM_DATABASE \ - ID_NET_NAME_ONBOARD \ - ID_NET_NAME_SLOT \ - ID_NET_NAME_PATH \ - ID_NET_NAME_MAC; do - name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E: $field=(.+)/\1/p") - if [[ $name ]]; then - NIC1=$name - break - fi - done - if [[ ! $name ]]; then - echo "$0: error: could not find systemd predictable network name" - exit 1 - fi ++ NIC1=ens3 ++ return + fi - fi + if [[ ! $name ]]; then + echo "$0: error: could not find systemd predictable network name. Using $NIC1." + fi + } + + newnicnames + CIDR=$(ip -o -f inet addr show $NIC1 | awk '{print $4}') + if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then - if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ] - then - cat > $target/etc/network/interfaces <<-EOF + if ifclass VM; then ++ ++ # note, this condition would apply to the elif below too, ++ # but I don't specify a static ip in fai, so not bothering + cat > $target/etc/network/interfaces <<-EOF - # generated by FAI - auto lo $NIC1 - iface lo inet loopback - iface $NIC1 inet dhcp + # generated by FAI + auto lo $NIC1 + iface lo inet loopback + iface $NIC1 inet dhcp EOF + else + cat > $target/etc/network/interfaces <<-EOF + # generated by FAI + auto lo br0 + iface lo inet loopback + iface $NIC1 inet manual + # make a bridge by default so we can have bridged vms. + # Some example I read had stp on, but i don't need stp, + # and it causes a vm to fail pxe boot, presumably unless + # you add some delay. + # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed + iface br0 inet dhcp + bridge_ports $NIC1 + bridge_stp off + bridge_maxwait 0 +EOF + fi - elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ] - then - [ -n "$IPADDR" ] && cat > $target/etc/network/interfaces <<-EOF - # generated by FAI - auto lo $NIC1 - iface lo inet loopback - iface $NIC1 inet static - address $IPADDR - netmask $NETMASK - broadcast $BROADCAST - gateway $GATEWAYS + elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then - [ -n "$CIDR" ] && cat > $target/etc/network/interfaces <<-EOF ++ [ -n "$CIDR" ] && cat > $target/etc/network/interfaces <<-EOF + # generated by FAI + auto lo $NIC1 + iface lo inet loopback + iface $NIC1 inet static + address $CIDR + gateway $GATEWAYS EOF [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc/networks if [ ! -L $target/etc/resolv.conf -a -e /etc/resolv.conf ]; then diff --combined fai/config/scripts/DEBIAN/40-misc index b6fd305,8308bbe..8d4e85d --- a/fai/config/scripts/DEBIAN/40-misc +++ b/fai/config/scripts/DEBIAN/40-misc @@@ -1,24 -1,8 +1,24 @@@ #! /bin/bash - # (c) Thomas Lange, 2001-2015, lange@debian.org + # (c) Thomas Lange, 2001-2016, lange@debian.org # (c) Michael Goetze, 2010-2011, mgoetze@mgoetze.net + +# on ubuntu 16.04 which didn't run this script, some things which didn't +# apply: +# /etc/dpkg/dpkg.cfg.d/fai didn't exist, +# machine-id was already setup. + +# on that system and a debian stretch system, after reboot, +# some things done here don't seem to persist: +# some thin/etc/mtab is symlink somewhere else, +# and mailname is $HOSTNAME.lan + +# the adjtime thing is to support changing the system clock +# from representing UTC (the default) to localtime (windows default). + +# afaik, the only useful thing here for me is setting /etc/hostname + error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code # a list of modules which are loaded at boot time @@@ -27,9 -11,9 +27,9 @@@ for module in $MODULESLIST; d done fcopy -Mv /etc/hostname || echo $HOSTNAME > $target/etc/hostname - ainsl -av /etc/mailname ${HOSTNAME} + ainsl -a /etc/mailname ${HOSTNAME} if [ ! -e $target/etc/adjtime ]; then - printf "0.0 0 0.0\n0\nUTC" > $target/etc/adjtime + printf "0.0 0 0.0\n0\nUTC\n" > $target/etc/adjtime fi if [ "$UTC" = "yes" ]; then sed -i -e 's:^LOCAL$:UTC:' $target/etc/adjtime @@@ -50,11 -34,15 +50,15 @@@ f ln -fs /proc/mounts $target/etc/mtab - rm -f $target/etc/dpkg/dpkg.cfg.d/fai + rm -f $target/etc/dpkg/dpkg.cfg.d/fai $target/etc/dpkg/dpkg.cfg.d/unsafe-io - [ $FAI_ACTION = "install" -a -f /etc/fai/fai.conf ] && cp /etc/fai/fai.conf $target/etc/fai/fai.conf - ainsl -av /etc/fai/fai.conf "FAI_CONFIG_SRC=$FAI_CONFIG_SRC" + if [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ] ; then + [ -f /etc/fai/fai.conf ] && cp /etc/fai/fai.conf $target/etc/fai/fai.conf + fi + + ainsl -a /etc/fai/fai.conf "FAI_CONFIG_SRC=$FAI_CONFIG_SRC" fcopy -Miv /etc/fai/fai.conf + fcopy -iv /etc/rc.local exit $error diff --combined fai/config/scripts/GRUB_PC/10-setup index 88b557e,7a04760..160dfa2 --- a/fai/config/scripts/GRUB_PC/10-setup +++ b/fai/config/scripts/GRUB_PC/10-setup @@@ -4,6 -4,11 +4,11 @@@ error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code set -a + + # do not set up grub during dirinstall + if [ "$FAI_ACTION" = "dirinstall" ] ; then + exit 0 + fi # during softupdate use this file [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh @@@ -21,24 -26,33 +26,36 @@@ if [ $FAI_ACTION != "install" ]; the fi $ROOTCMD grub-mkdevicemap --no-floppy -GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE) + # Check if RAID is used for the boot device if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then + GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE) raiddev=${BOOT_DEVICE#/dev/} # install grub on all members of RAID for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do echo Install grub on /dev/$device $ROOTCMD grub-install --no-floppy "/dev/$device" done + + elif [[ $GROOT =~ 'hostdisk' ]]; then + cat > $target/boot/grub/device.map <$error?$?:$error))' ERR # save maximum error code - if [ "$FAI_ACTION" = "dirinstall" ] ; then + if [ "$FAI_ACTION" = "dirinstall" -o $do_init_tasks -eq 0 ] ; then : else # check if mdadm has been forgotten @@@ -15,14 -15,13 +15,14 @@@ fi fi - usedm=$(dmsetup ls | egrep -v '^live-rw|^live-base|^No devices found' | wc -l) - if [ $usedm -ne 0 ]; then - if [ ! -d $target/etc/lvm ]; then - echo ERROR: Found lvm devices, but the lvm2 package was not installed - error=1 - fi - fi + # # commented because it does false possitive + # usedm=$(dmsetup ls | egrep -v '^live-rw|^live-base|^No devices found' | wc -l) + # if [ $usedm -ne 0 ]; then + # if [ ! -d $target/etc/lvm ]; then + # echo ERROR: Found lvm devices, but the lvm2 package was not installed + # error=1 + # fi + # fi fi # remove backup files from cfengine, but only if cfengine is installed @@@ -46,7 -45,7 +46,7 @@@ if [ $do_init_tasks -eq 1 ] ; the fi # Make sure everything is configured properly -if ifclass DEBIAN ; then +if ifclass DEBIAN || ifclass UBUNTU; then echo "Running \"apt-get -f install\" for the last time." $ROOTCMD apt-get -f install fi @@@ -59,4 -58,36 +59,36 @@@ f # copy sources.list fcopy -iM /etc/apt/sources.list + + setrel() { + + # if release is not set, try to determine it + + if [ -n "$release" ]; then + return + fi + if [ ! -f $target/etc/os-release ]; then + return + fi + + dists="jessie stretch xenial trusty" + for d in $dists; do + if grep -iq $d $target/etc/os-release; then + release=$d + break + fi + done + echo "\$release set to $release" + } + + # if installation was done from CD, replace useless sources.list + setrel + if [ -f $target/etc/apt/sources.list -a -n "$release" ]; then + grep -q 'file generated by fai-cd' $target/etc/apt/sources.list && cat < $target/etc/apt/sources.list + deb http://httpredir.debian.org/debian $release main contrib non-free + deb http://httpredir.debian.org/debian-security $release/updates main contrib non-free + deb [trusted=yes] http://fai-project.org/download $release koeln + EOF + fi + exit $error