Skip to content

Instantly share code, notes, and snippets.

@Darksecond
Last active May 17, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darksecond/46ef19fb93dd7e515f99c3a45f260f5e to your computer and use it in GitHub Desktop.
Save Darksecond/46ef19fb93dd7e515f99c3a45f260f5e to your computer and use it in GitHub Desktop.
Arch installer
#!/bin/bash
DRIVE=/dev/xvda
MOUNT_OPTS=defaults,x-mount.mkdir,compress=lzo,ssd,noatime
# Set up partitions
sgdisk --clear \
--new=1:0:+512MiB --typecode=1:ef00 --change-name=1:EFI \
--new=2:0:0 --typecode=2:8300 --change-name=2:system \
$DRIVE
# Wait until labels are available
sleep 5
mkfs.fat -F32 -n EFI /dev/disk/by-partlabel/EFI
mkfs.btrfs --force --label system /dev/disk/by-partlabel/system
# Set up subvolumes
mount -t btrfs LABEL=system /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/snapshots
umount -R /mnt
# Mount
mount -t btrfs -o subvol=root,$MOUNT_OPTS LABEL=system /mnt
mount -t btrfs -o subvol=home,$MOUNT_OPTS LABEL=system /mnt/home
mount -t btrfs -o subvol=snapshots,$MOUNT_OPTS LABEL=system /mnt/.snapshots
mkdir /mnt/boot
mount LABEL=EFI /mnt/boot
# Install
pacstrap /mnt base linux linux-firmware vim
genfstab -L -p /mnt >> /mnt/etc/fstab
# Generate locale
arch-chroot /mnt <<EOF
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
EOF
# Run systemd-firstboot
systemd-firstboot \
--welcome=no \
--force \
--root=/mnt \
--locale=en_US.UTF-8 \
--timezone=Europe/Oslo \
--prompt-hostname \
--prompt-root-password
# Enable ntp
arch-chroot /mnt <<EOF
timedatectl set-ntp true
EOF
# Set up bootloader
arch-chroot /mnt <<EOF
bootctl install
EOF
cat <<EOF > /mnt/boot/loader/loader.conf
default arch.conf
EOF
cat <<EOF > /mnt/boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root="LABEL=system" rootflags=subvol=root
EOF
# Set up networking
arch-chroot /mnt <<EOF
systemctl enable systemd-networkd
systemctl enable systemd-resolved
EOF
rm /mnt/etc/resolve.conf
ln -sf /run/systemd/resolve/stub-resolv.conf /mnt/etc/resolv.conf
cat <<EOF > /mnt/etc/systemd/network/wired.network
[Match]
Name=eth0
[Network]
DHCP=yes
EOF
# Cleanup
umount -R /mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment