©2015 - 2022 Chad’s Technoworks. Disclaimer and Terms of Use

Chad’s TechnoWorks My Journal On Technology

HOW TO ADD SWAP SPACE IN SOLARIS


Quite often when you install a software, it would do a pre-requisite check of the environment and the most common one that you would encounter is the swap space being small for the application to efficiently run. In Solaris, there are several methods to adjust the swap space addressing two types of file system - ufs and zfs. The following are my compilation of steps.


How to add swap file in Solaris UFS

How to remove swap file in Solaris UFS

How to add or resize swap space in Solaris ZFS

 


HOW TO ADD SWAP FILE IN SOLARIS UFS


1. Check current swap usage and size:


# swap -l

swapfile             dev  swaplo blocks   free

/dev/dsk/c0t0d0s1   136,1      16 1040384 1040384

# swap -s

total: 25344k bytes allocated + 5472k reserved = 30816k used, 1331024k available


2. Locate a mount point with disk space for the additional swap file.


oracle>df -k

Filesystem            kbytes    used   avail capacity  Mounted on

/dev/dsk/c0t0d0s0    10326052 10313752       0   100%    /

/proc                      0       0       0     0%    /proc

mnttab                     0       0       0     0%    /etc/mnttab

fd                         0       0       0     0%    /dev/fd

swap                 1325440      40 1325400     1%    /var/run

swap                 1325416      16 1325400     1%    /tmp

/dev/dsk/c0t0d0s3    66099228 10341225 55097011    16%    /space


* In this example, /space has more available disk space.


3. Create a file for use as UNIX swap file.


# mkfile 2048m /space/swapfile


4. Activate the file as a swap file.


# /usr/sbin/swap -a /space/swapfile


5. Verify swap list.


# swap -l

swapfile             dev  swaplo blocks   free

/dev/dsk/c0t0d0s1   136,1      16 1040384 1040384

/space/swapfile       -       16 4194288 4194288

# swap -s

total: 26160k bytes allocated + 5720k reserved = 31880k used, 3422408k available


6. Make the swap file available during reboot by declaring it in

   /etc/vfstab file.

   

# cp vfstab vfstab.bak1

# vi vfstab

"vfstab" 10 lines, 323 characters

#device         device          mount           FS      fsck    mount   mount

#to mount       to fsck         point           type    pass    at boot options

#

/proc           -               /proc           proc    -       no      -

fd              -               /dev/fd         fd      -       no      -

swap            -               /tmp            tmpfs   -       yes     -


/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no -

/dev/dsk/c0t0d0s3 /dev/rdsk/c0t0d0s3 /space ufs 1 yes -

/dev/dsk/c0t0d0s1 -     - swap - no -

/space/swapfile -       - swap - no -




HOW TO REMOVE A SWAP FILE IN SOLARIS UFS


1. Become root.


2. Remove the swap space.


# /usr/sbin/swap -d /space/swapfile

   

3. Edit /etc/vfstab and remove the entry of swap file.


4. Recover the disk space.


# rm /space/swapfile




HOW TO ADD OR RESIZE SWAP SPACE IN SOLARIS ZFS


Note: you must be root to perform the tasks.


1. Check existing swap volume and determin if it is currently in use (free size is lower than total blocks size).


example:

root@s111oem:~# swap -l

swapfile                 dev    swaplo   blocks     free

/dev/zvol/dsk/rpool/swap 285,2         8  4194296  4194296


2. Resize the swap volume.


   If the swap is _not_ in use, proceed to resize existing volume.

   example resize to 12gb:

   root@s111oem:~# zfs get volsize rpool/swap

   NAME        PROPERTY  VALUE  SOURCE

   rpool/swap  volsize   2G     local

   root@s111oem:~# zfs set volsize=12g rpool/swap

   root@s111oem:~# zfs get volsize rpool/swap

   NAME        PROPERTY  VALUE  SOURCE

   rpool/swap  volsize   12G    local

   root@s111oem:~#

   root@s111oem:~# swap -l

   swapfile                 dev    swaplo   blocks     free

   /dev/zvol/dsk/rpool/swap 285,2         8  4194296  4194296

   /dev/zvol/dsk/rpool/swap 285,2   4194312 20971512 20971512

   root@s111oem:~#

   

   If swap is currently in use, proceed to add another swap volume.

   root@s111oem:~# zfs create -V 2G rpool/swap2

   

   now, activate the new swap volume

   root@s111oem:~# swap -a /dev/zvol/dsk/rpool/swap2

   root@s111oem:~# swap -l

   

3. If necessary, reboot the server.

   shutdown -y -g0 -i6

   

   then, verify the swap size:

   root@s111oem:~# swap -l

   swapfile                 dev    swaplo   blocks     free

   /dev/zvol/dsk/rpool/swap 285,2         8 25165816 25165816

   root@s111oem:~#

Information Technology