Using Swap Files Instead Of Swap Partitions

From The Brainwrecked Wiki
Revision as of 21:52, 5 January 2014 by BrainwreckedTech (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The tradition swap space setup in Linux has been to use a partition instead of a file. This was due to the performace penalty of filesystem access overhead. Since kernel version 2.6 this penalty is gone since the kernel now accesses the disk space occupied by the swap file directly.

Creating The Swap File

It's best to do this at install time to get an unfragmented swap file. If you have a temporary place big enough to store your root filesystem and a live Linux environment you can boot from (e.g, Ubuntu Live CD), you can do the following.

cp -av [system-root]/* [backup-location]
rm -rv [system-root]/*

...follow the directions below...

cp -av [backup-location]/* [system-root]

To create the swap file:

dd if=/dev/zero of=[swapfile] bs=1M count=[megabytes]
chmod 600 [swapfile]
mkswap [swapfile]

To use this swap space, add this to /etc/fstab

[swapfile] swap swap defaults 0 0

Hibernation

The Arch wiki has an excellent article on this at https://wiki.archlinux.org/index.php/Uswsusp