Skip to content

Instantly share code, notes, and snippets.

@d-513
Last active October 9, 2023 18:38
Show Gist options
  • Save d-513/d2fe4009383f850fb92273332adbf02b to your computer and use it in GitHub Desktop.
Save d-513/d2fe4009383f850fb92273332adbf02b to your computer and use it in GitHub Desktop.
Arch Linux on OVH VPS

Install Arch on OVH VPS

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

!!! Remember to replace /dev/sdX with the actual drive, e.g /dev/sdb !!!

Get into recovery

Go to VPS Panel, choose Boot -> Reboot and select recovery mode. image

SSH to recovery

Check your email for the IP and Password for recovery OS.
SSH to it.

ssh root@x.x.x.x

If you get a hostkey mismatch, remove ~/.ssh/known_hosts. This happens because the recovery os uses a temporary ssh fingerprint.

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/2022.05.01/archlinux-bootstrap-2022.05.01-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

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.
OVH uses BIOS with GPT, so don't bother with EFI partition. However, you have to make bios boot like mentioned in the table at the start of the guide.

tip: remember to set the bios boot partition type to BIOS, by typing t after 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

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"/

Optional: enable pacman parrarel downloading

Save some time while downloading packages

sed 's/#ParallelDownloads/ParallelDownloads/' -i /etc/pacman.conf

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

Generate fstab:

genfstab -U /mnt >> /mnt/etc/fstab
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

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 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/' /etc/default/grub
# remove everything from GRUB_CMDLINE_LINUX_DEFAULT=, hiding logs is useless and makes debugging harder
sed 's/GRUB_CMDLINE_LINUX_DEFAULT.*/GRUB_CMDLINE_LINUX_DEFAULT=""/' -i /etc/default/grub

Install grub

grub-install --target=i386-pc /dev/sdX
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

Update

pacman -Syu

Locale

echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
locale-gen

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 root SSH

sed 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' -i /etc/ssh/sshd_config

Enable ssh at boot

systemctl enable sshd

Finish

exit
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.

Bonus: Low ram VPS: Reclaim space

Remember the bootstrap partition we made? Yeah, we don't need that anymore.

fdisk /dev/sdX

Then type d and choose partition number 2. This will remove useless partition.
Now, the tricky part: also remove partition 10. Type d, followed by 10. BUT, when it asks you, DO NOT erase the ext4 header, otherwise you will have to redo the process. Now make another partition with id 10 and fill entire drive with it. Write the changes with w and reboot. It should automatically fsck the filesystem and fix up stuff. Now the filesystem is reclaimed.

Thanks for reading this guide, If you have any problems, comment below.

image Mandatory neofetch

@Rykian
Copy link

Rykian commented Jul 10, 2022

Just in case if you're interested, I've forked your instruction for baremetal server on OVH and fixed something with the genfstab generation: https://gist.github.com/Rykian/864aedef8aa2813d4c8a7a74edfd1870

@d-513
Copy link
Author

d-513 commented Jul 11, 2022

Just in case if you're interested, I've forked your instruction for baremetal server on OVH and fixed something with the genfstab generation: https://gist.github.com/Rykian/864aedef8aa2813d4c8a7a74edfd1870

Thanks, I’ll check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment