Add support for disk-encryption

This commit is contained in:
Fierelier 2022-09-21 11:43:59 +02:00
parent f5b41742ea
commit 5962d2f882
3 changed files with 59 additions and 2 deletions

View File

@ -58,6 +58,38 @@ while true; do
fi
done
# Ask for encryption
WDVN_ENCRYPT=""
WDVN_ENCRYPT_PASS=""
while true; do
read -p "Encrypt the disk? You will have to share a passphrase if you plan to share the computer [y,n]: " WDVN_ENCRYPT
WDVN_ENCRYPT="$(echo "$WDVN_ENCRYPT" | tr "[:upper:]" "[:lower:]")"
if [ "$WDVN_ENCRYPT" == "y" ]; then
apt -y install cryptsetup
echo ""
source /etc/default/keyboard
loadkeys us
echo "WARNING: Temporarily switching to US keyboard. Ignore this, type your password as you would on your regular keyboard."
while true; do
echo ""
read -s -p "Encryption password: " WDVN_ENCRYPT_PASS
echo ""
read -s -p "Confirm password: " WDVN_ENCRYPT_PASS_CONFIRM
echo ""
if [ "$WDVN_ENCRYPT_PASS" == "$WDVN_ENCRYPT_PASS_CONFIRM" ]; then
break
fi
echo "Passwords don't match."
done
loadkeys "$XKBLAYOUT"
break
fi
if [ "$WDVN_ENCRYPT" == "n" ]; then
break
fi
done
# Create partitions
echo "Creating partitions ..."
wipefs --all "$DEVICE"
@ -67,9 +99,16 @@ while true; do
sgdisk --hybrid=1:2:3 "$DEVICE"
PART_EFI="$(echo "${DEVICE}"*2)"
PART_DATA="$(echo "${DEVICE}"*3)"
DEV_DATA="$PART_DATA"
# Format partitions
echo "Formatting partitions ..."
if [ "$WDVN_ENCRYPT" == "y" ]; then
echo "$WDVN_ENCRYPT_PASS" | cryptsetup luksFormat --type luks1 "$PART_DATA"
echo "$WDVN_ENCRYPT_PASS" | cryptsetup luksOpen "$PART_DATA" system
PART_DATA="/dev/mapper/system"
fi
mkfs.fat -F32 "$PART_EFI"
mkfs.ext4 "$PART_DATA"
@ -91,19 +130,36 @@ while true; do
echo "Adding files ..."
unsquashfs -f -d "/media/install" "/lib/live/mount/medium/live/filesystem.squashfs"
if [ "$WDVN_ENCRYPT" == "y" ]; then
echo "GRUB_ENABLE_CRYPTODISK=y" > "/media/install/etc/default/grub.d/cryptodisk.cfg"
fi
# Set hostname
echo "Setting hostname ..."
echo "$(head -c4 </dev/urandom|xxd -p -u)" >"/media/install/etc/hostname"
# Write fstab
UUID_PART_DATA="$(blkid -o value -s UUID "$PART_DATA")"
UUID_DEV_DATA="$(blkid -o value -s UUID "$DEV_DATA")"
echo "Writing fstab ..."
echo "UUID=$(blkid -o value -s UUID "$PART_DATA") / ext4 errors=remount-ro 0 1" >>"/media/install/etc/fstab"
if [ "$WDVN_ENCRYPT" == "y" ]; then
echo "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX cryptdevice=UUID=$UUID_DEV_DATA root=UUID=$UUID_PART_DATA\"" >> "/media/install/etc/default/grub.d/cryptodisk.cfg"
fi
if [ "$WDVN_ENCRYPT" == "y" ]; then
echo "system UUID=$UUID_DEV_DATA none luks" >"media/install/etc/crypttab"
fi
echo "UUID=$UUID_PART_DATA / ext4 errors=remount-ro 0 1" >>"/media/install/etc/fstab"
echo "/swap none swap sw 0 0" >>"/media/install/etc/fstab"
# Remove live-specific packages
echo "Removing live-specific packages ..."
wdvn-chroot "/media/install" apt -y remove live-boot live-boot-initramfs-tools
wdvn-chroot "/media/install" apt -y autoremove
if [ "$WDVN_ENCRYPT" == "y" ]; then
wdvn-chroot "/media/install" apt -y install cryptsetup-initramfs
fi
wdvn-chroot "/media/install" update-initramfs -u
rm "/media/install/bin/login"
mv "/media/install/bin/login.oobe" "/media/install/bin/login"

View File

@ -0,0 +1 @@
apt install -y --download-only cryptsetup cryptsetup-initramfs

View File

@ -1,4 +1,4 @@
#!/bin/bash
export WDVN_PACKAGES="$WDVN_PACKAGES gdisk dosfstools squashfs-tools"
export WDVN_PACKAGES="$WDVN_PACKAGES gdisk dosfstools squashfs-tools console-data"
export WDVN_REMOVE="$WDVN_REMOVE dosfstools squashfs-tools"
cp "$1/bin/login" "$1/bin/login.oobe"