Increase Swap file size that already exists (EC 2 linux)

I created swap file doing this:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=4096
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1

I would like to increase to 16GB

I tried running this command

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=16384

but got error:

/bin/dd: failed to open ‘/var/swap.1’: Text file busy

How would I increase swap file size?


Solution 1:

First do sudo /sbin/swapoff /var/swap.1, then run dd and mkswap and swapon as you did before.