File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # ## File: /usr/local/bin/btrfs-fix-default.sh
2+
3+ #! /bin/bash
4+ set -euo pipefail
5+
6+ EXPECTED_PATH=" @"
7+ LOG=" /var/log/btrfs-fix-default.log"
8+
9+ log () { echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] $* " | tee -a " $LOG " ; }
10+
11+ # Get current default subvolume path
12+ CURRENT=$( btrfs subvolume get-default / | awk ' {print $NF}' )
13+
14+ if [[ " $CURRENT " == " $EXPECTED_PATH " ]]; then
15+ log " Btrfs default subvolume is correct ($CURRENT ). Nothing to do."
16+ exit 0
17+ fi
18+
19+ log " Btrfs default is '$CURRENT ', expected '$EXPECTED_PATH '. Fixing..."
20+
21+ # Find ID of @ subvolume
22+ SUBVOL_ID=$( btrfs subvolume list / | awk ' / path @$/ {print $2}' )
23+
24+ if [[ -z " $SUBVOL_ID " ]]; then
25+ log " ERROR: Could not find subvolume '@'. Aborting."
26+ exit 1
27+ fi
28+
29+ log " Setting default subvolume to ID $SUBVOL_ID (@)..."
30+ btrfs subvolume set-default " $SUBVOL_ID " /
31+
32+ log " Rebuilding initramfs..."
33+ mkinitcpio -P
34+
35+ log " Regenerating GRUB config..."
36+ update-grub
37+
38+ log " Done. Reboot recommended."
You can’t perform that action at this time.
0 commit comments