16.01.2020 – Linux/Add_swapfile.md

Add swapfile

Adjust the desired size in the dd call. Sometimes it’s suggested that fallocate is used to allocate space for the swapfile, however only by writing the entire file with dd the space is really allocated. Otherwise, you might end up with a swapon: /var/tmp/swapfile: swapon failed: Invalid argument error message.

1
2
3
4
$ sudo dd if=/dev/zero of=/var/tmp/swapfile count=1024 bs=4M
$ sudo chmod 600 /var/tmp/swapfile
$ sudo mkswap /var/tmp/swapfile
$ sudo swapon /var/tmp/swapfile

Also add the following line to /etc/fstab

1
/var/tmp/swapfile	swap	swap	defaults	0	0