Tuxfreaks

Are you too????

  • Subscribe to RSS

  • Ads
  • Follow Me on twitter

    twitstamp.com
  • Create a SwapFile

    Posted by kranny on October 17th, 2009;This post is viewed 1,901 times

    The famous question i often hear is “Is swap really necessary”

    Well its not really mandatory to have swap.Many people,including me run swapless systems without trouble,so if you really want to go without swap, there’s no real reason not to if you’ve got enough RAM.But if u got anything less than or equal to 1 GB,i would recommend you to have atleast swap of 1-1.5 times of your RAM.the rationale behind the number is simple and it is for hibernation.This article deals with creating swapfile if you forgot to create one during install.

    Create a swapfile in the root directory

    kranny@kranny-desktop$ cd /
    kranny@kranny-desktop$  sudo touch Swapfile
    kranny@kranny-desktop$  sudo chmod 0600 Swapfile
    kranny@kranny-desktop$ dd if=/dev/zero of=/aSwapfile bs=1024 count=1000000

    Well dd  is used to copy a specified number of bytes from an input file to an Output file.Here the dd command copy null characters from the special file “/dev/zero” and copy it to the output file “Swapfile”.The “bs”  specifies  that  the characters are read as BYTES. The “count”  specifies the size in kilobytes.I specified 1 GB here.

    kranny@kranny-desktop:/$ mkswap Swapfile

    It will sphew some Output like
    Setting up swapspace version 1, size = 999996 KiB
    no label, UUID=72b29cd6-xxxx-4edc-xxxx-d684d70f9ae0

    Use the “swapon” command to activate the swap file created.

    kranny@kranny-desktop:/$ swapon /Swapfile

    As a permanent Change Edit the fstab “/etc/fstab” to enable the swap after a reboot.

    kranny@kranny-desktop$ vi /etc/fstab
    Add the following line to the fstab file.
    /Swapfile swap swap defaults 0 0

    you can check your swap usage

    kranny@kranny-dekstop$ free -m

    total       used       free     shared    buffers     cached
    Mem:           939        824        1 14          0         17        583
    -/+ buffers/cache:        324        614
    Swap:          976          130        846

    • Share/Save/Bookmark
    kranny
    1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
    Loading ... Loading ...

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>