Tuesday, April 10, 2012

would like to add more swap space to my Linux system. Can you explain with clear examples on how to increase the swap space?

You can either use a dedicated hard drive partition to add new swap space, or create a swap file on an existing filesystem and use it as swap space.

How much swap space is currently used by the system?

Free command displays the swap space. free -k shows the output in KB.
# free -k
             total       used       free     shared    buffers     cached
Mem:       3082356    2043700    1038656          0      50976    1646268
-/+ buffers/cache:     346456    2735900
Swap:      4192956          0    4192956
Swapon command with option -s, displays the current swap space in KB.
# swapon -s
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       4192956 0       -1
Swapon -s, is same as the following.
# cat /proc/swaps
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       4192956 0       -1

Method 1: Use a Hard Drive Partition for Additional Swap Space

If you have an additional hard disk, (or space available in an existing disk), create a partition using fdisk command. Let us assume that this partition is called /dev/sdc1
Now setup this newly created partition as swap area using the mkswap command as shown below.
# mkswap /dev/sdc1
Enable the swap partition for usage using swapon command as shown below.
# swapon /dev/sdc1
To make this swap space partition available even after the reboot, add the following line to the /etc/fstab file.
# cat /etc/fstab
/dev/sdc1               swap                    swap    defaults        0 0
Verify whether the newly created swap area is available for your use.
# swapon -s
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       4192956 0       -1
/dev/sdc1                       partition       1048568 0       -2

# free -k
             total       used       free     shared    buffers     cached
Mem:       3082356    3022364      59992          0      52056    2646472
-/+ buffers/cache:     323836    2758520
Swap:      5241524          0    5241524
Note: In the output of swapon -s command, the Type column will say “partition” if the swap space is created from a disk partition.

Method 2: Use a File for Additional Swap Space

If you don’t have any additional disks, you can create a file somewhere on your filesystem, and use that file for swap space.
The following dd command example creates a swap file with the name “myswapfile” under /root directory with a size of 1024MB (1GB).
# dd if=/dev/zero of=/root/myswapfile bs=1M count=1024
1024+0 records in
1024+0 records out

# ls -l /root/myswapfile
-rw-r--r--    1 root     root     1073741824 Aug 14 23:47 /root/myswapfile
Change the permission of the swap file so that only root can access it.
# chmod 600 /root/myswapfile
Make this file as a swap file using mkswap command.
# mkswap /root/myswapfile
Setting up swapspace version 1, size = 1073737 kB
Enable the newly created swapfile.
# swapon /root/myswapfile
To make this swap file available as a swap area even after the reboot, add the following line to the /etc/fstab file.
# cat /etc/fstab
/root/myswapfile               swap                    swap    defaults        0 0
Verify whether the newly created swap area is available for your use.
# swapon -s
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       4192956 0       -1
/root/myswapfile                file            1048568 0       -2

# free -k
             total       used       free     shared    buffers     cached
Mem:       3082356    3022364      59992          0      52056    2646472
-/+ buffers/cache:     323836    2758520
Swap:      5241524          0    5241524
Note: In the output of swapon -s command, the Type column will say “file” if the swap space is created from a swap file.
If you don’t want to reboot to verify whether the system takes all the swap space mentioned in the /etc/fstab, you can do the following, which will disable and enable all the swap partition mentioned in the /etc/fstab
# swapoff -a

# swapon -a

How to Mount a Data store in ESX Server ?


You need to use the esxcfg-volume command. It can be used in this way:
  • Execute this command to list the volumes that are detected as snapshots/replicas:

    # esxcfg-volume -l

    The output appears similar to:

    VMFS3 UUID/label: 49d22e2e-996a0dea-b555-001f2960aed8/VMFS_1
    Can mount: Yes
    Can resignature: Yes
    Extent name: naa.60a98000503349394f3450667a744245:1 range: 0 - 97023 (MB)


    Here the Datastore UUID is 49d22e2e-996a0dea-b555-001f2960aed8 and its last label is VMFS_1.

  • To mount the volume without performing a resignaturing of that volume (this volume is unmounted when the ESX host is rebooted), run this command:

    # esxcfg-volume -m

    For example:

    # esxcfg-volume -m "VMFS_1"
    # esxcfg-volume -m "49d22e2e-996a0dea-b555-001f2960aed8"


  • To mount the volume without performing a resignaturing of that volume (this volume is mounted when the ESX host is rebooted), run this command:

    # esxcfg-volume -M


    For example:

    # esxcfg-volume -M "VMFS_1"
    # esxcfg-volume -M "49d22e2e-996a0dea-b555-001f2960aed8"


  • Run this command to resignature the volume (the volume is mounted immediately after the resignature):

    # esxcfg-volume -r

    For example:

    # esxcfg-volume -r "VMFS_1"
    # esxcfg-volume -r "49d22e2e-996a0dea-b555-001f2960aed8"

acm bottom ad