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?
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:
1 -
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo mkswap /swapfile
sudo swapon /swapfile
To enable it by default after reboot, add this line to /etc/fstab:
/swapfile swap swap defaults 0 0
2 -
sudo dd if=/dev/zero of=/var/swapfile bs=1M count=2048 &&
sudo chmod 600 /var/swapfile &&
sudo mkswap /var/swapfile &&
echo /var/swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab &&
sudo swapon -a
That said, which one is best? swap partition or swap file?
Thank you very much in advance for your time.