To add a swap file in Solaris or OpenSolaris, follow these steps:
- 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.
- 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.
- Use the
swap -a
command to add the swap file to the system as a swap device. For example:
sudo swap -a /swapfile
- 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.
- 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.
- 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.