mithlond-public/OKF/guides/01-arch-install.md
Lukasz Boryn c12604ebb4 feat(template): publish the Mithlond self-hosted Gitea template
A spare-machine Gitea forge, hardened, backed up and with CI, as a template.
Personal values are placeholders listed in the README.
2026-10-16 15:04:18 +02:00

212 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
type: Guide
purpose: Install headless Arch Linux on an old laptop or mini PC from a live USB.
answers:
- "How is the base OS installed on the server?"
---
# 01 — Arch Linux Install
Headless Arch Linux on BIOS-based hardware (an old laptop works well). No desktop environment. Ethernet recommended during install.
## Prerequisites
- USB drive ≥ 1GB
- Arch Linux ISO: https://archlinux.org/download/
- Tool to write ISO: `dd` on Linux/macOS, Rufus or Etcher on Windows
- Ethernet cable connected to router
## 1. Write bootable USB
```bash
# Linux/macOS — replace /dev/sdX with your USB device
dd if=archlinux-*.iso of=/dev/sdX bs=4M status=progress oflag=sync
```
## 2. Boot from USB
Enter BIOS (usually F2, F12 or Del, depending on the vendor). Set USB as first boot device. Save and reboot.
## 3. Verify internet and clock
```bash
ping -c 3 archlinux.org
```
If no connection: `ip link` to find interface name, then `dhcpcd <interface>`.
Sync the clock. An old laptop very likely has a dead CMOS battery, so the clock
resets to its factory date on every power-off. A wrong clock makes `pacstrap` fail with GPG
signature errors that look like a broken mirror.
```bash
timedatectl set-ntp true
sleep 10
timedatectl # confirm the date is correct and "System clock synchronized: yes"
```
## 4. Partition disk
Find the disk name. **Do not assume `/dev/sda`** — with the installer USB
plugged in, the USB stick itself is often `/dev/sda` and the internal drive is
`/dev/sdb`. Partitioning the wrong one destroys the installer mid-install.
```bash
lsblk -o NAME,SIZE,MODEL,TRAN
```
Pick the device with `TRAN=sata` — the internal laptop HDD (~120–320GB). Never
the `TRAN=usb` device (the ~57.7G Kingston DataTraveler installer).
Store it once so the rest of this section can't pick the wrong disk:
```bash
DISK=/dev/sdX # replace sdX with the TRAN=sata device
lsblk "$DISK" # verify: correct size, no usb model name
```
Partition with fdisk (MBR layout for BIOS hardware):
```bash
fdisk "$DISK"
```
Inside fdisk:
```
o # new MBR partition table
n # new partition
p # primary
1 # partition 1
<enter> # default start
+512M # 512MB for /boot
n # new partition
p # primary
2 # partition 2
<enter> # default start
+2G # 2GB swap
n # new partition
p # primary
3 # partition 3
<enter> # default start
<enter> # rest of disk for /
t # change type
2 # select partition 2
82 # Linux swap
w # write and exit
```
## 5. Format partitions
```bash
mkfs.ext4 "${DISK}1" # /boot
mkswap "${DISK}2"
swapon "${DISK}2"
mkfs.ext4 "${DISK}3" # /
```
## 6. Mount
```bash
mount "${DISK}3" /mnt
mkdir /mnt/boot
mount "${DISK}1" /mnt/boot
```
## 7. Install base system
```bash
pacstrap -K /mnt \
base base-devel linux linux-firmware \
intel-ucode \
grub \
networkmanager \
openssh \
docker docker-compose \
ddclient \
nftables \
fail2ban \
vim \
sudo
```
## 8. Generate fstab
```bash
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab # verify — three entries: /boot, swap, /
```
## 9. chroot
```bash
arch-chroot /mnt
```
## 10. Configure locale and timezone
```bash
# Set timezone — replace with your zone
ln -sf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime
hwclock --systohc
# Locale
sed -i 's/#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
```
## 11. Hostname
```bash
echo "mithlond" > /etc/hostname
```
Add to `/etc/hosts`:
```
127.0.0.1 localhost
::1 localhost
127.0.1.1 mithlond.localdomain mithlond
```
## 12. Install GRUB bootloader
`$DISK` does not exist inside the chroot — type the real device from step 4
(the `TRAN=sata` one), with no partition number.
```bash
grub-install --target=i386-pc /dev/sdX
grub-mkconfig -o /boot/grub/grub.cfg # picks up intel-ucode automatically
```
## 13. Create user
```bash
# Set root password (needed for recovery only)
passwd
# Create non-root user
useradd -m -G wheel,docker -s /bin/bash admin
passwd admin
# Allow wheel group to use sudo
sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
```
## 14. Enable services
```bash
systemctl enable sshd
systemctl enable NetworkManager
systemctl enable docker
```
**Do not enable `nftables` or `fail2ban` here.** Both are installed but have no
configuration yet. Enabling `nftables` now loads Arch's stock ruleset, which
permits port 22 and rejects everything else — so the moment SSH moves to port
2234 in [03-ssh-hardening.md](03-ssh-hardening.md) you lock yourself out and
have to walk back to the machine. They get enabled with their real configs in
[03](03-ssh-hardening.md), [08-firewall.md](08-firewall.md) and
[09-fail2ban.md](09-fail2ban.md).