101 lines
2.1 KiB
Bash
Executable file
101 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
|
|
function first_stage(){
|
|
set -e
|
|
echo foo first_stage
|
|
|
|
echo -n luks_password:
|
|
read -s luks_password
|
|
|
|
lsblk -ftpo NAME,FSTYPE,LABEL,UUID,FSAVAIL,MOUNTPOINT
|
|
select DEVICE in $(lsblk -frpno NAME); do
|
|
echo using $DEVICE
|
|
break
|
|
done
|
|
|
|
apt install -y debootstrap cryptsetup btrfs-progs lvm2
|
|
|
|
if [ -d /dev/vg0 ]; then
|
|
swapoff /dev/vg0/swap || true
|
|
vgchange -an /dev/vg0
|
|
fi
|
|
|
|
if [ -b /dev/mapper/cryptlvm ]; then
|
|
cryptsetup luksClose cryptlvm
|
|
fi
|
|
|
|
wipefs -a ${DEVICE}
|
|
|
|
(
|
|
echo o
|
|
echo n
|
|
echo p
|
|
echo 1
|
|
echo
|
|
echo +2G
|
|
echo n
|
|
echo p
|
|
echo 2
|
|
echo
|
|
echo
|
|
echo w
|
|
) | fdisk ${DEVICE}
|
|
|
|
echo mkfs.ext4 ${DEVICE}1
|
|
yes | mkfs.ext4 ${DEVICE}1
|
|
|
|
(
|
|
echo $luks_password
|
|
echo $luks_password
|
|
)| cryptsetup luksFormat ${DEVICE}2
|
|
echo $luks_password | cryptsetup luksOpen ${DEVICE}2 cryptlvm
|
|
pvcreate /dev/mapper/cryptlvm
|
|
vgcreate vg0 /dev/mapper/cryptlvm
|
|
|
|
LVM_SIZE=$(dev_size /dev/mapper/cryptlvm)
|
|
|
|
SWAP_SIZE=$(($(mem_size)/1024/1024/1024))
|
|
ROOT_SIZE=$(($LVM_SIZE/1024/1024/1024-SWAP_SIZE))
|
|
|
|
echo lvcreate /dev/vg0 --name=root --size=${ROOT_SIZE}G
|
|
lvcreate /dev/vg0 --name=root --size=${ROOT_SIZE}G
|
|
yes | mkfs.btrfs /dev/vg0/root
|
|
|
|
echo lvcreate /dev/vg0 --name=swap --size=${SWAP_SIZE}G
|
|
lvcreate /dev/vg0 --name=swap --size=${SWAP_SIZE}G
|
|
mkswap /dev/vg0/swap
|
|
swapon /dev/vg0/swap
|
|
|
|
echo mount /dev/vg0/root $TARGET
|
|
mount /dev/vg0/root $TARGET
|
|
|
|
echo debootstrap sid $TARGET
|
|
debootstrap sid $TARGET
|
|
|
|
mount ${DEVICE}1 $TARGET/boot
|
|
echo mount ${DEVICE}1 $TARGET/boot
|
|
|
|
genfstab -U $TARGET | tee $TARGET/etc/fstab
|
|
UUID=$(lsblk -lpo NAME,UUID | grep ${DEVICE}2 | awk '{print $2}')
|
|
echo cryptlvm UUID=${UUID} none luks > $TARGET/etc/crypttab
|
|
}
|
|
|
|
function second_stage(){
|
|
set -e
|
|
echo bar second_stage
|
|
passwd
|
|
echo -n > /etc/motd
|
|
apt install -y linux-image-amd64 grub2 cryptsetup btrfs-progs lvm2 locales tzdata keyboard-configuration console-common
|
|
mkdir /snap
|
|
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_basesystem)
|
|
apt install -y task-mate-desktop mate-desktop-environment-extra
|
|
|
|
}
|
|
|
|
function post_install_stage(){
|
|
sleep 0.5
|
|
mount | grep target | awk '{print $3}'| sort -r | while read LINE; do
|
|
umount -l $LINE;
|
|
done
|
|
}
|