2017-12-18 15:45:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-07-09 15:14:44 +02:00
|
|
|
# Based on
|
|
|
|
# https://wiki.alpinelinux.org/wiki/LVM_on_LUKS
|
|
|
|
|
|
|
|
# Prerequisites for this script
|
2017-12-18 15:45:17 +01:00
|
|
|
# setup-interfaces
|
|
|
|
# ifup eth0
|
|
|
|
|
|
|
|
# Set up repositories
|
|
|
|
cat <<EOF >/etc/apk/repositories
|
2018-07-09 15:14:44 +02:00
|
|
|
http://dl-cdn.alpinelinux.org/alpine/v3.8/main
|
|
|
|
http://dl-cdn.alpinelinux.org/alpine/v3.8/community
|
2017-12-28 09:45:21 +01:00
|
|
|
#http://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
|
|
#http://dl-cdn.alpinelinux.org/alpine/edge/community
|
|
|
|
#http://dl-cdn.alpinelinux.org/alpine/edge/testing
|
2017-12-18 15:45:17 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Install disk management tools
|
|
|
|
apk --no-cache add lvm2 cryptsetup e2fsprogs syslinux
|
|
|
|
|
|
|
|
# Create disk partitions
|
|
|
|
cat <<EOF | fdisk /dev/sda
|
|
|
|
n
|
|
|
|
p
|
|
|
|
1
|
|
|
|
|
|
|
|
+100m
|
|
|
|
a
|
|
|
|
1
|
|
|
|
n
|
|
|
|
p
|
|
|
|
2
|
|
|
|
|
|
|
|
|
|
|
|
t
|
|
|
|
2
|
|
|
|
8e
|
|
|
|
w
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Set up partition encryption
|
|
|
|
echo -n 'password' | cryptsetup -q luksFormat /dev/sda2
|
|
|
|
echo -n 'password' | cryptsetup open --type luks /dev/sda2 system
|
|
|
|
|
|
|
|
# Set up LVM
|
|
|
|
pvcreate /dev/mapper/system
|
|
|
|
vgcreate vg0 /dev/mapper/system
|
|
|
|
lvcreate -l 100%FREE vg0 -n root
|
|
|
|
|
|
|
|
# Format
|
|
|
|
mkfs.ext4 -m0 /dev/sda1
|
|
|
|
mkfs.ext4 -m1 /dev/vg0/root
|
|
|
|
|
|
|
|
# Mount
|
|
|
|
mount -t ext4 /dev/vg0/root /mnt
|
|
|
|
mkdir /mnt/boot
|
|
|
|
mount -t ext4 /dev/sda1 /mnt/boot
|
|
|
|
|
|
|
|
# Install Alpine linux
|
|
|
|
setup-disk -m sys /mnt
|
|
|
|
|
|
|
|
# Update boot-time volume information
|
2018-07-09 15:14:44 +02:00
|
|
|
BOOT_UUID=$(blkid /dev/sda1 | cut -d' ' -f2 | tr -d '"')
|
2017-12-18 15:45:17 +01:00
|
|
|
cat <<EOF >/mnt/etc/fstab
|
2018-07-15 19:02:40 +02:00
|
|
|
/dev/vg0/root / ext4 rw,noatime,data=ordered 0 1
|
|
|
|
${BOOT_UUID} /boot ext4 rw,noatime,data=ordered 0 2
|
|
|
|
/dev/vg0/swap swap swap defaults 0 0
|
2017-12-18 15:45:17 +01:00
|
|
|
EOF
|
|
|
|
echo "system /dev/sda2 none luks" >/mnt/etc/crypttab
|
|
|
|
|
|
|
|
# Rebuild initfs
|
|
|
|
sed -i 's/lvm/lvm cryptsetup/' /mnt/etc/mkinitfs/mkinitfs.conf
|
|
|
|
mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt $(ls /mnt/lib/modules)
|
|
|
|
|
2018-07-09 15:14:44 +02:00
|
|
|
# Update extlinux (ignore the errors)
|
2017-12-18 15:45:17 +01:00
|
|
|
sed -i 's/rootfstype=ext4/rootfstype=ext4 cryptroot=\/dev\/sda2 cryptdm=system/' /mnt/etc/update-extlinux.conf
|
|
|
|
chroot /mnt update-extlinux
|
|
|
|
|
|
|
|
# Set time zone
|
|
|
|
chroot /mnt setup-timezone -z Europe/Prague
|
|
|
|
|
|
|
|
# Set hostname
|
2018-09-03 17:24:48 +02:00
|
|
|
echo 'spotter.vm' >/mnt/etc/hostname
|
2018-09-04 21:42:26 +02:00
|
|
|
echo -e '127.0.0.1 localhost\n::1 localhost' >/mnt/etc/hosts
|
2018-03-25 22:47:19 +02:00
|
|
|
sed -i '/hostname/d' /mnt/etc/network/interfaces
|
2017-12-18 15:45:17 +01:00
|
|
|
|
|
|
|
# Enable services on boot
|
|
|
|
ln -s /etc/init.d/networking /mnt/etc/runlevels/boot
|
|
|
|
ln -s /etc/init.d/urandom /mnt/etc/runlevels/boot
|
|
|
|
|
|
|
|
# Install bootloader to MBR
|
|
|
|
dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda
|
|
|
|
|
|
|
|
# Unmount and shut down
|
|
|
|
umount /mnt/boot
|
|
|
|
umount /mnt
|
|
|
|
vgchange -a n
|
|
|
|
cryptsetup luksClose system
|
|
|
|
poweroff
|