#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # Arcline OS — btrfs subvolume layout initialiser # # btrfs/init.sh (e.g. /dev/sda2) # btrfs/init.sh --list # # 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 }" 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"