2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: Apache-2.0
5 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
6 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
8 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
9 source /a
/bin
/bash-bear-trap
/bash-bear
11 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
13 subvol
=$1 # eg ubuntubionic
16 if (( $# != 2 )); then
17 echo $0: error expected
2 arguments
21 # lots of this is taken from default.PARTITION
23 if (($
(nproc
) > 2)); then
27 rm -f $nr/etc
/{fs
,crypt}tab
28 while read -r line
; do
29 printf "%s none keyscript=decrypt_keyctl,discard,luks,initramfs\n" "$line" >>$nr/etc
/crypttab
30 done < <(awk '{print $1,$2}' /mnt
/root
/root2-crypttab
)
31 awk '$3 == "/dev/urandom" {print}' /etc
/crypttab
>>$nr/etc
/crypttab
34 rootdev
=$
(awk '$2 == "/mnt/root2" {print $1}' /mnt
/root
/root2-fstab
)
35 fstabstd
=x-systemd.device-timeout
=30s
,x-systemd.mount-timeout
=30s
36 bootdev
=$
(awk '$2 == "/mnt/boot2" {print $1}' /mnt
/root
/root2-fstab
)
39 cat >> $nr/etc
/fstab
<<EOF
40 $rootdev / btrfs $fstabstd,noatime,subvol=root_$subvol$mopts 0 0
41 $rootdev /mnt/root btrfs $fstabstd,noatime,subvolid=0$mopts 0 0
42 $bootdev /boot btrfs nofail,$fstabstd,noatime,subvol=boot_$subvol 0 0
43 $bootdev /mnt/boot btrfs nofail,$fstabstd,noatime,subvolid=0 0 0
44 tmpfs /tmp tmpfs nodev,nosuid,size=50%,mode=1777 0 0
46 awk '$2 == "/boot/efi" {print}' /etc
/fstab
>>$nr/etc
/fstab
49 while read -r mdname
; do
50 cat >> $nr/etc
/fstab
<<EOF
51 /dev/mapper/$mdname none swap nofail,$fstabstd,sw 0 0
53 done < <(awk '$3 == "/dev/urandom" {print $1}' /etc
/crypttab
)