avoid boot hang
[automated-distro-installer] / fai / config / hooks / partition.DEFAULT
1 #!/bin/bash -x
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 PS4='+ $LINENO '
19 set -eE -o pipefail
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21
22 if [[ $EUID != 0 ]]; then
23 echo "$0: error: need to run as root" >&2
24 exit 1
25 fi
26
27 # for calling outside of FAI:
28 # fai-redep
29 # s
30 # source /b/fai/fai-wrapper
31 # - set any appropriate classes with: fai-setclass OPT1... which sets CLASS_OPT1=true...
32 # or run eval-fai-classfile FILE
33 # export luks_dir=/q/root/luks
34 #
35 # OPTIONS:
36 #
37 # environment variables:
38 #
39 # HOSTNAME: if frodo, we exclude 2 devices from the /boot array, which
40 # the bios does not see. if demohost, we set the luks password to just
41 # 'x'.
42 #
43 # SPECIAL_DISK: For use outside of fai. A base disk name like
44 # /dev/sdk. If set, we just cryptsetup and partition this one disk then
45 # exit. This is useful for partitioning a disk in preparation to replace
46 # a failed or failing disk from a raid10 array.
47 #
48 # classes:
49 #
50 # REPARTITION: forces repartitioning even if we detect the proper amount
51 # of partitions already exist.
52 #
53 # NOWIPE: use existing subvolumes if they exist
54 #
55 # ROTATIONAL: forces to install onto hdds instead of sdds. normally sdds
56 # are chosen if they exist.
57 #
58 # PARTITION_PROMPT: command line prompt before partitioning
59 #
60 # RAID0: forces raid0 filesystem. Normally with 4+ devices, we use
61 # raid10.
62 # RAID1: forces raid1 filesystem.
63
64 if [[ $SPECIAL_DISK ]]; then
65 export CLASS_REPARTITION=true
66 fi
67
68 # # fai's setup-storage won't do btrfs on luks,
69 # # so we do it ourself :)
70 # inspiration taken from files in fai-setup-storage package
71
72 # if we are not running in fai, skiptask won't be defined, so carry on.
73 skiptask partition || ! type skiptask
74
75 if ! type -p devbyid; then
76 for d in $FAI/distro-install-common \
77 /a/bin/fai/fai/config/distro-install-common $FAI $PWD; do
78 [[ -d $d ]] || continue
79 if [[ -e $d/devbyid ]]; then
80 devbyid=$d/devbyid
81 devbyid() { $devbyid "$@"; }
82 break
83 fi
84 done
85 if [[ ! $devbyid ]]; then
86 echo "$0: error: failed to find devbyid script" >&2
87 exit 1
88 fi
89 fi
90
91
92
93 #### begin configuration
94
95 rootn=1
96 swapn=2
97 bootn=3
98 efin=4
99 # ext partition so grub can write persistent variables,
100 # so it can do a one time boot. grub can't write to
101 # btrfs or any cow fs because it's more
102 # more complicated to do and they don't want to.
103 grub_extn=5
104 # bios boot partition,
105 # https://wiki.archlinux.org/index.php/GRUB
106 bios_grubn=6
107 lastn=$bios_grubn
108
109
110
111 ##### end configuration
112
113
114 add-part() { # add partition suffix to $dev
115 local d ret
116 if [[ $# == 1 ]]; then
117 d=$dev
118 part=$1
119 else
120 d=$1
121 part=$2
122 fi
123 echo $d-part$part
124 }
125
126 bootdev() { add-part $@ $bootn; }
127 rootdev() { add-part $@ $rootn; }
128 swapdev() { add-part $@ $swapn; }
129 efidev() { add-part $@ $efin; }
130 grub_extdev() { add-part $@ $grub_extn; }
131 bios_grubdev() { add-part $@ $bios_grubn; }
132
133 crypt-dev() { echo /dev/mapper/crypt_dev_${1##*/}; }
134 crypt-name() { echo crypt_dev_${1##*/}; }
135 root-cryptdev() { crypt-dev $(rootdev $@); }
136 swap-cryptdev() { crypt-dev $(swapdev $@); }
137 root-cryptname() { crypt-name $(rootdev $@); }
138 swap-cryptname() { crypt-name $(swapdev $@); }
139
140 dev-mib() {
141 echo $(( $(parted -m $dev unit MiB print | \
142 sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1))
143 }
144
145 ##### end function defs
146
147 if ifclass REPARTITION; then
148 partition=true # force a full wipe
149 else
150 partition=false # change to true to force a full wipe
151 fi
152 if ifclass NOWIPE; then
153 wipe=false
154 else
155 wipe=true
156 fi
157
158 if ((`nproc` > 2)); then
159 mopts=,compress=zstd
160 fi
161
162 declare -A disk_excludes
163 if ! ifclass USE_MOUNTED; then
164 ## ignore disks that are mounted, eg when running from fai-cd
165 while read -r l; do
166 eval "$l"
167 if [[ ! $PKNAME ]]; then
168 PKNAME="$KNAME"
169 fi
170 if [[ $MOUNTPOINT ]]; then
171 disk_excludes[$PKNAME]=true
172 fi
173 done < <(lsblk -nP -o KNAME,MOUNTPOINT,PKNAME)
174 fi
175
176 hdds=()
177 ssds=()
178 # this excludes usb. note: i may encounter some other type in the future.
179 for disk in $(lsblk -do name,tran -n | awk '$2 ~ "^(sata|nvme)$" { print $1 }'); do
180 if [[ ${disk_excludes[$disk]} ]]; then
181 continue
182 fi
183 case $(cat /sys/block/$disk/queue/rotational) in
184 0) ssds+=(/dev/$disk) ;;
185 1) hdds+=(/dev/$disk) ;;
186 *) echo "$0: error: unknown /sys/block/$disk/queue/rotational: \
187 $(cat $disk/queue/rotational)"; exit 1 ;;
188 esac
189 done
190
191 # install all ssds, or if there are none, all hdds.
192 # Note, usb flash disks are seen as rotational, which is
193 # very odd, but convenient for ignoring them here.
194 # TODO: find a reliable way to ignore them.
195 if ! ifclass ROTATIONAL && (( ${#ssds[@]} > 0 )); then
196 short_devs=( ${ssds[@]} )
197 else
198 short_devs=( ${hdds[@]} )
199 fi
200
201 # check if the partitions exist have the right filesystems
202 #blkid="$(blkid -s TYPE)"
203 for dev in ${short_devs[@]}; do
204 if $partition; then break; fi
205 y=$(readlink -f $dev)
206 arr=($y?*)
207 if (( ${#arr[@]} != lastn )); then
208 partition=true
209 fi
210 # On one system, blkid is missing some partitions.
211 # maybe we need a flag, like FUZZY_BLKID or something, so we
212 # can check that at least some exist.
213 # for x in "`rootdev`: TYPE=\"crypto_LUKS\"" "`bootdev`: TYPE=\"btrfs\""; do
214 # echo "$blkid" | grep -Fx "$x" &>/dev/null || partition=true
215 # done
216 done
217
218 if $partition && ifclass PARTITION_PROMPT; then
219 echo "Press any key except ctrl-c to continue and partition these drives:"
220 echo " ${short_devs[*]}"
221 read -r
222 fi
223
224 devs=()
225 shopt -s extglob
226 for short_dev in ${short_devs[@]}; do
227 devs+=($(devbyid $short_dev))
228 done
229 if [[ ! ${devs[0]} ]]; then
230 echo "$0: error: failed to detect devs" >&2
231 exit 1
232 fi
233
234 boot_space=0
235 first=true
236 boot_devs=()
237 for dev in ${devs[@]}; do
238 if ifclass frodo; then
239 # I ran into a machine where the bios doesn't know about some disks,
240 # so 1st stage of grub also doesn't know about them.
241 # Also, grub does not support mounting degraded btrfs as far as
242 # I can tell with some googling.
243 # From within an arch install env, I could detect them by noting
244 # their partitions were mixed with the next disk in /dev/disk/by-path,
245 # and I have mixed model disks, and I could see the 8 models which showed
246 # up in the bios, and thus see which 2 models were missing.
247 # hdparm -I /dev/sdh will give model info in linux.
248 # However, in fai on jessie, /dev/disk/by-path dir doesn't exist,
249 # and I don't see another way, so I'm hardcoding them.
250 # We still put grub on them and partition them the same, for uniformity
251 # and in case they get moved to a system that can recognize them,
252 # we just exclude them from the boot filesystem.
253 cd /dev/disk/by-id/
254 bad_disk=false
255 for id in ata-TOSHIBA_MD04ACA500_8539K4TQFS9A \
256 ata-TOSHIBA_MD04ACA500_Y5IFK6IJFS9A; do
257 if [[ $(readlink -f $id) == "$(readlink -f $dev)" ]]; then
258 bad_disk=true
259 break
260 fi
261 done
262 $bad_disk || boot_devs+=($(bootdev))
263 else
264 boot_space=$(( boot_space + $(parted -m $dev unit MiB print | \
265 sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1))
266 boot_devs+=($(bootdev))
267 fi
268 if $first && [[ $boot_devs ]]; then
269 first_efi=$(efidev)
270 first_grub_extdev=$(grub_extdev)
271 first=false
272 fi
273 done
274 first_boot_dev=${boot_devs[0]}
275
276 even_raid=false
277 if ifclass RAID0 || (( ${#boot_devs[@]} == 1 )); then
278 raid_level=0
279 elif ifclass RAID1 || (( ${#boot_devs[@]} <= 3 )); then
280 if (( ${#boot_devs[@]} == 2 )); then
281 even_raid=true
282 fi
283 raid_level=1
284 else
285 raid_level=10
286 fi
287
288 ### Begin calculate boot partition space
289 # due to raid duplication
290 case $raid_level in
291 1*) boot_space=$(( boot_space / 2 )) ;;
292 esac
293 if (( boot_space > 60000 )); then
294 # this is larger than needed for several /boot subvols,
295 # becuase I keep a minimal debian install on it for
296 # recovery needs and for doing pxe-kexec.
297 boot_mib=10000
298 elif (( boot_space > 30000 )); then
299 boot_mib=$(( 5000 + (boot_space - 30000) / 2 ))
300 else
301 # Small vms don't have room for /boot recovery. With 3 kernels
302 # installed, i'm using 132M on t8, so this seems like plenty of
303 # room. note: rhel 8 recomments 1g for /boot.
304 boot_mib=500
305 #
306 fi
307 case $raid_level in
308 1*) boot_mib=$(( boot_mib * 2 )) ;;
309 esac
310 ### end calculate boot partition space
311
312
313
314 if [[ ! $DISTRO ]]; then
315 if ifclass VOL_BUSTER_BOOTSTRAP; then
316 DISTRO=debianbuster_bootstrap
317 elif ifclass VOL_STRETCH; then
318 DISTRO=debianstretch
319 elif ifclass VOL_BUSTER; then
320 DISTRO=debianbuster
321 elif ifclass VOL_BULLSEYE; then
322 DISTRO=debianbullseye
323 elif ifclass VOL_TESTING; then
324 DISTRO=debiantesting
325 elif ifclass VOL_XENIAL; then
326 DISTRO=ubuntuxenial
327 elif ifclass VOL_BIONIC; then
328 DISTRO=ubuntubionic
329 elif ifclass VOL_FOCAL; then
330 DISTRO=ubuntufocal
331 elif ifclass VOL_FLIDAS; then
332 DISTRO=trisquelflidas
333 elif ifclass VOL_ETIONA; then
334 DISTRO=trisqueletiona
335 elif ifclass VOL_NABIA; then
336 DISTRO=trisquelnabia
337 else
338 echo "PARTITIONER ERROR: no distro class/var set" >&2
339 exit 1
340 fi
341 fi
342
343
344 bpart() { # btrfs a partition
345 case $raid_level in
346 0) mkfs.btrfs -f $@ ;;
347 1) mkfs.btrfs -f -m raid1 -d raid1 $@ ;;
348 10) mkfs.btrfs -f -m raid10 -d raid10 $@ ;;
349 esac
350 }
351
352
353 if [[ ! $luks_dir ]]; then
354 # see README for docs about how to create these
355 luks_dir=$FAI/distro-install-common/luks
356 fi
357
358 luks_file=$luks_dir/host-$HOSTNAME
359 if [[ ! -e $luks_file ]]; then
360 hostkeys=($luks_dir/host-*)
361 # if there is only one key, we might be deploying somewhere
362 # where dhcp doesnt give us a proper hostname, so use that.
363 if [[ ${#hostkeys[@]} == 1 && -e ${hostkeys[0]} ]]; then
364 luks_file=${hostkeys[0]}
365 else
366 echo "$0: error: no key for hostname at $luks_file" >&2
367 exit 1
368 fi
369 fi
370
371 # # note, corresponding changes in /b/ds/keyscript-{on,off}
372 if ifclass demohost; then
373 lukspw=x
374 elif [[ -e $luks_dir/$HOSTNAME ]]; then
375 lukspw=$(cat $luks_dir/$HOSTNAME)
376 else
377 lukspw=$(cat $luks_dir/iank)
378 fi
379
380
381 first_root_crypt=$(root-cryptdev ${devs[0]})
382
383 # 1.5 x based on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-disk-partitioning-setup-x86.html#sect-custom-partitioning-x86
384 swap_mib=$(( $(grep ^MemTotal: /proc/meminfo | \
385 awk '{print $2}') * 3/(${#devs[@]} * 2 ) / 1024 ))
386
387 mkdir -p /tmp/fai
388 root_devs=()
389 for dev in ${devs[@]}; do
390 root_devs+=($(rootdev))
391 done
392 shopt -s nullglob
393 if $partition; then
394
395 ### begin wipefs
396 if [[ ! $SPECIAL_DISK ]]; then
397 for dev in ${devs[@]}; do
398 # if we repartition to the same as an old partition,
399 # we don't want any old fses hanging around.
400 for (( i=1; i <= lastn; i++ )); do
401 x=$(add-part $i)
402 [[ -e $x ]] || continue
403 count_down=10
404 # wipefs has failed, manual run works, google suggests timing issue
405 while ! wipefs -a $x; do
406 sleep 2
407 count_down=$((count_down - 1))
408 (( count_down > 0 )) || exit 1
409 done
410 done
411 done
412 fi
413 ### end wipefs
414
415
416 if $even_raid; then
417 for dev in ${devs[@]}; do
418 cur_mib=$(dev-mib)
419 if [[ ! $disk_mib ]] || (( cur_mib < disk_mib )); then
420 disk_mib=$cur_mib
421 fi
422 done
423 fi
424
425 for dev in ${devs[@]}; do
426 if [[ $SPECIAL_DISK ]]; then
427 dev=$(devbyid $SPECIAL_DISK)
428 fi
429
430 # parted will round up the disk size. Do -1 so we can have
431 # fully 1MiB unit partitions for easy resizing of the last partition.
432 # Otherwise we would pass in -0 for the end argument for the last partition.
433 #
434 # Note: parted print error output is expected. example:
435 # Error: /dev/vda: unrecognised disk label
436 if ! $even_raid; then
437 disk_mib=$(dev-mib)
438 fi
439 root_end=$(( disk_mib - swap_mib - boot_mib / ${#boot_devs[@]} ))
440 swap_end=$(( root_end + swap_mib))
441
442 parted -s $dev mklabel gpt
443 # MiB because parted complains about alignment otherwise.
444 pcmd="parted -a optimal -s -- $dev"
445 $pcmd mkpart primary ext3 524MiB ${root_end}MiB
446 # without naming, systemd gives us misc errors like:
447 # dev-disk-by\x2dpartlabel-primary.device: Dev dev-disk-by\x2dpartlabel-primary.device appeared twice
448 $pcmd name $rootn root
449 # normally a swap is type "linux-swap", but this is encrypted swap. using that
450 # label will confuse systemd.
451 $pcmd mkpart primary "" ${root_end}MiB ${swap_end}MiB
452 $pcmd name $swapn swap
453 $pcmd mkpart primary "" ${swap_end}MiB ${disk_mib}MiB
454 $pcmd name $bootn boot
455 # eufi = bloated, half a gig gimme a break.
456 $pcmd mkpart primary "fat32" 12MiB 524MiB
457 $pcmd name $efin efi
458 $pcmd set $efin esp on
459 # note, this is shown here: https://support.system76.com/articles/bootloader/
460 # but not mentioned https://wiki.archlinux.org/index.php/EFI_system_partition
461 # probably not needed
462 $pcmd set $bootn boot on
463 # i only need a few k, but googling min size,
464 # I found someone saying that gparted required
465 # required at least 8 because of their hard drive cylinder size.
466 # And 8 is still very tiny.
467 $pcmd mkpart primary "ext2" 4MiB 12MiB
468 $pcmd name $grub_extn grubext
469 # gpt ubuntu cloud image uses ~4 mb for this partition. fai uses 1 MiB.
470 # so, I use 3, whatever.
471 # note: parted manual saying cheap flash media
472 # should to start at 4.
473 $pcmd mkpart primary "" 1MiB 4MiB
474 $pcmd name $bios_grubn biosgrub
475 $pcmd set $bios_grubn bios_grub on
476 $pcmd set $bootn boot on # generally not needed on modern systems
477 # the mkfs failed before on a vm, which prompted me to add
478 # sleep .1
479 # then it failed again on a physical machine
480 # with:
481 # Device /dev/disk/by-id/foo doesn't exist or access denied,
482 # so I added a wait until it existed.
483 # Then I added the mkfs.ext2, which claimed to succeed,
484 # but then couldn't be found upon reboot. In that case we didn't
485 # wait at all. So I've added a 3 second minimum wait.
486 sleep 3
487 secs=0
488 while [[ ! -e $(rootdev) ]] && (( secs < 10 )); do
489 sleep 1
490 secs=$((secs +1))
491 done
492
493 mkfs.fat -F32 $(efidev)
494
495 # Holds just a single file, rarely written, so
496 # use ext2, like was often used for the /boot partition.
497 # This exists because grub can only persist data to a non-cow fs.
498 # And we use persisting a var in grub to do a one time boot.
499 # We could pass the data on the kernel command line and persist it
500 # to grubenv after booting, but that relies on the boot always succeeding.
501 # This is just a bit more robust, and it could work for booting
502 # into ipxe which can't persist data, if we ever got that working.
503 mkfs.ext2 $(grub_extdev)
504 # when we move to newer than trisquel 9, we can remove
505 # --type luks1. We can also check on cryptsetup --help | less /compil
506 # to see about the other settings. Default in debian 9 is luks2.
507 # You can convert from luks2 to luks 1 by adding a temporary key:
508 # cryptsetup luksAddKey --pbkdf pbkdf2
509 # then remove the new format keys with cryptsetup luksRemoveKey
510 # then cryptsetup convert DEV --type luks1, then readd old keys and remove temp.
511 yes YES | cryptsetup luksFormat $(rootdev) $luks_file \
512 --type luks1 -c aes-cbc-essiv:sha256 -s 256 || [[ $? == 141 ]]
513 yes "$lukspw" | \
514 cryptsetup luksAddKey --key-file $luks_file \
515 $(rootdev) || [[ $? == 141 ]]
516 # background: Keyfile and password are treated just
517 # like 2 ways to input a passphrase, so we don't actually need to have
518 # different contents of keyfile and passphrase, but it makes some
519 # security sense to a really big randomly generated passphrase
520 # as much as possible, so we have both.
521 #
522 # This would remove the keyfile.
523 # yes 'test' | cryptsetup luksRemoveKey /dev/... \
524 # /key/file || [[ $? == 141 ]]
525
526 cryptsetup luksOpen $(rootdev) $(root-cryptname) \
527 --key-file $luks_file
528
529 if [[ $SPECIAL_DISK ]]; then
530 exit 0
531 fi
532 done
533 ls -la /dev/btrfs-control # this was probably for debugging...
534 sleep 1
535 bpart $(for dev in ${devs[@]}; do root-cryptdev; done)
536 bpart ${boot_devs[@]}
537 else
538 for dev in ${devs[@]}; do
539 if [[ -e /dev/mapper/$(root-cryptname) ]]; then
540 continue
541 fi
542 cryptsetup luksOpen $(rootdev) $(root-cryptname) \
543 --key-file $luks_file
544 done
545 sleep 1
546 fi
547
548
549 if $wipe && [[ $DISTRO != debianbuster_bootstrap ]]; then
550 # bootstrap distro doesn't use separate encrypted root.
551 mount -o subvolid=0 $first_root_crypt /mnt
552 # systemd creates subvolumes we want to delete.
553 s=($(btrfs subvolume list --sort=-path /mnt |
554 sed -rn "s#^.*path\s*(root_$DISTRO/\S+)\s*\$#\1#p"))
555 for subvol in ${s[@]}; do btrfs subvolume delete /mnt/$subvol; done
556 btrfs subvolume set-default 0 /mnt
557 [[ ! -e /mnt/root_$DISTRO ]] || btrfs subvolume delete /mnt/root_$DISTRO
558
559 ## create subvols ##
560 cd /mnt
561
562 btrfs subvolume create root_$DISTRO
563
564 # could set default subvol like this, but no reason to.
565 # btrfs subvolume set-default \
566 # $(btrfs subvolume list . | grep "root_$DISTRO$" | awk '{print $2}') .
567
568 # no cow on the root filesystem. it's setup is fully scripted,
569 # if it's messed up, we will just recreated it,
570 # and we can get better perf with this.
571 # I can't remember exactly why, but this is preferable to mounting with
572 # -o nodatacow, I think because subvolumes inherit that.
573 chattr -Rf +C root_$DISTRO
574 cd /
575 umount /mnt
576 fi
577
578 mount -o subvolid=0 $first_boot_dev /mnt
579 cd /mnt
580 btrfs subvolume set-default 0 /mnt # already default, just ensuring it.
581
582 # for libreboot systems. grub2 only reads from subvolid=0
583 mkdir -p /mnt/grub2
584 cp $FAI/distro-install-common/libreboot_grub.cfg /mnt/grub2
585
586 if [[ $DISTRO == debianbuster_bootstrap ]]; then
587 # this is just convenience for the libreboot_grub config
588 # so we can glob the other ones easier.
589 boot_vol=$DISTRO
590 else
591 boot_vol=boot_$DISTRO
592 fi
593 if $wipe && [[ -e /mnt/$boot_vol ]]; then
594 btrfs subvolume delete /mnt/$boot_vol
595 fi
596 if [[ ! -e /mnt/$boot_vol ]]; then
597 btrfs subvolume create $boot_vol
598 fi
599 cd /
600 umount /mnt
601 ## end create subvols ##
602
603 dev=${boot_devs[0]}
604 mount $first_grub_extdev /mnt
605 grub-editenv /mnt/grubenv set did_fai_check=true
606 grub-editenv /mnt/grubenv set last_boot=/$boot_vol
607 umount /mnt
608
609 if [[ $DISTRO == debianbuster_bootstrap ]]; then
610 cat > /tmp/fai/fstab <<EOF
611 $first_boot_dev / btrfs noatime,subvol=$boot_vol 0 0
612 $first_efi /boot/efi vfat nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s 0 0
613 EOF
614 cat >/tmp/fai/disk_var.sh <<EOF
615 BOOT_DEVICE="${short_devs[@]}"
616 ROOT_PARTITION=$first_boot_dev
617 EOF
618 else
619 # note, fai creates the mountpoints listed here
620 cat > /tmp/fai/fstab <<EOF
621 $first_root_crypt / btrfs x-systemd.device-timeout=90s,x-systemd.mount-timeout=90s,noatime,subvol=root_$DISTRO$mopts 0 0
622 $first_root_crypt /mnt/root btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,subvolid=0$mopts 0 0
623 $first_boot_dev /boot btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,subvol=$boot_vol 0 0
624 $first_efi /boot/efi vfat nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s 0 0
625 $first_boot_dev /mnt/boot btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,subvolid=0 0 0
626 EOF
627 swaps=()
628 rm -f /tmp/fai/crypttab
629 for dev in ${devs[@]}; do
630 swaps+=($(swap-cryptname))
631 cat >>/tmp/fai/crypttab <<EOF
632 $(root-cryptname) $(rootdev) none keyscript=/root/keyscript,discard,luks,initramfs
633 $(swap-cryptname) $(swapdev) /dev/urandom swap,cipher=aes-xts-plain64,size=256,hash=ripemd160
634 EOF
635 cat >> /tmp/fai/fstab <<EOF
636 $(swap-cryptdev) none swap nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,sw 0 0
637 EOF
638 done
639
640 # fai would do this:
641 #BOOT_DEVICE=\${BOOT_DEVICE:-"${devs[0]}"}
642
643 # note: swaplist seems to do nothing.
644 cat >/tmp/fai/disk_var.sh <<EOF
645 BOOT_DEVICE="${short_devs[@]}"
646 BOOT_PARTITION=\${BOOT_PARTITION:-$first_boot_dev}
647 # ROOT_PARTITIONS is added by me, used in arch setup.
648 ROOT_PARTITIONS="${root_devs[@]}"
649 ROOT_PARTITION=\${ROOT_PARTITION:-$first_root_crypt}
650 SWAPLIST=\${SWAPLIST:-"${swaps[@]}"}
651 EOF
652 fi