To set up a 4 GB swap file on an Azure Debian 12 virtual machine, follow these steps:

1. Check for Existing Swap

Before creating a new swap file, check if swap space is already enabled:

If nothing is returned, then no swap space is currently active.

2. Create a Swap File

You can create a swap file using the fallocate command:

If fallocate is not available or if you want a more secure way, you can use dd:

This command creates a 4 GB swap file at /swapfile.

3. Secure the Swap File

Set the correct permissions so that only the root user can read and write to the swap file:

4. Set Up the Swap Area

Format the file as swap:

5. Enable the Swap File

Activate the swap file so it can be used immediately:

Verify that the swap is active:

6. Make the Swap Permanent

To ensure that the swap file is used at boot time, add it to the /etc/fstab file:

7. Adjust Swap Settings (Optional)

You can adjust the swappiness value, which defines how often the swap is used. The default value is 60. To change it, edit /etc/sysctl.conf:

Add or change the following line to your preferred swappiness value:

Save and apply the changes:

8. Verify Swap

Finally, check the swap summary to ensure everything is working as expected:

This will display the available swap and RAM on your system. Your 4 GB swap file should be listed here.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.