Live data from Hacker News

Arch Linux Btrfs with hibernation in a swapfile

nwb.sh

31–40 of 45 posts

Re: Arch Linux Btrfs with hibernation in a swapfile

#31

Fwiw I no longer use disk swap files for anything, but ZRAM swap instead. It's mature, it's in the linux kernel, it's faster, and less wearing on SSDs, and RAM is cheap. I don't have a linux laptop though, so don't know how it affects hibernation. Anyone know how/if hibernation works on a laptop using ZRAM swap instead of disk-based swap?

[deleted]

Re: Arch Linux Btrfs with hibernation in a swapfile

#32
post #29

Earlier quoted context omitted.

ZRAM is amazing for cloud VMs which typically have strict disk IOPS limits which means any significant swap usage is going to destroy IO performance or even lock the system. ZRAM w/o swap completely prevents this IO condition and is much faster than disk swap anyway.

Shouldn't a cloud VM have swap disabled by default if it's using networked block storage? It is on AWS at least.

Azure provides what they call "Azure Temporary disk" at typically /dev/sdb for most instance sizes; it's *not encrypted* and it's ephemeral, but is garanteed to be co-located (at least rack-level) with your CPUs.

Re: Arch Linux Btrfs with hibernation in a swapfile

#33
post #29

Earlier quoted context omitted.

ZRAM is amazing for cloud VMs which typically have strict disk IOPS limits which means any significant swap usage is going to destroy IO performance or even lock the system. ZRAM w/o swap completely prevents this IO condition and is much faster than disk swap anyway.

Shouldn't a cloud VM have swap disabled by default if it's using networked block storage? It is on AWS at least.

Linux generally gets very squirrely when it's in a low-memory state. I think it's a bit safer to turn swappiness down and use a small swapfile and/or zram just to keep it from getting completely bricked up. That way you're sacrificing IO for a few seconds/minutes to intervene.

Re: Arch Linux Btrfs with hibernation in a swapfile

#34
post #4

Interesting! I went on a similar journey recently with debian and FDE on luks2, which involved a fair amount of learning and messing around, but I got there. No Btrfs though, just plain old ext4+swap volumes using lvm on luks2, and a small uefi partition. My /boot is encrypted so I enter the LUKS2 passcode before grub can even access its config, and I've rolled an unlock key into the initramfs (which is loaded by gru…

OpenSuse's got a neat patch for grub that copies the password you enter at boot into the initrd. This way you don't need to store a key in your initrd and you don't need to worry about securing those initrd against theft.

https://build.opensuse.org/package/view_file/openSUSE:Factor...

Side note, you can use this same technique to add the LUKS password to the initrd just before doing kexec. This lets you reboot a remote system protected this way without having to pull up a VNC to enter the password.

My script for doing kexec with a preloaded LUKS password is here: https://gist.github.com/webstrand/381307348e24c28d5c4c9a5981...

Re: Arch Linux Btrfs with hibernation in a swapfile

#35

I just did this last week and ran into an issue with LUKS: https://lore.kernel.org/cryptsetup/CAD-Ua_hPjBLHK0cyEz3k7KYB... LUKS wouldn't accept my password, no matter how simple it was. Turns out a BIOS update somehow messed up RAM settings which caused memory errors. And as LUKS needs a lot of memory for some of it's description operations bit flips can cause all of that to fail. That was frustrating!

I feel you. God I wish there was a company taking ownership in building, selling and supporting a batteries-included Desktop Linux distro where all these quality-of-life niceties that are working so well by default on Windows (and MacOS?), would be working out of the box on Linux without any user maintenance or need to read tutorials or wikis, and also be tested together on various hardware combos so that I have assu…

> I love Linux on the server side, but I just don't have time to deal with frustrating bullshit issues caused by this bazaar-engineering on the desktop side, even if it's FOSS. I'd rather pay and have something that works.

Which is fair. As an enthusiast that enjoys nitpicking my config files to make it all work perfectly, I've slowly come to understand people that don't want to do that. Sometimes you just want to get your work done, and it can definitely be frustrating when every utility has a different config file format, some don't even have config files but instead use gconf, some require a restart and some don't, some rely on new libraries that your distro doesn't have yet, every application has a different-looking UI... it can be a frustrating experience if you just want a MacOS or Windows-like experience. And unfortunately that level of simplicity isn't quite a thing yet in the Linux world.

Re: Arch Linux Btrfs with hibernation in a swapfile

#36

Earlier quoted context omitted.

