Create swap partition without hibernation on existing system

i wanted to create a swap partition on my existing system but don’t know how to do that. what’s the basic difference b/w swap partition and swap file and where can i get a set a commands to execute to get one??

is swap anyway related to sleep and battery issues in sleep mode

A swap partition is ─ as the name says ─ a partition on your drive. This partition does not have any filesystem on it, because the kernel accesses the raw drive blocks. In order to create a swap partition, you’ll need to have the required free space on your drive.

How much exactly you need depends on how much RAM you have, and whether you intend to hibernate ─ i.e. suspend-to-disk ─ or not. If you plan to hibernate the machine, then the recommendation is about twice the size of your RAM, because it’ll need to be able to contain the entire contents of your RAM, plus that which was already in swap to begin with.

A swap file is a special file that resides on your root filesystem. It basically performs the same role as a swap partition, but the difference is that this is a file on a filesystem, and thus, that the kernel must first pass through the filesystem layer in order to locate and open the file.

Once the file is open, the kernel will also access the raw drive blocks in the file, which poses special requirements if you’re using a filesystem like btrfs, because btrfs uses copy-on-write (which re-allocates the blocks used by the file) and compression, and neither are supported for swap files.

Performance-wise, there is very little difference anymore these days, but a swap partition will still perform better. The advantage of a swap file on the other hand is flexibility ─ it is easier to create a bigger swap file than to resize a partition, or to create a swap file when you no longer have room on your drive for an extra partition.

Still, a swap partition bears preference over a swap file, because it’s more robust ─ you don’t have to pass through the filesystem layer, and you don’t have to mess with file attributes.

No, not normally. A sleep state leaves everything in memory, but halts the processor and the drive(s). It doesn’t touch the swap partition or swap file.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.