knowledge/technology/linux/filesystems/Btrfs.md
2023-12-04 11:02:23 +01:00

2 KiB

arch-wiki obj
https://wiki.archlinux.org/title/Btrfs filesystem

Btrfs

Btrfs is a modern copy on write (CoW) filesystem for Linux aimed at implementing advanced features while also focusing on fault tolerance, repair and easy administration. Btrfs is licensed under the GPL and open for contribution from anyone.

Create the filesystem

Single Device:

mkfs.btrfs -L _mylabel_ /dev/partition

Multiple Devices (similiar to RAID):

mkfs.btrfs -d single -m raid1 /dev/part1 /dev/part2 ...

Subvolumes

Subvolumes are their own seperated namespaces and work like ZFS Datasets. They can be mounted seperately. Each Btrfs file system has a top-level subvolume with ID 5.

Create a subvolume:

btrfs subvolume create /path/to/subvolume

List suvolumes:

btrfs subvolume list -p path

Delete subvolume:

btrfs subvolume delete /path/to/subvolume

Using Swapfiles

Swapfiles can be used by disabling CoW:

chattr +C /path/to/swapsubvolume

Use swapfile:

touch /swapfile
chattr +C /swapfile
fallocate -l 8G /swapfile
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile

Filesystem Usage

See Usage:

btrfs filesystem usage /

Available Space:

btrfs filesystem df /

Scrub

Btrfs can self heal itself or check for errors with scrubbing.
Start:

btrfs scrub start /

See Status:

btrfs scrub status /

Balance

Rebalance the filesystem.

btrfs balance start --bg /
btrfs balance status /

Snapshots

Btrfs can use snapshots

btrfs subvolume snapshot source [dest/]name

Resizing

Btrfs can be resized.

To extend the file system size to the maximum available size of the device:

btrfs filesystem resize max /

To extend the file system to a specific size:

btrfs filesystem resize size /

Add or remove size

btrfs filesystem resize +size /
btrfs filesystem resize -size /