Btrfs: Difference between revisions

From Alpine Linux
m (fixed category name)
(service file is now in btrfs-progs package)
 
Line 40: Line 40:
If you try mounting a Btrfs volume via your {{path|/etc/fstab}} and it doesn't show up, it could be because Btrfs does not know about the drives during boot.
If you try mounting a Btrfs volume via your {{path|/etc/fstab}} and it doesn't show up, it could be because Btrfs does not know about the drives during boot.


To work around this, you can create an OpenRC service that runs a <code>btrfs scan</code> to detect the drives. To do so, create a new service under {{path|/etc/init.d/btrfs-scan}} with the following content:
To work around this, you can enable the OpenRC service from the [https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/btrfs-progs/btrfs-scan.initd btrfs-progs] package:


{{cat|/etc/init.d/btrfs-scan|<nowiki>#!/sbin/openrc-run
{{Cmd|<nowiki># rc-update add btrfs-scan boot
 
name="btrfs-scan"
 
depend() {
  before localmount
}
 
start() {
  /sbin/btrfs device scan
}
</nowiki>}}
 
Make the service executable and register it:
 
{{Cmd|<nowiki># chmod +x /etc/init.d/btrfs-scan
# rc-update add btrfs-scan boot
</nowiki>}}
</nowiki>}}



Latest revision as of 16:08, 14 December 2024

Documentation how to use Btrfs on Alpine Linux.

Install

Installing Btrfs is relatively straight forward. Install the package and tell Alpine to load the module on startup:

# apk add btrfs-progs # echo btrfs >> /etc/modules

To load the module immediately, you can use the following command:

# modprobe btrfs

If using btrfs as your root filesystem, you should ensure that the initramfs is generated with the btrfs module, otherwise your system may fail to boot. To do so edit (as root) /etc/mkinitfs/mkinitfs.conf and ensure that "btrfs" is in the list of features; then (again as root) run the mkinitfs command.

Mounting a volume

To mount a volume on boot, add a new entry to your fstab:

Contents of /etc/fstab

... UUID=abcdef-0055-4958-990f-1413ed1186ec /var/data btrfs defaults,nofail,subvol=@ 0 0

If you use more specific mounting options like for example:

Contents of /etc/fstab

... UUID=005f5994-f51c-4360-8c9b-589fa59ea6fc /mnt/hddext btrfs nofail,rw,noatime,commit=64,nossd,autodefrag,compress=zstd:10 0 2

do not forget to install additional dependencies. If you enabled on the fly compression you need to install zstd:

# apk add zstd

More information about mounting can be found in the official Btrfs wiki

Troubleshooting

Mount failed

If you try mounting a Btrfs volume via your /etc/fstab and it doesn't show up, it could be because Btrfs does not know about the drives during boot.

To work around this, you can enable the OpenRC service from the btrfs-progs package:

# rc-update add btrfs-scan boot

The volume should mount correctly after a reboot.

See also