- — HOW-TO: Make Windows 7 Boot Faster
- — TWEAK: Filter Unread Emails in Gmail
- — TIP: Linux Virtual Machine Performance Tweaks
- — HOW-TO: Automated TV Series Downloads Using Raspberry-PI
- — FAQ: Mouse Randomly Freezing in Windows 7
- — TWEAK: Make Torrents Download Faster
HOW-TO: Add SWAP space from a file (Linux)
It may often be necessary to add swap space to an existing Linux machine as the application or service hosted demands additional space.
Swap in Linux is an entirely different beast from the /tmp. While Solaris or SunOS treats /tmp and swap as one. Adding swap can be done in two ways:  adding swap from a free partition; or  adding swap from a file. In this how-to, we will add swap from a file. How is this done?
In order to see the swap space and its usage, use "swapon -s" or "cat /proc/swaps" to get more information. The output will be somewhat similar to this:
Filename Type Size Used Priority
/dev/sda1 partition 859436 0 -1
To add swap, follow the directions below:
1. Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.
2. At a shell prompt as root, type the following command with count being equal to the desired block size:
root@host # dd if=/dev/zero of=/PATH/swapfile bs=1024 count=65536
root@host # dd if=/dev/zero of=/PATH/swapfile bs=1024 count=524288
root@host # dd if=/dev/zero of=/PATH/swapfile bs=1024 count=1048576
3. Setup the swap file with the command:
root@host # mkswap /PATH/swapfile
4. To enable the swap file immediately (but not automatically at boot time):
root@host # swapon /PATH/swapfile
After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command "cat /proc/swaps" or free.
To permanently enable the swap file at boot time, edit /etc/fstab to include below line:
/dev/sda1 swap swap defaults 0 0