Skip to content

Instantly share code, notes, and snippets.

@maltechx
Created March 9, 2023 19:44
Show Gist options
  • Save maltechx/7dac44ae9ce0bc4755cbac11f289eb36 to your computer and use it in GitHub Desktop.
Save maltechx/7dac44ae9ce0bc4755cbac11f289eb36 to your computer and use it in GitHub Desktop.
Personal Arch Install Script
#!/bin/bash
NVME=nvme0n1
HOSTNAME=neongruen
USERNAME=malte
read -rp "Enter your encryption passphrase: " PASSWORD
read -rp "Verify your encryption passphrase: " PASSWORD_VERIFY
if [ "$PASSWORD" != "$PASSWORD_VERIFY" ]; then
echo "Passphrases don't match"
exit 1
else
echo "Set passphrase: $PASSWORD"
fi
read -rp "Enter your account passphrase: " PASSWORD_USER
read -rp "Verify your account passphrase: " PASSWORD_USER_VERIFY
if [ "$PASSWORD_USER" != "$PASSWORD_USER_VERIFY" ]; then
echo "Passphrases don't match"
exit 1
else
echo "Set passphrase: $PASSWORD_USER"
fi
umount -R /mnt || true
cryptsetup remove /dev/mapper/root || true
blkdiscard -f /dev/$NVME
sgdisk -n 1:1M:+2G -t 1:EF00 /dev/$NVME
sgdisk -n 2:0:0 -t 2:8300 /dev/$NVME
mkfs.fat -F 32 /dev/${NVME}p1
echo "$PASSWORD" | cryptsetup -q luksFormat /dev/${NVME}p2
echo "$PASSWORD" | cryptsetup open /dev/${NVME}p2 root
mkfs.btrfs -L ROOT /dev/mapper/root
mount /dev/mapper/root /mnt
btrfs sub create /mnt/@
btrfs sub create /mnt/@home
btrfs sub create /mnt/@srv
btrfs sub create /mnt/@tmp
btrfs sub create /mnt/@pkg
btrfs sub create /mnt/@log
umount /mnt
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@ /dev/mapper/root /mnt
mkdir -p /mnt/{boot,home,srv,tmp,var/cache/pacman/pkg,var/log}
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@home /dev/mapper/root /mnt/home
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@srv /dev/mapper/root /mnt/srv
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@tmp /dev/mapper/root /mnt/tmp
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@pkg /dev/mapper/root /mnt/var/cache/pacman/pkg
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@log /dev/mapper/root /mnt/var/log
mount /dev/${NVME}p1 /mnt/boot
cat > /mnt/etc/hosts << EOL
[options]
HoldPkg = pacman glibc
Architecture = auto
Color
CheckSpace
ILoveCandy
SigLevel = Required DatabaseOptional
LocalFileSigLevel = Optional
ParallelDownloads = 10
[core]
Include = /etc/pacman.d/mirrorlist
[extra]
Include = /etc/pacman.d/mirrorlist
[community]
Include = /etc/pacman.d/mirrorlist
[multilib]
Include = /etc/pacman.d/mirrorlist
[maltech]
Server = https://repo.maltechx.de/arch/$arch
EOL
pacstrap /mnt linux linux-firmware base btrfs-progs intel-ucode efibootmgr gnome networkmanager sudo
genfstab -U /mnt >> /mnt/etc/fstab
echo "$HOSTNAME" > /mnt/etc/hostname
arch-chroot /mnt/ pacman-key --recv-keys C1EC5F6F3F04655B09C92EB865B98D1D51C5EC5C
arch-chroot /mnt/ pacman-key --lsign-key C1EC5F6F3F04655B09C92EB865B98D1D51C5EC5C
echo "de_DE.UTF-8 UTF-8" > /mnt/etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /mnt/etc/locale.gen
echo "de_DE ISO-8859-1" >> /mnt/etc/locale.gen
echo "de_DE@euro ISO-8859-15" >> /mnt/etc/locale.gen
cat > /mnt/etc/locale.conf << EOL
LANG=en_US.UTF-8
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_MONETARY=de_DE.UTF-8
LC_PAPER=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
EOL
echo KEYMAP=de-latin1 > /mnt/etc/vconsole.conf
echo FONT=lat9w-16 >> /mnt/etc/vconsole.conf
ln -sf /mnt/usr/share/zoneinfo/Europe/Berlin /mnt/etc/localtime
cat > /mnt/etc/hosts << EOL
127.0.0.1 localhost ${HOSTNAME}
::1 localhost ${HOSTNAME}
EOL
cat > /mnt/etc/mkinitcpio.conf << EOL
MODULES=(amdgpu)
BINARIES=()
FILES=()
HOOKS=(base udev autodetect keyboard keymap modconf block encrypt btrfs filesystems)
EOL
arch-chroot /mnt/ mkinitcpio -p linux
arch-chroot /mnt/ bootctl --path=/boot install
crypt_uuid=$(blkid -s UUID -o value /dev/${NVME}p2)
root_uuid=$(blkid -s UUID -o value /dev/mapper/root)
cat > /mnt/boot/loader/entries/arch.conf << EOL
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options root=UUID=${root_uuid} rw rootflags=subvol=/@ cryptdevice=UUID=${crypt_uuid}:root mem_sleep_default=deep
EOL
cat > /mnt/etc/sudoers.d/10-wheel << EOL
%wheel ALL=(ALL:ALL) ALL
EOL
arch-chroot /mnt/ useradd -m -g users -G wheel -s /bin/bash "$USERNAME"
arch-chroot /mnt/ systemctl enable gdm.service
arch-chroot /mnt/ systemctl enable NetworkManager.service
echo "$USERNAME:$PASSWORD_USER" | chpasswd -R /mnt/
umount -R /mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment