Files
os-build/btrfs/init.sh
Blake Ridgway f879bcf219 fix: btrfs/init.sh blkid probe (blkid -O is --offset, not "on device")
The deploy failed with:

    blkid: invalid offset argument '/dev/vda2': invalid argument
    error: /dev/vda2 is not a btrfs filesystem

`blkid -p -O "$DEV"` passed the device path to --offset, so the probe
always failed. Use a proper TYPE tag probe:

    blkid -p -s TYPE -o value "$DEV"   # -> "btrfs"

The guard now triggers only when the filesystem type is genuinely not
btrfs. The UUID lookups in deploy-disk.sh (-s UUID -o value) were already
correct.
2026-08-21 21:10:47 -05:00

68 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# Arcline OS — btrfs subvolume layout initialiser
#
# btrfs/init.sh <device> (e.g. /dev/sda2)
# btrfs/init.sh --list <device>
#
# Creates the Arcline subvolume layout on a fresh (or existing) btrfs device:
#
# @ → / system root (rolled back on failure)
# @home → /home user data
# @log → /var/log logs (not rolled back, survives)
# @snapshots → /.snapshots where arcline-snapshot keeps snapshots
#
# This is the step the installer runs; it is safe to re-run (existing
# subvolumes are kept, missing ones are created). Requires root.
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
DEV="${1:?usage: btrfs/init.sh <device>}"
TOP="/run/arcline-btrfs-init"
require_root() {
if [[ $EUID -ne 0 ]] && command -v sudo >/dev/null; then
exec sudo -E "$0" "$@"
elif [[ $EUID -ne 0 ]]; then
echo "error: needs root" >&2; exit 1
fi
}
require_root "$0" "$@"
command -v btrfs >/dev/null || { echo "error: btrfs-progs not installed" >&2; exit 1; }
# Note: `blkid -O` is --offset, not "on device". Use a TYPE tag probe.
if [[ "$(blkid -p -s TYPE -o value "$DEV" 2>/dev/null)" != "btrfs" ]]; then
echo "error: $DEV is not a btrfs filesystem" >&2
exit 1
fi
mkdir -p "$TOP"
mount -o subvolid=5 "$DEV" "$TOP"
trap 'umount "$TOP" 2>/dev/null || true; rmdir "$TOP" 2>/dev/null || true' EXIT
create_subvol() {
local name="$1"
if [[ -d "$TOP/$name" ]]; then
echo " keeping existing subvolume: $name"
else
echo " creating subvolume: $name"
btrfs subvolume create "$TOP/$name" >/dev/null
fi
}
echo "Arcline btrfs layout on $DEV:"
create_subvol "@"
create_subvol "@home"
create_subvol "@log"
create_subvol "@snapshots"
# mark @snapshots read-only friendly (snapper/arcline-snapshot manage it)
btrfs property set -ts "$TOP/@snapshots" ro false 2>/dev/null || true
echo "done. The installer mounts:"
echo " @ → /"
echo " @home → /home"
echo " @log → /var/log"
echo " @snapshots → /.snapshots"