I recently created a simple step by step guide to get a basic Arch Linux running on a VPS. Most providers don’t provide standard Arch Linux images but a VNC console + ISO upload solution, this guide is made for such an environment, I used a VPS from Hosteurope for this.
Getting started:
You can always download the latest ISO from my own mirror. Upload it to your hosting provider, restart the VPS with it and enable VNC access.
Setup network:
VNC is always tricky. The original RFC specifies a 8 character password, not more or less, also everything is plaintext and keyboard layouts often feel random and inconsistent. We will use VNC as short as possible. The ISO will print you a fancy syslinux menu where you can choose to boot a 32bit system, 64bit, or from the first hard disk, we will choose 64bit here. The system will automatically login on TTY1 with the zsh shell. Here we setup our network:
ip a a 37.61.204.220/24 dev enp0s5
ip r a 169.255.30.1 dev enp0s5
ip r a default via 169.255.30.1
The underlying hypervisor is a bit strange and requires us to set this point to point route + gateway. Setting up a DNS resolver isn’t needed but will speed up further SSH logins (because sshd does a reverse DNS lookup for every incoming connection):
echo "nameserver 80.237.128.144" > /etc/resolv.conf
systemctl start sshd
passwd
We can now connect via ssh to the VM \o/
You can use whatever partition schema you like or stay with the default one provided by the Hoster. I won’t go into details for creating partitions here because “the correct partitioning program” and the used schema is always very opinionated. I used the following, created with parted (1 is the bios_grub partiton that is needed for grub on GPT partition tables, 2 is for / and 3 is for separate data):
sh-4.3# parted /dev/sda unit s print
Model: ATA ubuntu1404-x86_6 (scsi)
Disk /dev/sda: 9017753600s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 4095s 2048s bios_grub
2 4096s 97656831s 97652736s ext4
3 97656832s 9017753566s 8920096735s xfs
sh-4.3#
You should check the correct alignment of your partitions:
for partition in {1..3}; do
parted /dev/sda align-check optimal "$partition";
done
If everything is correct we can start formatting, mount it and install the minimal list of needed packages for a good system:
mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda3
mount /dev/sda2 /mnt
mkdir /mnt/glusterfs
mount /dev/sda3 /mnt/glusterfs
pacstrap /mnt base base-devel vim htop grub openssh
Only base is needed to get a working system (this is a group of packages), but I can’t work without vim and htop. openssh is needed to enable remote access if we boot the system the first time. base-devel (also a group) is needed on many many systems as well, so I’m also installing it.
Configuration:
A system needs a fstab file, writing this from hand is always wacky. Specifying disks by their UUID is recommended, but doing this by hand is fault-prone so people tend to refer to their block device path like /dev/sda1
. This is okay until someone adds another hard disk or changes your disk driver. Thankfully the Arch developers created a little wrapper script to create the fstab for us with UUIDs:
genfstab -U /mnt >> /mnt/etc/fstab
Now we switch into a chroot environment to configure the future hostname, language, keyboard layout and stuff like this:
arch-chroot /mnt
echo myawesomeserver.mydomain.io > /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
passwd
Almost-final step: Make it bootable and accessible:
Arch Linux doesn’t ship a default initramfs, we need to generate one. Then we can install grub + create the grub configuration file:
mkinitcpio -p linux
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
Last step: Configure the network and enable sshd:
Systemd brings the cool systemd-networkd to automatically setup your network with a unified configuration format across every Linux distribution. We paste the following content in /etc/systemd/network/wired.network
:
[Match]
Name=enp0s5
[Address]
Address=37.61.204.220
Peer=169.255.30.1/32
#Address=2A01:488:67:1000:253D:CCDC:0:1
[Network]
Gateway=169.255.30.1
Gateway=fe80::1
DNS=80.237.128.144
DNS=80.237.128.145
We can enable the needed daemon and sshd with:
systemctl enable sshd
systemctl enable systemd-networkd
(Please also check out Doing IPv6 with systemd-networkd – the correct way where I describe a better way to handle IPv6)
However there is one current issue with systemd-networkd (maybe in combination with the used hypervisor, it won’t configure the specified IPv6 address (that’s why I commented it out) but throws a syntax error (wat?!). We can create a oneshot service to configure the address after the network is up in /etc/systemd/system/ipv6.service
:
[Unit]
Description=Adds IPv6 address
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/ip -6 address add 2A01:488:67:1000:253D:CCDC:0:1/128 dev enp0s5
We can’t enable user-generated units in a chroot, so we need to do it by hand:
ln -s /etc/systemd/system/ipv6.service /etc/systemd/system/multi-user.target.wants/ipv6.service
The default sshd config doesn’t allow root login with a password, you now have three options:
- create a seperate user
- Allow password based login
- Throw your ssh key (only public part please) into /root/.ssh/authorized_keys
Then we can exit the chroot environment, unmount everything and reboot \o/
Conclusion:
It took me 13 minutes to setup everything, from booting the ISO to the reboot. This can even be automated by a little bash script. My fellow Bluewind provided me a little script that automates the installation. The ISO can fetch and execute a script if you provide it on the kernel cmdline, this is useful if you want to completely automate the setup and boot the ISO via PXE.