2 # note, this script gets piped to bash, so cant cd to current dir
4 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
7 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
12 fai_reboot_arg
=,reboot
13 while [[ $1 == -* ]]; do
16 echo "see help from myfai-chboot"
45 m
() { printf "$pre %s\n" "$*"; "$@"; }
46 e
() { printf "$pre %s\n" "$*"; }
47 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
52 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
54 echo "$0: clearing pxe config and exiting"
58 # somewhat duplicated in brc hostip()
65 hostip
=$
(getent ahostsv4
"$host" |
awk '{ print $1 }' |
head -n1)
69 if [[ $hostip ]]; then
71 # assuming ipv4, or else we might need to deal with multiple addresses
72 # in an ipv4 + ipv6 network.
73 my_ip
=$
(ip
-4 route get
$hostip |
sed -nr 's,^.*src\s+(\S+).*,\1,p')
74 if [[ ! $my_ip ||
$my_ip =~
[[:space
:]] ]]; then
75 echo "$0: error: failed to get \$my_ip, got: $my_ip"
79 my_ip
=$
(ip r show default |
sed -r 's/.*via ([^ ]*).*/\1/' |
head -n1)
82 if [[ $host == default
]]; then
84 elif [[ $host == [0-9]*.
[0-9]*.
[0-9]*.
[0-9]* ]]; then
87 type -t host &>/dev
/null || apt-get
-y install dnsutils
88 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q' ||
:)
89 if [[ ! $ip ||
$ip =~
[[:space
:]] ]]; then
90 echo "$0: error: failed to get \$ip, got: $ip"
94 echo "$0: found ip of $host: $ip"
97 if modprobe nfsd
&>/dev
/null
; then
98 std_arg
="-u nfs://faiserver/srv/fai/config"
99 # nfsv4 wont do rw with overlayfs yet
100 # https://lists.uni-koeln.de/pipermail/linux-fai/2017-March/011641.html
101 root_arg
="$my_ip:/srv/fai/nfsroot:vers=3"
102 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
103 # I restrict it to one ip as simple but imperfect access control.
105 # we may chattr +i /etc/exports if we dun want it modified
106 # for example, if we made these exports more widely available
107 # while doing multiple installs or a recovery.
108 if [[ -w /etc
/exports
]]; then
109 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
110 cat >>/etc
/exports
<<EOF
111 /srv/fai/config $ip(async,ro,no_subtree_check,no_root_squash)
112 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
116 systemctl start nfs-server
# assumes recent os
118 std_arg
="-u http://faiserver:8080/config.tar.gz"
119 root_arg
="live:http://faiserver:8080/squash.img"
120 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
130 # man page doesn't explain this, but this deletes & thus disables
131 # all chboot systems.
132 m fai-chboot
-iv $std_arg default
# set it to default to get a val out of it next
133 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
134 default_k_args
=$
(fai-chboot
-L '^default$' | \
135 sed -r "s/^(\S+\s+){3}(.*)/\2/")
136 # example of default_k_args
137 # initrd=initrd.img-3.16.0-4-amd64 ip=dhcp root=192.168.1.3:/srv/fai/nfsroot FAI_CONFIG_SRC=nfs://faiserver/srv/fai/config FAI_ACTION=install
139 # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
140 # currently on needed on d16 samsung 870 qvo, but better to have this
141 # and not wait for more conditions where its needed.
142 #k_args=(FAI_ACTION=$fai_action libata.force=noncq ifname:bootnet0:08:60:6e:10:f0:fe ifname:bootnet1:08:60:6e:10:f0:98 bond=bond0:bootnet0,bootnet1:mode=balance-rr)
143 #k_args=(FAI_ACTION=$fai_action libata.force=noncq ifname:bootnet0:08:60:6e:10:f0:fe biosdevname=0 bootdev=bootnet0)
144 k_args
=(FAI_ACTION
=$fai_action libata.force
=noncq
)
146 k_args
+=(console
=tty0 console
=ttyS0
,115200)
149 for arg
in $default_k_args; do
151 # default root arg is /srv/fai/nfsroot
152 root
=*) k_args
+=(root
=$root_arg) ;;
153 # note: this works to only dhcp on one interface: ip=eth0:dhcp
156 k_args
+=("bond=bond0:eth0,eth1:mode=balance-rr ip=bond0:dhcp")
164 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
165 m fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"
167 # this is needed for autodiscover iso. i'm not sure, it might override
168 # the fai-chboot method of setting this, i'm not sure.
169 echo FAI_ACTION
=$fai_action >> /srv
/fai
/config
/class
/LAST.var