Create swap file using dd command

We can create the new swap file using the “dd” command, for example, we are creating the 4GB swap file.

Login into the server as a root user.

dd if=/dev/zero of=/swapfile bs=1024 count=4

Above command will create the /swapfile file with the 4GB size

mkswap /swapfile

swapon –a

Add the entry into the /etc/fstab file

/swapfile swap swap defaults 0 0

About Anant 384 Articles
Senior technical writer