Convenience script for arch setup
2026-10-02
Arch isn't as hard to install as the memes might make it seem, but it still contains a bunch of steps that aren't just clicking obvious buttons. I don't install arch as often as i used to, so i also forget how exactly i did set it up. For this reason i'm making a personal script to help me set up my archlinux.
STATUS: script exists
this is now an actual script: arch-init-scripts (archiso-install.sh). notes below are the manual version of the same flow.
Starting point
Minimal requirement is a running Archiso live system conntected to the internet. Since i use my personal, customized archiso image (insert link to blog post here) i might rely on certain files being present from there.
Data gathering
- cpu type for microcode: lscpu | grep -i vendor (AuthenticAMD or GenuineIntel for now)
- Hostname
- Disk to install on
- Disk (usb stick?) to put the LUKS key on if needed
Partitioning
Not sure if the script should do this, but if it should:
-
secure erase ssd: archwiki
-
fdisk /dev/nvmeXnX (in my case it complained disk in use, i rebooted)
-
g
-
n
-
enter
-
enter
-
+2G
-
t
-
uefi
-
n
-
enter a few times
-
w
-
EFI partition: 1 gb, type "uefi" (when done manually with fdisk, parted uses other)
-
Data partition: rest of disk, type "linux" (again fdisk, idk about parted)
-
NO swap partition (we'll set up a swap file)
in my first attempt, the disk may be partitioned already. might update later if neeeded.
LUKS setup (encrypted root partition)
cryptsetup -v luksFormat /dev/"$ROOTPARTITION" cryptsetup open /dev/"$ROOTPARTITION" cryptroot
Note: this is the point where we should likely add a keyfile on any system that should be able to boot unattended (link other blogpost here)
Keyfile on USB stick
wipefs -a /dev/sdX fdisk /dev/sdX g n w mkfs.ext4 /dev/sdX1 mkdir tmpmount && mount /dev/sdX1 tmpmount tr -dc '[:alnum:]' </dev/urandom | head -c64 > tmpmount/keyfile chmod 600 tmpmount/keyfile
add it to the partition "keyslots": cryptsetup luksAddKey "$ROOTPARTITION" tmpmount/keyfile
then configure mkinitcpio so the initramfs uses it (follow archwiki at https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#With_a_keyfile_stored_on_an_external_media)
- add ext4 module in /etc/mkinitcpio.conf (or vfat if using fat, but be ready for complaints about file permissions)
- add neccessary codepages if needed, also in modules (TODO)
- kernel parameters: TODO
TODO
Filesystems
- mkfs.fat -F 32 /dev/"$EFIPARTITION"
- mkfs.ext4 /dev/mapper/cryptroot
Mounting
- mount /dev/mapper/cryptroot /mnt
- mkdir /mnt/efi
- mount /dev/"$EFIPARTITION" /mnt/efi
Note: we don't use /boot on our efi partition. using UKI for booting, we want ONLY the finished UKI image on the efi partition, anything in /boot is "trusted" input we use to build that UKI. /boot SHOULD be on our encrypted root partition in this case.
Pacstrap
pacstrap -K /mnt base linux linux-firmware "$CPU_UCODE" vim neovim openssh
Note: networking will be done by systemd-networkd and systemd-resolved, which should ship with systemd package. remember to enable the services.
- systemd-networkd also needs a config file, otherwise it won't touch any interface. /etc/systemd/network/20-wired.network:
[Match]
Name=en* eth*
[Network]
DHCP=yesFstab
genfstab -U /mnt >> /mnt/etc/fstab
Copy useful files - only if from proper archiso
cp /etc/locale.gen /mnt/etc/locale.gen cp /etc/locale.conf /mnt/etc/locale.conf cp /etc/vconsole.conf /mnt/etc/vconsole.conf
cp /etc/ssh/sshd_config /mnt/etc/ssh/sshd_config mkdir /mnt/root/.ssh chmod 700 /mnt/root/.ssh cp /root/.ssh/authorized_keys /mnt/root/.ssh
Chroot
arch-chroot /mnt
Swap file
mkswap -U clear --size 4G --file /swapfile echo "/swapfile none swap defaults 0 0" >> /etc/fstab
more setup
ln -sf /usr/share/zoneinfo/Europe/Zurich /etc/localtime hwclock --systohc locale-gen echo "$HOSTNAME" > /etc/hostname
enable services
systemctl enable systemd-timesyncd systemctl enable systemd-networkd systemctl enable systemd-resolved systemctl enable sshd
UKI
(specify in /etc/kernel/cmdline, mkinitcpio SHOULD automatically use that) rd.luks.name=UUID-of-LUKS-part=cryptroot rd.luks.key=UUID-of-LUKS-part=/keyfile:UUID=UUID-of-USB-stick-part root=/dev/mapper/cryptroot rw
- add rd.luks.options=UUID-of-LUKS-part=keyfile-timeout=10s
- WITHOUT this, booting with the stick unplugged means a 90s wait and then the emergency shell WITHOUT asking for the passphrase (the unlock service never runs at all). with it, the boot waits 10s for the stick and then prompts for the passphrase. specify the /etc/kernel/cmdline in theprofile too, be explicit: default_options="--cmdline /etc/kernel/cmdline" edit the mkinitcpio preset: uncommend uki, comment others set uki path to /efi/EFI/BOOT/BOOTx64.EFI mkdir -p /efi/EFI/BOOT (ensure efi is mounted) mkinitcpio.conf adjust hooks to add systemd sd-encrypt ensure /efi is mounted and mkinitcpio -p linux and ensure the BOOTx64.EFI gets made HOPEFULLY bios auto finds it, otherwise use efibootmgr