# Swap file on LUKS partition

**URL:** https://discourse.nixos.org/t/swap-file-on-luks-partition/72234
**Category:** Help
**Created:** [November 17, 2025, 8:42pm UTC](https://discourse.nixos.org/t/swap-file-on-luks-partition/72234 "2025-11-17T20:42:08Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [November 18, 2025, 2:13am UTC](https://discourse.nixos.org/t/swap-file-on-luks-partition/72234/2 "2025-11-18T02:13:24Z")

</div>

This is definitely not expected behavior. Can you keep `dmesg -w` running in a terminal (potentially via ssh) to watch for kernel messages before the freeze happens?

Before you do that, though, to prevent potentially destructive mistakes, are you using btrfs? If so, check for data corruption before continuing to use the system, you can’t simply use a raw swap file on btrfs, you need to specially prepare it: [Swapfile — BTRFS documentation](https://btrfs.readthedocs.io/en/latest/Swapfile.html)

I really disrecommend using swapfiles in general, if you need more swap space just resize your partitions:

> [@Hibernate not working with swapfile](https://discourse.nixos.org/t/hibernate-not-working-with-swapfile/69440/4):
>
> Really, the more I think about this the more I disrecommend using swap files. They’re anything but noob-friendly, inherently cause reproducibility issues, technically less performant due to the possibility of fragmentation, and an inherent data destruction risk with certain file systems. The only benefit is that they’re easy to resize, but that inherently _causes_ the very fragmentation that makes them imperformant, so you should never _actually_ do that (and nobody tells you this…). Plus, this is not the early 2000s, resizing filesystems is quite possible.

---

_[View the full topic](https://discourse.nixos.org/t/swap-file-on-luks-partition/72234)._
