I manage an Ubuntu server part-time in a scientific research laboratory, which has 512G memory and 8G swap space. Recently, we occasionally encounter low-frequency memory shortage, so I plan to expand the swap space. Currently, this server cannot accept any shutdown or accident. I find that they all recommend restarting the device after configuring the swap,
and I'm not sure if I can avoid this
My plan is:
First, find current swap file
$ sudo swapon --show
NAME TYPE SIZE USED PRIO
/swap.img file 8G 7.3G -2
swap off and remove
sudo swapoff /swap.img
sudo rm /swap.img
create new swap file
sudo dd if=/dev/zero of=/swap.img bs=1M count=92160
sudo chmod 600 /swap.img
create swap
sudo mkswap /swap.img
enable swap
sudo swapon /swap.img
# not reboot
Is it ok and safe to do?
/etc/fastb
for if I just add not instead the old swap, or theswapon
will do it automatic – zhang Jun 03 '23 at 14:47/etc/fstab
. – Marco Jun 03 '23 at 14:57/etc/fstab
) (to complete the answer) – popey Jun 03 '23 at 15:33dd
will create a discontinuous file, which won't work for swap. Readman mkswap swapon fstab
. – waltinator Jun 03 '23 at 16:48man swapon
explicitly recommends to create swapfiles withdd
in the "Files with holes" section: "The most portable solution to create a swap file is to use dd(1) and /dev/zero." – Dietmar Feb 15 '24 at 07:58