Linux – Swap file automatic loading in Linux

linuxswap-file

How can I get the Swap file to load at boot up time rather than having to load it manually with GParted after each boot up? I have Linux Mint 17.2 Xcfe and Mate and both use the same swap file.

Here is the fdisk -l read out:

Disk /dev/sda: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders, total 312500000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00009462

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   156351532    78174742+  83  Linux
/dev/sda2       156352510   312498175    78072833    5  Extended
/dev/sda5       310667264   312498175      915456   82  Linux swap / Solaris
/dev/sda6       156352512   310667263    77157376   83  Linux

Partition table entries are not in disk order

Thanx so much.

Best Answer

As root in the command line:

echo "/dev/sda5 swap swap defaults 0 0" >> /etc/fstab

To have the change above take effect, run this command (still as root):

swapon -a

Alternatively: You can also open the file /etc/fstab in your favorite text editor (also as root) and add the following line to a new line at the bottom of that file:

/dev/sda5 swap swap defaults 0 0

Explanation

See this documentation on fstab.

Related Question