Creating a Swap Partition in AWS/EC2
<p>I have a t2.micro Ubuntu Server 1GB RAM and 30GB Hard Drive (HD). I am in need to take 2GB out of the 30GB HD in order to create a Swap partition. Could someone give me a help on how to that? </p>

<p>I have a doubt if whether I should create the swap partition as I asked above or should I create a swap file as shown bellow in item 1 and 2:</p>

<p>1 - </p>

<pre><code>sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo mkswap /swapfile
sudo swapon /swapfile
</code></pre>

<p>To enable it by default after reboot, add this line to /etc/fstab:</p>

<pre><code>/swapfile swap swap defaults 0 0
</code></pre>

<p>2 - </p>

<pre><code>sudo dd if=/dev/zero of=/var/swapfile bs=1M count=2048 &amp;&amp;
sudo chmod 600 /var/swapfile &amp;&amp;
sudo mkswap /var/swapfile &amp;&amp;
echo /var/swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab &amp;&amp;
sudo swapon -a
</code></pre>

<p>That said, which one is best? swap partition or swap file?</p>

<p>Thank you very much in advance for your time.</p>