For secureboot you may want to took a look at this project [0]. Don't think it has ever gotten easier to sign UKIs than that though systemd should have a new project (systemd-ukify) that aims to make it more integrated. Hiberation is not supported in lockdown mode because I'm assuming the kernel (maintainers) expect most people to have an unencrypted swap partition. If you have secured your swap, you can patch [1] th…

It is not because of an unencrypted swap partition. It is because, even if it is encrypted, you know the key and can thus replace the image with an arbitrary modified one, or, in theory, with a hacked version of a Windows boot loader, which would break DRM. There were some movements to remove this restriction, on the condition that the encryption key is properly sealed in the TPM and is not extractable.

Except you'd have to know the encryption passphrase to unlock the swap partition. Only after this step can you use the stolen key to manipulate the state of trusted images.

TPM has never been a pre-requisite for secureboot nor kernel_lockdown. Infact the proposal you are speaking of sounds very exclusionary since TPM hardware is still relatively new and not ubiqitous.

Re: Arch Linux Btrfs with hibernation in a swapfile

#37
post #20

Earlier quoted context omitted.

Seems silly to set aside ram to use when your ram runs out. What am I missing here?

You don't set it aside, unused pages just get compressed to save space.

Okay, I think I don't know how swap works on Linux. Is it:

When there's no more ram, swap is used

or

When ram hasn't been used in a while, it is sent to swap

Or maybe a mix of both?

Re: Arch Linux Btrfs with hibernation in a swapfile

#38
As a daily arch user for over a decade I can't help but be that guy; why not just RTFM? Isn't that arch/gentoo's thing? good docs? about 15 seconds of searching turned up all the info.

To be fair, I use a btrfs swapfile on an encrypted/compressed filesystem so I knew what to look for. But still, I find the wiki very reasonable to navigate and nearly always up to date.

https://wiki.archlinux.org/title/installation_guide

https://wiki.archlinux.org/title/Power_management#Suspend_an...

https://wiki.archlinux.org/title/Power_management/Suspend_an...

https://wiki.archlinux.org/title/btrfs#Swap_file

Added note, there is currently a bug in systemd's suspend-then-hibernate behavior (doesn't ever wake up and hibernate). To use it you'll have to downgrade to the arch-provided systemd version 251.7-4.

edit: formatting

Re: Arch Linux Btrfs with hibernation in a swapfile

#39

Earlier quoted context omitted.

It is not because of an unencrypted swap partition. It is because, even if it is encrypted, you know the key and can thus replace the image with an arbitrary modified one, or, in theory, with a hacked version of a Windows boot loader, which would break DRM. There were some movements to remove this restriction, on the condition that the encryption key is properly sealed in the TPM and is not extractable.

Except you'd have to know the encryption passphrase to unlock the swap partition. Only after this step can you use the stolen key to manipulate the state of trusted images. TPM has never been a pre-requisite for secureboot nor kernel_lockdown. Infact the proposal you are speaking of sounds very exclusionary since TPM hardware is still relatively new and not ubiqitous.

Correct. But you do know the passphrase, and, from the viewpoint of Secure Boot and the locked-down kernel, you (the legitimate owner) are also the attacker who tries to run some unapproved kernel-mode code and will stop at nothing in order to do that.

Re: Arch Linux Btrfs with hibernation in a swapfile

#40

As a daily arch user for over a decade I can't help but be that guy; why not just RTFM? Isn't that arch/gentoo's thing? good docs? about 15 seconds of searching turned up all the info. To be fair, I use a btrfs swapfile on an encrypted/compressed filesystem so I knew what to look for. But still, I find the wiki very reasonable to navigate and nearly always up to date. https://wiki.archlinux.org/title/installation_gui…

That's exactly what I did to make all of this work. While the Arch Wiki is the best thing since sliced bread, some things on it are spread out or aren't clear: given some of the sections actually have some talk going on. That was my experience trying to figure out the topic of my blog post. Anyway, I produced the blog post for fun and in hopes it may help someone who is confused or unclear as to why something they do may not be working. I 100% cited those exact wiki articles in my blog post and recommended the reader to go through them prior to doing anything else (especially if the configuration was slightly different, i.e., UEFI vs BIOS). While I agree that RTFM is a good attitude to have, it has too many gate-keeping vibes and can discourage new users from learning the ropes. Some people need a little bit of hand holding to get going before being let loose. I was once that person, and I wanted to share my experience with others. Nonetheless, I still agree with your comment. Just thought I'd clear it up some.
Post reply on HN