Bcachefs: Difference between revisions

From NixOS Wiki
imported>0x4A6F
mNo edit summary
imported>Onny
mNo edit summary
Line 38: Line 38:
Use following Nix expression to generate a ISO installation image with a bcachefs enabled kernel
Use following Nix expression to generate a ISO installation image with a bcachefs enabled kernel


<syntaxhighlight lang="nix">
{{file|iso.nix|nix|<nowiki>
# iso.nix
# This module defines a small NixOS installation CD. It does not
# This module defines a small NixOS installation CD. It does not
# contain any graphical stuff.
# contain any graphical stuff.
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
{
{
   imports = [
   imports = [
     <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
     # Currently fails to build due to ZFS incompatibility with bcachefs
    #<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
    <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix>
   ];
   ];
   boot.supportedFilesystems = [ "bcachefs" ];
   boot.supportedFilesystems = [ "bcachefs" ];
  # kernelPackages already defined in installation-cd-minimal-new-kernel-no-zfs.nix
  boot.kernelPackages = lib.mkOverride 0 pkgs.linuxPackages_testing_bcachefs;
   isoImage.squashfsCompression = "gzip -Xcompression-level 1";
   isoImage.squashfsCompression = "gzip -Xcompression-level 1";
}
}
</syntaxhighlight>
</nowiki>}}


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix
# nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix
</syntaxhighlight>
</syntaxhighlight>

Revision as of 13:40, 14 May 2023

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.

Installation

To enable filesystem support and availability of user-space utils, add following line to the system configuration

/etc/nixos/configuration.nix
boot.supportedFilesystems = [ "bcachefs" ];

Usage

Format and mount a signle device

# bcachefs format /dev/sda
# mount -t bcachefs /dev/sda /mnt

Format drive with encryption enabled, unlock and mount it afterwards. Following bcachefs commands will ask for a password:

# bcachefs format --encrypt /dev/sda
# bcachefs unlock /dev/sda
# mount -t bcachefs /dev/sda /mnt

Create a subvolume of a mounted bcachefs filesystem. The snapshot of the filesystem state is accessible in the directory /mnt/snap1.

# bcachefs subvolume snapshot /mnt /mnt/snap1

Tips and tricks

Generate bcachefs enabled installation media

Use following Nix expression to generate a ISO installation image with a bcachefs enabled kernel

iso.nix
# This module defines a small NixOS installation CD. It does not
# contain any graphical stuff.
{ config, pkgs, lib, ... }:
{
  imports = [
    # Currently fails to build due to ZFS incompatibility with bcachefs
    #&lt;nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix&gt;
    &lt;nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix&gt;
  ];
  boot.supportedFilesystems = [ "bcachefs" ];
  # kernelPackages already defined in installation-cd-minimal-new-kernel-no-zfs.nix
  boot.kernelPackages = lib.mkOverride 0 pkgs.linuxPackages_testing_bcachefs;
  isoImage.squashfsCompression = "gzip -Xcompression-level 1";
}
# nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix