Skip to content

Commit

Permalink
build initrd just once
Browse files Browse the repository at this point in the history
  • Loading branch information
punoko committed Aug 4, 2024
1 parent 2800636 commit 6e25feb
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

MOUNT="$(mktemp --directory)"

HOSTNAME="archlinux"
KEYMAP="us"
LOCALE="C.UTF-8"
TIMEZONE="UTC"

IMG_SIZE="2G"
IMG_FILE="image.img"
QCOW_FILE="image.qcow2"

ROOT_LABEL="Arch Linux"
ROOT_SUBVOL="@arch"
ROOT_FLAGS="compress=zstd,noatime,subvol=$ROOT_SUBVOL"
ROOT_GPT_TYPE="4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709" # Linux root (x86-64)

ESP_LABEL="ESP"
ESP_SIZE="100M"
ESP_DIR="efi"
ESP_GPT_TYPE="C12A7328-F81F-11D2-BA4B-00A0C93EC93B" # EFI System

ROOT_LABEL="Arch Linux"
ROOT_SUBVOL="@arch"
ROOT_FLAGS="compress=zstd,noatime,subvol=$ROOT_SUBVOL"
ROOT_GPT_TYPE="4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709" # Linux root (x86-64)

PACKAGES=(
base
base-devel
btrfs-progs
cloud-init
cloud-guest-utils
fzf
grml-zsh-config
htop
iptables-nft
linux
man-db
mkinitcpio
neovim
openssh
pacman-contrib
polkit
reflector
sudo
systemd-ukify
zsh
zsh-autosuggestions
Expand All @@ -53,11 +58,11 @@ SERVICES=(
systemd-timesyncd
systemd-time-wait-sync

[email protected]
paccache.timer
)
MASK=(
systemd-nsresourced.socket
systemd-userdbd.socket
systemd-homed
)

# Cleanup
Expand Down Expand Up @@ -108,29 +113,29 @@ CMDLINE="rootflags=$ROOT_FLAGS rw"
systemd-firstboot \
--root="$MOUNT" \
--force \
--keymap=us \
--locale=C.UTF-8 \
--timezone=UTC \
--keymap="$KEYMAP" \
--locale="$LOCALE" \
--hostname="$HOSTNAME" \
--timezone="$TIMEZONE" \
--root-shell=/usr/bin/zsh \
--kernel-command-line="$CMDLINE" \
;

# Bootloader
bootctl install --root "$MOUNT" --no-variables

rm -f "$MOUNT"/boot/initramfs-linux{,-fallback}.img
mv "$MOUNT/etc/mkinitcpio.d/linux."{preset,original}
cat <<EOF >"$MOUNT/etc/mkinitcpio.conf.d/custom.conf"
MODULES=(btrfs)
HOOKS=(systemd autodetect microcode modconf keyboard block)
EOF
cat <<EOF >"$MOUNT/etc/mkinitcpio.d/linux.preset"
PRESETS=('default')
default_kver="/boot/vmlinuz-linux"
default_uki="/efi/EFI/Linux/arch.efi"
default_uki="/$ESP_DIR/EFI/Linux/arch.efi"
default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp -S autodetect"
EOF
arch-chroot "$MOUNT" mkinitcpio --allpresets

# Kernel
pacstrap -cGM "$MOUNT" linux
sed -i "s/ -S autodetect//" "$MOUNT/etc/mkinitcpio.d/linux.preset"

# https://systemd.io/BUILDING_IMAGES/
Expand Down

0 comments on commit 6e25feb

Please sign in to comment.