Friday, December 11, 2009

Creating a Swap File

To add a swap file:

  1. Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.

  2. At a shell prompt as root, type the following command with count being equal to the desired block size:

    dd if=/dev/zero of=/swapfile bs=1024 count=65536
  3. Setup the swap file with the command:

    mkswap /swapfile
  4. To enable the swap file immediately but not automatically at boot time:

    swapon /swapfile
  5. To enable it at boot time, edit /etc/fstab to include the following entry:

    /swapfile          swap            swap    defaults        0 0

    The next time the system boots, it enables the new swap file.

  6. After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.

Extending Swap on an LVM2 Logical Volume

To extend an LVM2 swap logical volume (assuming /dev/VolGroup00/LogVol01 is the volume you want to extend):

1. Disable swapping for the associated logical volume:

# swapoff -v /dev/VolGroup00/LogVol01

2. Resize the LVM2 logical volume by 256 MB:

# lvm lvresize /dev/VolGroup00/LogVol01 -L +256M

3. Format the new swap space:

# mkswap /dev/VolGroup00/LogVol01

4. Enable the extended logical volume:

# swapon -va

5. Test that the logical volume has been extended properly:

# cat /proc/swaps # free

Thursday, June 11, 2009

Linux to help animals

Active Media Products just released the perfect gift for Linux nerds young and old.

The actual product wasn't made with Linux users in mind. Active Media teamed up with the WWF ( World Wildlife Fund) to make a bunch of USB drives themed after endangered animals. A portion of the proceeds from sales will go to the WWF to help stop cute animals such as Penguin from dying out.

There are four different versions of the Penguin USB drive available; 2GB, 4GB, 8GB, and 16GB versions. The 8GB version will retail for around $26 dollars, and all versions are available right now from Amazon.com and other retailers.


USB - Pen Drive 19
Dog style shape of USB pen drive.

USB - Pen Drive 20
penguin shape of USB pen drive.

USB - Pen Drive 21
Multi-penguin shape of USB pen drive.

USB - Pen Drive 22
Teddy bear shape of USB pen drive.

USB - Pen Drive 23

Tuesday, May 19, 2009

How to Create a swap file in Linux partition

Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

Steps to create swap file

1. Use the "dd" command to create a file.

dd if=/dev/zero of=/aSwapFile bs=1024 count=65536

where dd: - is used to copy a specified number of bytes from an Input file (if) to an Output file (of).
Here the dd command copy null characters from the special file "/dev/zero" and copy it to the output file "aSwapFile" in the "/" directory. The "bs" specifies that the characters are read as BYTES. The "count" specifies the size of the bytes block that is to be created in the output file.

2. Use the "mkswap" command to set up the Linux swap area on the file created.

mkswap /aSwapFile

3. Use the "swapon" command to activate the swap file created.

swapon /aSwapFile

4. Edit the fstab "/etc/fstab" to enable the swap after a reboot.

vi /etc/fstab
(Add the following line to the fstab file.)
/aSwapFile swap swap defaults 0 0