Pages

Showing posts with label SWAP. Show all posts
Showing posts with label SWAP. Show all posts

Sunday, July 9, 2017

Extending SWAP

Example HTML page
Swap extension in linux can be done in two ways.

a) By creating a file
b) By creating a disk

We will see the steps for both the methods.

a) By creating a disk

a.1 Extend SWAP with the existing LVM

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

(i) Disable swap for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01

(ii) Resize the LVM2 logical volume by 256 MB:
# lvresize /dev/VolGroup00/LogVol01 -L +256M

(iii) Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01

(iv) Enable the extended logical volume:
# swapon -va

(v) Test that the logical volume has been extended properly:
# cat /proc/swaps # free

a.2  Extend SWAP by Creating a new LVM

To add a swap volume group (assuming /dev/VolGroup00/LogVol02 is the swap volume you want to add):

(i) Create the LVM2 logical volume of size 256 MB:
# lvm lvcreate VolGroup00 -n LogVol02 -L 256M

(ii) Format the new swap space:
# mkswap /dev/VolGroup00/LogVol02

(iii) Add the following entry to the /etc/fstab file:
/dev/VolGroup00/LogVol02   swap     swap    defaults     0 0

# swapon -va
Test that the logical volume has been extended properly. Above command will enable the extended logical volume:

# cat /proc/swaps # free

b) By creating a Swap File

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.

(i) dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:

(ii) mkswap /swapfile
To enable the swap file immediately but not automatically at boot time:

(iii) swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:

/swapfile          swap            swap    defaults        0 0