Skip to content

Instantly share code, notes, and snippets.

@carterprince
Created December 26, 2023 20:41
Show Gist options
  • Save carterprince/ab24372660ac29dcc03d70196a67e7b8 to your computer and use it in GitHub Desktop.
Save carterprince/ab24372660ac29dcc03d70196a67e7b8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# configuration
HOSTNAME=desktop
TIMEZONE="America/New_York"
DISK=/dev/sda
EFI=/dev/sda1
SWAP=/dev/sda2
ROOT=/dev/sda3
# list some packages to install, AUR packages work too
NETWORKING="dhcpcd networkmanager"
UCODE="intel-ucode" # replace with amd-ucode if using AMD
MISC="neovim alacritty curl git chromium mpv nsxiv"
GNOME="gnome-shell nautilus gnome-tweaks gnome-control-center gdm xdg-user-dirs papirus-icon-theme gnome-shell-extension-dash-to-dock" # more minimal GNOME install
PACKAGES="$NETWORKING $UCODE $MISC $GNOME" # this is what will be installed
ROOT_PASSWORD=password
USER=foo
USER_PASSWORD=bar
# partition the disks
parted $DISK --script -- mklabel gpt mkpart ESP fat32 1MiB 513MiB set 1 esp on mkpart primary linux-swap 513MiB 32513MiB mkpart primary 32513MiB 100%
# this is a sane layout that should work for most purposes:
# Partition Size Type
# --------- ---- ----------------
# /dev/sda1 512M EFI System
# /dev/sda2 32G Linux swap
# /dev/sda3 Rest Linux filesystem
# format the partitions
mkfs.ext4 $ROOT
mkswap $SWAP
mkfs.fat -F 32 $EFI
# mount the partitions
mount $ROOT /mnt
mount --mkdir $EFI /mnt/boot
swapon $SWAP
# uncomment ParallelDownloads = 5 in /etc/pacman.conf
# just makes the installation a little faster
sed -i 's/#Pa/Pa/' /etc/pacman.conf
# install base system, can take a few minutes depending on your download speed
pacstrap -K /mnt base linux linux-firmware sudo base-devel
# generate /etc/fstab
genfstab -U /mnt >> /mnt/etc/fstab
# set up a chroot alias to make this part faster
alias ch='arch-chroot /mnt'
# set the timezone
ch ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
# generate /etc/adjtime
ch hwclock --systohc
# set up locale
echo 'en_US.UTF-8 UTF-8' > /mnt/etc/locale.gen
ch locale-gen
echo 'LANG=en_US.UTF-8' > /mnt/etc/locale.conf
# set the hostname, replace with your desired hostname
echo $HOSTNAME > /mnt/etc/hostname
# enable ParallelDownloads again on installed system
sed -i 's/#Pa/Pa/' /mnt/etc/pacman.conf
# set the root password, you want to change this
echo "$ROOT_PASSWORD\n$ROOT_PASSWORD" | ch passwd
# add the user, set the user password
ch useradd -m $USER
echo "$USER_PASSWORD\n$ROOT_PASSWORD" | ch passwd $USER
# add user to sudoers
mkdir -p /mnt/etc/sudoers.d
echo "$USER ALL=(ALL) NOPASSWD: ALL" | tee /mnt/etc/sudoers.d/00_$USER
# install paru
URL=$(curl -s https://api.github.com/repos/Morganamilo/paru/releases/latest | grep "x86" | cut -d : -f 2,3 | tr -d \" | tail -1 | awk '{$1=$1};1')
curl -sL $URL | sudo tee /mnt/tmp/paru.tar.zst > /dev/null
tar -xvf /mnt/tmp/paru.tar.zst paru --to-stdout > /mnt/usr/bin/paru
chmod +x /mnt/usr/bin/paru
# install some useful packages, you can really put whatever you want here
# you probably want dhcpcd for ethernet and networkmanager for wifi
ch su - $USER -c "'paru -S $PACKAGES'"
# install the bootloader
ch bootctl install
echo "title Arch Linux
linux /vmlinuz-linux
initrd intel-ucode.img
initrd /initramfs-linux.img
options root=$ROOT rw" > /mnt/boot/loader/entries/arch.conf
# recreate the initramfs image
ch mkinitcpio -P
# enable dhcpcd, needed for ethernet
ch systemctl enable dhcpcd
# enable gdm, optional
ch systemctl enable gdm
# shut the system down, be sure to remove the installation medium
poweroff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment