Debian Codegraph @

bin/fai-make-nfsroot

raw symbols SCIP
1 #! /bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 #*********************************************************************
4 #
5 # fai-make-nfsroot -- create nfsroot directory and add additional packages
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # (c) 2000-2026 by Thomas Lange, [email protected]
9 # Universitaet zu Koeln
10 # (c) 2004 by Henning Glawe, [email protected]
11 # Freie Universitaet Berlin
12 #
13 #*********************************************************************
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
23 #
24 # A copy of the GNU General Public License is available as
25 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
26 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
27 # can also obtain it by writing to the Free Software Foundation, Inc.,
28 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 #*********************************************************************
30
31 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 usagescip-shell shell fai 6.6 usage().() {
33
34 catscip-shell system . . cat. <<-EOF
35 Copyright (C) 1999-2026 Thomas Lange
36
37 Usage: fai-make-nfsroot [OPTIONS]
38 Create an NFSROOT for FAI.
39 Read the man pages pages fai-make-nfsroot(8).
40 EOF
41 exit 0
42 }
43 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44 diescip-shell shell fai 6.6 die().() {
45
46 local e=$1 # first parameter is the exit code
47 shift
48
49 echoscip-shell system . . echo. "ERROR: $*"
50 echoscip-shell system . . echo. "Log file written to /var/log/fai/fai-make-nfsroot.log"
51 exit $e
52 }
53 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54 check_nfsrootscip-shell shell fai 6.6 check_nfsroot().() {
55
56 local lname
57 set +e
58 # simple test, to see if important thing are available inside the nfsroot
59 if [scip-shell system . . `[`. ! -x $NFSROOT/usr/bin/dracut ]; then
60 diescip-shell shell fai 6.6 die(). 1 "dracut was not installed into the nfsroot."
61 fi
62
63 echoscip-shell system . . echo. "FAI packages and related packages inside the nfsroot:"
64 $ROOTCMD dpkg-query -W -f='${Package;-18} ${Version}\n' fai-client fai-nfsroot fai-setup-storage dracut-network dracut dracut-live dracut-squash 2>/dev/nullscip-shell filesystem . . `/dev/null`.
65
66 # check if all important packages are installed
67 n=$($ROOTCMD dpkg-query -l fai-client fai-nfsroot fai-setup-storage dracut-network dracut 2>/dev/nullscip-shell filesystem . . `/dev/null`.|grepscip-shell system . . grep. -c -E ^ii)
68 if [scip-shell system . . `[`. $n -ne 5 ]; then
69 echoscip-shell system . . echo. "ERROR: Some essential packages are missing."
70 bad_exitscip-shell shell fai 6.6 bad_exit().
71 fi
72
73 lname=$(readlinkscip-shell system . . readlink. $NFSROOT/sbin/init)
74 if ! [[ "$lname" =~ "lib/systemd/systemd" ]]; then
75 echoscip-shell system . . echo. "ERROR: It seems that you did not installed systemd into the nfsroot."
76 echoscip-shell system . . echo. "Make sure this old config line does NOT appear in /etc/fai/NFSROOT:"
77 echoscip-shell system . . echo. "sysvinit-core systemd-sysv-"
78 bad_exitscip-shell shell fai 6.6 bad_exit().
79 fi
80
81 local files=$(lsscip-shell system . . ls. $NFSROOT/boot/initrd* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
82 [scip-shell system . . `[`. -z "$files" ] && diescip-shell shell fai 6.6 die(). 1 "No initrd installed."
83 grepscip-shell system . . grep. -E -q "^ERROR: |^E: Sub-process |^dpkg: error processing |^dpkg: dependency problems" /var/log/fai/fai-make-nfsroot.logscip-shell filesystem . . `/var/log/fai/fai-make-nfsroot.log`. && bad_exitscip-shell shell fai 6.6 bad_exit().
84 return 0
85 }
86 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87
88 PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbinscip-shell filesystem . . `/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin`.
89
90 merror="properly"
91 exitcode=0
92 sshpreserve=0
93 adjust=0
94 generic=0
95 force=0
96 usexz=1
97 full=1
98
99 # option e currently does nothing
100 while getopts aghervc:C:B:fkKpPUzsN opt ; do
101 case "$opt" in
102 a) adjust=1 ;;
103 g) generic=1 ;;
104 z) usexz=0 ;;
105 c) classes=$OPTARG
106 classes=${classes//,/ } ;;
107 C) cfdir=$OPTARG ;;
108 B) basetgz=$OPTARG
109 if [scip-shell system . . `[`. ! -r "$basetgz" ] ; then
110 diescip-shell shell fai 6.6 die(). 7 "Specified $basetgz can not be read."
111 fi
112 ;;
113 v) verbose=1 ; v=-v ;;
114 U) diescip-shell shell fai 6.6 die(). 1 "Option -U is not supported any more." ;;
115 r) diescip-shell shell fai 6.6 die(). 1 "Option -r is not supported any more." ;;
116 f) force=1 ;;
117 k) kinstall=1 ;;
118 K) kremove=1;;
119 N) nonfree=NONFREE ;;
120 h) usagescip-shell shell fai 6.6 usage(). ;;
121 e) expert=1 ;; # a dummy option, that only fai-setup uses
122 p) sshpreserve=1 ;;
123 P) sshpreserve=2 ;;
124 s) full=0 ;; # do only install a smaller list of packages
125 ?) exit 5 ;; # error in option parsing
126 esac
127 done
128
129 [scip-shell system . . `[`. $(idscip-shell system . . id. -u) != "0" ] && diescip-shell shell fai 6.6 die(). 9 "Run this program as root."
130
131 set -e
132 shopt -s nullglob
133
134 # use FAI_ETC_DIR from environment variable
135 if [scip-shell system . . `[`. -n "$FAI_ETC_DIR" ] && [scip-shell system . . `[`. -z "$cfdir" ]; then
136 echoscip-shell system . . echo. "Using environment variable \$FAI_ETC_DIR."
137 fi
138 [scip-shell system . . `[`. -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
139 cfdir=$(readlinkscip-shell system . . readlink. -f $cfdir) # canonicalize path
140 [scip-shell system . . `[`. ! -d "$cfdir" ] && diescip-shell shell fai 6.6 die(). 6 "$cfdir is not a directory"
141
142 [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Using configuration files from $cfdir"
143 . $cfdir/fai.conf
144 : ${FAI:=/var/lib/fai/config} # default value
145 : ${MNTPOINT:=/media/mirror} # default value
146
147 # read config file for this tool
148 [scip-shell system . . `[`. -f "$cfdir/nfsroot.conf" ] || diescip-shell shell fai 6.6 die(). 8 "Can't read $cfdir/nfsroot.conf"
149 . $cfdir/nfsroot.conf
150
151 # IMO this may be removed, since all information should be included into sources.list
152 [scip-shell system . . `[`. -z "$NFSROOT" ] && diescip-shell shell fai 6.6 die(). 1 "\$NFSROOT is not set. Please check your settings in $cfdir/nfsroot.conf."
153 [scip-shell system . . `[`. -z "$TFTPROOT" ] && diescip-shell shell fai 6.6 die(). 1 "\$TFTPROOT is not set. Please check your settings in $cfdir/nfsroot.conf."
154 [scip-shell system . . `[`. ! -d "$cfdir/apt" ] && diescip-shell shell fai 6.6 die(). 1 "$cfdir/apt/ does not exists. Can't continue."
155
156 deldir=$NFSROOT
157
158 set +e
159 if [scip-shell system . . `[`. -z "$ROOTCMD" ]; then
160 # check if unshare can be used (e.g. not possible in some container environments)
161 if unsharescip-shell system . . unshare. --fork --kill-child --mount-proc chroot /scip-shell filesystem . . `/`. ls >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then
162 ROOTCMD="unshare --fork --kill-child --mount-proc chroot $NFSROOT"
163 else
164 ROOTCMD="chroot $NFSROOT"
165 fi
166 fi
167 set -e
168 export DEBIAN_FRONTEND=noninteractive
169
170 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171 adjust_nfsrootscip-shell shell fai 6.6 adjust_nfsroot().() {
172
173 # add install server specific data (like network parameters) into the nfsroot
174 # a generic nfsroot must already be available
175 trap '' EXIT
176 add_etc_hosts_entriesscip-shell shell fai 6.6 add_etc_hosts_entries().
177 set_root_pwscip-shell shell fai 6.6 set_root_pw().
178 call_verbosescip-shell shell fai 6.6 call_verbose(). setup_ssh
179 exit 0
180 }
181 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 bad_exitscip-shell shell fai 6.6 bad_exit().() {
183
184 merror="with errors"
185 exitcode=1
186 echoscip-shell system . . echo. "An error occured during fai-make-nfsroot."
187 echoscip-shell system . . echo. "Please fix the error or try fai-make-nfsroot -v"
188 }
189 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
190 call_verbosescip-shell shell fai 6.6 call_verbose().() {
191
192 if [scip-shell system . . `[`. X$verbose = X1 ]; then
193 "$@"
194 return $?
195 else
196 "$@" > /dev/nullscip-shell filesystem . . `/dev/null`.
197 return $?
198 fi
199 }
200 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 setclassesscip-shell shell fai 6.6 setclasses().() {
202
203 local iarch distro c
204 # Export all the information we have about the system
205 iarch=$($ROOTCMD dpkg --print-architecture|trscip-shell system . . tr. /a-z/scip-shell filesystem . . `/a-z/`. /A-Z/scip-shell filesystem . . `/A-Z/`.)
206 distro=$(. $NFSROOT/etc/os-release; echoscip-shell system . . echo. ${ID} ${ID}_${VERSION_ID} | trscip-shell system . . tr. '[:lower:].' '[:upper:]_')
207
208 # do we want to install the full list of packages?
209 if [scip-shell system . . `[`. $full = 1 ]; then
210 c=FULL
211 fi
212 export classes="NFSROOT $c $iarch $distro $nonfree $classes"
213 if [scip-shell system . . `[`. X$verbose = X1 ] ; then
214 echoscip-shell system . . echo. Classes are set to $classes
215 fi
216 }
217 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218 setup_sshscip-shell shell fai 6.6 setup_ssh().() {
219
220 # nothing to do if no ssh is available in nfsroot
221 [scip-shell system . . `[`. -f $NFSROOT/usr/bin/ssh ] || return 0
222
223 # enable root login
224 sedscip-shell system . . sed. -i -e '/PermitRootLogin/dscip-shell filesystem . . `/PermitRootLogin/d`.' $NFSROOT/etc/ssh/sshd_config
225 ainsl $NFSROOT/etc/ssh/sshd_config 'PermitRootLogin yes'
226
227 if [scip-shell system . . `[`. $sshpreserve -ge 1 ]; then
228 tarscip-shell system . . tar. -C $NFSROOT -xf $tmptar
229 rmscip-shell system . . rm. $tmptar
230 return 0
231 fi
232
233 mkdirscip-shell system . . mkdir. -p -m 700 $NFSROOT/root/.ssh
234 if [scip-shell system . . `[`. -n "$LOGUSER" ] ; then
235 loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
236 [scip-shell system . . `[`. -f $loguserhome/.ssh/known_hosts ] && cpscip-shell system . . cp. $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
237 [scip-shell system . . `[`. -d $loguserhome/.ssh ] && {
238 [scip-shell system . . `[`. -f $loguserhome/.ssh/id_ed25519 ] &&
239 cpscip-shell system . . cp. -p $loguserhome/.ssh/id_ed25519* $NFSROOT/root/.ssh/
240 [scip-shell system . . `[`. -f $loguserhome/.ssh/id_rsa ] &&
241 cpscip-shell system . . cp. -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
242 }
243 fi
244
245 if [scip-shell system . . `[`. -f "$SSH_IDENTITY" ]; then
246 installscip-shell system . . install. -m0644 $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
247 echoscip-shell system . . echo. You can log into install clients without password using $SSH_IDENTITY
248 fi
249
250 # seting StrictHostKeyChecking to no inside the nfsroot would enable
251 # easy login to the install server even if the host key is not known
252
253 }
254 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
255 set_root_pwscip-shell shell fai 6.6 set_root_pw().() {
256
257 [scip-shell system . . `[`. $generic = 1 ] && return # do nothing here if we generate a generic nfsroot
258 # set root pw inside the nfsroot
259 $ROOTCMD usermod -p "$FAI_ROOTPW" root
260 return # do not copy fai files at all
261 }
262 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
263 mount_special_into_nfsrootscip-shell shell fai 6.6 mount_special_into_nfsroot().() {
264
265 mkdirscip-shell system . . mkdir. -p $NFSROOT/dev/pts
266 mountscip-shell system . . mount. -t proc /procscip-shell filesystem . . `/proc`. $NFSROOT/proc
267 mountscip-shell system . . mount. -t sysfs /sysscip-shell filesystem . . `/sys`. $NFSROOT/sys
268 mountscip-shell system . . mount. -t devpts devpts $NFSROOT/dev/pts
269 }
270 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
271 call_debootstrapscip-shell shell fai 6.6 call_debootstrap().() {
272
273 [scip-shell system . . `[`. -z "$FAI_DEBOOTSTRAP" ] && diescip-shell shell fai 6.6 die(). 4 "\$FAI_DEBOOTSTRAP not defined."
274
275 # check if NFSROOT directory is mounted with bad options
276 fs=$(dfscip-shell system . . df. -P $NFSROOT | tailscip-shell system . . tail. -1 | awkscip-shell system . . awk. '{print $6}')
277 if mountscip-shell system . . mount. | grepscip-shell system . . grep. "on $fs " | awkscip-shell system . . awk. '{print $6}' | grepscip-shell system . . grep. -E -q "nosuid|nodev"; then
278 diescip-shell shell fai 6.6 die(). 1 "NFSROOT directory $NFSROOT is mounted using nosuid or nodev. Aborting"
279 fi
280 local dversion=$(dpkg-queryscip-shell system . . dpkg-query. -Wf '${Version}\n' debootstrap)
281 echoscip-shell system . . echo. "Creating base system using debootstrap version $dversion"
282
283 echoscip-shell system . . echo. "Calling debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2"
284 LC_ALL=C call_verbosescip-shell shell fai 6.6 call_verbose(). debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
285 if [scip-shell system . . `[`. $? -ne 0 ]; then
286 echoscip-shell system . . echo. "ERROR: debootstrap did not complete successfully."
287 echoscip-shell system . . echo. "This is mostly caused by a broken mirror."
288 echoscip-shell system . . echo. "Please check your mirror or use an official mirror."
289 [scip-shell system . . `[`. X$verbose = X1 ] || echoscip-shell system . . echo. "Call fai-make-nfsroot -v for better debugging."
290 exit 10
291 fi
292
293 if [scip-shell system . . `[`. ! -f $NFSROOT/usr/bin/apt-get ]; then
294 echoscip-shell system . . echo. "No apt-get executable available inside the NFSROOT."
295 echoscip-shell system . . echo. "Maybe debootstrap did not finish successfully. Aborting."
296 [scip-shell system . . `[`. X$verbose = X1 ] || echoscip-shell system . . echo. "Call fai-make-nfsroot -v for better debugging."
297 exit 11
298 fi
299 }
300 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
301 add_etc_hosts_entriesscip-shell shell fai 6.6 add_etc_hosts_entries().() {
302
303 # some default entries
304 ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
305 ainsl $NFSROOT/etc/hosts "# Following entries are specific to your environment"
306 ainsl $v $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
307
308 # add entries for all network devices
309 local ips=$(ip -br ad show up| awkscip-shell system . . awk. '/UP / {if ($3) print $3}scip-shell filesystem . . `/UP / {if ($3) print $3}`.' |sedscip-shell system . . sed. -e 's#\/[0-9]\+##g')
310
311 local line
312 for eth in $ips; do
313 line=$(getentscip-shell system . . getent. hosts $eth || truescip-shell system . . true.)
314 if [scip-shell system . . `[`. -n "$line" ] ; then
315 ainsl $v $NFSROOT/etc/hosts "$line"
316 else
317 echoscip-shell system . . echo. "Warning: no hostname for $eth found, not adding to /etc/hosts."
318 fi
319 done
320
321 if [scip-shell system . . `[`. -f /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. ]; then
322 cpscip-shell system . . cp. -Lp $v /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. $NFSROOT/etc/resolv.conf-installserver
323 cpscip-shell system . . cp. -Lp $v /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. $NFSROOT/etc/resolv.conf # this is needed during fai-make-nfsroot
324 fi
325 }
326 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
327 create_basescip-shell shell fai 6.6 create_base().() {
328
329 command -v debootstrap >&/dev/null || diescip-shell shell fai 6.6 die(). 1 "Can't find debootstrap command. Aborting."
330 call_debootstrapscip-shell shell fai 6.6 call_debootstrap(). $FAI_DEBOOTSTRAP
331 $ROOTCMD apt-get clean
332 rmscip-shell system . . rm. -f $NFSROOT/etc/resolv.conf $NFSROOT/etc/hostname $NFSROOT/etc/udev/rules.d/70-persistent-net.rules $NFSROOT/var/lib/dbus/machine-id
333 > $NFSROOT/etc/machine-id
334 if [scip-shell system . . `[`. $usexz -eq 0 ]; then
335 echoscip-shell system . . echo. "Creating base.tar.zst"
336 else
337 echoscip-shell system . . echo. "Creating base.tar.xz"
338 fi
339 tarscip-shell system . . tar. --xattrs --acls --one-file-system -C $NFSROOT -cf $NFSROOT/var/tmp/base.tar --exclude var/tmp/base.tar --exclude 'var/lib/apt/lists/*_*' .
340 if [scip-shell system . . `[`. $usexz -eq 1 ]; then
341 nicescip-shell system . . nice. xz -q $NFSROOT/var/tmp/base.tar &
342 else
343 nicescip-shell system . . nice. zstd --rm -q -7 -T4 $NFSROOT/var/tmp/base.tar &
344 fi
345 }
346 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
347 extract_basescip-shell shell fai 6.6 extract_base().() {
348
349 if cd $NFSROOT ; then
350 printfscip-shell system . . printf. "Extracting $basetgz: "
351 case $basetgz in
352 *tar.zst|*.tzst)
353 tarscip-shell system . . tar. --xattrs --acls --xattrs-include=* -C $NFSROOT --zstd -xpf "$basetgz" || diescip-shell shell fai 6.6 die(). 1 "Error while extracting ${basetgz} in ${NFSROOT}."
354 cpscip-shell system . . cp. -p "$basetgz" $NFSROOT/var/tmp/base.tar.zst
355 ;;
356
357 *tar.xz|*.txz)
358 tarscip-shell system . . tar. --xattrs --acls --xattrs-include=* -C $NFSROOT -Jxpf "$basetgz" || diescip-shell shell fai 6.6 die(). 1 "Error while extracting ${basetgz} in ${NFSROOT}."
359 cpscip-shell system . . cp. -p "$basetgz" $NFSROOT/var/tmp/base.tar.xz
360 ;;
361 *)
362 diescip-shell shell fai 6.6 die(). 14 "Unknow file name suffix"
363 esac
364 echoscip-shell system . . echo. done
365 fi
366 }
367 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
368 create_nfsrootscip-shell shell fai 6.6 create_nfsroot().() {
369
370 local fslist
371
372 mkdirscip-shell system . . mkdir. -p $NFSROOT/$FAI
373 cd $NFSROOT || diescip-shell shell fai 6.6 die(). 1 "Can't cd to $NFSROOT"
374
375 if [scip-shell system . . `[`. -n "$basetgz" ] ; then
376 extract_basescip-shell shell fai 6.6 extract_base().
377 else
378 create_basescip-shell shell fai 6.6 create_base().
379 fi
380 touchscip-shell system . . touch. .THIS_IS_THE_FAI_NFSROOT
381 # save the list of all packages in the base.tar.zst
382 $ROOTCMD dpkg --get-selections | awkscip-shell system . . awk. '/install$/ {print $1}scip-shell filesystem . . `/install$/ {print $1}`.' > var/tmp/base-pkgs.lis
383
384 if [scip-shell system . . `[`. -n "$FAI_DEBMIRROR" ]; then
385 [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
386 mkdirscip-shell system . . mkdir. -p $NFSROOT/$MNTPOINT
387 mountscip-shell system . . mount. -o ro,noatime $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
388 die 1 "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
389 fi
390
391 # liloconfig, dump needs this file
392 > etc/fstab
393
394 # we need these option before installing the first package. So we
395 # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
396 catscip-shell system . . cat. >$NFSROOT/etc/apt/apt.conf.d/10fai <<EOF
397 APT::Install-Recommends no;
398 APT::Get::AllowUnauthenticated true;
399 Acquire::AllowInsecureRepositories "true";
400 Aptitude::CmdLine::Ignore-Trust-Violations yes;
401 Acquire::Languages none;
402 Acquire::Check-Valid-Until false;
403 EOF
404
405 mkdirscip-shell system . . mkdir. $NFSROOT/etc/dracut.conf.d
406 if [scip-shell system . . `[`. $full = 1 ];then
407 echoscip-shell system . . echo. 'add_dracutmodules+=" livenet "' > $NFSROOT/etc/dracut.conf.d/13-add-cd-support.conf
408 fslist="nfs lockd ext4"
409 else
410 echoscip-shell system . . echo. 'add_dracutmodules+=" dmsquash-live "' > $NFSROOT/etc/dracut.conf.d/13-add-cd-support.conf
411 fslist="ext4"
412 fi
413 echoscip-shell system . . echo. 'add_dracutmodules+=" systemd-hostnamed systemd-networkd "' > $NFSROOT/etc/dracut.conf.d/11-network.conf
414 echoscip-shell system . . echo. 'hostonly="no"' > $NFSROOT/etc/dracut.conf.d/20-generic-image.conf
415 echoscip-shell system . . echo. 'compress="zstd"' > $NFSROOT/etc/dracut.conf.d/20-zstd-compress.conf
416 # we do not need all those filesystems inside the initrd
417 catscip-shell system . . cat. <<EOF > $NFSROOT/etc/dracut.conf.d/22-fai.conf
418 omit_dracutmodules+=" btrfs crypt lvm resume usrmount modsign mdraid shutdown virtfs "
419 filesystems="$fslist"
420 install_items+=" ethtool "
421 EOF
422
423 local fname=$(readlinkscip-shell system . . readlink. -f $cfdir/apt/sources.list)
424 if [scip-shell system . . `[`. -d $fname ]; then
425 fcopy -s $cfdir/apt -t $NFSROOT/etc/apt sources.list
426 else
427 # this copies sources.list and sources.list.d into the nfsroot
428 cpscip-shell system . . cp. -aL $cfdir/apt $NFSROOT/etc
429 fi
430
431 add_etc_hosts_entriesscip-shell shell fai 6.6 add_etc_hosts_entries().
432
433 # use a proxy if variable is defined
434 if [scip-shell system . . `[`. -n "$APTPROXY" ]; then
435 echoscip-shell system . . echo. "Acquire::http::Proxy \"$APTPROXY\";" > $NFSROOT/etc/apt/apt.conf.d/02proxy
436 fi
437
438 [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Upgrading $NFSROOT"
439 LC_ALL=C call_verbosescip-shell shell fai 6.6 call_verbose(). upgrade_nfsroot
440 LC_ALL=C add_packages_nfsrootscip-shell shell fai 6.6 add_packages_nfsroot().
441
442 # remove file diversion, then create initrd
443 rmscip-shell system . . rm. $NFSROOT/etc/kernel/postinst.d/dracut
444 $ROOTCMD dpkg-divert --rename --remove /etc/kernel/postinst.d/dracutscip-shell filesystem . . `/etc/kernel/postinst.d/dracut`.
445 $ROOTCMD dpkg-reconfigure dracut
446
447 set_root_pwscip-shell shell fai 6.6 set_root_pw().
448
449 # set timezone in nfsroot
450 [scip-shell system . . `[`. -f /etc/timezonescip-shell filesystem . . `/etc/timezone`. ] && cpscip-shell system . . cp. -fH /etc/timezonescip-shell filesystem . . `/etc/timezone`. etc/timezone
451 cpscip-shell system . . cp. -a /etc/localtimescip-shell filesystem . . `/etc/localtime`. etc/localtime
452 lnscip-shell system . . ln. -sf ../proc/self/mounts etc/mtab
453
454 echoscip-shell system . . echo. "AUTO -all" > etc/mdadm/mdadm.conf # do not activate RAID arrays
455
456 LC_ALL=C $ROOTCMD systemctl set-default fai.target
457
458 # this second rm of the same file is needed!
459 rmscip-shell system . . rm. -f etc/udev/rules.d/70-persistent-net.rules
460 # remove Ubuntu-specific rules to auto-start volume groups, which confuses
461 # setup-storage
462 rmscip-shell system . . rm. -f lib/udev/rules.d/85-lvm2.rules
463 # definition for loopback device
464 mkdirscip-shell system . . mkdir. -p etc/network
465 echoscip-shell system . . echo. "iface lo inet loopback" > etc/network/interfaces
466
467 catscip-shell system . . cat. >> root/.profile <<-EOF
468 PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
469 export PATH
470 set -a
471 . /usr/lib/fai/subroutines
472 . /tmp/fai/variables.log 2>/dev/null
473 EOF
474
475 }
476 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
477 upgrade_nfsrootscip-shell shell fai 6.6 upgrade_nfsroot().() {
478
479 local pkgs
480
481 mount_special_into_nfsrootscip-shell shell fai 6.6 mount_special_into_nfsroot().
482 /usr/lib/fai/mkramdiskscip-shell filesystem . . `/usr/lib/fai/mkramdisk`. $NFSROOT/var/lib/dpkg $NFSROOT/var/cache
483 mkdirscip-shell system . . mkdir. $NFSROOT/etc/mdadm; touchscip-shell system . . touch. $NFSROOT/etc/mdadm/mdadm.conf # stop mdadm from calling mkconf
484
485 # add any 3rd party repository keys that you may need installed into the NFSROOT
486 if [scip-shell system . . `[`. -d $cfdir/apt/keys ]; then
487 local f
488 for f in $(findscip-shell system . . find. $cfdir/apt/keys -type f -name '*.gpg'); do
489 cpscip-shell system . . cp. $f $NFSROOT/etc/apt/trusted.gpg.d
490 done
491 fi
492
493 if [scip-shell system . . `[`. $full = 1 ];then
494 pkgs=nfs-common
495 fi
496
497 $ROOTCMD apt-get update
498 # disable generating the initrd
499 fdivertscip-shell shell fai 6.6 fdivert(). /etc/kernel/postinst.d/dracutscip-shell filesystem . . `/etc/kernel/postinst.d/dracut`.
500 $ROOTCMD ln -s /bin/truescip-shell filesystem . . `/bin/true`. /etc/kernel/postinst.d/dracutscip-shell filesystem . . `/etc/kernel/postinst.d/dracut`.
501
502 # fai-nfsroot must be sucessfully installed before anything else
503 $ROOTCMD apt-get -yf --no-install-recommends install fai-nfsroot dracut-config-generic dracut-live dracut-network dracut-squash
504 $ROOTCMD apt-get -y dist-upgrade
505 fdivertscip-shell shell fai 6.6 fdivert(). /usr/sbin/update-grubscip-shell filesystem . . `/usr/sbin/update-grub`.
506 }
507 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
508 add_packages_nfsrootscip-shell shell fai 6.6 add_packages_nfsroot().() {
509
510 export FAI_ROOT=$NFSROOT
511 local err
512
513 setclassesscip-shell shell fai 6.6 setclasses().
514 > $NFSROOT/var/lib/dpkg/available
515 install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
516 echoscip-shell system . . echo. "Adding additional packages to $NFSROOT:"
517 catscip-shell system . . cat. $NFSROOT/var/tmp/packages.nfsroot
518 set +e
519 call_verbosescip-shell shell fai 6.6 call_verbose(). install_packages $v -p$cfdir
520 err=$?
521 if [scip-shell system . . `[`. $err -ne 0 ]; then
522 diescip-shell shell fai 6.6 die(). 12 "install_packages had exit code: $err"
523 fi
524 set -e
525 }
526 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
527 umount_dirsscip-shell shell fai 6.6 umount_dirs().() {
528
529 cd /scip-shell filesystem . . `/`.
530 [scip-shell system . . `[`. -d $NFSROOT/proc/self ] && umountscip-shell system . . umount. $NFSROOT/proc
531 [scip-shell system . . `[`. -d $NFSROOT/sys/class ] && umountscip-shell system . . umount. $NFSROOT/sys
532 [scip-shell system . . `[`. -d $NFSROOT/proc/self ] && diescip-shell shell fai 6.6 die(). 1 "/proc still mounted inside the nfsroot.scip-shell filesystem . . `/proc still mounted inside the nfsroot.`."
533 umountscip-shell system . . umount. $NFSROOT/dev/pts 2> /dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
534
535 mountpointscip-shell system . . mountpoint. -q $NFSROOT/var/lib/dpkg && \
536 /usr/lib/fai/mkramdisk -u $NFSROOT/var/lib/dpkg $NFSROOT/var/cache
537
538 if [scip-shell system . . `[`. -n "$FAI_DEBMIRROR" ]; then
539 testscip-shell system . . test. -d $NFSROOT/$MNTPOINT && umountscip-shell system . . umount. $NFSROOT/$MNTPOINT || truescip-shell system . . true.
540 rmdirscip-shell system . . rmdir. $NFSROOT/$MNTPOINT || truescip-shell system . . true.
541 fi
542 # show directories still mounted on nfsroot
543 _cnfsroot=$(readlinkscip-shell system . . readlink. -f $NFSROOT)
544 mountscip-shell system . . mount. | grepscip-shell system . . grep. " on $_cnfsroot " || truescip-shell system . . true.
545 }
546 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
547 setup_tftpscip-shell shell fai 6.6 setup_tftp().(){
548
549 # tftp environment
550 rmscip-shell system . . rm. -f $NFSROOT/boot/*.bak
551 mkdirscip-shell system . . mkdir. -p $TFTPROOT/pxelinux.cfg
552 chmodscip-shell system . . chmod. a+r $NFSROOT/boot/initrd.img-* || diescip-shell shell fai 6.6 die(). 9 "No initrd was created. Check the package name of the linux-image package in /etc/fai/NFSROOT."
553 cpscip-shell system . . cp. -p $v $NFSROOT/boot/vmlinu?-* $NFSROOT/boot/initrd.img-* $TFTPROOT
554 cpscip-shell system . . cp. -u $v $NFSROOT/usr/lib/PXELINUX/lpxelinux.0 $TFTPROOT/pxelinux.0
555 if [scip-shell system . . `[`. -f $NFSROOT/usr/lib/syslinux/modules/bios/ldlinux.c32 ]; then
556 cpscip-shell system . . cp. -u $NFSROOT/usr/lib/syslinux/modules/bios/ldlinux.c32 $TFTPROOT
557 fi
558 if [scip-shell system . . `[`. -f $NFSROOT/usr/lib/syslinux/modules/efi64/ldlinux.e64 ]; then
559 cpscip-shell system . . cp. -u $NFSROOT/usr/lib/syslinux/modules/efi64/ldlinux.e64 $TFTPROOT
560 fi
561 if [scip-shell system . . `[`. -f $NFSROOT/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi ]; then
562 cpscip-shell system . . cp. -u $NFSROOT/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi $TFTPROOT
563 fi
564 if [scip-shell system . . `[`. X$verbose = X1 ]; then
565 echoscip-shell system . . echo. "TFTP environment prepared. Enable DHCP and start the TFTP daemon on root $TFTPROOT."
566 fi
567 }
568 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
569 fdivertscip-shell shell fai 6.6 fdivert().() {
570
571 local item
572 for item in "$@"; do
573 LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
574 done
575 }
576 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
577 run_hooksscip-shell shell fai 6.6 run_hooks().() {
578
579 local file
580 [scip-shell system . . `[`. -z "$NFSROOT_HOOKS" ] && return 0
581 [scip-shell system . . `[`. -d "$NFSROOT_HOOKS" ] || return 0
582
583 echoscip-shell system . . echo. "Running hooks..."
584 for file in $(run-partsscip-shell system . . run-parts. --lsbsysinit --list "$NFSROOT_HOOKS"); do
585 . $file $v
586 done
587 }
588 # - - - - - - - - - - - - - - - - - - - - - - - - - -
589 write_variablesscip-shell shell fai 6.6 write_variables().() {
590
591 local varfile=/var/log/fai/variablesscip-shell filesystem . . `/var/log/fai/variables`.
592 local fai_version=$($ROOTCMD dpkg-query -W -f='${Version}' fai-client)
593
594 # remove old values from file
595 [scip-shell system . . `[`. -s $varfile ] && sedscip-shell system . . sed. -i -e '/FAI_VERSION/dscip-shell filesystem . . `/FAI_VERSION/d`.' -e '/NFSROOT/dscip-shell filesystem . . `/NFSROOT/d`.' $varfile
596 echoscip-shell system . . echo. "FAI_VERSION=$fai_version" >> $varfile
597 echoscip-shell system . . echo. "NFSROOT=$NFSROOT" >> $varfile
598 }
599 # - - - - - - - - - - - - - - - - - - - - - - - - - -
600
601 # main routine
602
603 trap 'echo "Aborting";umount_dirs' EXIT
604 trap "bad_exit" ERR
605
606 [scip-shell system . . `[`. $adjust = 1 ] && adjust_nfsrootscip-shell shell fai 6.6 adjust_nfsroot().
607
608 # remove all kernels from nfsroot
609 [scip-shell system . . `[`. -n "$kremove" ] && {
610 echoscip-shell system . . echo. "Removing all kernels from NFSROOT."
611 LC_ALL=C $ROOTCMD apt-get -qq purge linux-image\*
612 exit
613 }
614
615 # just upgrade the nfsroot and install packages into it
616 [scip-shell system . . `[`. -n "$kinstall" ] && {
617 echoscip-shell system . . echo. "Upgrading nfsroot and installing new packages into the nfsroot."
618 mount_special_into_nfsrootscip-shell shell fai 6.6 mount_special_into_nfsroot().
619 $ROOTCMD apt-get update
620 $ROOTCMD apt-get -y dist-upgrade
621 LC_ALL=C add_packages_nfsrootscip-shell shell fai 6.6 add_packages_nfsroot().
622 setup_tftpscip-shell shell fai 6.6 setup_tftp().
623 run_hooksscip-shell shell fai 6.6 run_hooks().
624 umount_dirsscip-shell shell fai 6.6 umount_dirs().
625 trap "true" EXIT
626 echoscip-shell system . . echo. "fai-make-nfsroot finished $merror."
627 exit $exitcode
628 }
629
630 # repeat message, so it will appear in the log file
631 rmscip-shell system . . rm. -f /var/log/fai/fai-make-nfsroot.logscip-shell filesystem . . `/var/log/fai/fai-make-nfsroot.log`.
632 [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Using configuration files from $cfdir" > /var/log/fai/fai-make-nfsroot.logscip-shell filesystem . . `/var/log/fai/fai-make-nfsroot.log`.
633
634 {
635 if [scip-shell system . . `[`. -d $NFSROOT ] && [scip-shell system . . `[`. "$force" -ne 1 ] ; then
636 echoscip-shell system . . echo. "-----------------------------------------------------------------"
637 echoscip-shell system . . echo. "Error: $NFSROOT exists already." >&2
638 echoscip-shell system . . echo. "Neither force nor update option present, exiting." >&2
639 echoscip-shell system . . echo. "-----------------------------------------------------------------"
640 echoscip-shell system . . echo. "NOTE: Use -f option to force overwriting an existing nfsroot."
641 echoscip-shell system . . echo. " Use -k option to update/install packages defined in NFSROOT config."
642 exit 1
643 fi
644
645 echoscip-shell system . . echo. "Creating FAI nfsroot in $NFSROOT"
646
647 if [scip-shell system . . `[`. $sshpreserve -ge 1 ]; then
648 [scip-shell system . . `[`. -d $NFSROOT/root/.ssh ] || echoscip-shell system . . echo. "Cannot preserve non-existing $NFSROOT/root/.ssh."
649 tmptar=$(mktempscip-shell system . . mktemp.) || diescip-shell shell fai 6.6 die(). 12 "Cannot create tmp file"
650 pdirs="root/.ssh"
651 if [scip-shell system . . `[`. $sshpreserve -eq 2 ]; then
652 pdirs="root/.ssh etc/ssh/ssh_host_*"
653 fi
654 export pdirs
655 [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Preserving $pdirs from inside the nfsroot."
656 (
657 cd $NFSROOT || exit # needed for * in $pdirs to work
658 tarscip-shell system . . tar. -C $NFSROOT -cf $tmptar $pdirs
659 )
660 unset pdirs
661 fi
662
663 if [scip-shell system . . `[`. -d $NFSROOT/proc ]; then
664 umountscip-shell system . . umount. $NFSROOT/dev/pts >&/dev/null || truescip-shell system . . true.
665 [scip-shell system . . `[`. -L $NFSROOT/proc/self ] && umountscip-shell system . . umount. $NFSROOT/proc || truescip-shell system . . true.
666 [scip-shell system . . `[`. -L $NFSROOT/proc/self ] && diescip-shell shell fai 6.6 die(). 1 "/proc is still mounted inside the nfsroot.scip-shell filesystem . . `/proc is still mounted inside the nfsroot.`."
667 umountscip-shell system . . umount. $NFSROOT/$MNTPOINT 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true. # it's safer to try to umount
668 # remove old nfsroot using a background process
669 rmscip-shell system . . rm. -rf $deldir/../.will-now-be-deleted
670 if mvscip-shell system . . mv. $deldir $deldir/../.will-now-be-deleted ; then
671 nicescip-shell system . . nice. rm -rf $deldir/../.will-now-be-deleted &
672 else
673 rmscip-shell system . . rm. -rf $deldir
674 fi
675 fi
676
677 create_nfsrootscip-shell shell fai 6.6 create_nfsroot().
678 setup_tftpscip-shell shell fai 6.6 setup_tftp().
679 call_verbosescip-shell shell fai 6.6 call_verbose(). setup_ssh
680 run_hooksscip-shell shell fai 6.6 run_hooks().
681 check_nfsrootscip-shell shell fai 6.6 check_nfsroot().
682 write_variablesscip-shell shell fai 6.6 write_variables().
683
684 if [scip-shell system . . `[`. $generic = 1 ]; then
685 # remove fai.conf which comes from package fai-client
686 rmscip-shell system . . rm. -f $NFSROOT/etc/hosts $NFSROOT/etc/resolv.conf* $NFSROOT/etc/fai/fai.conf $NFSROOT/var/lib/apt/lists/*_*
687 ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
688 fi
689
690 umount_dirsscip-shell shell fai 6.6 umount_dirs().
691
692 # Wait for background jobs to finish
693 BGJOBS=$(jobs -p)
694 if [scip-shell system . . `[`. -n "$BGJOBS" ]; then
695 echoscip-shell system . . echo. "Waiting for background jobs to finish"
696 jobs
697 for job in $BGJOBS; do
698 wait $job
699 done
700 fi
701
702 echoscip-shell system . . echo. "fai-make-nfsroot finished $merror."
703 exit $exitcode
704 } |& teescip-shell system . . tee. -a /var/log/fai/fai-make-nfsroot.logscip-shell filesystem . . `/var/log/fai/fai-make-nfsroot.log`.
705 RC=${PIPESTATUS[0]}
706 umount_dirsscip-shell shell fai 6.6 umount_dirs().
707 trap "true" EXIT
708 if [scip-shell system . . `[`. $generic = 0 ]; then
709 cpscip-shell system . . cp. -p /var/log/fai/fai-make-nfsroot.logscip-shell filesystem . . `/var/log/fai/fai-make-nfsroot.log`. $NFSROOT/var/tmp
710 msg="and $NFSROOT/var/tmp"
711 fi
712 echoscip-shell system . . echo. "Log file written to /var/log/fai/fai-make-nfsroot.log $msg"
713 exit ${RC}