snipt

Ctrl+h for KB shortcuts

Bash

Add swap space/file to running linux server

# Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

# Set up a Linux swap area:
mkswap /swapfile1

# Activate /swapfile1 swap space immediately:
swapon /swapfile1

# To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:
vi /etc/fstab

# Append the following line:
/swapfile1 swap swap defaults 0 0
https://snipt.net/embed/490c637fefc015bb1f86329cee8f5f9a/
/raw/490c637fefc015bb1f86329cee8f5f9a/
490c637fefc015bb1f86329cee8f5f9a
bash
Bash
14
2019-05-25T07:03:47
True
False
False
/api/public/snipt/34121/
add-and-enable-swap-file-to-running-server
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):</span> </span><span id="L-2"><a name="L-2"></a>dd <span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>/swapfile1 <span class="nv">bs</span><span class="o">=</span><span class="m">1024</span> <span class="nv">count</span><span class="o">=</span>524288 </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># Set up a Linux swap area:</span> </span><span id="L-5"><a name="L-5"></a>mkswap /swapfile1 </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="c1"># Activate /swapfile1 swap space immediately:</span> </span><span id="L-8"><a name="L-8"></a>swapon /swapfile1 </span><span id="L-9"><a name="L-9"></a> </span><span id="L-10"><a name="L-10"></a><span class="c1"># To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:</span> </span><span id="L-11"><a name="L-11"></a>vi /etc/fstab </span><span id="L-12"><a name="L-12"></a> </span><span id="L-13"><a name="L-13"></a><span class="c1"># Append the following line:</span> </span><span id="L-14"><a name="L-14"></a>/swapfile1 swap swap defaults <span class="m">0</span> 0 </span></pre></div> </td></tr></table>
bash, linux, memory, server, swap