#! /bin/bash
-
# mk-basefile, create basefiles for some distributions
#
- # Thomas Lange, Uni Koeln, 2011-2018
+ # Thomas Lange, Uni Koeln, 2011-2020
# based on the Makefile implementation of Michael Goetze
#
# Usage example: mk-basefile -J STRETCH64
# Supported distributions (each i386/amd64):
# Debian GNU/Linux
# Ubuntu 14.04/16.04
- # CentOS 5/6/7
+ # CentOS 5/6/7/8
# Scientific Linux Cern 5/6
#
# Packages you might want to install to use this command:
# For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
MIRROR_DEBIAN=http://deb.debian.org/debian/
MIRROR_UBUNTU=http://mirror.netcologne.de/ubuntu/
+MIRROR_TRISQUEL=http://mirror.fsf.org/trisquel/
MIRROR_CENTOS=http://mirror.netcologne.de/
EXCLUDE_SQUEEZE=isc-dhcp-client,isc-dhcp-common,info
EXCLUDE_WHEEZY=info
EXCLUDE_JESSIE=info
EXCLUDE_STRETCH=info
- EXCLUDE_BUSTER=info
+ EXCLUDE_BUSTER=
+ EXCLUDE_BULLSEYE=
EXCLUDE_SID=
+EXCLUDE_BELENOS=dhcp3-client,dhcp3-common,info
EXCLUDE_TRUSTY=dhcp3-client,dhcp3-common,info
EXCLUDE_XENIAL=udhcpc,dibbler-client,info
+EXCLUDE_FLIDAS=udhcpc,dibbler-client,info
EXCLUDE_BIONIC=udhcpc,dibbler-client,info
+EXCLUDE_ETIONA=udhcpc,dibbler-client,info
+ EXCLUDE_FOCAL=udhcpc,dibbler-client,info
# here you can add packages, that are needed very early
INCLUDE_DEBIAN=
-
+INCLUDE_ETIONA=ifupdown
setarch() {
check() {
- if [ `id -u` != 0 ]; then
+ if [ $(id -u) != 0 ]; then
echo "You must be root to create chroots."
exit 1
fi
cleanup-deb() {
+ if [[ $cmd ]]; then
+ if [[ -e $cmd ]]; then
+ cp "$cmd" $xtmp/tmp
+ chroot $xtmp "/tmp/$cmd"
+ else
+ chroot $xtmp $cmd
+ fi
+ fi
chroot $xtmp apt-get clean
rm -f $xtmp/etc/hostname $xtmp/etc/resolv.conf \
$xtmp/var/lib/apt/lists/*_* $xtmp/usr/bin/qemu-*-static \
tarit() {
- tar $attributes --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
+ tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
}
dist=${DIST%%[0-9][0-9]}
local exc="EXCLUDE_$dist"
[ -n "${!exc}" ] && exc="--exclude=${!exc}" || unset exc
+ local inc="INCLUDE_$dist"
+ [ -n "${!inc}" ] && inc="--include=${!inc}" || unset inc
dist=${dist,,}
check
- if [ -n "$INCLUDE_DEBIAN" ]; then
- local inc="--include=$INCLUDE_DEBIAN"
- fi
if [ -n "$arch" ]; then
qemu-debootstrap --arch $arch ${exc} $inc $dist $xtmp $mirror
CENTOS5_32 CENTOS5_64
CENTOS6_32 CENTOS6_64
CENTOS7_32 CENTOS7_64
+ CENTOS8_64
SLC5_32 SLC5_64
SLC6_32 SLC6_64
SLC7_64
TRUSTY32 TRUSTY64
XENIAL32 XENIAL64
+ FLIDAS64
BIONIC64
+ ETIONA64
+ FOCAL64
SQUEEZE32 SQUEEZE64
WHEEZY32 WHEEZY64
JESSIE32 JESSIE64
STRETCH32 STRETCH64
BUSTER32 BUSTER64
+ BULLSEYE32 BULLSEYE64
SID32 SID64
"
}
cat <<EOF
mk-basefile, create minimal base files for a Linux distritubtion
- Copyright (C) 2011-2018 by Thomas Lange
+ Copyright (C) 2011-2020 by Thomas Lange
Usage: mk-basefile [OPTION] ... DISTRIBUTION
-z Use gzip for compressing the tar file.
-J Use xz for compressing the tar file.
-k Keep the temporary subtree structure, do not remove it.
+ -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
+ Debian based only
-h Print help.
Usage example: mk-basefile -J STRETCH64
cleanup=1
attributes="--xattrs --selinux --acls"
-while getopts ashzJd:kf: opt ; do
+while getopts ashzJd:kf:x: opt ; do
case "$opt" in
a) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
d) export TMPDIR=$OPTARG ;;
k) cleanup=0 ;;
h) usage ;;
s) prtdists ; exit 0;;
+ x) cmd="$OPTARG" ;;
?) exit 3 ;; # error in option parsing
esac
done
- shift $(($OPTIND - 1))
+ shift $((OPTIND - 1))
xtmp=$(mktemp --tmpdir -d basefiles.XXXXXXXX)
if [ $? -eq 1 ]; then
CENTOS6_64) centos amd64 6 ;;
CENTOS7_32) centos i386 7 ;;
CENTOS7_64) centos amd64 7 ;;
+ CENTOS8_64) centos amd64 8 ;;
SLC5_32) slc i386 5 ;;
SLC5_64) slc amd64 5 ;;
SLC6_32) slc i386 6 ;;
SLC6_64) slc amd64 6 ;;
SLC7_64) slc amd64 7 ;;
- TRUSTY*|XENIAL*|BIONIC*)
+ BELENOS*|FLIDAS*|ETIONA*)
+ debgeneric $target $MIRROR_TRISQUEL ;;
+ TRUSTY*|XENIAL*|BIONIC*|FOCAL*)
debgeneric $target $MIRROR_UBUNTU ;;
- SQUEEZE*|WHEEZY*|JESSIE*|STRETCH*|BUSTER*|SID*)
+ SQUEEZE*|WHEEZY*|JESSIE*|STRETCH*|BUSTER*|BULLSEYE*|SID*)
debgeneric $target $MIRROR_DEBIAN $ARCH;;
*) echo "Unknown distribution. Aborting."
prtdists
-#! /bin/bash
+#!/bin/bash
# assign classes to hosts based on their hostname
# do not use this if a menu will be presented
[ "$flag_menu" ] && exit 0
-# use a list of classes for our demo machine
-case $HOSTNAME in
- faiserver)
- echo "FAIBASE DEBIAN DEMO FAISERVER" ;;
- demohost|client*)
- echo "FAIBASE DEBIAN DEMO" ;;
- xfcehost)
- echo "FAIBASE DEBIAN DEMO XORG XFCE LVM";;
- gnomehost)
- echo "FAIBASE DEBIAN DEMO XORG GNOME";;
- ubuntuhost)
- echo "FAIBASE DEBIAN DEMO UBUNTU FOCAL FOCAL64 XORG";;
- centos)
- echo "FAIBASE CENTOS" # you may want to add class XORG here
- ifclass AMD64 && echo CENTOS8_64
- ;;
- slchost)
- # Scientific Linux Cern, is very similar to CentOS. SLC should alsways use the class CENTOS
- echo "FAIBASE CENTOS SLC" # you may want to add class XORG here
- ifclass I386 && echo SLC7_32
- ifclass AMD64 && echo SLC7_64
- ;;
- *)
- echo "FAIBASE DEBIAN DEMO" ;;
-esac
++# set these early so they are lowest priority.
++echo FAIBASE STANDARD DEBIAN
++
+
+# For multi-boot system.
+# We check that we aren't in a pxe boot environment.
+# There is probably a better way to do this.
+# We check the reverse condition in 51-multi-boot,
+# and set what os we are installing, but don't check it
+# into git since it changes regularly.
+
+#
+#
+# Each host defines following:
+# The base distro:
- # UBUNTU, DEBIAN
++# UBUNTU or nothing. DEBIAN is always defined as a base.
+#
+# The base disto version, only use so far is the basefile name if it exists.
+# Debian stable basefile gets built by faisetup and gets used otherwise.
+# With X suffix, means it has gone through the dirinstall process and has eXtra
+# things installed, to speed up installation.
+# STRETCH64, BUSTER64, XENIAL64, FLIDAS64, FLIDAS64BIG, ETIONA64, BIONIC64, FOCAL64
+#
+# The distro subvol name, we can add as many of these as we want:
+# VOL_TESTING, VOL_STRETCH, VOL_BUSTER, VOL_XENIAL, VOL_FLIDAS,
+# VOL_ETIONA VOL_STRETCH_BOOTSTRAP. Using VOL_STRETCH_BOOTSTRAP sets up
+# the install to act like a pxe rom if grub sets a specific var.
+#
+# The apt sources files we want, STRETCH_FREE, STRETCH_NONFREE,
+# BUSTER_FREE, BUSTER_NONFREE, TESTING_FREE, TESTING_NONFREE,
+# XENIAL_FREE, BIONIC, FOCAL, FLIDAS, ETIONA, STRETCH_LINODE.
+#
+# It's all a little redundant in some cases, but it keeps things
+# simpler.
+#
+#
+# Other notable classes:
+#
+# INSTALL: for autodiscover iso, this is needed. We could also add it to
+# the autodiscover grub, but then we have to burn a new iso if we want a
+# non-install one. It sets the class for the corresponding INSTALL.var,
+# which sets FAI_ACTION=INSTALL. I'm not sure if this variable overrides
+# FAI_ACTION outside of autodiscover, todo: test it out, if it doesn't,
+# make install be default in 51-multi-boot, and disable it if needed.
+#
+# DESKTOP: install a bunch of extra packages. For creating X suffix
+# basefiles. See README.
+#
+# REPARTITION: we try to reuse partitions/filesystems to install a new
+# os into a multi-os system, if we see some basic hueristics, like the
+# right amount of them. This overrides that.
+#
+# PARTITION_PROMPT: If we don't see partitions to reuuse, prompt
+# to make sure we really want to repartition and use a completely
+# fresh install. I use this in case our repartition check has
+# a bug in it, or I accidentally set REPARTITION.
+#
+# ROTATIONAL: in a system with ssd and hdd, install to the hdd
+# instead of the default ssd.
+#
+# RAID0: Use raid 0 even if there are >= 4 disks with boot partititions.
+#
+# LINODE: For running a vm on linode, especially one created with fai-cd.
+
+###### begin Template for 51-multi-boot ######
+#
+# It has reasonable combinations of above classes.
+# It's a noop until we replace _ with host names.
+
+#!/bin/bash
+if [[ ! -e /a/bin/fai/fai-wrapper || $FAI_ACTION == dirinstall ]]; then
+ case $HOSTNAME in
+ # stretch based minimal recovery / bootstraping os:
- _) echo DEBIAN STRETCH64 VOL_STRETCH_BOOTSTRAP STRETCH_FREE ;;
++ _) echo STRETCH64 VOL_STRETCH_BOOTSTRAP STRETCH_FREE ;;
+ # flidas
+ _) echo UBUNTU FLIDAS64 VOL_FLIDAS FLIDAS ;;
+ # etiona
+ _) echo UBUNTU ETIONA64 VOL_ETIONA ETIONA ;;
+ # stretch
- _) echo DEBIAN STRETCH64 VOL_STRETCH STRETCH_FREE ;;
++ _) echo STRETCH64 VOL_STRETCH STRETCH_FREE ;;
+ # buster
- _) echo DEBIAN BUSTER64 VOL_BUSTER BUSTER_FREE ;;
++ _) echo BUSTER64 VOL_BUSTER BUSTER_FREE ;;
+ # testing
- _) echo DEBIAN STRETCH64 VOL_TESTING TESTING_FREE ;;
++ _) echo STRETCH64 VOL_TESTING TESTING_FREE ;;
+ # xenial
+ _) echo UBUNTU XENIAL64 VOL_XENIAL XENIAL_FREE ;;
+ # bionic
+ _) echo UBUNTU BIONIC64 VOL_BIONIC BIONIC ;;
+ # focal
+ _) echo UBUNTU FOCAL64 VOL_FOCAL FOCAL ;;
+ esac
+fi
+###### end Template for 51-multi-boot ######
+
+if [[ -e /a/bin/fai/fai-wrapper ]]; then
+ source /a/bin/distro-functions/src/identify-distros
+ if isdeb; then
+ codename=$(debian-codename)
+ echo ${codename^^}
+ distro=$(distro-name)
+ case $distro in
+ debian)
+ echo ${distro^^}
+ # nonfree repo is not going away any time soon due to
+ # gcc-doc being in nonfree
+ echo ${codename^^}_NONFREE
+ ;;
+ trisquel)
+ # easier to stay with fai example config if we just call it ubuntu
+ echo UBUNTU
+ ;;
+ esac
+ fi
+ case $HOSTNAME in
+ li|lj) echo "LINODE" ;;
+ bk|je) echo "NOCRYPT" ;;
+ esac
+fi
+
- echo FAIBASE STANDARD
+
+#echo "PARTITION_PROMPT"
+#echo REPARTITION
+
+
+if grep ^52:54:00: /sys/class/net/eth0/address &>/dev/null; then
+ # if our eth0 mac is in the kvm range, we are a vm.
+ echo "VM"
+fi
--release=buster
--apt_cdn=http://deb.debian.org
--security_cdn=http://security.debian.org
++# sources are set with fcopy
++#release=buster
++#apt_cdn=http://deb.debian.org
++#security_cdn=http://security.debian.org
CONSOLEFONT=
KEYMAP=us-latin1
# if you have enough RAM (>2GB) you may want to enable this line. It
# also puts /var/cache into a ramdisk.
-#FAI_RAMDISKS="$target/var/lib/dpkg $target/var/cache"
+# ian: uncommented
+FAI_RAMDISKS="$target/var/lib/dpkg $target/var/cache"
# if you want to use the faiserver as APT proxy
-#APTPROXY=http://faiserver:3142
+# APTPROXY=http://faiserver:3142
- DEBIAN.var
-ubuntumirror=http://archive.ubuntu.com
-ubuntudist=focal
++#iank, i define these by classes. commenting
++# to make sure these arent used
++#ubuntumirror=http://archive.ubuntu.com
++#ubuntudist=focal
- updatebase.DEBIAN
+ #! /bin/bash
+
-# use external mirror, remove this script when using a mirror from CD
-
-cat <<EOM > $target/etc/apt/sources.list
-# external mirror
-deb $ubuntumirror/ubuntu $ubuntudist main restricted universe multiverse
-deb $ubuntumirror/ubuntu $ubuntudist-updates main restricted universe multiverse
-deb $ubuntumirror/ubuntu $ubuntudist-security main restricted universe multiverse
-EOM
-
-
+ # https://lists.uni-koeln.de/pipermail/linux-fai/2016-July/011398.html
+ # In Ubuntu 16.04 (but not 14.04), the locales configuration mechanism has
+ # changed. There is a /var/lib/dpkg/info/locales.config file, which
+ # overrides /var/lib/dpkg/info/locales.postinst and consults
+ # /var/lib/locales/supported.d/local instead of the debconf system. (See
+ # the code in /usr/share/debconf/frontend that prefers locales.config.) This
+ # hook applies the debconf setting. It must run after FAI's debconf task
+ # but before dpkg gets a chance to clobber debconf with an empty setting.
+
+ if [ ! -f "$target/var/lib/locales/supported.d/local" ]; then
+ $ROOTCMD debconf --owner=locales sh -c '
+ . /usr/share/debconf/confmodule
+ db_version 2.0
+ db_get locales/locales_to_be_generated &&
+ mkdir -p /var/lib/locales/supported.d &&
+ echo "$RET" > /var/lib/locales/supported.d/local' &&
+ $ROOTCMD dpkg-reconfigure locales
+ fi
# (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
> $target/etc/machine-id
fi
# recreate machine-id if the file is empty
- if [ X"$(stat -c '%s' $target/etc/machine-id 2>/dev/null)" = X0 -a -f /bin/systemd-machine-id-setup ]; then
+ if [ X"$(stat -c '%s' $target/etc/machine-id 2>/dev/null)" = X0 -a -f $target/bin/systemd-machine-id-setup ]; then
$ROOTCMD systemd-machine-id-setup
fi
error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
+set -x
set -a
# do not set up grub during dirinstall
# 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
+ for device in $(LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; s/(nvme.+?)p/$1/g; print }' /proc/mdstat); do
echo Install grub on /dev/$device
$ROOTCMD grub-install --no-floppy "/dev/$device"
done
else
- $ROOTCMD grub-install --no-floppy "$GROOT"
- if [ $? -eq 0 ]; then
- echo "Grub installed on $BOOT_DEVICE = $GROOT"
- fi
+ for dev in $BOOT_DEVICE; do
+ GROOT=$($ROOTCMD grub-probe -tdrive -d $dev)
+ $ROOTCMD grub-install --no-floppy "$GROOT"
+ if [ $? -eq 0 ]; then
+ echo "Grub installed on $dev = $GROOT"
+ fi
+ done
fi
$ROOTCMD update-grub
fi
fi
- usedm=$(dmsetup ls 2>/dev/null | 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
+ # i use dm for crypt, not lvm, so this gives false positive. todo, send patch to remove this
+ # upstream.
+ # usedm=$(dmsetup ls 2>/dev/null | 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
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
+ $ROOTCMD apt-get -f install -y
fi
if [ $FAI_ACTION = "install" ]; then
return
fi
- dists="jessie stretch buster bullseye bookworm bionic xenial trusty"
+ dists="jessie stretch buster bullseye bookworm focal bionic xenial trusty"
for d in $dists; do
if grep -iq $d $target/etc/os-release; then
release=$d
#! /bin/bash
- # ian: just taking part of the corresponding fai example script
++# iank: we already set mirrors, i dont want to have to add "external mirror"
++# to every sources.list. Leaving the rest of this file so future merges will flag up
++# changes easier
++exit 0
+
- ainsl -v /etc/locale.gen '^en_US.UTF-8 UTF-8'
- $ROOTCMD locale-gen
- $ROOTCMD update-locale LANG=en_US.UTF-8
+ # check if we already use an external mirror
+ grep -q "external mirror" $target/etc/apt/sources.list && exit 0
+
+ cat <<EOM > $target/etc/apt/sources.list
+ # external mirror
-deb $ubuntumirror/ubuntu $ubuntudist main restricted universe multiverse
-deb $ubuntumirror/ubuntu $ubuntudist-updates main restricted universe multiverse
-deb $ubuntumirror/ubuntu $ubuntudist-security main restricted universe multiverse
++deb $ubuntumirror/ubuntu $ubuntudist main universe
++deb $ubuntumirror/ubuntu $ubuntudist-updates main universe
++deb $ubuntumirror/ubuntu $ubuntudist-security main universe
+ EOM