A long time ago I wrote a blog post about installing Arch Linux:
I’m aware of the fact that there isn’t one definitive guide for installing it. This highly depends on your hardware, your use case for the system and for the desired software. Nevertheless I thought I update my previous article, because:
- that’s an easy topic to get back to blogging!
- I’m lazy and like to have a copy and paste script :P
Assumptions
- We install a headless server that’s accessible via DHCP/SSH
- It’s booted via BIOS mode, no UEFI
- the OS will be stored as /dev/sda
Bootstrap the base system
# clean old partition tables / filesystem information wipefs --all /dev/sda # create a fresh GPT partition table parted /dev/sda --script mklabel gpt # parted won't format partitions, you've to specify any filesystem # but the attribute will be ignore # bios boot partition parted /dev/sda --script mkpart primary ext3 2048s 4095s # /boot parted /dev/sda --script mkpart primary ext3 4096s 1953791s # rest for LVM parted /dev/sda --script mkpart primary ext3 1953792s 100% parted /dev/sda --script set 1 bios_grub on # setup LVM pvcreate /dev/sda3 vgcreate vg0 /dev/sda3 lvcreate --size 50G --name root vg0 mkfs.ext4 -v /dev/sda2 mkfs.ext4 -v /dev/mapper/vg0-root mount /dev/mapper/vg0-root /mnt mkdir /mnt/boot mount /dev/sda2 /mnt/boot # use own mirror with aur repository echo 'Server = http://mirror.virtapi.org/archlinux/$repo/os/$arch/' > /etc/pacman.d/mirrorlist # update local repository cache pacman -Syy # install base OS pacstrap /mnt base base-devel vim htop grub openssh linux-hardened linux-hardened-docs linux-hardened-headers linux linux-docs linux-firmware linux-headers linux-lts linux-lts-headers linux-lts-docs lvm2 inetutils man # generate fstab genfstab -U /mnt >> /mnt/etc/fstab
chroot into the new system
arch-chroot /mnt # setup you most favourite hostname echo myawesomebox.mylocaltld > /etc/hostname echo LANG=en_US.UTF-8 > /etc/locale.conf echo "en_US.UTF-8 UTF-8" > /etc/locale.gen locale-gen echo LANG=en_US.UTF-8 > /etc/locale.conf echo KEYMAP=de > /etc/vconsole.conf # setup a sane list of hooks sed -i 's/^HOOKS=.*/HOOKS=(base systemd keyboard sd-vconsole autodetect modconf block sd-lvm2 filesystems fsck)/' /etc/mkinitcpio.conf # you can omit the virtio* modules if this isn't a VM sed -i 's/^MODULES=.*/MODULES=(ext4 vfat usbhid hid igb virtio_balloon virtio_console virtio_scsi virtio_net virtio_pci virtio_ring virtio ne2k_pci)/' /etc/mkinitcpio.conf # regenerate initrds with all hooks + modules mkinitcpio --allpresets # start basic systemd services after first boot systemctl enable sshd systemd-networkd systemd-resolved systemd-networkd-wait-online # install grub + create grub config grub-install /dev/sda sed -i 's/quiet/quiet nomodeset/' /etc/default/grub sed -i 's/.*GRUB_DISABLE_LINUX_UUID.*/GRUB_DISABLE_LINUX_UUID=false/' /etc/default/grub echo 'GRUB_DISABLE_SUBMENU=y' >> /etc/default/grub sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=10/' /etc/default/grub grub-mkconfig -o /boot/grub/grub.cfg # setup ssh login sed -i 's/#PermitRoot.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config mkdir /root/.ssh curl https://github.com/bastelfreak.keys --silent > /root/.ssh/authorized_keys sed -i 's/^/no-port-forwarding,no-X11-forwarding,no-agent-forwarding /g' /root/.ssh/authorized_keys # change root password echo 'root:YOURNEWPASSWORD' | chpasswd # create a networkd config with DHCP dev=$(ip route show default | awk '/default/ {print $5}') mac=$(cat "/sys/class/net/${dev}/address") { echo '[Match]' echo "MACAddress=${mac}" echo '' echo '[Network]' echo 'DHCP=yes' } > /etc/systemd/network/wired.network # Add AUR repository { echo '' echo '[aur]' echo 'SigLevel = Optional TrustAll' echo 'Include = /etc/pacman.d/mirrorlist' } >> /etc/pacman.conf # Done \o/ exit umount /mnt/boot umount /mnt sync reboot
I hope that this basic setup might be useful for at least a few people. There isn’t anything special about it, but I tried to automate all the interactive parts away. You might like this for your own scripts.
Hi. Thanks a lot for the excellent information in your blog.
I’d like to clarify,why you use “ext3” filesystem in your script in 2020 ?
that’s a good question!
I think parted once had a functionality to format a filesystem. Or at least this was planned. While creating a new partition, parted expects a name for the desired filesystem. This defaults to ext3. But parted won’t actually create any filesystem. That’s why I call mkfs.ext4 later on.