Ubuntu Linux Create and Add Swap File Tutorial
Here's how you can create and add a swap file on Ubuntu Linux:
- Determine the size of the swap file: The recommended size for a swap file is equal to twice the size of your RAM. You can use the following command to determine the size of your RAM:
free -m- Create a swap file: Use the
ddcommand to create a new file with the desired size. Replacewith the size of the swap file you want to create, in MB.
sudo dd if=/dev/zero of=/swapfile bs=1024 count=- Set the correct permissions for the swap file:
sudo chmod 600 /swapfile- Mark the file as a swap file:
sudo mkswap /swapfile- Enable the swap file:
sudo swapon /swapfile- Make the swap file permanent: Add the following line to the
/etc/fstabfile to make the swap file permanent across reboots:
/swapfile none swap defaults 0 0After completing these steps, your swap file should be up and running, and you should be able to see the new swap space when you run the free command.
