Open Qubasa opened 5 years ago
Hmm, I'm not sure it's possible that way.
Do you need to be able to suspend-to-disk?
Otherwise you can use swapDevices.*.randomEncryption.enable = true
If you do, you cannot use randomEncryption
. See the ArchWiki
Two of the three approaches they suggest unlock the rootfs and swap using the same key (they are part of the same LUKS volume). But you want to have them separate and even have the key for the swap on the rootfs - I think that'd prevent you from suspending-to-disk, too.
But even if it didn't want to read it from there, we'd have to make sure to get order right and unlock the swap first.
Summary:
What do you want?
Is our swapDevices.*.encrypted
useful/working as it is?
Our script that swapons the device doesn't seem to care about .encrypted
.
That's why you see the behavior you're seeing: https://github.com/NixOS/nixpkgs-channels/blob/nixos-19.03/nixos/modules/config/swap.nix#L190
Yes, suspend to disk was what I was aiming for! There was a stackexchange answer which said it could/ should be done with a separate partition and I think this was also the idea behind the options given by swapDevices.*.encrypted
because you can define a keyfile and a blkDevice so it makes sence to be able to have them separate. I do think suspend to disk will work this way.
To tell the truth I find the current swapDevices.*.encrypted
not very useful / quite misleading with its options. It would be great if the script for swapon could be altered to be able to do that.
@Luis-Hebendanz, I'm fairly certain you have blkDevice and device reversed. If I'm understanding the documentation correctly (and that's how I have mine setup), then device is supposed to be the unencrypted block device (e.g. /dev/mapper/cryptswap
) and the blkDevice is supposed to be the luks encrypted device. I'm having some issues with swapDevices.*.encrypted
myself but my system is at least properly swapping on the proper device.
@gcoakes does suspend to disk work on your machine with an encrypted swap device and decrypting it on boot? Because if so then I will close this issue :)
@Luis-Hebendanz, not with swapDevices.*.encrypted
. Using the settings I described above, my system properly used it as an ecrypted swap device, but it seems to try to decrypt it too late in the boot process to be used for the resume device. Instead I ended up using this workaround. I suspect there is a bug in swapDevices.*.encrypted
.
Hello, I'm a bot and I thank you in the name of the community for opening this issue.
To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.
The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.
If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.
Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.
Why is this closed? Has anyone confirmed that swapDevices.*.encrypted
works as expected? Maybe I did something wrong but I am not able to make it work with a keyFile.
{
swapDevices = [ {
device = "/dev/disk/by-uuid/...ad"; # unlocked device
encrypted = {
enable = true;
blkDev = "/dev/disk/by-uuid/...a2"; # encrypted partition
keyFile = "/keyfile-swap.bin";
label = "swap";
};
} ];
}
Why is this closed? Has anyone confirmed that
swapDevices.*.encrypted
works as expected? Maybe I did something wrong but I am not able to make it work with a keyFile.
Can confirm it still doesn't work. My setup's essentially the same.
{
swapDevices = lib.mkForce [
{
device = "/dev/disk/by-uuid/31183799-..."; # my decrypted partition in /dev/mapper
encrypted = {
enable = true;
keyFile = "/mnt-root/persist/swap.key";
label = "swap";
blkDev = "/dev/disk/by-uuid/b63bf5df-..."; # my encrypted LUKS partition
};
}
];
}
However, mine fails for another reason. It doesn't even seem to mount and open up the encrypted partition. Instead it waits for the blkDev
to "come online" in Nix stage 1, and then fails. Then, it goes to Nix stage 2 where systemd waits for the device
to come online and waits for a minute and a half.
For me, unlocking the swap device works (supposedly even in stage 1, at least no error is reported), and it also ends up activated, but resume does not work. I have the following config:
{
swapDevices = [{
device = "/dev/mapper/cryptswap";
encrypted = {
enable = true;
keyFile = "/mnt-root/root/swap.key"; #Yes, /mnt-root is correct.
label = "cryptswap";
blkDev = "/dev/disk/by-uuid/...";
};
}];
}
Maybe there is a logical error in the lines following https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh#L465 ?
Edit: Indeed cryptswap
's ID_FS_TYPE
is reported as swap
, not swsuspend
as expected in https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh#L466 . Probably therefore the swap partition is not even considered for resume by the stage 1 script.
@wucke13 what would be a way to fix it ? PR and fixing https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh#L465 ? Could you open a PR for this issue ? Or should I give a try at fixing it ? Just changing ID_FS_TYPE
from swsuspend
to swap
or adding an or
clause ?
I have the same problem as the original issue. (using nixos-unstable) it seems that the luks device is not getting unlocked automatically at boot. So in stage 2 nixos is waiting for the swap device to get online and it will eventually boot without the swap partition.
I have the same problem as the original issue. (using nixos-unstable) it seems that the luks device is not getting unlocked automatically at boot. So in stage 2 nixos is waiting for the swap device to get online and it will eventually boot without the swap partition.
I'm having the same issue as well. I just disabled my swap until I figure out how to fix it.
FYI I found one hibernation/resume success on encrypted swap partition in 2022
https://discourse.nixos.org/t/unable-hibernate-with-encrypted-swap/23418/4
Otherwise there seems to be another way through a swap file, on a partition system encrypted with LUKS. And another success here too.
Describe the bug The
swapDevices.*.encrypted
does not work. It tries to swapon the partition containing the luks container instead of the luks container itself.To Reproduce $ fdisk -l
$ lsblk -o name,uuid
$ nixos-rebuild switch
I tried switching the uuids around or having the same uuids in blkDev as in device but with no success.
Metadata