Install Archlinux on low memory VPS

Installing Archlinux on low-memory VPS

Premise: Your VPS is less than or equal to 1.5G memory, and the hard disk is not less than 10G. And it does not support ISO external boot, you can refer to this article

It may be more appropriate to refer to this article for some obsessive-compulsive disorder users. After all, we all know how disgusting Ubuntu is (probably.

If you don’t want to repartition, you can go directly to the following link and use the automated script to switch to Archlinux, it only takes a few minutes

vps2arch

Then those who want to partition and install a new one can refer to this article (it is more suitable for those who can install Archlinux and use it

Some VPSs do not support ISO booting, and you can only use the official chip function to switch systems. For example, Alibaba Cloud does not provide the installation option of Archlinux (do you think it is too troublesome?
However, if you have a small memory machine, you cannot use Netboot to install it (the memory overflows directly.

Through the official documentation, there is a manual for Installing Arch Linux from an existing Linux distribution, and the implementation principle of the script provided above is the same as this one. But not for partition + reinstall case.

Here you can use the Ubuntu/Debian installation environment to install, and the installation environment itself is loaded into the memory without occupying the hard disk and can be operated directly. will not be affected.

Step 1: Download the Ubuntu Netboot environment in the VPS and boot it

This address is also officially provided, but it is not easy to find.
The save location can be saved to the root directory for easy finding. Here it is saved to the root directory and the file name is mini.iso

##Download the file and save it to the root directory
wget https://mirrors.cqu.edu.cn/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso -o /mini.iso

After the download is complete, you need to manually set the Grub countdown to -1, so that it is convenient to manually switch to the Grub command line mode. Of course, you can also manually write the startup item into it, but it feels more troublesome, so there is no need for this

##Edit /etc/default/grub.cfg with nano
nano /etc/default/grub.cfg
## Press Enter to find "Timeout" and change this value to -1
##You can refer to the following figure 1 to find the specified location
##Update the boot configuration file after the modification is complete
grub-mkconfig -o /boot/grub/grub.cfg
## Wait for completion and reboot
reboot

Restart will be stuck at the place where the startup item is selected, press c on the keyboard to enter the edit mode, and enter the following command

#load iso file
loopback loop /mini.iso
##If the prompt is not found, you can use the following method
##loopback (linux root partition number)/mini.iso
## For example loopback (hd0,msdos2)/mini.iso
#Load linux kernel related and start
linux (loop)/linux
initrd (loop)/initrd.gz
boot

After pressing Enter, the Ubuntu installation environment will be loaded
(Wrong? Why is it an Ubuntu environment, isn’t it necessary to install Archlinux?
(This is just using the Ubuntu environment, read it slowly

Step 2: Partition

Here you need to partition first, and then switch
After reaching the installation environment, this page will appear

Here is the next step, when you reach Choose a mirror of the Ubuntu Archive, choose the mirror source closest to you, you can also press Enter, but it will be very slow and not worth it
After that, you will be asked to set up an account, and you can set it up at will (anyway, it’s just a step-by-step procedure that doesn’t need to be set up, and it won’t be installed in Archlinux
Then it will reach the partition process (Partition disks), don’t press Enter here, but press esc twice to return to the main options page.
The above steps to the partition page are expected to take 3-5 minutes
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-

After returning to the main page, select the Execute a Shell option and press Enter, and then press Enter again to enter the shell page

After entering, enter fdisk space -l and press Enter to view the partition structure, usually /dev/sda or /dev/vda

After that, you need to partition. You can refer to my steps and methods, or you can Bing yourself

I believe that there is no good person who will not set the swap partition on the low-memory machine, but it must be set here, otherwise the later installation will directly crash (the memory is not enough

enter partition
fdisk /dev/vda

delete partition multiple times
Enter d and press Enter to return to command and repeat it several times until “No partition is defined yet!” appears

New partition
Create three new partitions, one for Boot, one for root and one for Swap
Enter n and press Enter four times to set the size and repeat multiple times

After the creation is complete, enter w and press Enter

The partition needs to be formatted after completion! ! !
In this tutorial, the boot partition uses FAT32 and the root partition is ext4

#Format boot partition
mkfs.fat -F 32 /dev/vda1
# format the root partition
mkfs.ext4 /dev/vda2
#Format swap partition and enable
mkswap /dev/vda3
swapon /dev/vda3

Step 3: Initialize the Arch installation environment

After the partition is completed, the installation environment needs to be initialized first. Otherwise, how can you install Archlinux directly in the Debian system?

#1. Switch to tmp and download the official bootstrap image
cd /tmp
wget http://mirrors.cqu.edu.cn/archlinux/iso/2023.04.01/archlinux-bootstrap-x86_64.tar.gz
#2. Unzip
tar xzf archlinux-bootstrap-x86_64.tar.gz
##If you did not enable swap before, there will be a splash screen during the decompression process, and you will fall back to the installation environment and many other situations. In this case, it is recommended that you re-partition and enable swap or just give up
#3. Arch environment initialization
##1. Create a shm folder, specifically for Baidu. It is needed here, otherwise the installation error will be reported later
mkdir /dev/shm
mkdir /tmp/root.x86_64/run/shm
##2. Modify the image source
nano /tmp/root.x86_64/etc/pacman.d/mirrorlist
### Add a "Server = https://mirrors.cqu.edu.cn/archlinux/$repo/os/$arch" and save
##3. Mount various required mount points
mount --bind /tmp/root.x86_64 /tmp/root.x86_64
cd /tmp/root.x86_64
cp /etc/resolv.conf etc
mount -t proc /proc proc
mount --make-rslave --rbind /sys sys
mount --make-rslave --rbind /dev dev
mount --make-rslave --rbind /run run
chroot /tmp/root.x86_64 /bin/bash

It will look like this when finished

But the initialization is not finished yet, you need to update the mirror source and mount point

#1. Create a new pacman keyring
pacman-key --init
pacman-key --populate archlinux
#2. Update pacman
pacman-Syy

After that is the normal installation steps, you can refer to the official archlinux installation documentation to start from the mount partition