2020-12-09 12:09:15 +01:00
#!/usr/bin/env bash
set -o xtrace
set -o nounset
set -o errexit
2024-04-22 16:28:45 +02:00
DEVICE = "/dev/sda"
2020-12-09 12:09:15 +01:00
if [ [ ! -b " ${ DEVICE } " ] ] ; then
2024-05-27 12:36:34 +02:00
printf '%s does not look like a device\n' " ${ DEVICE } "
2020-12-09 12:09:15 +01:00
exit 1
fi
if [ [ ! -d /sys/firmware/efi/efivars ] ] ; then
2024-05-27 12:36:34 +02:00
printf 'efivars does not exist, looks like the system is not booted in EFI mode\n'
2020-12-09 12:09:15 +01:00
exit 1
fi
loadkeys de-latin1
timedatectl set-ntp true
sed -e 's/\s*\([^#]*\).*/\1/' << EOF | sfdisk ${DE VICE}
label: gpt
device: ${ DEVICE }
${ DEVICE } 1 : name = uefi , size = 512M , type = uefi
2020-12-14 12:11:12 +01:00
${ DEVICE } 2 : name = boot , size = 512M , type = linux
2020-12-09 12:09:15 +01:00
${ DEVICE } 3 : name = cryptpart , type = linux
EOF
# might take a bit for the new partion table to be updated in-kernel
sleep 1
2024-05-11 13:36:06 +02:00
while : ; do
cryptsetup --batch-mode luksFormat --iter-time 1000 ${ DEVICE } 3
cryptsetup --batch-mode open --tries 1 ${ DEVICE } 3 cryptpart && break
done
2020-12-09 12:09:15 +01:00
pvcreate /dev/mapper/cryptpart
vgcreate vgbase /dev/mapper/cryptpart
lvcreate -L 16G vgbase -n swap
lvcreate -l 100%FREE vgbase -n root
yes | mkfs.fat -F32 ${ DEVICE } 1
yes | mkfs.ext4 ${ DEVICE } 2
yes | mkfs.ext4 /dev/vgbase/swap
yes | mkfs.ext4 /dev/vgbase/root
mount /dev/vgbase/root /mnt
mkdir /mnt/efi
mount ${ DEVICE } 1 /mnt/efi
mkdir /mnt/boot
mount ${ DEVICE } 2 /mnt/boot
mkswap /dev/vgbase/swap
swapon /dev/vgbase/swap
2020-12-14 12:12:05 +01:00
pacstrap /mnt base linux-zen linux-firmware networkmanager amd-ucode lvm2 grub efibootmgr
2020-12-09 12:09:15 +01:00
genfstab -U /mnt >> /mnt/etc/fstab
cat << CHROOTSC RIPT > /mnt/chroot-script.sh
set -o xtrace
set -o errexit
set -o nounset
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc
sed -i 's/^#de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen
sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
printf 'LANG=en_US.UTF-8\n' > /etc/locale.conf
printf 'KEYMAP=de-latin1\nFONT=lat2-16\n' > /etc/vconsole.conf
printf 'ares\n' > /etc/hostname
cat <<EOF > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 ares
EOF
2025-10-21 10:24:22 +02:00
sed -i 's/^HOOKS=.*$/HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems resume fsck)/' /etc/mkinitcpio.conf
2020-12-09 12:09:15 +01:00
mkinitcpio -P
grub-install --target= x86_64-efi --efi-directory= /efi --bootloader-id= GRUB
sed -i " s/^GRUB_CMDLINE_LINUX=.* $/GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=\$(blkid -s UUID -o value ${ DEVICE } 3):cryptpart root=UUID=\$(blkid -s UUID -o value /dev/vgbase/root)\"/ " /etc/default/grub
sed -i " s/^GRUB_CMDLINE_LINUX_DEFAULT=.* $/GRUB_CMDLINE_LINUX_DEFAULT=\"resume=UUID=\$(blkid -s UUID -o value /dev/vgbase/swap)\"/ " /etc/default/grub
sed -i 's/^GRUB_DISABLE_RECOVERY=.*$/GRUB_DISABLE_RECOVERY=/' /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
systemctl enable NetworkManager
passwd
2024-04-22 16:28:45 +02:00
# enable root autologin on first boot
mkdir /etc/systemd/system/getty@tty1.service.d/
cat << EOF > /etc/systemd/system/getty@tty1.service.d/autologin.conf
[ Service]
ExecStart =
ExecStart = -/sbin/agetty -o '-p -f -- \\u' --noclear --autologin root %I $TERM
EOF
# ExecStartPost=/bin/rm /etc/systemd/system/getty@tty1.service.d/autologin.conf
# ExecStartPost=/bin/rmdir /etc/systemd/system/getty@tty1.service.d/
# Run
cat << 'EOF' > /root/.bash_profile
if [ [ "\$(tty)" = = "/dev/tty1" ] ] ; then
2024-05-11 13:46:30 +02:00
while ! ping -w 3 -c 3 8.8.8.8 ; do
nmtui
sleep 5
done
2024-04-22 16:28:45 +02:00
rm -rf /etc/systemd/system/getty@tty1.service.d/
if /var/lib/dotfiles/install.sh ; then
rm -f /root/.bash_profile
reboot
fi
fi
EOF
2020-12-09 12:09:15 +01:00
CHROOTSCRIPT
chmod +x /mnt/chroot-script.sh
arch-chroot /mnt /chroot-script.sh
rm -f /mnt/chroot-script.sh