Credit to @ryanc@infosec.exchange

I just did the graphic

you are viewing a single comment's thread
view the rest of the comments
[–] 25 points 15 hours ago (17 children)

People still use swap partitions instead of swap files?

  • source
  • hideshow 17 child comments
  • [–] 13 points 15 hours ago (5 children)

    This. Swap files on LUKS encrypted partition. Also, the swapspace daemon!

  • source
  • parent
  • hideshow 5 child comments
  • [–] 9 points 14 hours ago (4 children)

    I've seen so many setups where people encrypt their data but forget to encrypt their swap.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 5 points 10 hours ago (3 children)

    what's the problem? it's not like you dump the entire contents of your system's ram to disk any time use hibernate /s

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 10 hours ago (2 children)

    Even without hibernation, data in apps you have open will end up in the swap if your system is ever RAM-constrained.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 7 hours ago (1 child)

    Generally it only happens to programs you keep running in the background and might not use for a long time that also don't have much background activity. For example password managers.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 6 points 15 hours ago (8 children)

    Don't you need swap partitions to be able to use hibernation?

  • source
  • parent
  • hideshow 8 child comments
  • [–] 7 points 15 hours ago (1 child)

    Nope, I hibernate with a swap file and it's in a LUKS partition. Although IIRC that whole setup requires me to use systemd boot.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 7 hours ago

    I do the same and use ugrd. I think dracut would also work.
    You just set the resume kernel parameter to the decrypted memory device with the swapfile offset.
    As long as the initrd attempts a resume after it decrypted all volumes it'll work, and the initrd doesn't even need to understand why and what was resumed from

  • source
  • parent
  • [–] 3 points 12 hours ago* (1 child)

    It's doable with a swap file instead. But some filesystems are more supportive than others.

    For example BTRFS doesn't support swapfiles over multiple devices (so my raid1c3 spanning 3 differently sized disks for example) and also swapfiles must be completely pre-allocated.

    And no matter the filesystem you need to manually tell the kernel device and physical offset for the file via kernel parameters. Which can again be easier on some than on others (also causing the no-multiple-device filesystem problem mentioned above.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 7 hours ago

    btrfs's handling makes sense. The kernel talks to the disk directly, the file is just a pointer for what range it uses, and a placeholder for the filesystem. Something like raid, balancing, cow, all won't work because the kernel doesn't even go through btrfs to change the swap"file".
    If you want a proper file as swapfile, with the corresponding overhead, you can make a regular file and mount it via loopback then use it as a swap device.

  • source
  • parent
  • [–] 2 points 14 hours ago (2 children)

    I don't use hibernation so I'm not sure.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 12 hours ago (1 child)

    that's what trixie's netinst defaults to when i set up new desktops using encrypted lvm.. root and swap volumes inside that, unlocking together at boot. my use doesn't hit swap much, so it's nbd. i just leave it like it is. only where an installer doesn't support encrypted swap partitions do i use a file or ram-based swap instead.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 4 points 11 hours ago

    It's not as bad with LVM since LVM is more flexible. A swap file does still make it easier to change the size as needed though. If you need more swap, you can spin up a new swap file pretty much instantly while the system is running, without having to repartition. You can have both a swap partition and a swap file active at the same time though.

    On systems where the data is encrypted, also encrypting the swap makes sense so I'm glad Debian does that.

  • source
  • parent