Solaris / OpenSolaris Add Swap File

To add a swap file in Solaris or OpenSolaris, follow these steps:

  1. Determine the size of the swap file that you want to create. The size of the swap file should be at least as large as the amount of RAM installed on the system. For example, if you have 1GB of RAM, you may want to create a 1GB swap file.
  2. Create an empty file of the appropriate size using the mkfile command. For example, to create a 1GB swap file called /swapfile, use the following command:
sudo mkfile 1g /swapfile

Note that you will need to run this command as the root user or with sudo privileges.

  1. Use the swap -a command to add the swap file to the system as a swap device. For example:
sudo swap -a /swapfile
  1. Verify that the swap file has been added by running the swap -l command. This command lists all the available swap devices on the system:
sudo swap -l

You should see the new swap file listed in the output.

  1. Make the swap file permanent by adding it to the /etc/vfstab file. Open the /etc/vfstab file in a text editor and add the following line to the end of the file:
/swapfile - - swap - no -

Save and close the /etc/vfstab file.

  1. Finally, activate the new swap file by running the swap -a command again:
sudo swap -a

That’s it! You have added a swap file to your Solaris or OpenSolaris system. The system will now use this swap file as a backup memory pool when the physical memory is exhausted.

Leave a Comment