Ady Wicaksono Daily Activities

Archive for November 19th, 2007

Add swap space on linux without restarting linux

without comments

1. Allocate new file for swap, e.g 10 Mbytes

   # dd if=/dev/zero of=/swapfile01 bs=1024 count=10000
     10000+0 records in
     10000+0 records out
   # ls -l /swapfile01
     -rw-r--r--    1 root     root     10240000 Jan 26 17:27 /swapfile01

Now we have /swapfile01 for our swapfile

2. Now setup swaparea first

   # mkswap /swapfile01
     Setting up swapspace version 1, size = 9996 KiB

Check our current swap value

    # free
                total       used       free     shared    buffers     cached
    Mem:        604020     562100      41920          0      34100      42848
    -/+ buffers/cache:     485152     118868
    Swap:      1546056     692200     853856

3. activate our swap

 swapon /swapfile01

Check our current swap value

    # free
                total       used       free     shared    buffers     cached
    Mem:        604020     566796      37224          0      35576      43520
    -/+ buffers/cache:     487700     116320
    Swap:      1556048     691564     864484

Our swap file is increase by 10240000 bytes :)

Anytime we want to deactivate this swap file area, simply run

   swapoff /swapfile01

Written by adywicaksono

November 19, 2007 at 6:02 am

Posted in Linux