by marcuz-apl | 12 Oct 2024
Though Ubuntu uses swapfile, Debian 12 applies swap partition (size: 1 GB). Such a small-sized partition makes non-sense to me, and converting a swap partition to a swapfile in Debian 12.9 involves several steps:
1- Disable the existing swap partition
sudo swapoff -a
2- Remove the swap partition entry from /etc/fstab
Open /etc/fstab with a text editor (e.g., nano or vim) and comment out or remove the line corresponding to your swap partition. This line typically contains swap in the third field.
sudo nano /etc/fstab
Example of a line to comment out:# UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx none swap sw 0 0
3- Create a swap file.
Use the dd command to create a file of the desired size. For example, to create a 2GB swap file:
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
(Replace 2048 with the desired size in MB.)
4- Set appropriate permissions for the swap file
sudo chmod 600 /swapfile
5- Format the swap file as a swap area
sudo mkswap /swapfile
6- Enable the new swap file
sudo swapon /swapfile
7- Add the swap file entry to /etc/fstab for persistence
Open /etc/fstab again and add a new line for the swap file:
/swapfile none swap sw 0 0
8- Verify the new swap configuration
sudo swapon -s
free -h
These commands should now show the swap file in use instead of the old swap partition.
9- Optional: Delete the old swap partition (if desired)
You can use a tool like gparted or fdisk to remove the old swap partition and reclaim the space. Exercise caution when modifying partitions.