Bcachefs: Difference between revisions
Add keyutils to installation media |
Console4852 (talk | contribs) github issue referenced in wiki is now fixed, so remove note. |
||
(13 intermediate revisions by 5 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 57: | Line 57: | ||
--label=hdd.hdd3 /dev/sde \ | --label=hdd.hdd3 /dev/sde \ | ||
--label=ssd.ssd1 /dev/sdf \ | --label=ssd.ssd1 /dev/sdf \ | ||
--label=ssd.ssd2 /dev/sdg | --label=ssd.ssd2 /dev/sdg \ | ||
--foreground_target=ssd \ | --foreground_target=ssd \ | ||
--promote_target=ssd \ | --promote_target=ssd \ | ||
Line 71: | Line 71: | ||
--label=hdd.hdd3 /dev/sde \ | --label=hdd.hdd3 /dev/sde \ | ||
--label=ssd.ssd1 /dev/sdf \ | --label=ssd.ssd1 /dev/sdf \ | ||
--label=ssd.ssd2 /dev/sdg | --label=ssd.ssd2 /dev/sdg \ | ||
--foreground_target=ssd \ | --foreground_target=ssd \ | ||
--promote_target=ssd \ | --promote_target=ssd \ | ||
Line 82: | Line 82: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# bcachefs subvolume snapshot /mnt /mnt/snap1 | # bcachefs subvolume snapshot /mnt /mnt/snap1 | ||
</syntaxhighlight> | |||
Filesystem check, fix errors and corruptions where a Bcachefs filesystem is on <code>/dev/sda</code>: | |||
<syntaxhighlight lang="console"> | |||
# 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 105: | Line 113: | ||
== Tips and tricks == | == Tips and tricks == | ||
=== NixOS installation on bcachefs === | === NixOS installation on bcachefs === | ||
Line 160: | Line 133: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# mkfs.fat -F 32 -n boot /dev/sda1 | # mkfs.fat -F 32 -n boot /dev/sda1 | ||
# nix shell -p bcachefs-tools | |||
# mkfs.bcachefs -L nixos /dev/sda2 | # mkfs.bcachefs -L nixos /dev/sda2 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Formatting and unlocking the encrypted partition would look like this | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# nix- | # nix-shell -p keyutils --run 'keyctl link @u @s' | ||
# nix-shell -p bcachefs-tools | |||
# bcachefs format --encrypted /dev/sda2 | # bcachefs format --encrypted /dev/sda2 | ||
# bcachefs unlock /dev/sda2 | # bcachefs unlock /dev/sda2 | ||
Line 191: | Line 165: | ||
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]. | ||
=== Remote encrypted disk unlocking === | |||
See article on [[Remote disk unlocking#Bcachefs unlocking|remote disk unlocking]] for a guide on how to enable SSH decryption of Bcachefs enabled systems. | |||
=== Automatically mount encrypted device on boot === | |||
Since the Bcachefs mount options do [https://github.com/koverstreet/bcachefs-tools/pull/266 not support supplying a key file yet], we could use the <code>bcachefs</code> command and run it on boot using a [[Systemd]] unit:<syntaxhighlight lang="nix"> | |||
systemd.services."bcachefs-mount" = { | |||
after = [ "local-fs.target" ]; | |||
wantedBy = [ "multi-user.target" ]; | |||
environment = { | |||
DEVICE_PATH = "/dev/sda1"; | |||
MOUNT_POINT = "/mnt"; | |||
}; | |||
script = '' | |||
#!${pkgs.runtimeShell} -e | |||
{ | ${pkgs.keyutils}/bin/keyctl link @u @s | ||
# 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 | |||
done | |||
=== | # Mount the device | ||
${pkgs.bcachefs-tools}/bin/bcachefs mount -f /etc/keyfile_test "$DEVICE_PATH" "$MOUNT_POINT" | |||
''; | |||
serviceConfig = { | |||
Type = "oneshot"; | |||
User = "root"; | |||
}; | |||
}; | |||
</syntaxhighlight>This example unit mounts the Bcachefs encrypted partition <code>/dev/sda1</code> to the target <code>/mnt</code> by using the key file <code>/etc/keyfile_test</code>. | |||
[[Category:Filesystem]] | [[Category:Filesystem]] |