Btrfs: Difference between revisions
Prabuanand (talk | contribs) (renamed and created headings, rephrased and moved sentence to make things easier to follow) |
Prabuanand (talk | contribs) (added mount command, apk-snap, changed heading,rephrased sentence) |
||
Line 12: | Line 12: | ||
{{Cmd|# modprobe btrfs}} | {{Cmd|# modprobe btrfs}} | ||
If | If btrfs is used for root filesystem, ensure that the initramfs is generated with the btrfs module, otherwise the system may fail to boot. | ||
To do so edit the {{path|/etc/mkinitfs/mkinitfs.conf}} and ensure that "btrfs" is in the list of features as follows:{{Cat|/etc/mkinitfs/mkinitfs.conf|features{{=}}"ata base cdrom ext4 keymap kms mmc nvme raid scsi usb virtio btrfs"}} | |||
After making the above change, issue the command to regenerate the initramfs:{{Cmd|# mkinitfs}} | |||
== Configuration == | == Configuration == | ||
=== Mounting a | === Mounting a subvolume === | ||
To mount a subvolume {{ic|@alpine}} located in the btrfs partition {{Path|/dev/nvme0n1p3}}, the command is: {{Cmd|<nowiki># mount -o subvol=@alpine /dev/nvme0n1p3 /mnt</nowiki>}} | |||
=== Mounting a subvolume on boot === | |||
To mount a volume on boot, add a new entry to your {{path|/etc/fstab}} file as follows: {{cat|/etc/fstab|<nowiki>... | To mount a volume on boot, add a new entry to your {{path|/etc/fstab}} file as follows: {{cat|/etc/fstab|<nowiki>... | ||
Line 31: | Line 39: | ||
To ensure that that btrfs partitions are cleanly mounted, enable the {{ic|btrfs-scan}} service from the {{pkg|btrfs-progs}}package: {{Cmd|# rc-update add btrfs-scan boot}} | To ensure that that btrfs partitions are cleanly mounted, enable the {{ic|btrfs-scan}} service from the {{pkg|btrfs-progs}}package: {{Cmd|# rc-update add btrfs-scan boot}} | ||
=== apk-snap === | |||
The {{ic|apk-snap}} script from {{pkg|apk-snap}} package triggers filesystem snapshots before and after every apk commit. | |||
The {{pkg|apk-snap}} package is currently available in [[Repositories#Testing|testing]] repository. It can be safely installed by following the [[Repositories#Using_testing_repository|guidelines]]. | |||
This package autointalls {{pkg|snapper}} package and provides necessary apk hooks and script that causes {{ic|snapper}} to automatically take a pre and post snapshot before and after apk transactions, similar to how YaST does with OpenSuse. This provides a simple way to undo changes to a system after an apk transaction. | |||
By default the '''/''' (root) snapshots taken by snapper are saved in the '''/.snapshot''' folder. To make it easier to manage the snapshots created by snapper, it is better to mainain it outside of '''/(root)''' folder. To achieve this, create a subvolume {{ic|@snaps_root}} in the btrfs partition and mount the above subvolume on '''/.snapshot''' folder by having an entry in {{Path|etc/fstab}} file as follows: {{Cat|/etc/fstab|<nowiki>... | |||
UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b /.snapshots btrfs compress=zlib:3,subvol=@snaps_root 0 0</nowiki>}} | |||
== Troubleshooting == | == Troubleshooting == | ||
Line 36: | Line 54: | ||
=== Mount failed === | === Mount failed === | ||
If you try mounting a Btrfs volume via your {{path|/etc/fstab}} and it doesn't show up, | If you try mounting a Btrfs volume via your {{path|/etc/fstab}} and if it doesn't show up, this is related to {{Issue|9539|Can't mount BTRFS volume using fstab}}. This could be because Btrfs does not know about the drives during boot. To avoid this issue [[#Enable btrfs-scan service|enable the btrfs-scan service]]. The volume should mount correctly after a reboot. | ||
== See also == | == See also == | ||
Line 42: | Line 60: | ||
* [https://garrit.xyz/posts/2021-12-31-btrfs-on-alpine BTRFS on Alpine Linux] | * [https://garrit.xyz/posts/2021-12-31-btrfs-on-alpine BTRFS on Alpine Linux] | ||
* [https://web.archive.org/web/20221127043947/https://nparsons.uk/blog/using-btrfs-on-alpine-linux Using BTRFS on Alpine Linux] | * [https://web.archive.org/web/20221127043947/https://nparsons.uk/blog/using-btrfs-on-alpine-linux Using BTRFS on Alpine Linux] | ||
* [https://wiki.archlinux.org/title/Btrfs ArchWiki] | * [https://wiki.archlinux.org/title/Btrfs ArchWiki] | ||
* [https://wiki.gentoo.org/wiki/Btrfs Gentoo Wiki] | * [https://wiki.gentoo.org/wiki/Btrfs Gentoo Wiki] |
Latest revision as of 11:27, 3 April 2025
Documentation how to use Btrfs on Alpine Linux.
Installation
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 btrfs is used for root filesystem, ensure that the initramfs is generated with the btrfs module, otherwise the system may fail to boot.
To do so edit the /etc/mkinitfs/mkinitfs.conf and ensure that "btrfs" is in the list of features as follows:
Contents of /etc/mkinitfs/mkinitfs.conf
After making the above change, issue the command to regenerate the initramfs:
# mkinitfs
Configuration
Mounting a subvolume
To mount a subvolume @alpine
located in the btrfs partition /dev/nvme0n1p3, the command is:
# mount -o subvol=@alpine /dev/nvme0n1p3 /mnt
Mounting a subvolume on boot
To mount a volume on boot, add a new entry to your /etc/fstab file as follows:
Contents of /etc/fstab
If you use more specific mounting options like for example:
Contents of /etc/fstab
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
Enable btrfs-scan service
To ensure that that btrfs partitions are cleanly mounted, enable the btrfs-scan
service from the btrfs-progspackage:
# rc-update add btrfs-scan boot
apk-snap
The apk-snap
script from apk-snap package triggers filesystem snapshots before and after every apk commit.
The apk-snap package is currently available in testing repository. It can be safely installed by following the guidelines.
This package autointalls snapper package and provides necessary apk hooks and script that causes snapper
to automatically take a pre and post snapshot before and after apk transactions, similar to how YaST does with OpenSuse. This provides a simple way to undo changes to a system after an apk transaction.
By default the / (root) snapshots taken by snapper are saved in the /.snapshot folder. To make it easier to manage the snapshots created by snapper, it is better to mainain it outside of /(root) folder. To achieve this, create a subvolume @snaps_root
in the btrfs partition and mount the above subvolume on /.snapshot folder by having an entry in etc/fstab file as follows:
Contents of /etc/fstab
Troubleshooting
Mount failed
If you try mounting a Btrfs volume via your /etc/fstab and if it doesn't show up, this is related to #9539. Can't mount BTRFS volume using fstab. This could be because Btrfs does not know about the drives during boot. To avoid this issue enable the btrfs-scan service. The volume should mount correctly after a reboot.