Install Arch Linux on EFI

Most what you will find in this post comes from this gist. I’m rewritting this here as a note in any case. Some more info about the installation process here on ArchWiki and also more info about the post-installation process.

  1. Boot USB flash drive and make sure it’s connected via Ethernet.
  2. Change terminal keys if you are not in qwerty:
    loadkeys fr
  3. Disable the beeping sound (this one will save your ears and sanity):
    setterm -blength 0
  4. Check if the system was booted with UEFI:
    cat /sys/firmware/efi/fw_platform_size

    It should exists and be 64 if it’s booted in UEFI x86_64. If that’s the case, continue.

  5. Check that you have an IP address and try a ping to check your Internet connectivity:
    ip address
    ping 8.8.8.8
    
  6. Update system clock and check status:
    timedatectl set-ntp true
    timedatectl status
  7. Enable SSH, this might be useful if you want to continue the installation from elsewhere or transfer files via sftp:
    systemctl start sshd
  8. List the disks then proceed with creating the partitions:
    fdisk -l
    cfdisk /dev/sda
    

    Create a EFI partition of 256M to 512M, a several GB swap partition and what is left with a Linux root partition.

  9. Format the partitions:
    mkfs.fat -F32 /dev/sda1
    mkfs.ext4 -L root -m 0 /dev/sda3
    
  10. Mount the root partition:
    mount -o noatime /dev/sda3 /mnt
    
  11. Install the base packages:
    pacstrap -Ki /mnt base linux linux-firmware
    
  12. Generate the fstab:
    genfstab -U -p /mnt >> /mnt/etc/fstab
    
  13. Chroot in the filesystem:
    arch-chroot /mnt
    
  14. Configure the terminal keyboard:
    vim /etc/vconsole.conf
  15. Set the timezone:
    ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime
    
  16. Update the hardware clock:
    hwclock --systohc
    
  17. Install other packages:
    pacman -S grub efibootmgr dosfstools openssh os-prober mtools net-tools inetutils netctl dhcpcd dhclient vim
    
  18. Edit and set-up the locale:
    vim /etc/locale.gen
    locale-gen
    
  19. Setup root password:
    passwd
    
  20. Create and mount EFI directory:
    mkdir /boot/EFI
    mount -o noatime /dev/sda1 /boot/EFI
  21. Time to install the GRUB bootloader and write the config:
    grub-install --target=x86_64-efi --bootloader-id=grub_uefi --recheck
    grub-mkconfig -o /boot/grub/grub.cfg
    
  22. If needed you might configure an extra entry within the GRUB boot list, for instance for a dualboot with FreeBSD. To that end, edit /etc/grub.d/40_custom and add (at the end of this file):
    menuentry FreeBSD {
      insmod ufs2
      set root='(hd0,gpt3)'
      chainloader /boot/loader.efi
    }
    

    Then update the grub configuration with:

    grub-mkconfig -o /boot/grub/grub.cfg
  23. Time to reboot:
    exit
    reboot
    

Post install ArchLinux

In the past few months, I had to install ArchLinux several times. While it’s now my Linux distribution of choice for an everyday use, a clean install of Arch is rather bland. So in this post, I’ll try to resume the different step I took to spice a default Arch install a bit more to my taste. Most of the choices here are purely personals.

New user

By default, no user is created, so you have to create one along with its home directory. Also ensure that your home is in 750 instead of 755.

useradd -m youruser
chmod 750 /home/youruser

Fstab and tmpfs

By default, on a new install, /etc/fstab comes up mostly empty as most of it is hidden away by systemd. But I usually change some options and add tmpfs. Here’s an example:

/dev/vda2 / ext4 rw,noatime,nodiscard,stripe=4 0 1
/dev/vda1 /boot vfat rw,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro	0 2

/dev/vdb1 none swap sw 0 0
/dev/vdb2 /mnt/data ext4 rw,noatime,nodiscard 0 0

tmpfs /tmp tmpfs noatime,mode=1777 0 0
tmpfs /run tmpfs noatime,nosuid,noexec,mode=755 0 0
tmpfs /run/shm tmpfs noatime,nosuid,nodev,mode=1777 0 0

pacman cache

If you have a separate data partition/hdd, it may be a good idea to move the pacman cache there. However you cannot do so using symlinks, pacman won’t like that at all. Instead you have to edit the CacheDir entry in /etc/pacman.conf.

yay

Arch comes with its binary package manager (pacman) and also the community maintained Arch User Repository (AUR) providing access to more packages that are generally built from source. Yay is a AUR package manager so you don’t have to clone and install AUR repos manually.

Note that the commands below need to be run as your normal user, otherwise makepkg will complain about possible catastrophic happenstances.

sudo pacman -S --needed base-devel git
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

legacy network interface name

Back in the days, network interfaces on Linux had simple names like eth0, wlan0, and so on. This changed multiple times because the order in which the interface drivers are loaded make these names not 100% predictable. However, if you know that your boot order is pretty static and never change, you might want to get the legacy naming scheme. To do so, either add net.ifnames=0 to the kernel parameters or override the appropriate udev rule. In this case I use the latter option.

ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

netctl

