4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
6 # # fai's setup-storage won't do btrfs on luks,
7 # # so we do it ourself :)
24 ! ifclass tp || letters
=(a b
)
28 # 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
29 swap_end
=$
(( $
(grep ^MemTotal
: /proc
/meminfo|
awk '{print $2}') * 3/(${#letters[@]} * 2 ) / 1000 + boot_end
))MiB
33 for letter
in ${letters[@]}; do
36 [[ -e $dev[0-9] ]] && for x
in $dev[0-9]; do wipefs
-a $x; done
37 parted
-s $dev mklabel gpt
38 # gpt ubuntu cloud image uses ~4. fai uses 1 MiB. ehh, i'll do 4.
39 parted
-s $dev mkpart primary
"ext3" 4MB
${boot_end}MiB
40 parted
-s $dev set 1 boot on
41 parted
-s $dev mkpart primary
"linux-swap" ${boot_end}MiB
$swap_end
42 parted
-s -- $dev mkpart primary
"" $swap_end -0
43 parted
-s $dev set 3 raid on
44 parted
-s $dev mkpart primary
"" 1MiB
4MiB
45 parted
-s $dev set 4 bios_grub on
46 # the mkfs failed randomly on a vm, so I threw a sleep in here.
50 if ((${#devs[@]} > 1)); then
52 yes | mdadm
--create /dev
/$crypt --level=raid0
--force --run \
53 --raid-devices=${#devs[@]} ${devs[@]/%/3} ||
[[ $?
== 141 ]]
57 head -c 2048 /dev
/urandom |
od > /tmp
/fai
/crypt_dev_
$crypt
58 yes YES | cryptsetup luksFormat
/dev
/$crypt /tmp
/fai
/crypt_dev_
$crypt \
59 -c aes-cbc-essiv
:sha256
-s 256 ||
[[ $?
== 141 ]]
60 yes $
(cat /var
/lib
/fai
/config
/distro-install-common
/luks
/traci
) | \
61 cryptsetup luksAddKey
--key-file \
62 /tmp
/fai
/crypt_dev_
$crypt /dev
/$crypt ||
[[ $?
== 141 ]]
63 # this would remove the keyfile. we will do that manually later.
64 # yes 'test' | cryptsetup luksRemoveKey /dev/... \
65 # /key/file || [[ $? == 141 ]]
66 cryptsetup luksOpen
/dev
/$crypt crypt_dev_
$crypt --key-file \
67 /tmp
/fai
/crypt_dev_
$crypt
68 parted
${devs[0]} set 1 boot on
69 mkfs.btrfs
-f /dev
/mapper
/crypt_dev_
$crypt
70 mount
/dev
/mapper
/crypt_dev_
$crypt /mnt
72 btrfs subvolume create a
73 btrfs subvolume create root
74 btrfs subvolume set-default $
(btrfs subvolume list . |
grep 'root$' |
awk '{print $2}') .
78 /var
/lib
/fai
/config
/distro-install-common
/reset-btrfs-root
81 cat > /tmp
/fai
/crypttab
<<EOF
82 crypt_dev_$crypt /dev/$crypt none keyscript=/root/keyscript,discard,luks
85 for dev
in ${devs[@]}; do
86 cat >> /tmp
/fai
/crypttab
<<EOF
87 swap ${dev}2 /dev/urandom swap,cipher=aes-xts-plain64,size=256,hash=ripemd160
91 # this is duplicated in arch-init
92 cat > /tmp
/fai
/fstab
<<EOF
93 /dev/mapper/crypt_dev_$crypt / btrfs noatime,subvol=/root 0 0
94 /dev/mapper/crypt_dev_$crypt /a btrfs noatime,subvol=/a 0 0
95 ${devs[0]}1 /boot ext4 noatime 0 2
99 cat >/tmp
/fai
/disk_var.sh
<<EOF
100 ROOT_PARTITION=\${ROOT_PARTITION:-/dev/mapper/crypt_dev_$crypt}
101 BOOT_PARTITION=\${BOOT_PARTITION:-${devs[0]}1}
102 BOOT_DEVICE=\${BOOT_DEVICE:-"${devs[0]}"}
103 SWAPLIST=\${SWAPLIST:-"${devs[@]/%/2}"}