Modern Linux kernels have removed the performance penalty of a swapfile. This means you can simplify your drive partitioning by using a swapfile rather than a dedicated swap partition. If you run multiple versions or copies of Linux, a partition might still be a good idea as each bootable copy (including a USB live system) can use the same swap area. Otherwise, a swapfile is convenient. I like to put it on the root partition after I have set up the drive for a 12 GB root and remainder as home. The process here is from Techie Buzz.
as root:
- Create an empty contiguous swap file ‘dd if=/dev/zero of=/swapfile bs=1048576 count=1000‘ will make a 1GB file
- Make it a swapfile – ‘mkswap /swapfile‘
- Turn it on – ‘swapon /swapfile‘
- add to /etc/fstab ‘/swapfile swap swap defaults 0” to enable on boot
- check with ‘swapon -s‘ to see if it is in use
You should make the swapfile at least as large as your system memory, especially on machines that might be put into a power saving mode that moves memory to the swap to power down. The dd command example copies 1048576 bytes as 1000 blocks (1048576000 total) from ‘dev/zero’ to the swapfile. /dev/zero is a special file that provides as many zero byte values as needed. It seems that ‘bs=2GB count=1’ might work as well, or better, than the example given for a machine with 1GB ram installed. A drawback is that, unless you have a current swapfile, you might get an out of memory error. Double the count for 2 GB if needed.
Post a Comment