| 1 | #!/bin/bash |
| 2 | |
| 3 | #********************************************************************* |
| 4 | # |
| 5 | # fai-cd -- make a fai CD, a bootable CD that performs the FAI |
| 6 | # |
| 7 | # This script is part of FAI (Fully Automatic Installation) |
| 8 | # (c) 2004-2026 by Thomas Lange, [email protected] |
| 9 | # Universitaet zu Koeln |
| 10 | # Support for grub2 added by Sebastian Hetze, [email protected] |
| 11 | # with major support from Michael Prokop, [email protected] |
| 12 | # dracut/squashfs support by Kerim Gueney, [email protected] |
| 13 | # based on a script called make-fai-bootcd by Niall Young <[email protected]> |
| 14 | # |
| 15 | #********************************************************************* |
| 16 | # This program is free software; you can redistribute it and/or modify |
| 17 | # it under the terms of the GNU General Public License as published by |
| 18 | # the Free Software Foundation; either version 2 of the License, or |
| 19 | # (at your option) any later version. |
| 20 | # |
| 21 | # This program is distributed in the hope that it will be useful, but |
| 22 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | # General Public License for more details. |
| 25 | # |
| 26 | # A copy of the GNU General Public License is available as |
| 27 | # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution |
| 28 | # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You |
| 29 | # can also obtain it by writing to the Free Software Foundation, Inc., |
| 30 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 31 | #********************************************************************* |
| 32 | |
| 33 | set -e |
| 34 | |
| 35 | # last die exit code 22 |
| 36 | |
| 37 | count=0 |
| 38 | space=0 |
| 39 | config_space="" |
| 40 | configset=0 |
| 41 | forceremoval=0 |
| 42 | burn=0 |
| 43 | bootonly=0 |
| 44 | squash_only=0 |
| 45 | nomirror=0 |
| 46 | hidevartmp=0 |
| 47 | rel=0 |
| 48 | target=0 |
| 49 | autodiscover=0 |
| 50 | vname="FAI_CD" |
| 51 | |
| 52 | hidedirs="/usr/share/locale /usr/share/doc /var/lib/apt /var/lib/aptitude /var/cache/debconf /var/cache/apt /var/cache/man /usr/share/man /var/lib/dpkg/info /media/mirror/aptcache " |
| 53 | |
| 54 | # we need FAI_CONFIGDIR, NFSROOT |
| 55 | |
| 56 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 57 | usage() { |
| 58 | |
| 59 | cat <<-EOF |
| 60 | fai-cd Copyright (C) 2004-2026 Thomas Lange |
| 61 | |
| 62 | Usage: fai-cd [OPTIONS] -m MIRRORDIR ISONAME |
| 63 | Usage: fai-cd [OPTIONS] -B ISONAME |
| 64 | Usage: fai-cd [OPTIONS] -S IMAGEFILE |
| 65 | Create a FAI CD, a bootable CD that performs the FAI or a squashfs boot image. |
| 66 | Read the man pages pages fai-cd(8) for more information. |
| 67 | EOF |
| 68 | exit 0 |
| 69 | } |
| 70 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 71 | die() { |
| 72 | |
| 73 | local e=$1 # first parameter is the exit code |
| 74 | shift |
| 75 | |
| 76 | echo -e "ERROR: $*" >&2 # print error message |
| 77 | exit $e |
| 78 | } |
| 79 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 80 | check_programs() { |
| 81 | |
| 82 | local msg |
| 83 | [ $squash_only -eq 0 ] && ! command -v xorriso >&/dev/null && msg+="xorriso not found. Please install package." |
| 84 | command -v mksquashfs >&/dev/null || msg+="\nmksquashfs not found. Please install the package squashfs-tools." |
| 85 | command -v mkfs.vfat >&/dev/null || msg+="\nmkfs.vfat not found. Please install the package dosfstools." |
| 86 | command -v mcopy >&/dev/null || msg+="\nmcopy not found. Please install the package mtools." |
| 87 | |
| 88 | if [ -n "$msg" ]; then |
| 89 | die 8 "$msg" |
| 90 | fi |
| 91 | } |
| 92 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 93 | create_new_nfsroot() { |
| 94 | |
| 95 | mkdir -p $tmp/cow/work $tmp/cow/rw $NEW |
| 96 | |
| 97 | mount -t overlay -o lowerdir=$NFSROOT,upperdir=$tmp/cow/rw,workdir=$tmp/cow/work,default_permissions overlay $NEW |
| 98 | |
| 99 | customize_nfsroot $NEW |
| 100 | rm -f $NEW/etc/resolv.conf |
| 101 | } |
| 102 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 103 | create_autodiscover_iso() { |
| 104 | |
| 105 | # boot-only CD does not need some dracut modules |
| 106 | |
| 107 | local compress |
| 108 | local rel |
| 109 | rel=$(ls $NEW/lib/modules/|head -1) |
| 110 | local target=$NEW/lib/modules/$rel/kernel |
| 111 | |
| 112 | if [ -n "$_OPTJ" ]; then |
| 113 | compress="--xz" |
| 114 | else |
| 115 | compress="--zstd" |
| 116 | fi |
| 117 | rm $NEW/boot/initrd.img* |
| 118 | mountpoint -q $NEW/proc || mount --bind /proc $NEW/proc |
| 119 | mountpoint -q $NEW/sys || mount --bind /sys $NEW/sys |
| 120 | TMPDIR=/tmp chroot $NEW dracut -o ' fs-lib livenet rootfs-block ' -a 'overlayfs bash fai-autodiscover' "$compress" /boot/initrd.img-$rel $rel 2>/dev/null |
| 121 | umount $NEW/proc |
| 122 | umount $NEW/sys |
| 123 | customize_nfsroot $target |
| 124 | } |
| 125 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 126 | create_squashfs_image() { |
| 127 | |
| 128 | local output_path |
| 129 | |
| 130 | # this is where the squashfs.img needs to be placed |
| 131 | mkdir -p $tmp/LiveOS |
| 132 | |
| 133 | # create the squashfs.img |
| 134 | output_path=$tmp/LiveOS/squashfs.img |
| 135 | |
| 136 | if [ $squash_only -eq 1 ]; then |
| 137 | output_path=$isoname |
| 138 | fi |
| 139 | |
| 140 | echo "Make squashfs file system" |
| 141 | mksquashfs $NEW $output_path $sqopt -xattrs-exclude '^system.posix_acl_access|system.posix_acl_default' |
| 142 | } |
| 143 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 144 | prepare_grub_cfg() { |
| 145 | |
| 146 | # prepare grub.cfg |
| 147 | cp $grub_config $NEW/tmp/grub.cfg |
| 148 | # insert date into grub menu |
| 149 | perl -pi -e "s/_VERSIONSTRING_/ $isoversion /" $NEW/tmp/grub.cfg |
| 150 | if [ -n "$config_space" ] || [ $configset -eq 1 ]; then |
| 151 | perl -pi -e "s|FAI_CONFIG_SRC=(.*?)\S+|FAI_CONFIG_SRC=$config_space|" $NEW/tmp/grub.cfg |
| 152 | fi |
| 153 | provide_memtest_boot_option |
| 154 | } |
| 155 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 156 | copy_kernel_initrd() { |
| 157 | |
| 158 | # copy kernel and initrd |
| 159 | cp -p $NEW/boot/vmlinuz-$kernelversion $tmp/boot/vmlinuz |
| 160 | cp -p $NEW/boot/initrd.img-$kernelversion $tmp/boot/initrd.img |
| 161 | cp -p $NEW/boot/config-$kernelversion $tmp/boot/ |
| 162 | rm -f $NEW/tmp/grub.cfg |
| 163 | echo "$isoversion" > $tmp/FAI-CD |
| 164 | } |
| 165 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 166 | create_grub2_image_arm64() { |
| 167 | |
| 168 | mkdir -p $tmp/boot/grub |
| 169 | if [ -d $NEW/usr/lib/grub/arm64-efi ]; then |
| 170 | |
| 171 | prepare_grub_cfg |
| 172 | |
| 173 | # create arch.efi and copy to vfat file system |
| 174 | TMPDIR=tmp chroot $NEW grub-mkstandalone \ |
| 175 | --format=arm64-efi \ |
| 176 | --output=/tmp/grubaa64.efi \ |
| 177 | --locales="" \ |
| 178 | "boot/grub/grub.cfg=/tmp/grub.cfg" |
| 179 | mv $NEW/tmp/grubaa64.efi $scratch/BOOTAA64.EFI |
| 180 | |
| 181 | mkfs.vfat -C $scratch/efiboot.img 6000 >/dev/null |
| 182 | mmd -i $scratch/efiboot.img EFI EFI/boot |
| 183 | mcopy -i $scratch/efiboot.img $scratch/BOOTAA64.EFI ::EFI/boot/ |
| 184 | else |
| 185 | die 11 "No grub-efi-arm64-bin installation found in NFSROOT. Aborting." |
| 186 | fi |
| 187 | copy_kernel_initrd |
| 188 | } |
| 189 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 190 | create_grub2_image_x86() { |
| 191 | |
| 192 | mkdir -p $tmp/boot/grub |
| 193 | |
| 194 | if [ -d $NEW/usr/lib/grub/x86_64-efi ]; then |
| 195 | |
| 196 | prepare_grub_cfg |
| 197 | |
| 198 | # Populates the grub efi programs and grub config |
| 199 | cp $NEW/tmp/grub.cfg $tmp/boot/grub/grub.cfg |
| 200 | cp $NEW/tmp/grub.cfg $scratch/grub.cfg |
| 201 | cp $NEW/usr/lib/shim/shimx64.efi.signed $scratch/BOOTx64.EFI |
| 202 | cp $NEW/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed $scratch/grubx64.efi |
| 203 | |
| 204 | mkdir -p $tmp/EFI/BOOT/ |
| 205 | cp $NEW/usr/lib/shim/shimx64.efi.signed $tmp/EFI/BOOT/BOOTx64.EFI |
| 206 | mkfs.vfat -C $scratch/efiboot.img 6000 >/dev/null |
| 207 | mmd -i $scratch/efiboot.img efi efi/boot |
| 208 | mcopy -i $scratch/efiboot.img $scratch/grub.cfg ::efi/boot/ |
| 209 | mcopy -i $scratch/efiboot.img $scratch/BOOTx64.EFI ::efi/boot/ |
| 210 | mcopy -i $scratch/efiboot.img $scratch/grubx64.efi ::efi/boot/ |
| 211 | else |
| 212 | die 11 "No grub-efi-amd64-bin installation found in NFSROOT. Aborting." |
| 213 | fi |
| 214 | if [ -d $NEW/usr/lib/grub/i386-pc ]; then |
| 215 | cp -a $NEW/usr/lib/grub/i386-pc $NEW/tmp/grub |
| 216 | echo -e "ext2\niso9660\ntar\n" > $NEW/tmp/grub/fs.lst |
| 217 | TMPDIR=/tmp chroot $NEW grub-mkstandalone \ |
| 218 | --directory=/tmp/grub \ |
| 219 | --format=i386-pc \ |
| 220 | --output=/tmp/core.img \ |
| 221 | --locales="" --fonts="" \ |
| 222 | --install-modules="linux normal iso9660 biosdisk memdisk search ls echo test chain msdospart part_msdos part_gpt minicmd ext2 keystatus all_video font sleep gfxterm regexp read" \ |
| 223 | --modules="linux normal iso9660 biosdisk search" \ |
| 224 | "boot/grub/grub.cfg=/tmp/grub.cfg" |
| 225 | cat $NEW/usr/lib/grub/i386-pc/cdboot.img $NEW/tmp/core.img > $scratch/bios.img |
| 226 | rm -rf $NEW/tmp/core.img $NEW/tmp/grub |
| 227 | else |
| 228 | die 11 "No grub-pc installation found in NFSROOT. Aborting." |
| 229 | fi |
| 230 | copy_kernel_initrd |
| 231 | } |
| 232 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 233 | provide_memtest_boot_option() { |
| 234 | |
| 235 | if [ $bootonly -eq 1 ]; then |
| 236 | return |
| 237 | fi |
| 238 | |
| 239 | if [ -f $NEW/boot/memtest86+x64.efi ] || [ -f $NEW/boot/memtest86+x64.bin ]; then |
| 240 | cp -p $NEW/boot/memtest86+x64* $tmp/boot |
| 241 | echo "Adding memtest86+ to grub menu" |
| 242 | else |
| 243 | return 0 |
| 244 | fi |
| 245 | |
| 246 | cat >> $NEW/tmp/grub.cfg <<'EOF' |
| 247 | |
| 248 | if [ "$grub_platform" == efi -a "$grub_cpu" == x86_64 ]; then |
| 249 | menuentry "Memory test (memtest86+)" --unrestricted { |
| 250 | search --set=root --file /FAI-CD |
| 251 | linux /boot/memtest86+x64.efi |
| 252 | } |
| 253 | fi |
| 254 | if [ "$grub_platform" == pc ]; then |
| 255 | menuentry "Memory test (memtest86+)" --unrestricted { |
| 256 | search --set=root --file /FAI-CD |
| 257 | linux /boot/memtest86+x64.bin |
| 258 | } |
| 259 | fi |
| 260 | EOF |
| 261 | } |
| 262 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 263 | customize_nfsroot() { |
| 264 | |
| 265 | # hide/remove some dirs to save space and make the CD image smaller |
| 266 | local path=$1 |
| 267 | local d |
| 268 | |
| 269 | for d in $hidedirs; do |
| 270 | if [ -d $path/$d ]; then |
| 271 | [ "$debug" ] && echo "hiding $d" |
| 272 | rm -rf $path/$d/* |
| 273 | fi |
| 274 | done |
| 275 | } |
| 276 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 277 | cleanup_liveos_mounts() { |
| 278 | |
| 279 | mountpoint -q $NEW && umount $NEW |
| 280 | rm -rf $tmp $scratch |
| 281 | } |
| 282 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 283 | mkiso_x86() { |
| 284 | |
| 285 | echo "Writing FAI CD-ROM image to $isoname. This may need some time." |
| 286 | xorriso -report_about HINT -as mkisofs -iso-level 3 \ |
| 287 | -full-iso9660-filenames \ |
| 288 | -volid "$vname" -appid "$aname" \ |
| 289 | -eltorito-boot boot/grub/bios.img \ |
| 290 | -no-emul-boot -boot-load-size 4 -boot-info-table \ |
| 291 | --eltorito-catalog boot/grub/boot.cat \ |
| 292 | --grub2-boot-info \ |
| 293 | --grub2-mbr $NFSROOT/usr/lib/grub/i386-pc/boot_hybrid.img \ |
| 294 | -eltorito-alt-boot -e EFI/efiboot.img -no-emul-boot \ |
| 295 | -partition_offset 16 -appended_part_as_gpt \ |
| 296 | -append_partition 2 0xef $scratch/efiboot.img \ |
| 297 | -e --interval:appended_partition_2:all:: \ |
| 298 | --exclude $tmp/cow \ |
| 299 | -o $isoname -graft-points \ |
| 300 | --sort-weight 0 / --sort-weight 1 /boot \ |
| 301 | "$tmp" \ |
| 302 | /boot/grub/bios.img=$scratch/bios.img \ |
| 303 | /EFI/debian/grub.cfg=$scratch/grub.cfg \ |
| 304 | || die 12 "xorriso failed." |
| 305 | |
| 306 | echo -n "ISO image size and filename: "; du -h $isoname |
| 307 | } |
| 308 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 309 | mkiso_arm64() { |
| 310 | |
| 311 | echo "Writing FAI CD-ROM image to $isoname. This may need some time." |
| 312 | cp $scratch/efiboot.img $tmp/boot/grub/efi.img |
| 313 | xorriso -as mkisofs -r \ |
| 314 | -volid "$vname" -appid "$aname" \ |
| 315 | -J -joliet-long \ |
| 316 | -e boot/grub/efi.img -no-emul-boot \ |
| 317 | --exclude $tmp/cow \ |
| 318 | -append_partition 2 0xef $scratch/efiboot.img \ |
| 319 | -partition_cyl_align all \ |
| 320 | "$tmp" \ |
| 321 | -o $isoname \ |
| 322 | || die 12 "xorriso failed." |
| 323 | |
| 324 | echo -n "ISO image size and filename: "; du -h $isoname |
| 325 | } |
| 326 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 327 | addmirror() { |
| 328 | |
| 329 | [ $nomirror -eq 1 ] && return |
| 330 | |
| 331 | mkdir $NEW/media/mirror |
| 332 | |
| 333 | echo "Copying the mirror to CD image" |
| 334 | cp -Pr $mirrordir/{dists,pool} $NEW/media/mirror 2>/dev/null || die $? "Not enough space left on image for the mirror" |
| 335 | |
| 336 | # create the sources.list for the CD |
| 337 | cat > $NEW/etc/apt/sources.list <<EOF |
| 338 | # mirror location for fai CD, file generated by fai-cd |
| 339 | EOF |
| 340 | |
| 341 | dists=$(find $mirrordir -name "Packages*" | grep binary | sed 's/binary-.*//' | \ |
| 342 | sed "s#$mirrordir/*dists/##" | xargs -r -n 1 dirname | sort | uniq ) |
| 343 | [ -z "$dists" ] && die 19 "No suitable Packages file found in mirror." |
| 344 | |
| 345 | for i in $dists ; do |
| 346 | comp=$(find $mirrordir/dists/$i -maxdepth 2 -type d -name "binary-*" | \ |
| 347 | sed -e "s#$mirrordir/*dists/$i/##" -e 's#/binary-.*##' | uniq | tr '\n' " ") |
| 348 | echo "deb [trusted=yes] file:/media/mirror $i $comp" >> $NEW/etc/apt/sources.list |
| 349 | done |
| 350 | } |
| 351 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 352 | add_config_space() { |
| 353 | |
| 354 | # copy config space into nfsroot-copy unless -d is given |
| 355 | if [ $configset -eq 0 ]; then |
| 356 | echo "Copying the config space to CD image" |
| 357 | cp -Ppr $FAI_CONFIGDIR/. $NEW/var/lib/fai/config/ || die $? "Not enough space left on image for the config directory" |
| 358 | fi |
| 359 | } |
| 360 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 361 | burniso() { |
| 362 | |
| 363 | wodim -v -eject $isoname |
| 364 | } |
| 365 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 366 | # main program |
| 367 | |
| 368 | sqopt="-quiet -comp zstd -Xcompression-level 5" |
| 369 | |
| 370 | # Parse commandline options |
| 371 | while getopts "AekfhHg:Jbs:SBMn:m:V:c:C:d:" opt ; do |
| 372 | case "$opt" in |
| 373 | A) autodiscover=1 ;; |
| 374 | c) csdir="$OPTARG" ;; |
| 375 | C) cdir="$OPTARG" |
| 376 | echo "Using configuration files from $cdir";; |
| 377 | e) hidevartmp=1 ;; |
| 378 | f) forceremoval=1 ;; |
| 379 | h) usage ;; |
| 380 | H) hidedirs="" ;; |
| 381 | g) grub_config="$OPTARG" ;; |
| 382 | J) _OPTJ=1; sqopt="-quiet -comp xz";; |
| 383 | M) nomirror=1 ;; |
| 384 | m) mirrordir="$OPTARG" ;; |
| 385 | n) setnfsroot="$OPTARG" ;; |
| 386 | b) burn=1;; |
| 387 | s) echo "WARNING. Option -s is ignored" > /dev/stderr ;; |
| 388 | S) squash_only=1 ;; |
| 389 | B) bootonly=1 ;; |
| 390 | V) vname="$OPTARG" ;; |
| 391 | d) config_space="$OPTARG"; configset=1 ;; |
| 392 | ?) usage ;; |
| 393 | esac |
| 394 | done |
| 395 | shift $((OPTIND - 1)) |
| 396 | isoname=$1 |
| 397 | |
| 398 | |
| 399 | if [ $autodiscover -eq 1 ]; then |
| 400 | nomirror=1 |
| 401 | bootonly=1 |
| 402 | hidedirs=" |
| 403 | sound |
| 404 | net/ceph |
| 405 | fs/ceph |
| 406 | fs/ocfs2 |
| 407 | fs/btrfs |
| 408 | fs/xfs |
| 409 | fs/bcachefs |
| 410 | drivers/net/wireless |
| 411 | drivers/block/drbd |
| 412 | drivers/hwmon |
| 413 | drivers/iio |
| 414 | drivers/staging/lustre |
| 415 | drivers/scsi |
| 416 | drivers/ata |
| 417 | drivers/target |
| 418 | drivers/pcmcia |
| 419 | drivers/mmc |
| 420 | drivers/media |
| 421 | drivers/infiniband |
| 422 | drivers/isdn |
| 423 | drivers/video |
| 424 | drivers/mtd |
| 425 | drivers/md |
| 426 | drivers/gpu/drm |
| 427 | " |
| 428 | fi |
| 429 | |
| 430 | [ $nomirror -eq 1 -a -n "$mirrordir" ] && die 6 "Do not use -M and -m at the same time." |
| 431 | [ "$#" -eq 0 ] && die 2 "Please specify the output file for the ISO image." |
| 432 | if [ $bootonly -eq 0 -a $nomirror -eq 0 ]; then |
| 433 | [ -z "$mirrordir" ] && die 4 "Please specify the directory of your mirror using -m" |
| 434 | [ -d "$mirrordir" ] || die 5 "$mirrordir is not a directory" |
| 435 | [ -z "$(ls $mirrordir)" ] && die 18 "No mirror found in $mirrordir. Empty directory." |
| 436 | fi |
| 437 | [ -f "$isoname" ] && [ $forceremoval -eq 1 ] && rm $isoname |
| 438 | [ -f "$isoname" ] && die 3 "Outputfile $isoname already exists. Please remove it or use -f." |
| 439 | |
| 440 | if [ $bootonly -eq 0 ]; then |
| 441 | [ $(id -u) != "0" ] && die 9 "Run this program as root." |
| 442 | fi |
| 443 | |
| 444 | check_programs |
| 445 | |
| 446 | # use FAI_ETC_DIR from environment variable |
| 447 | if [ -n "$FAI_ETC_DIR" -a -z "$cdir" ]; then |
| 448 | echo "Using environment variable \$FAI_ETC_DIR." |
| 449 | cfdir=$FAI_ETC_DIR |
| 450 | fi |
| 451 | [ -n "$cdir" ] && cfdir=$cdir |
| 452 | : ${cfdir:=/etc/fai} |
| 453 | cfdir=$(readlink -f $cfdir) # canonicalize path |
| 454 | if [ ! -d "$cfdir" ]; then |
| 455 | echo "$cfdir is not a directory" >&2 |
| 456 | exit 6 |
| 457 | fi |
| 458 | . $cfdir/fai.conf |
| 459 | . $cfdir/nfsroot.conf |
| 460 | : ${FAI:=/var/lib/fai/config} # default value |
| 461 | |
| 462 | if [ -n "$setnfsroot" ]; then |
| 463 | NFSROOT=$setnfsroot # override by -n |
| 464 | fi |
| 465 | if [ -n "$csdir" ]; then |
| 466 | FAI_CONFIGDIR=$csdir # override by -c |
| 467 | fi |
| 468 | NFSROOT=$(readlink -f $NFSROOT) # resolve symlinks |
| 469 | |
| 470 | [ -f "$NFSROOT/bin/dracut" ] || die 10 "Please create a NFSROOT that includes dracut." |
| 471 | |
| 472 | [ $hidevartmp -eq 1 ] && hidedirs+="/var/tmp" |
| 473 | |
| 474 | if [ -z "$grub_config" ]; then |
| 475 | grub_config="$cfdir/grub.cfg" # set default if undefined |
| 476 | [ $autodiscover -eq 1 ] && grub_config="$cfdir/grub.cfg.autodiscover" # set default if undefined |
| 477 | fi |
| 478 | |
| 479 | # if grub_config contains / do not change it, else add prefix $cfdir |
| 480 | echo $grub_config | grep -q '/' || grub_config="$cfdir/$grub_config" |
| 481 | [ -f "$grub_config" ] || die 13 "Grub menu file $grub_config not found." |
| 482 | |
| 483 | if [ $bootonly -eq 0 -o $configset -eq 1 ]; then |
| 484 | [ -z "$FAI_CONFIGDIR" ] && die 14 "Variable \$FAI_CONFIGDIR not set." |
| 485 | [ -d $FAI_CONFIGDIR ] || die 15 "Can't find config space $FAI_CONFIGDIR." |
| 486 | [ -d $FAI_CONFIGDIR/class ] || die 16 "Config space $FAI_CONFIGDIR seems to be empty." |
| 487 | fi |
| 488 | |
| 489 | tmp=$(mktemp -t -d fai-cd.XXXXXX) || exit 13 |
| 490 | scratch=$(mktemp -t -d scratch.XXXXXX) || exit 13 |
| 491 | NEW=$tmp/nfsroot |
| 492 | |
| 493 | trap "cleanup_liveos_mounts" EXIT ERR |
| 494 | |
| 495 | create_new_nfsroot |
| 496 | if [ $bootonly -eq 0 ]; then |
| 497 | addmirror |
| 498 | add_config_space |
| 499 | create_squashfs_image |
| 500 | fi |
| 501 | |
| 502 | if [ $autodiscover -eq 1 ]; then |
| 503 | create_autodiscover_iso |
| 504 | fi |
| 505 | |
| 506 | [ $squash_only -eq 1 ] && exit 0 |
| 507 | |
| 508 | kernelversion=$(ls -tr $NEW/boot/vmlinu?-* | tail -1 | sed -e 's#.*/vmlinuz-##') |
| 509 | faiversion=$(dpkg --root=$NEW -l fai-client 2>/dev/null |awk '/fai-client/ {print $3}') |
| 510 | isoversion=$(printf "FAI %-6s build $(date '+%Y %b %d - %R')" "$faiversion") |
| 511 | aname="Fully Automatic Installation by Thomas Lange, $isoversion" |
| 512 | |
| 513 | case $(uname -m) in |
| 514 | x86_64) |
| 515 | create_grub2_image_x86 |
| 516 | umount $NEW |
| 517 | rmdir $NEW |
| 518 | mkiso_x86 |
| 519 | ;; |
| 520 | aarch64) |
| 521 | create_grub2_image_arm64 |
| 522 | umount $NEW |
| 523 | rmdir $NEW |
| 524 | mkiso_arm64 |
| 525 | ;; |
| 526 | esac |
| 527 | |
| 528 | [ "$burn" -eq 1 ] && burniso |
| 529 | exit 0 |