+++++++++ lvm configure ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_6_Volume_Group_and_Logical_Volume
http://www.thegeekstuff.com/2010/08/how-to-create-lvm/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##############################################################################
############# Reduce a logical volume in existing LV Group ###################
###########Sahan tested and no data loss happend. But be careful##############
##############################################################################
File system is as bellows
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 4.2G 43G 9% /
tmpfs 927M 0 927M 0% /dev/shm
/dev/sda1 485M 67M 393M 15% /boot
/dev/mapper/VolGroup-lv_home 94G 1.2G 88G 2% /home
## Reduce "/dev/mapper/VolGroup-lv_home" to 20GB
Unmount file system first.
umount /dev/mapper/VolGroup-lv_home
*** fuser -km /dev/mapper/VolGroup-lv_home (Force un mount) ****
fsck -fC /dev/VolGroup/lv_home
resize2fs -p /dev/VolGroup/lv_home 20G
lvreduce -L -68G /dev/VolGroup/lv_home
mount -a
******* Undo changes if not mounting or any error *******
vgcfgrestore -l VolGroup
vgcfgrestore -f /etc/lvm/archive/VolGroup_00000-437102674.vg VolGroup
##############################################################################
############# Extend a logical volume in existing LV Group ###################
###########Sahan tested and no data loss happend. But be careful##############
##############################################################################
Now we can extend "/dev/mapper/VolGroup-lv_root" from +68GB we got from above.
Enter "vgdisplay" command and check "Free PE / Size". This must be 68G now.
lvextend -L+68G /dev/mapper/VolGroup-lv_root
resize2fs /dev/mapper/VolGroup-lv_root
mount -a
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 117G 4.3G 106G 4% /
tmpfs 927M 0 927M 0% /dev/shm
/dev/sda1 485M 67M 393M 15% /boot
/dev/mapper/VolGroup-lv_home 20G 1.2G 18G 7% /home
******* Undo changes if not mounting or any error *******
vgcfgrestore -l VolGroup
vgcfgrestore -f /etc/lvm/archive/VolGroup_00000-437102674.vg VolGroup
###########################################################################################################################################
################################################ LVG Theory and more detail ###############################################################
###########################################################################################################################################
LVM provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes onto which fixed size file systems are created, LVM provides a way to group together disk space into logical volumes which can be easily resized and moved. In addition LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted the administrator can simply add more space without having to move the user files to a different file system. LVM consists of the following components:
Volume Group (VG)
The Volume Group is the high level container which holds one or more logical volumes and physical volumes.
Physical Volume (PV)
A physical volume represents a storage device such as a disk drive or other storage media.
Logical Volume (LV)
A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain a file system.
Physical Extent (PE)
Each physical volume (PV) is divided into equal size blocks known as physical extents.
Logical Extent (LE)
Each logical volume (LV) is divided into equal size blocks called logical extents. Let's suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space in order to function so we allocate three disk partitions /dev/sda1, /dev/sdb1 and /dev/sdb2. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group made up of the three physical volumes. If we run out of space in LogVol001 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.
=========== Getting Information about Logical Volumes ======================
GUI - yum install system-config-lvm
CLI commands - "mount" "vgdisplay" "lvdisplay" "pvdisplay" "pvscan"
=========== Creating new LVM =======================
$ sudo yum intall lvm2(Only if not installed by default)
$ sudo pvcreate /dev/sda6 /dev/sda7
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
$ sudo pvscan
PV /dev/sda6 lvm2 [1.86 GB]
PV /dev/sda7 lvm2 [1.86 GB]
Total: 2 [3.72 GB] / in use: 0 [0 ] / in no VG: 2 [3.72 GB]
In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.
$ sudo vgcreate vol_grp1 /dev/sda6 /dev/sda7
Volume group "vol_grp1" successfully created
Now, everything is ready to create the logical volumes from the volume groups.
lvcreate command creates the logical volumes. Think vol_grp1 is 4TB
Create 2TB >>> lvcreate --name ProjectsBackup --size 2000G vol_grp1
Create 100GB >> lvcreate --name DevServer45 --size 100G vol_grp1
Allocate all remaining >>> lvcreate --name InternalServers --extents 100%FREE vol_grp1
After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.
$ sudo mkfs.ext3 /dev/vol_grp1/ProjectsBackup
We can extend the size of the logical volumes after creating it by using lvextend utility as shown below. The changes the size of the logical volume from 80MB to 100MB.
$ sudo lvextend -L100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 100.00 MB
Logical volume logical_vol1 successfully resized
We can also add additional size to a specific logical volume as shown below.
$ sudo lvextend -L+100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 200.00 MB
Logical volume logical_vol1 successfully resized
=========== Increasing Exsisting LV-Group in new disk /dev/sdb/ =======================
Adding Additional Space to an RHEL 6 Volume Group from the Command Line
Just as with the previous steps to gather information about the current Logical Volume Management configuration of an RHEL 6 system, changing this configuration can be performed both from the command line and from within the graphical volume management tool. In this section we will focus on the use of command line tools.
In the remainder of this chapter we will assume that a new disk has been added to the system and that it is being seen by the operating system as /dev/sdb. We shall also assume that this is a new disk that does not contain any existing partitions. If existing partitions are present they should be backed up and then the partitions deleted from the disk using the fdisk utility.
The first step is to convert this disk into a physical volume. This is achieved using the pvcreate command:
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
With the physical volume created we now need to add it to the volume group (in this case vg_kvmfed11) using the vgextend command:
# vgextend vg_rhel6 /dev/sdb
Volume group "vg_rhel6" successfully extended
The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume. To do this we run the lvextend tool providing the size by which we wish to extend the volume. In this case we want to extend the size of lv_root by 10 GB. Note that we need to provide the path to the logical volume which can be obtained from the lvdisplay command (in this case /dev/vg_rhel6/lv_root):
# lvextend -L+10G /dev/vg_rhel6/lv_root
Extending logical volume lv_root to 23.54 GiB
Logical volume lv_root successfully resized
The last step in the process is to resize the file system residing on the logical volume so that it uses the additional space. Since we are assuming a default RHEL 6 installation here this can be achieved using the resize2fs command:
# resize2fs /dev/vg_rhel6/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_rhel6/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_rhel6/lv_root to 6170624 (4k) blocks.
The filesystem on /dev/vg_rhel6/lv_root is now 6170624 blocks long.
Once the resize completes the file system will have been extended to use the additional space provided by the new disk drive. All this has been achieved without moving a single file or even having to restart the server. As far as any users on the system are concerned nothing has changed (except, of course, that there is now more disk space).
=========== Decresing Exsisting LV-Group in new disk /dev/sdb/ =======================
Example to shrink from 5 GB file system to say 3GB.
You need less than 3GB of data for this to work.
If you have free space in lvm partition data lose ***might not**** will happen(better have a backup).
Unmount file system first.
fsck -fC /dev/VolGroup00/LogVol00
resize2fs -p /dev/VolGroup00/LogVol00 3G
now reduce the logical volume
lvreduce -L -2G /dev/VolGroup00/LogVol00
Sahan tested and no data loss happend. But be careful.
http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_6_Volume_Group_and_Logical_Volume
http://www.thegeekstuff.com/2010/08/how-to-create-lvm/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##############################################################################
############# Reduce a logical volume in existing LV Group ###################
###########Sahan tested and no data loss happend. But be careful##############
##############################################################################
File system is as bellows
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 4.2G 43G 9% /
tmpfs 927M 0 927M 0% /dev/shm
/dev/sda1 485M 67M 393M 15% /boot
/dev/mapper/VolGroup-lv_home 94G 1.2G 88G 2% /home
## Reduce "/dev/mapper/VolGroup-lv_home" to 20GB
Unmount file system first.
umount /dev/mapper/VolGroup-lv_home
*** fuser -km /dev/mapper/VolGroup-lv_home (Force un mount) ****
fsck -fC /dev/VolGroup/lv_home
resize2fs -p /dev/VolGroup/lv_home 20G
lvreduce -L -68G /dev/VolGroup/lv_home
mount -a
******* Undo changes if not mounting or any error *******
vgcfgrestore -l VolGroup
vgcfgrestore -f /etc/lvm/archive/VolGroup_00000-437102674.vg VolGroup
##############################################################################
############# Extend a logical volume in existing LV Group ###################
###########Sahan tested and no data loss happend. But be careful##############
##############################################################################
Now we can extend "/dev/mapper/VolGroup-lv_root" from +68GB we got from above.
Enter "vgdisplay" command and check "Free PE / Size". This must be 68G now.
lvextend -L+68G /dev/mapper/VolGroup-lv_root
resize2fs /dev/mapper/VolGroup-lv_root
mount -a
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 117G 4.3G 106G 4% /
tmpfs 927M 0 927M 0% /dev/shm
/dev/sda1 485M 67M 393M 15% /boot
/dev/mapper/VolGroup-lv_home 20G 1.2G 18G 7% /home
******* Undo changes if not mounting or any error *******
vgcfgrestore -l VolGroup
vgcfgrestore -f /etc/lvm/archive/VolGroup_00000-437102674.vg VolGroup
###########################################################################################################################################
################################################ LVG Theory and more detail ###############################################################
###########################################################################################################################################
LVM provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes onto which fixed size file systems are created, LVM provides a way to group together disk space into logical volumes which can be easily resized and moved. In addition LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted the administrator can simply add more space without having to move the user files to a different file system. LVM consists of the following components:
Volume Group (VG)
The Volume Group is the high level container which holds one or more logical volumes and physical volumes.
Physical Volume (PV)
A physical volume represents a storage device such as a disk drive or other storage media.
Logical Volume (LV)
A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain a file system.
Physical Extent (PE)
Each physical volume (PV) is divided into equal size blocks known as physical extents.
Logical Extent (LE)
Each logical volume (LV) is divided into equal size blocks called logical extents. Let's suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space in order to function so we allocate three disk partitions /dev/sda1, /dev/sdb1 and /dev/sdb2. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group made up of the three physical volumes. If we run out of space in LogVol001 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.
=========== Getting Information about Logical Volumes ======================
GUI - yum install system-config-lvm
CLI commands - "mount" "vgdisplay" "lvdisplay" "pvdisplay" "pvscan"
=========== Creating new LVM =======================
$ sudo yum intall lvm2(Only if not installed by default)
$ sudo pvcreate /dev/sda6 /dev/sda7
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
$ sudo pvscan
PV /dev/sda6 lvm2 [1.86 GB]
PV /dev/sda7 lvm2 [1.86 GB]
Total: 2 [3.72 GB] / in use: 0 [0 ] / in no VG: 2 [3.72 GB]
In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.
$ sudo vgcreate vol_grp1 /dev/sda6 /dev/sda7
Volume group "vol_grp1" successfully created
Now, everything is ready to create the logical volumes from the volume groups.
lvcreate command creates the logical volumes. Think vol_grp1 is 4TB
Create 2TB >>> lvcreate --name ProjectsBackup --size 2000G vol_grp1
Create 100GB >> lvcreate --name DevServer45 --size 100G vol_grp1
Allocate all remaining >>> lvcreate --name InternalServers --extents 100%FREE vol_grp1
After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.
$ sudo mkfs.ext3 /dev/vol_grp1/ProjectsBackup
We can extend the size of the logical volumes after creating it by using lvextend utility as shown below. The changes the size of the logical volume from 80MB to 100MB.
$ sudo lvextend -L100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 100.00 MB
Logical volume logical_vol1 successfully resized
We can also add additional size to a specific logical volume as shown below.
$ sudo lvextend -L+100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 200.00 MB
Logical volume logical_vol1 successfully resized
=========== Increasing Exsisting LV-Group in new disk /dev/sdb/ =======================
Adding Additional Space to an RHEL 6 Volume Group from the Command Line
Just as with the previous steps to gather information about the current Logical Volume Management configuration of an RHEL 6 system, changing this configuration can be performed both from the command line and from within the graphical volume management tool. In this section we will focus on the use of command line tools.
In the remainder of this chapter we will assume that a new disk has been added to the system and that it is being seen by the operating system as /dev/sdb. We shall also assume that this is a new disk that does not contain any existing partitions. If existing partitions are present they should be backed up and then the partitions deleted from the disk using the fdisk utility.
The first step is to convert this disk into a physical volume. This is achieved using the pvcreate command:
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
With the physical volume created we now need to add it to the volume group (in this case vg_kvmfed11) using the vgextend command:
# vgextend vg_rhel6 /dev/sdb
Volume group "vg_rhel6" successfully extended
The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume. To do this we run the lvextend tool providing the size by which we wish to extend the volume. In this case we want to extend the size of lv_root by 10 GB. Note that we need to provide the path to the logical volume which can be obtained from the lvdisplay command (in this case /dev/vg_rhel6/lv_root):
# lvextend -L+10G /dev/vg_rhel6/lv_root
Extending logical volume lv_root to 23.54 GiB
Logical volume lv_root successfully resized
The last step in the process is to resize the file system residing on the logical volume so that it uses the additional space. Since we are assuming a default RHEL 6 installation here this can be achieved using the resize2fs command:
# resize2fs /dev/vg_rhel6/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_rhel6/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_rhel6/lv_root to 6170624 (4k) blocks.
The filesystem on /dev/vg_rhel6/lv_root is now 6170624 blocks long.
Once the resize completes the file system will have been extended to use the additional space provided by the new disk drive. All this has been achieved without moving a single file or even having to restart the server. As far as any users on the system are concerned nothing has changed (except, of course, that there is now more disk space).
=========== Decresing Exsisting LV-Group in new disk /dev/sdb/ =======================
Example to shrink from 5 GB file system to say 3GB.
You need less than 3GB of data for this to work.
If you have free space in lvm partition data lose ***might not**** will happen(better have a backup).
Unmount file system first.
fsck -fC /dev/VolGroup00/LogVol00
resize2fs -p /dev/VolGroup00/LogVol00 3G
now reduce the logical volume
lvreduce -L -2G /dev/VolGroup00/LogVol00
Sahan tested and no data loss happend. But be careful.