From SpectLog
Jump to: navigation, search

: swap, swapon, swapoff, mkswap

Create free space for swap

In order to add additional swap, a partition with (type) ID=0x82 should be created by fdisk (or parted).

Note from man mkswap: the Linux kernel does not look at partition Id’s, but many installation scripts will assume that partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions.

Format partition for swap

mkswap /dev/sdX

Enable swap

spapon /dev/sdX

Disable disable

spapoff /dev/sdX

Check currently enabled swaps

All currently configured swap spaces are listed in /proc/swaps file:

cat /proc/swaps
Filename                Type        Size     Used    Priority
/dev/dm-0               partition   10239992 0       -1
/dev/sdaX               partition    7531512 0       -2                       

Persistent configuration

In order to automatically enable swap during boot-time, add it to /etc/fstab as usual (mount point and filesystem type are both swap):

/dev/sdX  swap  swap  defaults  0 0

Alternatively, the common technique to keep /etc/fstab configuration resistant to drive name changes is to use UUID which is based on filesystem deployed on the drive. Get UUID of the swap filesystem:

blkid /dev/sdX
/dev/sdX: UUID="849b6533-bfcb-485c-bda7-556f3eeab5f3" TYPE="swap" 

Replace previously configured line in /etc/fstab by the following:

UUID="849b6533-bfcb-485c-bda7-556f3eeab5f3" swap  swap  defaults  0 0