Bcachefs: Difference between revisions
imported>Onny mNo edit summary |
imported>Onny Update installation media generation to nix flakes |
||
Line 54: | Line 54: | ||
=== Generate bcachefs enabled installation media === | === Generate bcachefs enabled installation media === | ||
Use following Nix expression | Use following Nix [[Flakes|Flake-expression]] to generate a ISO installation image with a bcachefs enabled kernel | ||
< | {{file|flake.nix|nix|<nowiki> | ||
{ | { | ||
description = "Bcachefs enabled installation media"; | |||
inputs.nixos.url = "nixpkgs/23.11-beta"; | |||
outputs = { self, nixos }: { | |||
nixosConfigurations = { | |||
exampleIso = nixos.lib.nixosSystem { | |||
system = "x86_64-linux"; | |||
modules = [ | |||
"${nixos}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" | |||
({ lib, pkgs, ... }: { | |||
boot.supportedFilesystems = [ "bcachefs" ]; | |||
boot.kernelPackages = lib.mkOverride 0 pkgs.linuxPackages_testing_bcachefs; | |||
}) | |||
]; | |||
}; | |||
}; | |||
}; | |||
} | } | ||
</ | </nowiki>}} | ||
The following commands will generate the iso-image which will be available in the directory <code>./result/iso</code> | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# nix | # git init | ||
# git add flake.nix | |||
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 08:51, 23 November 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 single 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
Configuration
Change encryption password for Bcachefs formatted device /dev/sda1
# bcachefs set-passphrase /dev/sda1
Enable zstd compression for device /dev/sda1
/etc/nixos/hardware-configuration.nix
fileSystems."/" =
{ device = "/dev/sda1";
fsType = "bcachefs";
options = [ "compression=zstd" ];
};
Tips and tricks
Generate bcachefs enabled installation media
Use following Nix Flake-expression to generate a ISO installation image with a bcachefs enabled kernel
flake.nix
{
description = "Bcachefs enabled installation media";
inputs.nixos.url = "nixpkgs/23.11-beta";
outputs = { self, nixos }: {
nixosConfigurations = {
exampleIso = nixos.lib.nixosSystem {
system = "x86_64-linux";
modules = [
"${nixos}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
({ lib, pkgs, ... }: {
boot.supportedFilesystems = [ "bcachefs" ];
boot.kernelPackages = lib.mkOverride 0 pkgs.linuxPackages_testing_bcachefs;
})
];
};
};
};
}
The following commands will generate the iso-image which will be available in the directory ./result/iso
# git init
# git add flake.nix
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage
NixOS installation on bcachefs
Using the installation media generated above, continue the installation as usual following the instructions of the NixOS manual.
For a UEFI installation, the partitioning needs to be adjusted as following
# parted /dev/sda -- mklabel gpt
# parted /dev/sda -- mkpart ESP fat32 1MB 512MB
# parted /dev/sda -- set 1 esp on
# parted /dev/sda -- mkpart primary 512MB 100%
Formatting the boot partition /dev/sda1
and the root filesystem /dev/sda2
# mkfs.fat -F 32 -n boot /dev/sda1
# mkfs.bcachefs -L nixos /dev/sda2
In case you want to enable filesystem encryption, there's a workaround for a bug affecting NixOS 23.05. Formatting and unlocking the encrypted partition would look like this
# nix-env -iA nixos.keyutils
# keyctl link @u @s
# bcachefs format --encrypt /dev/sda2
# bcachefs unlock /dev/sda2
Mount filesystems
# mount /dev/sda2 /mnt
# mkdir /mnt/boot
# mount /dev/disk/by-label/boot /mnt/boot
Continue installation as recommended by the NixOS manual.