Skip to content

Instantly share code, notes, and snippets.

@kingbri1
Created August 9, 2025 19:44
Show Gist options
  • Save kingbri1/f4d46aa4368a0f662c04af08372a764e to your computer and use it in GitHub Desktop.
Save kingbri1/f4d46aa4368a0f662c04af08372a764e to your computer and use it in GitHub Desktop.
BTRFS on raspberry pi

BTRFS on RaspberryPi OS 12 (bookworm)

  • It is best to have a GUI install of RaspiOS on your SDCard and your storage drive
  • Fresh install RaspiOS to your storage drive and boot it once
  • Make sure to run sudo apt update && sudo apt upgrade before rebooting back to your SD card

All these steps are done from your SD card install

Convert MBR to GPT (optional)

  • mbr2gpt can be found here. Look for usb-boot.zip
# ./mbr2gpt /dev/sdX

Convert EXT4 to BTRFS

# btrfs-convert /dev/sdX2

Create subvolumes

# mount /dev/sdX1 /mnt/bootfs
# mount /dev/sdX2 /mnt/rootfs

# cd /mnt/rootfs
# btrfs subvolume create @
# btrfs subvolume create @home
# btrfs subvolume create @log
# btrfs subvolume create @archives
# btrfs subvolume create @.snapshots

Move everything to subvolumes

# mv home/* @home/
# rm -rf home/
# rm -rf lost+found

Run the following script to move all other folders/files

#!/bin/bash
# Usage: ./move_into_subvol.sh @
# Moves everything except items starting with '@', 'ext2_saved', and the script itself into the target subvolume

TARGET_SUBVOL="$1"

if [[ -z "$TARGET_SUBVOL" ]]; then
    echo "Usage: $0 <target-subvolume>"
    exit 1
fi

SCRIPT_NAME="$(basename "$0")"

for item in *; do
    # Skip the target subvolume, ext2_saved, any subvolumes starting with @, and the script itself
    if [[ "$item" != "$TARGET_SUBVOL" && "$item" != "ext2_saved" && "$item" != @(@*) && "$item" != "$SCRIPT_NAME" ]]; then
        echo "Moving $item -> $TARGET_SUBVOL/"
        mv "$item" "$TARGET_SUBVOL"/
    fi
done

Update bootfs/cmdline.txt

  • How to get PARTUUID?
# blkid /dev/sdX2

Inside bootfs/cmdline.txt, add the following:

... root=PARTUUID=S0me-P4RTUU1D rootfstype=btrfs rootflags=subvol=@ fsck.repair=no ...

Update rootfs/@/etc/fstab

# Root
PARTUUID=Some-PARTUUID   /                       btrfs   noatime,ssd,discard=async,space_cache=v2,compress=zstd:3,subvol=@      0 0
PARTUUID=Some-PARTUUID   /home                   btrfs   relatime,ssd,discard=async,space_cache=v2,compress=zstd:3,subvol=@home 0 0
PARTUUID=Some-PARTUUID   /var/log                btrfs   relatime,ssd,discard=async,space_cache=v2,compress=zstd:3,subvol=@log  0 0
PARTUUID=Some-PARTUUID   /var/cache/apt/archives btrfs   relatime,ssd,discard=async,space_cache=v2,subvol=@archives 0 0
PARTUUID=Some-PARTUUID   /.snapshots             btrfs   relatime,ssd,discard=async,space_cache=v2,compress=zstd:3,[email protected] 0 0

Remove old ext4 subvolume

# btrfs subvolume delete ext2_saved

Update boot order

# sudo raspi-config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment