Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active November 3, 2021 09:45
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 rstacruz/dd24b2a2be5b36bf77965060ceed2f69 to your computer and use it in GitHub Desktop.
Save rstacruz/dd24b2a2be5b36bf77965060ceed2f69 to your computer and use it in GitHub Desktop.
Arch Linux installation helper

⚠️ NB: This has project moved. For a more updated version, see: https://github.com/rstacruz/arch-install-helper


Arch installer script

A small script to make it easier to install Arch Linux on VM's.

Boot the Arch Linux installer. Get online. (for VM's - you're probably already online.)

root@archiso:~$ ping 8.8.8.8

Set up your partitions and mount things to /mnt.

lsblk
# ^ find the block devices (sda is what we want in this example)
#   NAME   MAJ:MIN SIZE   RO TYPE
#   loop0  7:0     673.1M 1  loop
#   sda    8:0     32G    0  disk

cfdisk /dev/sda
# ^ partition the disk:
#   - Set label type: `gpt`
#   - Add new partition: 1M
#   - Change type to: BIOS boot
#   - Add new partition: (remaining size)
#   - Type: Linux filesystem
#   - "Write" then "Quit"

mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt

In the Archiso, Download this file and edit it.

curl -sL https://git.io/JPEr0 -o install.sh
vim install.sh

Save it and run it.

bash install.sh
#!/usr/bin/env bash
# https://gist.github.com/rstacruz/dd24b2a2be5b36bf77965060ceed2f69
# Edit these things
export TIME_ZONE="Australia/Melbourne"
export SYSTEM_HOSTNAME="vm-arch"
# Your user
export USERNAME="rsc"
export PASSWORD="123456"
export ROOT_PASSWORD="123456"
# Locales
export LOCALES="en_US.UTF-8 UTF-8" # and "en_US ISO-8859-1"
export LANG="en_US.UTF-8"
# Packages to install
export PACKAGES="base linux linux-firmware"
# Other packages to install
PACKAGES+=" base-devel"
PACKAGES+=" vim git sudo openssh" # dev tools
PACKAGES+=" xorg" # xorg
PACKAGES+=" tig neovim tmux"
PACKAGES+=" firefox" # browser
PACKAGES+=" xfce4 ttf-inconsolata ttf-dejavu ttf-croscore" # xfce4
PACKAGES+=" lightdm lightdm-gtk-greeter" # lightdm
#PACKAGES+=" chromium"
#PACKAGES+=" fish pkgfile" # fish shell
#PACKAGES+=" gnome gnome-tweaks gdm" # gnome
#PACKAGES+=" docker docker-compose" # docker
#PACKAGES+=" networkmanager" # for laptops
#PACKAGES+=" intel-ucode" # intel processors
#PACKAGES+=" amd-ucode" # amd processors
# --------------------------------------------------------------------------------
# Ensure that there's something in /mnt
if ! findmnt /mnt &>/dev/null; then
echo "Can't continue:"
echo "Mount a drive to /mnt before running this."
exit 1
fi
# Enable parallel downloads
sed '/ParallelDownloads/s/^#//g' -o /etc/pacman.conf
# Install packages
pacstrap /mnt $PACKAGES
# Generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# Set timezone
arch-chroot /mnt sh -c "
ln -sf '/usr/share/zoneinfo/$TIME_ZONE' /etc/localtime
hwclock --systohc
"
# Locale
arch-chroot /mnt sh -c "
echo '$LOCALES' >> /etc/locale.gen
echo 'LANG=$LANG' > /etc/locale.conf
locale-gen
"
# Hostname
arch-chroot /mnt sh -c "
echo '$SYSTEM_HOSTNAME' > /etc/hostname
echo '127.0.0.1 localhost' >> /etc/hosts
echo '::1 localhost' >> /etc/hosts
echo '127.0.1.1 $SYSTEM_HOSTNAME.localdomain $SYSTEM_HOSTNAME' >> /etc/hosts
"
# Root password
arch-chroot /mnt sh -c "
(echo '$ROOT_PASSWORD'; echo '$ROOT_PASSWORD') | passwd
"
# Add user
arch-chroot /mnt sh -c "
useradd -Nm -g users -G wheel,sys,audio,input,video,network,rfkill '$USERNAME'
(echo '$PASSWORD'; echo 'PASSWORD') | passwd '$USERNAME'
"
# Sudo
arch-chroot /mnt sh -c "
echo '%wheel ALL=(ALL) NOPASSWD: ALL' | sudo EDITOR='tee -a' visudo
"
# --------------------------------------------------------------------------------
# Bootloader setup
# --------------------------------------------------------------------------------
# ===== GRUB (BIOS mode) =====
DRIVE="/dev/sda"
arch-chroot /mnt sh -c "
pacman -S --needed --noconfirm grub
grub-install '$DRIVE'
grub-mkconfig -o /boot/grub/grub.cfg
"
# --------------------------------------------------------------------------------
# Optional features:
# uncomment blocks here that you may like
# --------------------------------------------------------------------------------
# ===== DHCP for networking (recommended for VM's) =====
# Enabling this will enable the dhcpcd@<interface> service. Use
# `ip addr` to find this interface name. VMWare Player usually has
# ens33.
#
#DHCP_INTERFACE=ens33
#arch-chroot /mnt sh -c "
# pacman -S --needed --noconfirm dhcpcd
# systemctl enable 'dhcpcd@$DHCP_INTERFACE'
#"
# ===== NetworkManager (recommended for laptops) =====
#
#arch-chroot /mnt sh -c "
# pacman -S --needed --noconfirm networkmanager
# systemctl enable NetworkManager.service
# systemctl mask NetworkManager-wait-online.service
#"
# ===== Time synchronization =====
#
#arch-chroot /mnt sh -c "
# systemctl enable --now systemd-timesyncd.service
#"
# ===== Pacman customizations =====
#
#arch-chroot /mnt sh -c "
# sed -i '/Color/s/^#//g' /etc/pacman.conf
# sed -i '/VerbosePkgLists/s/^#//g' /etc/pacman.conf
# sed -i '/ParallelDownloads/s/^#//g' /etc/pacman.conf
#"
# ===== VMWare tools (open-vm-tools) =====
#
#arch-chroot /mnt sh -c "
# pacman -S --needed --noconfirm \
# xf86-video-vmware open-vm-tools
# systemctl enable vmtoolsd.service
# systemctl enable vmware-vmblock-fuse.service
#"
# ===== VirtualBox tools =====
#
#arch-chroot /mnt sh -c "
# pacman -S --needed --noconfirm \
# linux-headers virtualbox-guest-utils
# sudo systemctl enable vboxservice.service
#"
# ===== Swap file via systemd-swap =====
#
#arch-chroot /mnt sh -c "
# pacman -S --noconfirm --needed systemd-swap
# sed -i 's/swapfc_enabled=0/swapfc_enabled=1/' /etc/systemd/swap.conf
# systemctl enable systemd-swap
#"
# ===== Swap file =====
#
#SWAP_SIZE="8G"
#arch-chroot /mnt sh -c "
# fallocate -l $SWAP_SIZE /swapfile
# chmod 600 /swapfile
# mkswap /swapfile
# echo '/swapfile none swap defaults 0 0' | tee -a /etc/fstab
#"
# ===== Alternate keymap =====
# For those using dvorak or colemak.
#
#KEYMAP="dvorak"
#arch-chroot /mnt sh -c "
# echo 'KEYMAP=$KEYMAP' > /etc/vconsole.conf
#"
echo ''
echo 'Done! Type "reboot" to reboot :)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment