Install Arch on OVH Baremetal server
This guide will show you how to install Arch Linux on an OVH VPS.
As you may have noticed, OVH does not have an Arch image, which is a problem. Follow these instructions to install Arch using recovery mode.
Conventions
Assume anything reffered to as low ram vps in the guide to be a VPS with <8gb ram
This guide assumes the following:
- Your VPS has one drive
- The following partition layout is used:
| PARTITION | DEVICE | TYPE |
|---|---|---|
| Boot | /dev/sdX1 | BIOS Boot (4) |
| Bootstrap (only low ram vps) | /dev/sdX2 | Linux Filesystem (ext4) |
| Root | /dev/sdX10 | Linux Filesystem (ext4) |
Please follow these instructions carefully. Make sure you understand arch installation and don't blindly copy paste commands. Ignore bootstrap partition if your VPS can fit an arch bootstrap image on tmpfs, which makes it a lot simpler. Assume if your VPS has <8gb ram you need a bootstrap partition
Download arch bootstrap image
You need to download arch bootstrap image to be able to do anything.
tip: change the date to last iso date. see last one at https://mirror.rackspace.com/archlinux/iso/latest/
cd /tmp wget https://mirror.rackspace.com/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.gz
tip: the gzipped image itself will fit on tmpfs even on starter vps, so you dont need to do anything special here if you have a smaller vps, but you will have to later
tip: you can use another mirror closer to you, I chose rackspace because it's a global CDN. https://archlinux.org/download/
Wipe the drive
Легше, та набагато швидше це робити з
cfdisk
list drives: fdisk -l
tip: choose the biggest drive. The 1GB drive will be the recovery livecd, which we don't want to overwrite.
wipe drive: wipefs -a /dev/sdX
Paritioning
tip: it doesn't make sense to use other partition types than ext4 here really, because OVH likely has RAID on their servers and most features of the other filesystems wont be useful in a virtualized environment
fdisk /dev/sdX
Parition the drive like you would normally. Refer to Archwiki install guide for partitioning tips.
Use GPT disklabel.
tip: remember to set the bios boot partition type to BIOS, by typing
tafter you make the partition tip: bios partition should be 1mb or more, for safety I made it 500mb
Paritioning: 8gb VPS
Create a Linux filesystem partition spanning the whole drive.
Partitioning: Low ram VPS
This will be tricky, as we need to get the bootstrap image loaded on the drive before we extract it.
For this, create your main partition, which will span the entire drive, minus 6 gigabyes.
To make this easier, just say -6G when fdisk asks you for the last sector
Now you need to make another partition, which will span the 6 gigabytes you left free for bootstrap image. Don't worry, you will be able to reclaim the space later. For this, I recommend just selecting fdisk defeaults as it will pick the last sector correctly.
Make ext4 labels:
mkfs.ext4 /dev/sdX10
# Only if using low-ram vps:
mkfs.ext4 /dev/sdX2
Extract bootstrap
8gb VPS
mkdir /bootstrap
mount -t tmpfs tmpfs /bootstrap
Low ram VPS
mkdir /bootstrap
mount /dev/sdX2 /bootstrap
Extracting
cd /bootstrap
tar xzf /tmp/archlinux-bootstrap-x86_64.tar.gz --numeric-owner
mv root.x86_64/* .
rmdir root.x86_64
Mount system
mount /dev/sdX10 /bootstrap/mnt
mkdir /bootstrap/mnt/boot
mount /dev/sdX11 /bootstrap/mnt/boot
Enable a mirror in the bootstrap system
Bootstrap system is very barebones, so we have to do this before chrooting.
# uncomment a mirror, e.g the rackspace one
sed -e /etc/pacman.d/mirrorlist 's/"#Server = https:\/\/mirror.rackspace.com"/"Server = https:\/\/mirror.rackspace.com"/
Chroot to bootstrap
/bootstrap/bin/arch-chroot /bootstrap
Initialize pacman cache
pacman-key --init
pacman-key --populate archlinux
tip: this can take a while because of entropy generation.
Pacstrap base system
pacstrap /mnt base linux-lts linux-firmware openssh grub
tip: you can use another kernel, linux-lts is optimal for servers though as you won't make use of new features in a virtual environment anyways
Generate fstab:
genfstab -U /mnt >> /mnt/etc/fstab
Now exit your bootstrap chroot:
exit
Chroot to newly installed system
/bootstrap/bin/arch-chroot /bootstrap/mnt/
Install bootloader
Optional: Configure grub
default config is fine, but you can make it better.
# change GRUB_TIMEOUT= to a lower value for faster boot
sed -e /etc/default/grub 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/'
# remove everything from GRUB_CMDLINE_LINUX_DEFAULT=, hiding logs is useless and makes debugging harder
sed -e /etc/default/grub 's/GRUB_CMDLINE_LINUX_DEFAULT.*/GRUB_CMDLINE_LINUX_DEFAULT=""/'
Install grub
pacman -S efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
Install grub for no efi
grub-install --target=i386-pc /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
Post-Installation
Your Arch is ready by now. But you should do some post-config steps to make it work better
tip: if you lock youself out of the VPs, use the KVM option on the OVH panel to debug
Network
systemctl enable systemd-networkd
cat << EOF > /etc/systemd/network/20-ovh.network
[Match]
Name=en*
[Network]
DHCP=true
EOF
echo "nameserver 1.1.1.1" > /etc/resolv.conf
my version
First copy the example ethernet-static network profile to /etc/netctl/ directory.
cp /etc/netctl/examples/ethernet-static /etc/netctl
Then edit this file.
vim /etc/netctl/ethernet-static
Change this file to the following. You may need to adjust red texts.
Description='A basic static ethernet connection'
Interface=enp1s0
Connection=ethernet
IP=static
Address=('173.242.56.133/20')
Gateway='173.242.48.1'
DNS=('8.8.8.8')
Save and close the file. Next, bring down the ens3 interface.
ip link set dev ens3 down
Now load ethernet-static network profile.
netctl start ethernet-static
You should have Internet connection now.
Update
pacman -Syu
Locale
Uncomment the encoding for English in the relevant file (you would edit locale.gen):
vim /etc/locale.gen
Uncomment the line for en_US.UTF-8.
After this, save the changes and exit nano, then generate the locales:
locale-gen
To enable the English language, execute:
echo "LANG=en_US.UTF-8" > /etc/locale.conf
time
Set up the system clock. For example:
ln -sf /usr/share/zoneinfo/Europe/Nicosia /etc/localtime
The region is set. Now synchronize the hardware clock:
hwclock --systohc
Generate Mirrorlist
pacman -S reflector
reflector --latest 20 --sort rate --save /etc/pacman.d/mirrorlist
This will take a while depending on VPS network speed, as it should test and choose the fastest mirror.
Hostname
echo "archvps" > /etc/hostname
Build the initramfs
mkinitcpio -P
Set root password
passwd
Enable ssh at boot
systemctl enable sshd
Add new user
useradd -m -g users -G wheel,storage,power -s /bin/bash <username>
pacman -S sudo
Edit sudoer file.
Finish
exit
umount /bootstrap/mnt/boot
umount /bootstrap/mnt
umount /bootstrap
exit
Done!
Now go to ovh panel and reboot the VPS. It should boot right into Arch.
If you can't ssh to it, connect using KVM in the OVH panel and debug the issue.