This tutorial explains how to install Arch Linux on KVM VPS. Arch Linux will be used as a server operating system, so I will only install basic component for a server and skip installing GUI stuff.
Step 1: Boot Your VPS from Arch Linux ISO
In your VPS control panel, find the virtual optical disk drive and insert Arch Linux ISO to it. Then establish a VNC connection to your VPS. You can get VNC login info from your hosting provider. After that, click boot button in the control panel to boot up your VPS.
Normally you have to press a key like F12 in the VNC window. This allows you to select which device your VPS will boot from. Select optical disk drive so your VPS will boot the Arch Linux ISO image.
The default firmware for KVM virtual machines is called SeaBIOS.
Now you are greeted by the Arch Linux boot menu. Select the first option to boot into Arch Linux live environment.
Step 2: Connect To the Internet
By default, your Arch Linux is not likely to have Internet connection.
In KVM environment, your hosting provider offers you a static IP address. The KVM VPS can establish a static ethernet connection to the KVM host and thus it can access external Internet.
First copy the example ethernet-static network profile to
cp /etc/netctl/examples/ethernet-static /etc/netctl
Then edit this file.
Change this file to the following. You may need to adjust red texts. Your KVM host IP is usually something like xx.xx.xx.1
Interface=ens3 Connection=ethernet IP=static Address=('your-vps-public-IP-address') Netmask=('255.255.255.0') Gateway=('your-kvm-host-IP') DNS=('18.104.22.168')
Save and close the file. Next, bring down the ens3 interface.
ifconfig ens3 down
Now load ethernet-static network profile.
netctl start ethernet-static
You should have Internet connection now.
ping -c6 google.com
Step 3: Create Partitions
If you want to have a MBR partition table on
/dev/sda, use this command:
parted /dev/sda mklabel msdos
This tutorial creates a GPT partition table:
parted /dev/sda mklabel gpt
Now create partitions on
If you created GPT partition table in the previous step, you need to create a
bios_grub partition of 1MiB since the default firmware for KVM virtual machine is seaBIOS which is a free and open source BIOS implementation. Later the Grub 2 boot loader will be installed inside bios_grub partition.
Make ensure that bios_grub partition starts at least 31 KiB (63 sectors) from the start of the disk because the first 63 sectors is reserved for MBR boot code. However, it will give us performance benefit if we align partitions so the bios_grub partition might start at 1MiB from the start of the disk.
Create bios_grub partition with this command:
mkpart primary 1MiB 2MiB
Set it as a bios_grub partition
set 1 biso_grub on
Then create the second partition. 100% means it will use all the following space of the disk. This tutorial use a single root partition. If you need advanced setup, you can adjust it.
mkpart primary 2MiB 100%
Exit out of parted.
Now format the second partition to ext4 file system.
mkfs -t ext4 /dev/sda2
Mount the second partition in /mnt directory.
mount /dev/sda2 /mnt
Step 4: Installing Basic Stuff
First open the mirrorlist file to choose a good mirror for your software installation.
To choose a mirror, just copy the address of your preferred mirror to the beginning of the file then save and close this file.
Now use pacstrap to install the base system onto the second partition mounted under
pacstrap -i /mnt base
After that, generate a
genfstab -U -p /mnt >> /mnt/etc/fstab
Chroot into the base system.
Find the en_US.UTF-8 UTF-8 line and remove the # sign from this line. Save this file.
/etc/locale.conf file and set
en_US.UTF-8 as the default locale.
echo LANG=en_US.UTF-8 > /etc/locale.conf export LANG=en_US.UTF-8
Set your server’s time zone. I set it to New York.
ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
The core, extra and community repository is good enough for an Arch Linux server and they are enabled by default, so normally you don’t have to configure repositories. If for any reason you have to configure it, use nano text editor to edit
After that, set a password for root user.
Install Grub and os-prober.
pacman -S grub os-prober
Install Grub boot loader to the first disk. Since we are using BIOS firmware, so the target should be i386-pc.
grub-install /dev/sda --target=i386-pc
Generate Grub boot menu.
grub-mkconfig -o /boot/grub/grub.cfg
Exit out of chroot environment.
Reboot your KVM VPS.
shutdown -r now
Step 5: Post-installation
Now your KVM VPS is rebooted, connect to it again with VNC. Login as root. Your Arch Linux once again is not connected to the Internet. So we have to create a static ethernet connection to the KVM host again. But this time, we have to make a little modification to the ethernet-static network profile.
/24 to your VPS public IP address and comment out the Netmask line. the /24 is equivalent to 255.255.255.0. You must use CIDR notation this time.
Interface=ens3 Connection=ethernet IP=static Address=('your-vps-public-IP-address/24') #Netmask=('255.255.255.0') Gateway=('your-kvm-host-IP') DNS=('22.214.171.124')
Save and close the this file. Bring down the ens3 interface.
ifconfig ens3 down
Load ethernet-static network profile.
netctl start ethernet-static
Check Internet connection now.
ping -c6 google.com
Now create a user and add it to wheel, storage, power group.
useradd -m -g users -G wheel,storage,power -s /bin/bash <username>
Set password for this user.
Install sudo utility.
pacman -S sudo
Edit /etc/suoders file.
Find this line:
# %wheel ALL=(ALL) ALL
Remove # sign and save the file. This means allow members of the wheel group to use sudo.
Install SSH server
pacman -S openssh
sudo vi /etc/ssh/sshd_config
Add these two lines at the end of this file. Adjust the username.
AllowUsers <username> PermitRootLogin no
The first line means to allow your newly created user to ssh into Arch Linux server. The second means disable root user ssh login. This is the basic requirement of server security. Save and close this file.
Start SSH server
systemctl start sshd
Enable SSH server auto-start when Arch Linux is booted up
systemctl enable sshd
Now open a SSH client on your own computer, and try to SSH into your Arch Linux server. You should be able to ssh login as the normal user and should not be able to ssh login as root user.
Once you ssh into your server, update Arch Linux.
sudo pacman -Syu
Here are some tools you may want to install. To be able to use ifconfig command, we need net-tools.
sudo pacman -S net-tools wget unzip parted htop
Enable NTP network time synchronization.
timedatectl set-ntp true
Congrats! You just installed an Arch Linux on KVM VPS. Enjoy!