X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=fai%2Fconfig%2Fhooks%2Fpartition.DEFAULT;h=e3cd178e173f0970e73d50de27b656d80e07e29c;hb=a129832a849aa87163b866982c214bbdd7314a52;hp=2632da4a990c4e6685a72a5afbe656ecc49bfc9c;hpb=d0bc04c56ce310be93f95b79e6a5e0e602cbb6db;p=automated-distro-installer diff --git a/fai/config/hooks/partition.DEFAULT b/fai/config/hooks/partition.DEFAULT index 2632da4..e3cd178 100755 --- a/fai/config/hooks/partition.DEFAULT +++ b/fai/config/hooks/partition.DEFAULT @@ -8,9 +8,6 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR partition=false -# keyfiles generated like: -# head -c 2048 /dev/urandom | od | s dd of=/q/root/luks/host-demohost -luks_dir=/var/lib/fai/config/distro-install-common/luks letters=(a) @@ -38,6 +35,14 @@ for dev in ${devs[@]}; do done done +# keyfiles generated like: +# head -c 2048 /dev/urandom | od | s dd of=/q/root/luks/host-demohost +luks_dir=/var/lib/fai/config/distro-install-common/luks +if ifclass tp; then + lukspw=$(cat $luks_dir/traci) +else + lukspw=$(cat $luks_dir/ian) +fi boot_end=504 @@ -58,6 +63,17 @@ fi # 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 swap_end=$(( $(grep ^MemTotal: /proc/meminfo| awk '{print $2}') * 3/(${#letters[@]} * 2 ) / 1000 + boot_end ))MiB +create_subvols() { + cd /mnt + for x in a home root; do + btrfs subvolume list . | grep "$x$" >/dev/null || btrfs subvolume create $x + done + btrfs subvolume set-default \ + $(btrfs subvolume list . | grep 'root$' | awk '{print $2}') . + cd / + umount /mnt +} + shopt -s nullglob if $partition; then mkdir -p /tmp/fai @@ -85,8 +101,7 @@ if $partition; then yes YES | cryptsetup luksFormat /dev/$crypt $luks_dir/host-$HOSTNAME \ -c aes-cbc-essiv:sha256 -s 256 || [[ $? == 141 ]] - yes $(cat $luks_dir/traci) | \ - cryptsetup luksAddKey --key-file \ + yes "$lukspw" cryptsetup luksAddKey --key-file \ $luks_dir/host-$HOSTNAME /dev/$crypt || [[ $? == 141 ]] # this would remove the keyfile. we will do that manually later. # yes 'test' | cryptsetup luksRemoveKey /dev/... \ @@ -96,17 +111,12 @@ if $partition; then parted ${devs[0]} set 1 boot on mkfs.btrfs -f /dev/mapper/crypt_dev_$crypt mount /dev/mapper/crypt_dev_$crypt /mnt - cd /mnt - btrfs subvolume create a - btrfs subvolume create root - btrfs subvolume set-default $(btrfs subvolume list . | grep 'root$' | awk '{print $2}') . - cd / - umount /mnt + create_subvols else for dev in ${devs[@]}; do mkfs.ext4 -F ${dev}1 done - yes $(cat $luks_dir/traci) | \ + yes "$lukspw" | \ cryptsetup luksOpen /dev/$crypt crypt_dev_$crypt || [[ $? == 141 ]] sleep 1 mount -o subvolid=0 /dev/mapper/crypt_dev_$crypt /mnt @@ -116,9 +126,7 @@ else for subvol in ${s[@]}; do btrfs subvolume delete /mnt/$subvol; done btrfs subvolume set-default 0 /mnt btrfs subvolume delete /mnt/root - btrfs subvolume create /mnt/root - btrfs subvolume set-default $(btrfs subvolume list /mnt | grep 'root$' | awk '{print $2}') /mnt - umount /mnt + create_subvols fi cat > /tmp/fai/crypttab < /tmp/fai/fstab <