Difference between revisions of "Creating Swap File"
From PrgmrWiki
m |
(missing chmod) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 5: | Line 5: | ||
# dd if=/dev/zero of=/var/swap2 bs=1024k count=500 | # dd if=/dev/zero of=/var/swap2 bs=1024k count=500 | ||
# chown root:root /var/swap2 | # chown root:root /var/swap2 | ||
− | # chmod | + | # chmod 600 /var/swap2 |
# mkswap /var/swap2 | # mkswap /var/swap2 | ||
# swapon /var/swap2 | # swapon /var/swap2 | ||
</pre> | </pre> | ||
− | To have the swap file | + | To have the swap file used by the kernel after a reboot, add the following to /etc/fstab (its the same as running swapon) |
<pre> | <pre> | ||
/var/swap2 none swap sw 0 0 | /var/swap2 none swap sw 0 0 | ||
</pre> | </pre> | ||
+ | |||
+ | '''To expand existing swap space after memory upgrade:''' | ||
+ | <ul> | ||
+ | <li>Turn off existing swap: <code>swapoff -a</code> | ||
+ | <li>Remove old swap: <code>rm /var/swap</code> | ||
+ | <li>Create new larger swap, in this example we are going from the 500mb above to 1024mb: <code>dd if=/dev/zero of=/var/swap bs=1024k count=1024</code> | ||
+ | <li>Set permissions: <code>chmod 600 /var/swap</code> | ||
+ | <li>Make it swap: <code> mkswap /var/swap</code> | ||
+ | <li>Turn it back on <code>swapon -a </code> | ||
+ | <li> run the free command to confirm its there with the size you want. | ||
+ | </ul> | ||
+ | |||
+ | |||
+ | [[Category:for Users]] | ||
+ | [[Category:Getting Started]] |
Latest revision as of 06:56, 31 January 2016
To add a swap file to your vps run the following as root
To add a 500mb swap file change count=500 to another number for a smaller or bigger swap file
# dd if=/dev/zero of=/var/swap2 bs=1024k count=500 # chown root:root /var/swap2 # chmod 600 /var/swap2 # mkswap /var/swap2 # swapon /var/swap2
To have the swap file used by the kernel after a reboot, add the following to /etc/fstab (its the same as running swapon)
/var/swap2 none swap sw 0 0
To expand existing swap space after memory upgrade:
- Turn off existing swap:
swapoff -a
- Remove old swap:
rm /var/swap
- Create new larger swap, in this example we are going from the 500mb above to 1024mb:
dd if=/dev/zero of=/var/swap bs=1024k count=1024
- Set permissions:
chmod 600 /var/swap
- Make it swap:
mkswap /var/swap
- Turn it back on
swapon -a
- run the free command to confirm its there with the size you want.