Skip to content

Instantly share code, notes, and snippets.

@bartprokop
Last active July 31, 2023 18:38
Show Gist options
  • Save bartprokop/59c4362cb124e6a8eb7be21ee1d69d69 to your computer and use it in GitHub Desktop.
Save bartprokop/59c4362cb124e6a8eb7be21ee1d69d69 to your computer and use it in GitHub Desktop.
Arch, BTRFS, rEFInd, subvolumes
#!/bin/bash
# *** Valid for archlinux-2022.04.05-x86_64.iso
# *** GPG verify ISO file
gpg --auto-key-locate clear,wkd -v --locate-external-key pierre@archlinux.de
gpg --verify archlinux-2022.04.05-x86_64.iso.sig
# gpg: assuming signed data in 'archlinux-2022.04.05-x86_64.iso'
# gpg: Signature made Tue Apr 5 17:05:57 2022 GMTST
# gpg: using RSA key 4AA4767BBC9C4B1D18AE28B77F2D434B9741E8AC
# gpg: issuer "pierre@archlinux.de"
# gpg: Good signature from "Pierre Schmitz <pierre@archlinux.de>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg: There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 4AA4 767B BC9C 4B1D 18AE 28B7 7F2D 434B 9741 E8AC
# *** Boot downloaded image
# *** Update system clock
timedatectl set-ntp true
timedatectl status
# Local time: Tue 2022-04-26 20:19:26 UTC
# Universal time: Tue 2022-04-26 20:19:26 UTC
# RTC time: Tue 2022-04-26 20:19:26
# Time zone: UTC (UTC, +0000)
# System clock synchronized: yes
# NTP service: active
# RTC in local TZ: no
# *** This isn't necessary but it is easier to ssh into the server as root@IP address
passwd
ip a
# *** Create 1GiB EFI System Partition and use remaining space for Linux filesystem
fdisk -l
# Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
# Disk model: ST500DM002-1BD14
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 4096 bytes
# I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# Disklabel type: gpt
# Disk identifier: 35A04661-D563-426A-9810-CA2058558EED
#
# Device Start End Sectors Size Type
# /dev/sda1 2048 2099199 2097152 1G EFI System
# /dev/sda2 2099200 976773119 974673920 464.8G Linux filesystem
# *** If you are reinstalling, then wipe Linux filesystem
wipefs /dev/sda2
# DEVICE OFFSET TYPE UUID LABEL
# sda2 0x10040 btrfs 22d79b17-c99f-4d7f-8c4b-7a6b0c85c831 T20sda2
wipefs -a /dev/sda2
# /dev/sda2: 8 bytes were erased at offset 0x00010040 (btrfs): 5f 42 48 52 66 53 5f 4d
blkid
# /dev/sda1: LABEL_FATBOOT="EFI" LABEL="EFI" UUID="C043-FAA5" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="41e0082e-4360-6740-a650-4ac9e13d9105"
# /dev/sda2: PARTUUID="65265a7a-961d-1547-af8a-48e1ec0c159b"
# *** Create BTRFS on Linux filesystem partition
mkfs.btrfs -L t20sda2 /dev/sda2
# btrfs-progs v5.16.2
# See http://btrfs.wiki.kernel.org for more information.
#
# NOTE: several default settings have changed in version 5.15, please make sure
# this does not affect your deployments:
# - DUP for metadata (-m dup)
# - enabled no-holes (-O no-holes)
# - enabled free-space-tree (-R free-space-tree)
#
# Label: t20sda2
# UUID: 3212aa4a-d29a-4433-9368-0cdaee3f1ff9
# Node size: 16384
# Sector size: 4096
# Filesystem size: 464.76GiB
# Block group profiles:
# Data: single 8.00MiB
# Metadata: DUP 1.00GiB
# System: DUP 8.00MiB
# SSD detected: no
# Zoned device: no
# Incompat features: extref, skinny-metadata, no-holes
# Runtime features: free-space-tree
# Checksum: crc32c
# Number of devices: 1
# Devices:
# ID SIZE PATH
# 1 464.76GiB /dev/sda2
# *** Temporally mount BTRFS filesystem in order to create subvolumes for root and home
mount /dev/sda2 /mnt
cd /mnt
ls -l
# total 0
mkdir svols # directory for SubVOLumeS
mkdir snaps # directory for SNAPshotS
btrfs subvolume create svols/root
# Create subvolume 'svols/root'
btrfs subvolume create svols/home
# Create subvolume 'svols/home'
btrfs subvolume list /mnt
# ID 256 gen 8 top level 5 path svols/root
# ID 257 gen 9 top level 5 path svols/home
umount /mnt
# *** Mount everything
cd
mount -o noatime,nodiratime,compress=zstd,subvol=svols/root /dev/sda2 /mnt
mkdir /mnt/efi
mount /dev/sda1 /mnt/efi
mkdir /mnt/home
mount -o noatime,nodiratime,compress=zstd,subvol=svols/home /dev/sda2 /mnt/home
df -h
# Filesystem Size Used Avail Use% Mounted on
# dev 1.9G 0 1.9G 0% /dev
# run 1.9G 9.2M 1.9G 1% /run
# /dev/sdb1 746M 746M 0 100% /run/archiso/bootmnt
# cowspace 256M 832K 256M 1% /run/archiso/cowspace
# /dev/loop0 667M 667M 0 100% /run/archiso/airootfs
# airootfs 256M 832K 256M 1% /
# tmpfs 1.9G 0 1.9G 0% /dev/shm
# tmpfs 1.9G 0 1.9G 0% /tmp
# tmpfs 1.9G 2.3M 1.9G 1% /etc/pacman.d/gnupg
# tmpfs 384M 0 384M 0% /run/user/0
# /dev/sda2 465G 3.9M 463G 1% /mnt
# /dev/sda1 1022M 91M 932M 9% /mnt/efi
# /dev/sda2 465G 3.9M 463G 1% /mnt/home
# *** Install essential packages + BTRFS userspace utilities + nano
pacstrap /mnt base linux linux-firmware btrfs-progs nano
# *** Generate an fstab file
genfstab -L /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab
# # <file system> <dir> <type> <options> <dump> <pass>
# # /dev/sda2 UUID=381dc812-9bde-4a4e-8af1-cd6546ffec6e
# LABEL=t20sda2 / btrfs rw,noatime,nodiratime,compress=zstd:3,space_cache=v2,subvolid=256,subvol=/svols/root 0 0
# # /dev/sda1 UUID=C043-FAA5
# LABEL=EFI /efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2
# # /dev/sda2 UUID=381dc812-9bde-4a4e-8af1-cd6546ffec6e
# LABEL=t20sda2 /home btrfs rw,noatime,nodiratime,compress=zstd:3,space_cache=v2,subvolid=257,subvol=/svols/home 0 0
# *** Change root into the new system
arch-chroot /mnt
# *** Usual Arch config:
ln -sf /usr/share/zoneinfo/GB /etc/localtime
hwclock --systohc
nano /etc/locale.gen
locale-gen
# Generating locales...
# en_GB.UTF-8... done
# en_US.UTF-8... done
# Generation complete.
nano /etc/locale.conf
# LANG=en_GB.UTF-8
echo t20 > /etc/hostname
passwd
# New password:
# Retype new password:
# passwd: password updated successfully
nano /etc/hosts
# 127.0.0.1 localhost
# ::1 localhost
# 192.168.17.5 t20
networkctl list
# IDX LINK TYPE OPERATIONAL SETUP
# 1 lo loopback carrier unmanaged
# 2 eno1 ether routable configured
#
# 2 links listed.
nano /etc/systemd/network/20-wired.network
# [Match]
# Name=eno1
#
# [Network]
# Address=192.168.17.5/24
# Gateway=192.168.17.1
# DNS=192.168.17.1
systemctl enable systemd-networkd.service
mv /etc/resolv.conf /etc/resolv.conf-origin
ln -rsf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
systemctl enable systemd-resolved.service
# *** Bootloader and uCode
pacman -S refind
pacman -S intel-ucode
ls -l /boot
# total 56776
# -rw------- 1 root root 34125283 Apr 26 21:39 initramfs-linux-fallback.img
# -rw------- 1 root root 8841680 Apr 26 21:39 initramfs-linux.img
# -rw-r--r-- 1 root root 4706304 Apr 20 21:56 intel-ucode.img
# -rw-r--r-- 1 root root 10458688 Apr 26 21:39 vmlinuz-linux
refind-install
# ShimSource is none
# Installing rEFInd on Linux....
# ESP was found at /efi using vfat
# Running in BIOS mode with no existing default boot loader; installing to
# /efi/EFI/BOOT
# Note: IA32 (x86) binary not installed!
# Installing driver for btrfs (btrfs_x64.efi)
# Copied rEFInd binary files
#
# Copying sample configuration file as refind.conf; edit this file to configure
# rEFInd.
#
#
# Installation has completed successfully.
nano /efi/EFI/BOOT/refind.conf
# also_scan_dirs +,svols/root/boot
# extra_kernel_version_strings linux-hardened,linux-zen,linux-lts,linux
mkrlconf
# "Boot with standard options" "root=PARTUUID=65265a7a-961d-1547-af8a-48e1ec0c159b rw rootflags=subvol=svols/root initrd=svols/root\boot\intel-ucode.img initrd=svols/root\boot\initramfs-%v.img"
# "Boot Origin" "root=PARTUUID=65265a7a-961d-1547-af8a-48e1ec0c159b rw rootflags=subvol=svols/root initrd=svols/root\boot\initramfs-%v.img"
# *** Finish
exit
umount -R /mnt
reboot
# *** Arch Linux successfully installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment