When using a Linode VM, I needed to set up a custom swap configuration. A custom swap means utilizing a Volume Disk outside of the Virtual Machine’s primary storage.

The first step is to create the desired volume, for example, a 20 GB volume.

Second step, configure a newly attached 20 GB Linode volume as swap on Debian 12,

1. Identify the New Volume

First, identify the newly attached volume using the lsblk or fdisk command:

Look for the new volume, which should be something like /dev/sdX (replace X with the actual letter, such as sdb or sdc).

2. Create a Swap Partition

If the new volume is not already partitioned, create a swap partition:

Inside the fdisk interactive prompt:

  • Press n to create a new partition.
  • Press p to make it a primary partition.
  • Press 1 to assign it the first partition number.
  • Press Enter to accept the default first sector.
  • Press Enter again to accept the default last sector (this will use the entire 20 GB).
  • Press t to set the partition type.
  • Enter 82 to set the partition type to Linux swap.
  • Press w to write the changes and exit fdisk.

3. Format the Partition as Swap

Now, format the new partition as swap:

4. Enable the Swap

Enable the swap with the following command:

5. Make Swap Permanent

To ensure the swap is enabled on every boot, edit the /etc/fstab file:

Add the following line to the end of the file:

Replace /dev/sdX1 with the correct partition path for your volume.

6. Verify the Swap

You can verify the swap is working with the swapon or free command:

This should show the newly created swap partition.

Your 20 GB Linode volume is now set up and being used as swap on your Debian 12 server!

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.