Skip to content

Instantly share code, notes, and snippets.

@mikilian
Created June 27, 2021 20:28
Show Gist options
  • Save mikilian/5c18cd7a7290a9676b4c2937b0d736ca to your computer and use it in GitHub Desktop.
Save mikilian/5c18cd7a7290a9676b4c2937b0d736ca to your computer and use it in GitHub Desktop.
Minimal automatic installation for arch linux on an UEFI system with full encryption using dm-crypt and luks
#!/usr/bin/env bash
SETUP_KEYMAP='de-latin1'
SETUP_DEVICE='/dev/nvme0n1'
SETUP_WIFI=''
SETUP_AMD=''
printf -- "[+] wifi support (N, y): "
read SCRIPT_INPUT
case "${SCRIPT_INPUT}" in
'y'|'Y'|'yes'|'YES')
SETUP_WIFI='y'
;;
esac
printf -- "[+] AMD cpu: (N, y): "
read SCRIPT_INPUT
case "${SCRIPT_INPUT}" in
'y'|'Y'|'yes'|'YES')
SETUP_AMD='y'
;;
esac
printf -- "[+] keymap (%s): " "${SETUP_KEYMAP}"
read SCRIPT_INPUT
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_KEYMAP="${SCRIPT_INPUT}"
fi
printf -- "[+] target device (%s): " "${SETUP_DEVICE}"
read SCRIPT_INPUT
SETUP_PARTITION_PREFIX='p'
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_DEVICE="${SCRIPT_INPUT}";
printf -- "[+] target is a m2 SSD: (Y, n): "
read SCRIPT_INPUT
case "${SCRIPT_INPUT}" in
'n'|'N'|'no'|'NO')
SETUP_PARTITION_PREFIX=''
;;
esac
fi
SETUP_PARTITION_EFI="${SETUP_DEVICE}${SETUP_PARTITION_PREFIX}1"
SETUP_PARTITION_BOOT="${SETUP_DEVICE}${SETUP_PARTITION_PREFIX}2"
SETUP_PARTITION_ROOT="${SETUP_DEVICE}${SETUP_PARTITION_PREFIX}3"
printf -- "\n[!] loading keymap for %s\n" "${SETUP_KEYMAP}"
printf -- "[!] EFI partition: %s\n" "${SETUP_PARTITION_EFI}"
printf -- "[!] boot partition: %s\n" "${SETUP_PARTITION_BOOT}"
printf -- "[!] root partition: %s\n\n" "${SETUP_PARTITION_ROOT}"
printf -- "[!] the post installation after boot requires your approvement, type 'yes' in capital letters: "
read SCRIPT_INPUT
if [ "${SCRIPT_INPUT}" != 'YES' ]; then
printf -- "[!] aborting...\n"
exit 1
fi
SETUP_PACSTRAP='base base-devel dhcpcd efibootmgr git gptfdisk grub-efi-x86_64 lvm2 linux linux-firmware zsh vim'
if ! test -z "${SETUP_AMD}"; then
SETUP_PACSTRAP+=' amd-ucode'
else
SETUP_PACSTRAP+=' intel-ucode'
fi
if ! test -z "${SETUP_WIFI}"; then
SETUP_PACSTRAP+=' dialog wireless_tools iw crda wpa_supplicant networkmanager'
fi
loadkeys "${SETUP_KEYMAP}"
cgdisk "${SETUP_DEVICE}"
mkfs.vfat -F32 "${SETUP_PARTITION_EFI}"
mkfs.ext2 "${SETUP_PARTITION_BOOT}"
cryptsetup -c aes-xts-plain64 -y --use-random luksFormat "${SETUP_PARTITION_ROOT}"
cryptsetup luksOpen "${SETUP_PARTITION_ROOT}" luks
pvcreate /dev/mapper/luks
vgcreate vg0 /dev/mapper/luks
lvcreate --size 16G vg0 --name swap
lvcreate -l +100%FREE vg0 --name root
mkfs.ext4 /dev/mapper/vg0-root
mkswap /dev/mapper/vg0-swap
mount /dev/mapper/vg0-root /mnt
swapon /dev/mapper/vg0-swap
mkdir /mnt/boot
mount /dev/nvme0n1p2 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/nvme0n1p1 /mnt/boot/efi
pacstrap /mnt "${SETUP_PACSTRAP}"
genfstab /mnt >> /mnt/etc/fstab
arch-chroot /mnt /bin/bash
#!/usr/bin/env bash
SETUP_DEVICE='/dev/nvme0n1'
SETUP_WIFI=''
SETUP_TZ='Europe/Berlin'
SETUP_HOSTNAME='arch'
SETUP_IP='127.0.0.1'
SETUP_USERNAME='michael'
printf -- "[+] wifi support (N, y): "
read SCRIPT_INPUT
case "${SCRIPT_INPUT}" in
'y'|'Y'|'yes'|'YES')
SETUP_WIFI='y'
;;
esac
printf -- "[+] zone info: (%s): " "${SETUP_TZ}"
read SCRIPT_INPUT
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_TZ="${SCRIPT_INPUT}"
fi
printf -- "[+] hostname (%s): " "${SETUP_HOSTNAME}"
read SCRIPT_INPUT
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_HOSTNAME="${SCRIPT_INPUT}"
fi
printf -- "[+] local ip (%s): " "${SETUP_IP}"
read SCRIPT_INPUT
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_IP="${SCRIPT_INPUT}"
fi
printf -- "[+] default user (%s): " "${SETUP_USERNAME}"
read SCRIPT_INPUT
if ! test -z "${SCRIPT_INPUT}"; then
SETUP_USERNAME="${SCRIPT_INPUT}"
fi
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc --utc
vim /etc/locale.gen
locale-gen
cat <<EOF > /etc/hosts
# Static table lookup for hostnames.
# See hosts(5) for details.
${SETUP_IP} localhost
::1 localhost
${SETUP_IP} ${SETUP_HOSTNAME} ${SETUP_HOSTNAME}
EOF
echo LANGUAGE=en_US.UTF-8 >> /etc/locale.conf
passwd
ln -sf /usr/bin/vim /usr/bin/vi
useradd -m -g users -G wheel -s /bin/zsh "${SETUP_USERNAME}"
passwd "${SETUP_USERNAME}"
usermod -a -G "${SETUP_USERNAME}" "${SETUP_USERNAME}"
visudo
vim /etc/mkinitcpio.conf
mkinitcpio -p linux
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ArchLinux --removable --recheck --debug
vim /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment