Sunday, March 4, 2012

Swap Partition in RHEL6


The swap partition is the portion of the hard drive that linux uses as virtual memory when it runs out of physical memory. It's similar to the windows swap file only instead of using an actual file, linux uses a partition on the hard drive instead.

The partition size should typically be twice as much as the amount of memory that your computer has. So, for example, if your computer has 512Mb of ram, you should create a swap partition of at least 1024Mb.

 
Creating Extended Swap Partition of 2GB

First create a Partition of 2GB
#fdisk /dev/sda
Press p   (Than Enter)-----To Show Partition
Press n   (Than Enter)-----To create Partition
Than Enter in  First Cylinder
Than type +2G in Last Cylinder
Then type t and Enter--------To give partition id of swap
Then type partition No. 6 and Enter(we assume that it is 6 partition)
Then type lvm id 82 and Enter
Then type w and Enter (To save the partition)

#reboot (Then reboot the system)

After reboot the system
#mkswap /dev/sda6--------Format swap partition with swap file system
#swapon –a /dev/sda6----To Activate swap partition
#swapon –s------------------Check swap partition
#mkdir /swap----------------Creating a /swap directory
#vim /etc/fstab---------------Mount swap partition in /swap directory

/dev/sda6         /swap   swap    defaults 0 0

:wq
#mount –a
#swapon –s-----------------To check swap partition

To Delete Extended Swap Partition

First delete mount entry of swap partition  in /etc/fstab 
#swapoff /dev/sda6  
#fdisk /dev/sda
Press d (Than Enter)-----To delete a partition sda6
Press 6 (then Enter)-------To give partition No.
Press p (Then Enter)------To show Partition on sda harddisk
Press w(Then Enter)------To save & exit

#reboot-------To reboot the system
#swapon –s----To check swap partition

Sunday, February 26, 2012

Logical Volume Manager (LVM)

Logical Volume Manager also known as LVM, Its provide facility to create partitions flexibly. LVM gives System Administrator, power to extend or reduce the partitions online, means we can extend a logical volume while the data on it is being accessed by the users, without corruption of data.
It is important to understand the basic concept of LVM. There are mainly three steps(points) to create LVM:  

1) Physical Volume:- Actual hard-disk or a partition of disk. 
2) Volume Group :- Group of one or more than one physical Partition(s)
3) .Logical Volume :- Partition created from Volume Group.
To Create a lvm partition below r the following steps:-

Firstly create a normal partition of 2GB & change its partition id of lvm i.e. 8e  like this
#fdisk /dev/sda
     Press p   (Than Enter)-----To Show Partition
     Press n   (Than Enter)-----To create Partition
    Than Enter in  First Cylinder
    Than type +2G in Last Cylinder
    Then type t and Enter--------To give partition id of lvm
    Then type partition No. 6 and Enter(we assume that it is 6 partition)
    Then type lvm id 8e and Enter
    Then type w and Enter (To save the partition)

Then reboot the system
#reboot
After reboot the system

#fdisk –l ----- To check the  Partition
#pvcreate /dev/sda6 ----To create physical volume
#pvdisplay----To check the physical volume
 
#vgcreate vol0 /dev/sda6------To create volume group & name vol0
#vgdisplay------To check volume group

To create 1GB logical volume and name vol1
#lvcreate –L 1024M –n vol1 /dev/vol0
-L is used to define size of Lvm, -n is used to name Logical volume
#lvdisplay-----To check logical volume

To Format Logical Volume
#mkfs.ext4 /dev/vol0/vol1 
To create a lvm directory
#mkdir /lvm
To permanently mount it
#vim /etc/fstab 
------Type below line at last in this File
 /dev/vol0/vol1               /lvm      ext4      defaults 0 0
------& save it with :wq

#mount –a------To mounted partition
To check actual size of lvm partition mounted in /lvm directory
#df –h

 To Extend lvm partition vol1 upto 1300MB

#umount /lvm
#lvextend –L +300M /dev/vol0/vol1
#e2fsck –f /dev/vol0/vol1
#resize2fs /dev/vol0/vol1 1300M
#mount –a
#df –h
#lvdisplay

To reduce lvm partition vol1 of 1GB to 700MB

#umount /lvm
#e2fsck –f /dev/vol0/vol1
#resize2fs /dev/vol0/vol1 700M
#lvreduce –L -300M /dev/vol0/vol1
#mount –a
#df –h
#lvdisplay