I prefer to use netctl instead of systemd-networkd to manage the network. Since I constantly use other Unix and Unix-likes systems that are not Linux, and since I’ve been doing so for decades, I also prefer to use ifconfig instead of ip. When asked I also choose openresolv instead of systemd-resolved, the latter tries to do too many things in your back.

pacman -S net-tools inetutils netctl dhcpcd dhclient
systemctl enable netctl

Then you have to create a default profile, for instance in /etc/netctl/network. Here is a default config that configures the interface with DHCP for IPv4 and SLAAC for IPv6:

Description="Basic DHCP ethernet connection"
Interface=eth0
Connection=ethernet
IP=dhcp
IP6=stateless

You still have to enable the profile:

netctl enable network

Some packages

Here is the bare minimum I would install on a new install, whether headless or xorg powered.

  • uptimed
  • ntp/chrony
  • ncdu
  • zsh
  • htop
  • starship
  • neovim
  • wget/curl/lynx
  • tcpdump/nmap
  • fzf
  • tree
  • bzip2/xz/gzip/zstd
  • the_silver_searcher
  • git
  • cpio
  • rsync
  • dialog
  • ipv6calc
  • dos2unix
  • exa/bat

Some extra packages

  • openssh: remote access/sync stuff and so on
  • bindfs: useful if you need to rebind user/permission on mount points, for instance on a shared mount
  • tldr: recall any command usage (I recommend the tealdeer client, written in Rust)
  • doggo: DNS queries
  • vulkan-virtio/mesa-vdpau: useful for graphical acceleration in a Qemu VM

Install FreeBSD 11 with ZFS on Dedibox XC 2016

Online.net’s Dedibox XC 2016 comes with 16 GB DDR3 and 1 To SATA or 250 GB SSD on a 8 cores Atom CPU. This is a very nice entry-level dedicated box for anyone who want to upgrade from a small VPS (yes, there is some upgrade in the air). There is only one HDD and no RAID though. But they offer (for free) a 100 GB FTP storage space which is more than enough to backup the base system and bootstrap it again in case of disk failure.

An advantage of dedicated over VPS is that you can install almost any OS you want. The management console comes with an easy install for FreeBSD 11 on UFS. But I thought it would be nice to use ZFS instead. Yeah, I hear you, why using ZFS with only one HDD and non-ECC memory? But with 16 GB it still comes as a viable alternative.

The method I used was adapted from a post on Online.net’s forum. So here we go. First, reboot in rescue mode from the console. Choose FreeBSD 10.2 (or higher) as the rescue OS. Once you are logged on the rescue, switch to root and bootstrap FreeBSD:


SWAP_SIZE=4g
TEMP_ROOT_PASSWORD="1337rul35"

# Create partitions table
gpart destroy -F ada0
gpart create -s gpt ada0
gpart add -t freebsd-boot -l boot -s 512K ada0
gpart add -t freebsd-swap -l swap -s $SWAP_SIZE -a 1m ada0
gpart add -t freebsd-zfs -l zfs0 ada0

# Install MBR
dd if=/dev/zero of=ada0p3 count=560 bs=512
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

# Create ZFS pool and FS
zpool create -f -m none -o altroot=/mnt -o cachefile=/tmp/zpool.cache -O compress=lz4 -O atime=off zroot gpt/zfs0
zfs create -o mountpoint=/ zroot/ROOT
zfs create -o mountpoint=/usr zroot/usr
zfs create -o mountpoint=/var zroot/var
zfs create -o mountpoint=/tmp zroot/tmp
zfs create -o mountpoint=/www zroot/www
zfs create -o mountpoint=/usr/home zroot/usr/home
zpool set bootfs=zroot/ROOT zroot

# Bootstrap
cd /mnt
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/11.0-RELEASE/base.txz
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/11.0-RELEASE/kernel.txz
tar --unlink -Jxpf base.txz -C /mnt
tar --unlink -Jxpf kernel.txz -C /mnt
rm base.txz kernel.txz

# Configuration
# 1) fstab and swap
cat << EOF > /mnt/etc/fstab
ada0p2 none swap sw 0 0
EOF

# 2) rc.conf
cat << EOF > /mnt/etc/rc.conf
keymap="fr.acc"
ifconfig_igb0="DHCP"
ifconfig_igb1="DHCP"
fsck_y_enable="YES"
background_fsck="YES"
zfs_enable="YES"
sshd_enable="YES"
EOF

# 3) loader.conf
cat << EOF > /mnt/boot/loader.conf
zfs_load="YES"
vfs.root.mountfrom="zfs:zroot/ROOT"
boot_multicons="YES"
boot_serial="YES"
comconsole_speed="9600"
console="comconsole"
comconsole_port="0x2F8"
EOF

# 4) TTY for serial console
cat << EOF >> /mnt/etc/ttys
ttyu1 "/usr/libexec/getty std.9600" vt100 on secure
EOF

# 5) Temporary root password
echo "$TEMP_ROOT_PASSWORD" | pw -R /mnt user mod -n root -h 0

# Last step
cd ~
zpool export zroot
zpool import -o altroot=/mnt -o cachefile=/tmp/zpool.cache zroot
cp /tmp/zpool.cache /mnt/boot/zfs

# Terminated!
halt

Now from the management console, reboot in normal mode and connect to your box using serial connection. You should be able to login with root and continue the configuration from there.