Bcachefs: Difference between revisions

Onny (talk | contribs)
m Citation needed. Especially regarding stability compared to ZFS
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[https://bcachefs.org Bcachefs] is a next-generation CoW filesystem that aims to provide features from [[Btrfs]] and [[ZFS]] with a cleaner codebase, more stability, greater speed and a GPL-compatible license. It is built upon Bcache and is mainly developed by Kent Overstreet.  
[https://bcachefs.org Bcachefs] is a next-generation CoW filesystem that aims to provide features from [[Btrfs]] and [[ZFS]] with a cleaner codebase<ref name=":0">citation needed</ref>, more stability<ref name=":0" />, greater speed<ref name=":0" /> and a GPL-compatible license. It is built upon Bcache and is mainly developed by Kent Overstreet.  


== Installation ==
== Installation ==
Line 88: Line 88:
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# bcachefs fsck /dev/sda
# bcachefs fsck /dev/sda
</syntaxhighlight>Change partition encryption password for <code>/dev/sda1</code><syntaxhighlight lang="console">
# bcachefs set-passphrase /dev/sda1
</syntaxhighlight>
</syntaxhighlight>


Line 119: Line 121:
{
{
   description = "Bcachefs enabled installation media";
   description = "Bcachefs enabled installation media";
   inputs.nixos.url = "nixpkgs/nixos-24.05";
   inputs.nixos.url = "nixpkgs/nixos-24.11";
   outputs = { self, nixos }: {
   outputs = { self, nixos }: {
     nixosConfigurations = {
     nixosConfigurations = {
Line 142: Line 144:


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# git init
# git add flake.nix
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage
</syntaxhighlight>
</syntaxhighlight>
Line 169: Line 169:
</syntaxhighlight>
</syntaxhighlight>


In case you want to enable filesystem encryption, there's a workaround for [https://github.com/NixOS/nixpkgs/issues/32279 a bug] affecting NixOS 23.11. Formatting and unlocking the encrypted partition would look like this
Formatting and unlocking the encrypted partition would look like this


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# nix-env -iA nixos.keyutils
# nix-shell -p keyutils --run 'keyctl link @u @s'
# keyctl link @u @s
# bcachefs format --encrypted /dev/sda2
# bcachefs format --encrypted /dev/sda2
# bcachefs unlock /dev/sda2
# bcachefs unlock /dev/sda2
Line 194: Line 193:
</syntaxhighlight>
</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>.
And using it like <code>UUID=<UUID></code> in place of <code>/dev/sda1:/dev/sdb1</code> or even just <code>/dev/sda</code>.
Note: this is currently broken as per this [https://github.com/NixOS/nixpkgs/issues/317901 github issue]. As a workaround, use `/dev/disk/by-uuid/<UUID>` or `/dev/disk/by-id` instead. This seems to work for single device systems atleast, although atleast at the time of this writing I could not get it to work on my 4+ device raid system.


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].
Line 212: Line 213:
   after = [ "local-fs.target" ];
   after = [ "local-fs.target" ];
   wantedBy = [ "multi-user.target" ];
   wantedBy = [ "multi-user.target" ];
  environment = {
    DEVICE_PATH = "/dev/sda1";
    MOUNT_POINT = "/mnt";
  };
   script = ''
   script = ''
     #!${pkgs.runtimeShell} -e
     #!${pkgs.runtimeShell} -e
     ${pkgs.keyutils}/bin/keyctl link @u @s
     ${pkgs.keyutils}/bin/keyctl link @u @s
     while [ ! -b /dev/sda1 ]; do
 
       echo "Waiting for /dev/sda1 to become available..."
    # Check if the device path exists
     if [ ! -b "$DEVICE_PATH" ]; then
      echo "Error: Device path $DEVICE_PATH does not exist."
      exit 1
    fi
 
    # Check if the drive is already mounted
    if ${pkgs.util-linux}/bin/mountpoint -q "$MOUNT_POINT"; then
      echo "Drive already mounted at $MOUNT_POINT. Skipping..."
      exit 0
    fi
 
    # Wait for the device to become available
    while [ ! -b "$DEVICE_PATH" ]; do
       echo "Waiting for $DEVICE_PATH to become available..."
       sleep 5
       sleep 5
     done
     done
     ${pkgs.bcachefs-tools}/bin/bcachefs mount -f /etc/keyfile_test /dev/sda1 /mnt
 
    # Mount the device
     ${pkgs.bcachefs-tools}/bin/bcachefs mount -f /etc/keyfile_test "$DEVICE_PATH" "$MOUNT_POINT"
   '';
   '';
   serviceConfig = {
   serviceConfig = {