Skip to content

Instantly share code, notes, and snippets.

@Bouni
Last active December 4, 2019 20:42
Show Gist options
  • Save Bouni/828eb34241a8e3c9487b68e7916bf488 to your computer and use it in GitHub Desktop.
Save Bouni/828eb34241a8e3c9487b68e7916bf488 to your computer and use it in GitHub Desktop.
Arch linux install script
#
# 1. loadkeys us
# 2. passwd (set password for user root)
# 3. systemctl start sshd
# 4. ssh into system to work directly and not via VNC
# 5. wget this file
# 6. bash ./arch-install.sh
# 7. reboot
#
#/bin/bash
set -e
# ==========================================================================yy
DEVICE="/dev/sda"
HOSTNAME="archlinux"
DOMAIN="ffw"
ROOTPASS="arch"
USER="ffw"
USERPASS="arch"
REGION="Europe"
CITY="Berlin"
LOCALE="en_US.UTF-8"
LANG="LANG=en_US.UTF-8"
LANGUAGE="LANGUAGE=en_US:en"
KEYMAP="de_CH-latin1"
# ==========================================================================yy
# wipe partintion table
wipefs -a $DEVICE
# create partitions
(
echo o # Create a new empty DOS partition table
echo n # new partition
echo p # primary
echo 1 # parition 1
echo # default start
echo -2048M # all but 2038 MB
echo n # new partition
echo p # primary
echo 2 # partition 2
echo # default start
echo # default end
echo a # make partition bootable
echo 1 # partition 1
echo w # write partition table
echo q # quit
) | fdisk /dev/sda
# create filesystems
mkfs.ext4 "${DEVICE}1"
mkswap "${DEVICE}"2
swapon "${DEVICE}"2
# mount root partition
mount "${DEVICE}1" /mnt
# basic system installation
pacstrap /mnt base base-devel linux linux-firmware dhcpcd openssh neovim ansible git
# generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# set hostname
echo $HOSTNAME > /mnt/etc/hostname
# set timezone
arch-chroot /mnt ln -s -f /usr/share/zoneinfo/$REGION/$CITY > /etc/localtime
# set hwclock
arch-chroot /mnt hwclock --systohc
# activate locale for generation
sed -i "s/#$LOCALE/$LOCALE/" /mnt/etc/locale.gen
# generate locale
arch-chroot /mnt locale-gen
# set LANG
echo -e "$LANG\n$LANGUAGE" > /mnt/etc/locale.conf
# set keymap
echo -e $KEYMAP > /mnt/etc/vconsole.conf
# generate hosts file
echo -e "127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.0.1\t$HOSTNAME.$DOMAIN\t$HOSTNAME" > /mnt/etc/hosts
# install bootloader
arch-chroot /mnt pacman -Syu --noconfirm --needed grub dosfstools
arch-chroot /mnt grub-install --target=i386-pc --recheck $DEVICE
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
# set root password
printf "$ROOTPASS\n$ROOTPASS" | arch-chroot /mnt passwd
# create user
arch-chroot /mnt useradd -m -G wheel,storage,optical -s /bin/bash $USER
printf "$USERPASS\n$USERPASS" | arch-chroot /mnt passwd $USER
# allow all users of group wheel to use sudo
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers
# activate dhcpcd and sshd service
arch-chroot /mnt ln -s -f /usr/lib/systemd/system/dhcpcd.service /etc/systemd/system/multi-user.target.wants/dhcpcd.service
arch-chroot /mnt ln -s -f /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service
# exit chroot
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment