Btrfs and encrypted swap partition--plain-encrypted vs LVM on LUKS?
I'm planning my partition layout and want to use encrypted btrfs for the system partition (btrfs on LUKS) and then an encrypted swap partition (for hibernation). For encrypting the swap partition, my understanding is that there are two ways (since swap file isn't supported by btrfs and other methods involve performance degradation):
- LVM on LUKS, which means I can use the
resumehook for mkinitcpio - plain-encrypted (dm-crypt), which means I can't use
resumehook for mkinitcpio and must use a keyfile + an encrypted boot partition with GRUB
Is this correct and are these the only options available to me? I don't plan on resizing the swap partition so I want to avoid the (negligible) overhead from LVM on LUKS; however, it seems like to just use plain LUKS I need to use a keyfile and place that on a boot partition, which means the boot partition should be encrypted, which means I must use GRUB. Encrypting the boot partition appears to offer very little if not no security benefits since the ESP partition must be unencrypted.
So it seems like I need to decide whether I want the negligible overheard of LVM on LUKS or use GRUB, right? Are there other things that need to be taken account or other options available to me?
P.S. What does the following mean from the Arch Wiki:
The following three methods are alternatives for setting up an encrypted swap for resume-from-disk. If you apply any of them, be aware that critical data swapped out by the system may potentially stay in the swap over a long period (i.e. until it is overwritten). To reduce this risk consider setting up a system job which re-encrypts swap, e.g. each time the system is going into a regular shut-down, along with the method of your choice.
Why is this a concern? Isn't encrypted swap for hibernate decrypted when the rest of the system is decrypted and then encrypted when the rest of the system is encrypted (i.e. via hibernation or shutdown)? Isn't the problem it's describing prevalent on all encrypted disks (or unencrypted disks for that matter) where data is on HDD/SDD unless it's overwritten? I don't really get why there is a need to set a system job to re-encrypt swap.
EDIT: Actually, I can't use the first option since the rest of my system is not LVM on LUKS--it's btrfs on LUKS... this is more complicated than I thought... Is there really no one using btrfs filesystem while also using hibernation?
Edited 7 Nov 2016. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 15 · 100% up
- Kind
- Text
- ID
- 5box4o
24 comments
My Setup is:
I use grub2 in UEFI mode. Works perfect.
besides the flexibility of being able to change the size ratio of swap and btrfs partitions, does lvm provide any other benefits that are not readily available in btrfs?
could btrfs be a drop-in replacement for lvm?
It could. You only need it for swap. If you can live without that you can just go with btrfs on LUKS.
I don't have too much input on which solution would be better for you...I don't ever use hibernate, so I don't set up my systems with that in mind.
However, I wrote an article a year or so ago that completely outlines encrypted btrfs installation that may be of some help to you depending on which choices you make regarding boot and swap. Hope it helps!
My setup is btrfs on LVM on LUKS. LVM contains a single volume group with two logical volumes: one for swap, and the other for btrfs. As /boot is encrypted, I use grub as described here. Hibernation works fine.
I don't use lvm for the swap, nor an encrypted boot nor hibernte/suspend (well used to anyway until arch stopped booting - ( https://www.reddit.com/r/archlinux/comments/5au8fs/cant_boot_after_kernel_update/ ).
Way I see it is that if someone gets physical access to your computer encrypting boot is more or less pointless since they can install all sorts of snooping hw that makes an encrypted boot more or less pointless (anything from hw key loggers to devices that can dump the entire ram somewhere and either retrieve it later or have it upload the image somewhere to send it via radio some where and so on...) and not worth the hassle, no hibernate/suspend since it is/ was a desktop doubling as a plex media server/web server/sftp server/.... on more or less 24/7, power use in idle was quite low and if it is doing something then it can't hibernate/suspend anyway. So again, pretty much pointless.
Basically the main system is/was on a ssd with boot/efi being /dev/sda1, swap (~ 6GB ) plain dm_crypt on /dev/sda2 ( as described in https://wiki.archlinux.org/index.php/Dm-crypt/Swap_encryption ) + one larger (idk ~ 25 GB) with the same settings but the priorities set so that it would only be used or emergencies on a normal hdd just in case and / being btrfs on dm_crypt luks + btrfs on the same ssd (/dev/sda3 or /dev/mapper/main after the encryption) and some 50 gb unpartitioned space on the same ssd for over provisioning (it's a 500GB ssd, I can afford the loss in exchange for better drive performance/life time... besides / is was like ~60 GB)...
All multimedia files are / were on /media which was / is a huge btrfs partition made from 5 3 tb wd red hdds (raid 10 for metadata, data used to be raid 10 too, but since I ran out of space it was converted it do single until I can afford 6 tb wd reds), and vms/second swap on a 750 gb wd blue connected via usb 3 via sata to usb 3 adapter.
The first swap is/was hit very rarely, I think the only time it got any reall use was trying to rund btrfs dedupe on /media without storing the hashes on a disk file instead of ram, the second swap was never hit afaik).
Why are you even considering plain encryption? You should only consider it if you need deniable encryption, in which case you should keep /boot in a thumb drive so that it can be easily discarded. If you don't need deniable encryption, it just makes it a lot easier for you to mess up and make the encryption less secure.
We never plan to do it. It just happens that we some day need it and then you have to move partitions because you don't have LVM. Seriously, just use LVM. You're already encrypting your data, compared to that the LVM overhead is zero (not like it was ever near meaningful without encryption).
Can you explain how plain encryption offers deniable encryption and how other methods such as LVM on LUKS don't?
There is no metadata at all. Everything is passed as a parameter for decryption. I've found a few contradicting sources but I'm pretty sure that even on LUKS with external headers there's still metadata stored in your disk that indicates there's probably encrypted data stored there.
Thing is, there are shortcomings: there is no key derivation done (which means brute forcing gets a lot faster - you need a much longer password for the same security), and LUKS chooses safe parameters automatically for you - meanwhile, plain dm-crypt relies on you entirely to make it safe. And unless you really know what you're doing and have a good reason for using it, it's probably going to end up less secure.
Easy: a LUKS header is quite easy to identify. Plain encrypted data simply looks random and could be anything - maybe garbage.
I kept it simple. LVM is redundant because btrfs does all the same things so no point having another layer of all the same stuff.
rootAnd loop device for swap:
Before anyone says about swap being slow - it does not matter. OP said its for hibernation. I myself have 32 GB of ram and swap is touched pretty much never. Swap file is in
/mnt/swapsubvolume so it is excluded from root filesystem snapshots. Should you wish to move/bootto usb stick - that works flawless as well. Though i must say i did not test hibernation yet. Should go do that now.EDIT: turns out i never set up suspend to disk and it does not work. Reading on archlinux wiki it seems we have to resume from suspended state by pointing kernel to disk where swap file resides and giving physical offset of swap file on that disk. Given nature of btrfs i figured it might be risky therefore i stopped there. Did not investigate ability to resume from loop device. If you come up with something we all would love to hear you out on the subject. There seems to be very little info on subject of this specific setup.
I wouldn't use swap file - it's slow and complicated. Why not simply use a partition? That works fine and is easy to setup...
Agree now there is no limit on partitions with gpt beeing standard.
Because it is less flexible and speed does not matter in my case since swap is pretty much never used.
Dont worry about plain encryption, or even detached LUKS header, as long as you dont need deniability.
If you use the LVM on LUKS method, and place the swap partition on LVM, swap will be encrypted all the time on disk, and decrypted in memory. This is safer than encrypting and overwriting swap at shutdown.
I wouldnt use Grub for decryption, just leave boot unencrypted, it does not contain your personal data.
Can you explain how plain encryption/detached LUKS header is different from overwriting swap in terms of deniability? What makes it superior/inferior in terms of deniability and why is this issue not applicable to plain encryption for the system partition (i.e. why is it specific to swap, if that's the case)?
I might just do without hibernation and stick to btrfs on LUKS, since having btrfs on LVM on LUKS where LVM is only used to allow hibernation with swap seems excessive, given that btrfs can do most of what LVM can do anyway and in many ways better.
The second and the first sentence are not meant to be read in sequence. I edited to make it clearer.
Plenty of options and no LVM needed (if you don't need it otherwise). It mainly depends if you want hibernate. See https://wiki.archlinux.org/index.php/Dm-crypt/Swap_encryption#mkinitcpio_hook for example...
I completely forgot to mention the fact that I want hibernate on the machine, sorry. I mentioned exactly what you've linked (which I've also linked in the OP). Based on reading that, as I understand it (I'm a noob), the only options are the two I highlighted, I believe.
Sorry, didn't notice the link target. But that doesn't mean any of what you mentioned! So, first LVM ist not needed if you don't want to use it for anything else.
But to the second option: it needn't be plain, LUKS is absolutely fine - I'd even say preferred for the comfort and to hibernate you have to keep the content of swap intact anyway. You can use the resume hook (why not? Swap just has to be decrypted before). You needn't use a keyfile, although that is much more comfortable. You can use an encrypted boot partition with GRUB, but you don't have to.
I personally have my new laptop set up with UEFI (secure boot with my own keys), GRUB as bootloader, fully encrypted system (including boot), btrfs root with subvolumes and snapshots and an encrypted swap partition. I use LUKS for root and swap and unlock swap with a hook very similar to the one in the link. Everything works fine...
Based on that, I wonder how I could help you? If you're an absolute noob, you're probably better off with a less complicated setup. If it's just a minor detail you're missing, just ask - for example I could post you my hook for swap if you have problems adapting the example...
Deleted before we saved it.