Bcachefs: Difference between revisions

imported>Onny
mNo edit summary
imported>Krutonium
Add information about multi device formatting, as well as information about mounting and compression options.
Line 17: Line 17:
# mount -t bcachefs /dev/sda /mnt
# mount -t bcachefs /dev/sda /mnt
</syntaxhighlight>
</syntaxhighlight>
Or, format and mount multiple devices
<syntaxhighlight lang="console">
# bcachefs format /dev/sda:/dev/sdb:/dev/sdc
# mount -t bcachefs /dev/sda:/dev/sdb:/dev/sdc
</syntaxhighlight>
The same works with partitions, which is probably better for future proofing depending on your specific needs
<syntaxhighlight lang="console">
# bcachefs format /dev/sda1:/dev/sdb2:/dev/sdc3
# mount -t bcachefs /dev/sda1:/dev/sdb2:/dev/sdc3
</syntaxhighlight>


Format drive with encryption enabled, unlock and mount it afterwards. Following bcachefs commands will ask for a password:
Format drive with encryption enabled, unlock and mount it afterwards. Following bcachefs commands will ask for a password:
Line 24: Line 39:
# bcachefs unlock /dev/sda
# bcachefs unlock /dev/sda
# mount -t bcachefs /dev/sda /mnt
# mount -t bcachefs /dev/sda /mnt
</syntaxhighlight>
Format a drive with compression on by default, foreground and background
(Available Compression options are <code>gzip</code>, <code>lz4</code>, and <code>zstd</code>)
<syntaxhighlight lang="console">
# bcachefs format --compression=lz4 --background_compression=zstd /dev/sda
# mount -t bcachefs /dev/sda
</syntaxhighlight>
Format a multiple devices with storage tiers, so that reads and writes happen on the fastest disks, with data being stored on slower, bigger drives based on usage patterns
<syntaxhighlight lang="console">
# bcachefs format \
    --label=hdd.hdd1 /dev/sdc \
    --label=hdd.hdd2 /dev/sdd \
    --label=hdd.hdd3 /dev/sde \
    --label=ssd.ssd1 /dev/sdf \
    --label=ssd.ssd2 /dev/sdg
    --foreground_target=ssd \
    --promote_target=ssd \
    --background_target=hdd \
# mount -t bcachefs /dev/sdc:/dev/sdd:/dev/sde:/dev/sdf:/dev/sdg
</syntaxhighlight>
For a better mounting experience in the previous example, use the external UUID that was printed.
<syntaxhighlight lang="console">
# bcachefs format \
    --label=hdd.hdd1 /dev/sdc \
    --label=hdd.hdd2 /dev/sdd \
    --label=hdd.hdd3 /dev/sde \
    --label=ssd.ssd1 /dev/sdf \
    --label=ssd.ssd2 /dev/sdg
    --foreground_target=ssd \
    --promote_target=ssd \
    --background_target=hdd \
# mount -t bcachefs UUID=<UUID>
</syntaxhighlight>
</syntaxhighlight>


Line 33: Line 85:


== Configuration ==
== Configuration ==
Every option for the filesystem can be set by editing <code>/sys/fs/bcachefs/<uuid>/options</code>, for example the file <code>background_compression</code> will change the background compression scheme for background compression. These are persisted with the filesystems, so a bcachefs storage device being mounted on a different computer won't need to know what mount options to use to maintain the same compression levels.


Change encryption password for Bcachefs formatted device <code>/dev/sda1</code>
Change encryption password for Bcachefs formatted device <code>/dev/sda1</code>
Line 40: Line 94:
</syntaxhighlight>
</syntaxhighlight>


Enable zstd compression for device <code>/dev/sda1</code>
Enable zstd compression for device <code>/dev/sda1</code> at mount time


{{file|/etc/nixos/hardware-configuration.nix|nix|<nowiki>
{{file|/etc/nixos/hardware-configuration.nix|nix|<nowiki>
Line 117: Line 171:


Mount filesystems
Mount filesystems
There are two ways to mount a bcachefs filesystem. First, by device:


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
Line 123: Line 179:
# mount /dev/disk/by-label/boot /mnt/boot
# mount /dev/disk/by-label/boot /mnt/boot
</syntaxhighlight>
</syntaxhighlight>
For better reliability as with any other filesystem, one should mount the filesystem by UUID, by replacing any drive specifiers with it.
When you formatted, there was an external UUID shown, but if you lost it, you can retrieve it using
<syntaxhighlight lang="console">
# lsblk -o +uuid,fsType | grep bcachefs
</syntaxhighlight>
And using it like <code>UUID=<UUID></code> in place of <code>/dev/sda1:/dev/sdb1</code> or even just <code>/dev/sda</code>.


Continue installation as recommended by the [https://nixos.org/manual/nixos/stable/index.html#ch-installation NixOS manual].
Continue installation as recommended by the [https://nixos.org/manual/nixos/stable/index.html#ch-installation NixOS manual].