server-scripts/entry.sh

82 lines
1.7 KiB
Bash
Raw Normal View History

2020-01-25 16:41:16 +00:00
#!/bin/bash
2020-01-29 12:33:53 +00:00
2020-01-25 16:41:16 +00:00
function first_stage(){
2020-01-29 19:33:36 +00:00
set -e
2020-01-25 16:41:16 +00:00
echo foo first_stage
2020-01-29 20:49:39 +00:00
2020-01-29 20:22:39 +00:00
echo -n luks_password:
read -s luks_password
2020-01-29 19:41:05 +00:00
lsblk -ftpo NAME,FSTYPE,LABEL,UUID,FSAVAIL,MOUNTPOINT
2020-01-29 19:29:15 +00:00
select DEVICE in $(lsblk -frpno NAME); do
echo using $DEVICE
2020-01-29 19:32:56 +00:00
break
2020-01-29 19:29:15 +00:00
done
2020-01-29 12:37:36 +00:00
2020-01-29 20:49:39 +00:00
apt install -y debootstrap cryptsetup btrfs-progs lvm2
2020-01-29 20:51:19 +00:00
if [ -d /dev/vg0 ]; then
2020-01-29 21:02:58 +00:00
swapoff /dev/vg0/swap || true
2020-01-29 20:51:19 +00:00
vgchange -an /dev/vg0
fi
2020-01-29 20:42:06 +00:00
if [ -b /dev/mapper/cryptlvm ]; then
cryptsetup luksClose cryptlvm
fi
wipefs -a ${DEVICE}
2020-01-29 20:02:02 +00:00
(
echo o
echo n
2020-01-29 20:12:06 +00:00
echo p
echo 1
2020-01-29 20:06:12 +00:00
echo
2020-01-29 20:02:02 +00:00
echo +2G
echo n
2020-01-29 20:12:06 +00:00
echo p
echo 2
2020-01-29 20:02:02 +00:00
echo
2020-01-29 20:12:06 +00:00
echo
2020-01-29 20:02:02 +00:00
echo w
) | fdisk ${DEVICE}
2020-01-29 20:03:26 +00:00
lsblk
2020-01-29 20:02:02 +00:00
echo mkfs.ext4 ${DEVICE}1
2020-01-29 20:28:38 +00:00
yes | mkfs.ext4 ${DEVICE}1
2020-01-29 20:22:39 +00:00
(
echo $luks_password
echo $luks_password
)| cryptsetup luksFormat ${DEVICE}2
echo $luks_password | cryptsetup luksOpen ${DEVICE}2 cryptlvm
2020-01-29 20:35:15 +00:00
pvcreate /dev/mapper/cryptlvm
vgcreate vg0 /dev/mapper/cryptlvm
2020-01-29 20:43:13 +00:00
echo lvcreate /dev/vg0 --name=root --size=100G
lvcreate /dev/vg0 --name=root --size=100G
2020-01-29 21:22:36 +00:00
yes | mkfs.btrfs /dev/vg0/root
2020-01-29 20:49:39 +00:00
echo lvcreate /dev/vg0 --name=swap --size=16G
lvcreate /dev/vg0 --name=swap --size=16G
2020-01-29 20:52:15 +00:00
mkswap /dev/vg0/swap
swapon /dev/vg0/swap
2020-01-29 20:35:15 +00:00
echo mount /dev/vg0/root $TARGET
mount /dev/vg0/root $TARGET
2020-01-29 12:33:53 +00:00
echo debootstrap sid $TARGET
2020-01-29 12:38:18 +00:00
debootstrap sid $TARGET
2020-01-29 20:03:26 +00:00
mount ${DEVICE}1 $TARGET/boot
echo mount ${DEVICE}1 $TARGET/boot
2020-01-29 21:22:36 +00:00
genfstab -U $TARGET | tee $TARGET/etc/fstab
2020-01-29 21:32:34 +00:00
UUID=$(lsblk -lpo NAME,UUID | grep ${DEVICE}2 | awk '{print $1}')
echo cryptlvm UID=${UUID} none luks > $TARGET/etc/crypttab
2020-01-25 16:41:16 +00:00
}
function second_stage(){
2020-01-29 19:33:36 +00:00
set -e
2020-01-25 16:41:16 +00:00
echo bar second_stage
2020-01-29 19:29:15 +00:00
passwd
echo -n > /etc/motd
2020-01-29 20:35:15 +00:00
apt install -y linux-image-amd64 grub2 cryptsetup btrfs-progs lvm2 locales tzdata keyboard-configuration console-common
2020-01-25 16:41:16 +00:00
}
2020-01-29 21:22:36 +00:00