Bcachefs: Difference between revisions
→NixOS installation on bcachefs: Cleanup instruction |
→Automatically mount encrypted device on boot: Simplify and modernize |
||
| (One intermediate revision by the same user not shown) | |||
| Line 36: | Line 36: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# bcachefs format -- | # bcachefs format --encrypted /dev/sda | ||
# bcachefs unlock /dev/sda | # bcachefs unlock /dev/sda | ||
# mount -t bcachefs /dev/sda /mnt | # mount -t bcachefs /dev/sda /mnt | ||
| Line 192: | Line 192: | ||
=== Automatically mount encrypted device on boot === | === 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"> | 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 unlock</code> command and run it on boot using a [[Systemd]] unit:<syntaxhighlight lang="nix">fileSystems."/mnt" = { | ||
device = "/dev/disk/by-uuid/3c0d7d93-3293-49a3-842e-d9ef77576d97"; | |||
fsType = "bcachefs"; | |||
options = [ "nofail" ]; | |||
}; | |||
# Ensure to match the correct systemd unit name which gets created by NixOS | |||
# in the first place. We override the script part. | |||
systemd.services."unlock-bcachefs-mnt" = { | |||
serviceConfig.LoadCredential = [ "bcachefs-mnt:/etc/secret.key" ]; | |||
script = lib.mkForce '' | |||
${lib.getExe' pkgs.keyutils "keyctl"} link @u @s | |||
${config.boot.initrd.systemd.package}/bin/systemd-ask-password --credential=bcachefs-mnt --timeout=0 "enter passphrase for /mnt" | \ | |||
exec ${lib.getExe pkgs.bcachefs-tools} unlock \ | |||
"/dev/disk/by-uuid/3c0d7d93-3293-49a3-842e-d9ef77576d97" | |||
''; | ''; | ||
};</syntaxhighlight>This example unit unlocks the Bcachefs encrypted partition <code>/dev/disk/by-uuid/3c0d7d93-3293-49a3-842e-d9ef77576d97</code> whereas the fstab entry mounts it to the target <code>/mnt</code> by using the key file <code>/etc/secret.key</code>. Ensure that you replace all disk uuid and target file path occurences. | |||
}; | |||
</syntaxhighlight>This example unit | |||
[[Category:Filesystem]] | [[Category:Filesystem]] | ||