LVM

Manipulating LVM Swap Space

1. Extending Swap On LVM

#swapoff -v /dev/LVMName/Volume
#lvresize /dev/LVMName/Volume -L +Size_in_Megs

Format Extended Volume to Swap Filesystem
#mkswap /dev/LVMName/Volume
Enable Swap Sapce
#swapon -va

2. Creating LVM For Swap Space
#lvcreate VolGroupName -n Swap_Volume_Name -L Size_in _Megs
Format to Swap File System
#mkswap /dev/LVMName/Swap_Volume_Name
Appropriate name entry in /etc/fstab for permanent mounting
Enable swap space
#swapon -va

3. Creating a Swap File
#/sbin/fdisk /dev/sd? # prompt appears and following command need to execute on that prompt
>n # To create New Partition and select no. of partition say 1 2 or 3 if primary or 5 6 ... on
#if extended along with size of swap space required
>t # Asks for partition id, by default it is 83 for ext3. Change it to 82 i.e. for swap space
>p # Confirm new partition table
>w # Write necessary and commit changes
Kernel may not be aware of changes done by you so make sure changes are updated or not
#/sbin/fdisk -l
if changes are not appeared then either reboot your machine or run following command
#partprobe /dev/sd?
#mkswap /dev/sd??
if everything is running properly then update /etc/fstab file to mount file system permanently.

4. Alternative way to above procedure
Determine the blocksize of the swap file in megabytes. Multiply it by 1024 to determine the number of blocks
e.g. 256 * 1024 = 262144
# dd if=/dev/zero of=/swapfile bs=1024 count=262144
Make the swap filesystem on swap partition
# mkswap /swapfile
# swapon /swapfile
Update /etc/fstab file

Removing Swap Space

Reducing swap space from 1GB to 512MB on existing LVM
Turned off Swap space
#swapoff -v /dev/Volume_Name/Swap_Volume
Reduce the LVM logical Volume by 512MB
#lvreduce /dev/Volume_Name/Swap_Volume -L -512M
Fromat newly reduced swap space
#mkswap /dev/Volume_Name/Swap_Volume
Turned on the Swap Space
#swapon -va
Verify the changes in swap space
cat /proc/swaps

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options