This guide shows how to set up the following software composition:
Written for a Dedicated Hetzner server with the following hardware specifications:
CPU1: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz (Cores 8)
Memory: 15973 MB
Disk /dev/sda: 3000 GB (=> 2794 GiB)
Disk /dev/sdb: 3000 GB (=> 2794 GiB)
Total capacity 5589 GiB with 2 Disks
The following symbols show in which environment the code is executed:
- π» Client
- π Hetzner Rescue System
- π» Chroot from Rescue System into Arch
- π½ Arch OS
π» :
ssh root@your_server_ip
π :
nano /autosetup
Save the following content into this file:
## Hetzner Online GmbH - installimage - config
DRIVE1 /dev/sda
DRIVE2 /dev/sdb
## SOFTWARE RAID:
## activate software RAID? < 0 | 1 >
SWRAID 1
## Choose the level for the software RAID < 0 | 1 | 10 >
SWRAIDLEVEL 1
## BOOTLOADER:
BOOTLOADER grub
## HOSTNAME:
HOSTNAME hetzner-arch-luks
#Adapt the hostname to your needs
## PARTITIONS / FILESYSTEMS:
PART /boot btrfs 512M
PART lvm vg0 all
LV vg0 swap swap swap 8G
LV vg0 root / btrfs 10G
## OPERATING SYSTEM IMAGE:
IMAGE /root/.oldroot/nfs/install/../images/archlinux-latest-64-minimal.tar.gz
π :
installimage
π :
reboot
π» :
ssh-keygen -f "$HOME/.ssh/known_hosts" -R your_server_ip
ssh root@your_server_ip
π½ :
pacman -Syyu
π½ :
pacman -S nano
π½ :
pacman -S busybox mkinitcpio-dropbear mkinitcpio-utils mkinitcpio-netconf
π½ :
cp -v ~/.ssh/authorized_keys /etc/dropbear/root_key
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
systemctl enable sshd
π½ :
rm /etc/ssh/ssh_host_*
ssh-keygen -A -m PEM
π½ :
dropbearconvert openssh dropbear /etc/ssh/ssh_host_rsa_key /etc/dropbear/dropbear_rsa_host_key
π½ :
nano /etc/mkinitcpio.conf
Old:
HOOKS=(base udev autodetect modconf block mdadm_udev lvm2 filesystems keyboard fsck)
New:
HOOKS=(base udev autodetect modconf block mdadm_udev lvm2 netconf dropbear encryptssh filesystems keyboard fsck)
Activate the rescue system https://robot.your-server.de/server
π½ :
reboot
π» :
ssh-keygen -f "$HOME/.ssh/known_hosts" -R your_server_ip
ssh root@your_server_ip
π :
vgscan -v
vgchange -a y
mount /dev/mapper/vg0-root /mnt
π :
echo 0 >/proc/sys/dev/raid/speed_limit_max
mkdir /oldroot
cp -va /mnt/. /oldroot/.
echo 200000 >/proc/sys/dev/raid/speed_limit_max
π :
umount /mnt
π :
vgremove vg0
π :
cat /proc/mdstat
π :
cryptsetup --cipher aes-xts-plain64 --key-size 256 --hash sha256 --iter-time=10000 luksFormat /dev/md1
cryptsetup luksOpen /dev/md1 cryptroot
pvcreate /dev/mapper/cryptroot
vgcreate vg0 /dev/mapper/cryptroot
lvcreate -n swap -L8G vg0
lvcreate -n root -L10G vg0
mkfs.btrfs /dev/vg0/root
mkswap /dev/vg0/swap
π :
mount /dev/vg0/root /mnt
π :
echo 0 >/proc/sys/dev/raid/speed_limit_max
cp -av /oldroot/. /mnt/.
echo 200000 >/proc/sys/dev/raid/speed_limit_max
π :
mount /dev/md0 /mnt/boot
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
chroot /mnt
π» :
echo "cryptroot /dev/md1 none luks" >> /etc/crypttab
π» :
mkinitcpio -p linux
π» :
pacman -S grub
π» :
nano /etc/default/grub
Change the following parameters:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/md1:cryptroot ip=dhcp"
GRUB_ENABLE_CRYPTODISK=y
βΉοΈ Further information.
π» :
grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda
grub-install /dev/sdb
π» π :
exit
umount /mnt/boot /mnt/proc /mnt/sys /mnt/dev
umount /mnt
sync
reboot
π» :
ssh -o UserKnownHostsFile=/dev/null root@your_server_ip
cryptroot-unlock
exit
π» :
ssh-keygen -f "$HOME/.ssh/known_hosts" -R your_server_ip
ssh root@your_server_ip
π» :
lvresize -l +100%FREE /dev/vg0/root
btrfs filesystem resize max /
π :
cryptsetup luksOpen /dev/md1 cryptroot
mount /dev/vg0/root /mnt
mount /dev/md0 /mnt/boot
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
chroot /mnt
π» π :
exit
umount /mnt/boot /mnt/proc /mnt/sys /mnt/dev
umount /mnt
sync
reboot
π» :
mkinitcpio -p linux
grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda
grub-install /dev/sdb
The code is adapted from the following guides:
- http://daemons-point.com/blog/2019/10/20/hetzner-verschluesselt/
- https://www.howtoforge.com/using-the-btrfs-filesystem-with-raid1-with-ubuntu-12.10-on-a-hetzner-server
- https://code.trafficking.agency/arch-linux-remote-unlock-root-volume-with-mdraid-and-dmcrypt.html
- https://wiki.archlinux.org/index.php/Dm-crypt/Specialties#Remote_unlocking_(hooks:_netconf,_dropbear,_tinyssh,_ppp)
- https://gist.github.com/pezz/5310082