Allocate swap after Ubuntu 14.04 LTS installation
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
To answer your question indirectly, you don't need to manage swapfiles yourself. There is a package called swapspace which will dynamically add swap files as needed.
- sudo apt-get install swapspace
Then you are done. Your system will grow and shrink swap space as needed.