Nov 07 2008

Additional Swap in File on Linux/Solaris

Published by at 8:31 pm under Linux,Solaris

You need more swap but there’s no more disk space left to create a partition? Here’s a quick and easy fix creating a swap file on the existing filesystem. No reboot needed!

Solaris

[root@solaris]$ mkfile 1024m /export/tmpswap

[root@solaris]$ swap -a /export/tmpswap

[root@solaris]$ swap -l
swapfile              dev       swaplo      blocks         free
/dev/dsk/c1t0d0s1     55,65     8           4160824        4160824
/export/tmpswap       -         8           2097144        ©


Linux

[root@linux]$ dd if=/dev/zero of=tmpswap bs=1024 count=10240
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.528435 seconds, 19.8 MB/s

[root@linux]$ mkswap tmpswap
Setting up swapspace version 1, size = 10481 kB

[root@linux]$ swapon tmpswap

[root@linux]$ swapon -s
Filename           Type            Size           Used         Priority
/dev/hda2          partition       409648         0            -1
/tmp/tmpswap       file            10232          0            -2


Do not use swap files on a personal computer that is configured to “suspend to disk” since it requires a dedicated partition to save the memory content while going to hibernation. This is not a problem on servers.


No responses yet

Comments RSS

Leave a Reply