add swapspace file on ubuntu.

https://askubuntu.com/questions/566745/allocate-swap-after-ubuntu-14-04-lts-installation

----------------------------------------------

40down voteaccepted

First, to create 4,000 MB of swap space:

$ sudo dd if=/dev/zero of=/swapspace bs=1M count=4000
4000+0 records in
4000+0 records out
4194304000 bytes (4.2 GB) copied, 5.92647 s, 708 MB/s

or

$ sudo fallocate -l 4000M /swapspace 

Next turn it into a usable swap file:

$ sudo mkswap /swapspace
Setting up swapspace version 1, size = 4095996 KiB
no label, UUID=7d1895e4-7ccf-42c6-979a-51ebddb49e91

Activate it:

$ sudo swapon /swapspace 

Confirm active swap spaces:

$ cat /proc/swaps
Filename                Type        Size    Used    Priority
/swapspace              file        4095996 0       -1

Next, add the following line to /etc/fstab to activate the new swap at boot:

/swapspace none swap defaults 0 0

See also this wiki page: https://help.ubuntu.com/community/SwapFaq

原文地址:https://www.cnblogs.com/oxspirt/p/8579016.html