User Tools

Site Tools


os:linux:create_swap_file

Linux - Create Swap File

Short

fallocate -l 1G /swapfile
mkswap /swapfile
swapon /swapfile
vim /etc/fstab
/swapfile       none            swap    sw              0       0

Long

Create File (eg. size 1GB).

root@server:~# fallocate -l 1G /swapfile

Set permissions.

root@server:~# chmod 0600 /swapfile

Set up swap space.

root@server:~# mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=2903a264-5dc1-484c-8e1d-b0b6f687e65a

Activate Swap space.

root@server:~# swapon /swapfile

Edit fstab

root@server:~# vim /etc/fstab

add:

/swapfile       none            swap    sw              0       0

Show Status

swapon --summary

Example.

root@server:~# swapon --summary
Filename                                Type            Size    Used    Priority
/swapfile                               file            3145724 346156  -2
os/linux/create_swap_file.txt · Last modified: 2023-01-27 19:00 by Manuel Frei