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:
1 |
lsblk |
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:
1 |
sudo fdisk /dev/sdX |
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 exitfdisk
.
3. Format the Partition as Swap
Now, format the new partition as swap:
1 |
sudo mkswap /dev/sdX1 |
4. Enable the Swap
Enable the swap with the following command:
1 |
sudo swapon /dev/sdX1 |
5. Make Swap Permanent
To ensure the swap is enabled on every boot, edit the /etc/fstab
file:
1 |
sudo nano /etc/fstab |
Add the following line to the end of the file:
1 |
/dev/sdX1 none swap sw 0 0 |
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:
1 2 |
sudo swapon --show free -h |
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!
Reffrence