Archive

Posts Tagged ‘vgdisplay’

Logical Volume Manager HOWTO: What is LVM?

November 13th, 2008 1 comment

LVM stands for Logical Volume Manager is most useful method for deploying logical partition rather than physical partition, LVM is a method of allocating hard drive space into logical volumes that can be easily resized instead of partitions.

A physical disk is divided into one or more physical volumes, The Volume Groups are created by combining physical volumes. These volume groups are in turn subdivided into virtual disks called Logical Volumes. The logical volumes may be used just like regular disks with file system created on them and mounted in the Unix/Linux file system tree. The logical volumes can span multiple disks.

Benefits of Logical Volume Management

1. Logical volumes can be easily resized without any downtime or rebooting server.
2. LVM created in conjunction with RAID can provide fault tolerance coupled with scalability and easy disk management.

Drawback of Logical Volume Management

1. LVM cannot be used for the /boot because the boot loader can not read it. If you want to have the root / partition on a logical volume, you will need to create a separate /boot partition with normal ext3 file system type which is not a part of a volume group.
2. The physical volumes can’t be resized.

LVM Configuration

There are two way to configure LVM.

1) While installing fresh OS -
LVM can be configured during the graphical installation of Red Hat Linux You can use the utilities from the lvm package to create your LVM configuration. An overview of the steps required to configure LVM:

• Create physical volumes from the hard drives.
• Create volume groups from the physical volumes.
• Create logical volumes from the volume groups and assign the logical volumes mount points.

2) After OS reinstallation

One of our client want big size of /home partition with LVM support so I am considering /dev/sda7 on first HDD and /dea/sdb1 partition on secondary HDD, I want to combine both HDD space one partition as /home .

To create a LVM, follow following step process.

A. The first step in setting up LVM need to create these physical partitions properly with ‘Linux LVM’ – 0x8e so that they can be recognized by the LVM system. If we’re adding a physical partition. If it is normal ext3 partition please run fdisk command to change file system type and set it as as ‘Linux LVM’ – 0x8e’, you can follow the following steps

Quote:
fdisk /dev/sdb

* Enter p to display the current parttion created on this HDD
* Enter t to change the default Linux partition type ext3 type (0×83) to LVM partition type (0×8e),
* Enter w to write the partition table .

B.The first command pvcreate will “initialize a disk or partition for use by LVM”.

Quote:
# pvcreate /dev/sda7 /dev/sdb1
# pvscan

The above step creates a physical volume from 2 partitions which I want to initialize for inclusion in a volume group.

You can use following command to check various attributes of physical volume(s)

Quote:
#pvdisplay

It will show result like this

Quote:
# pvdisplay
— Physical volume —
PV Name /dev/sda7
VG Name vg
PV Size 423.76 GB / not usable 3.54 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 108481
Free PE 0
Allocated PE 108481
PV UUID cB2G1L-i8w2-Qynm-6p3H-IrEr-1HEZ-dtAtqb

— Physical volume —
PV Name /dev/sdb1
VG Name vg
PV Size 465.76 GB / not usable 1.50 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 119234
Free PE 0
Allocated PE 119234
PV UUID 40WuGe-iHs9-3bNR-22wq-da71-ZmPt-0MeFwu

C.The second command vgcreate create the Volume Group vg with a physical extent size (PE size) of 16M , The default extent size (4 MB) limits the volume to about 256 GB; a size of 1 TB would require extents of atleast 16 MB

Quote:
# vgcreate -s 16M vg1 /dev/sda7 /dev/sdb1

You can use vgdisply command to display volume group information , It will show output like this

Quote:
# vgdisplay
— Volume group —
VG Name vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 889.51 GB
PE Size 4.00 MB
Total PE 227715
Alloc PE / Size 227715 / 889.51 GB
Free PE / Size 0 / 0
VG UUID 6vE0NI-mMP0-mKYr-VB5B-xtjs-gUl0-0YVJ3S

D.Now next step needs to create of one or more “logical volumes” using the volume group which you have created previous step. The following commands create a 50GB logical volume (LV) called lvol0 on volume group vg:

Quote:
# lvcreate -L 50GB -n lvol0 vg
Where –L = LogicalVolumeSize
-n = LogicalVolumeName

The above will create a softlink /dev/vg/lvol0 point to a correspondence block device file called /dev/mapper/vg-lvol0.

You can use lvdisplay command to check the information about a logical volume , It will show output look this

Quote:
# lvdisplay
— Logical volume —
LV Name /dev/vg/lvol0
VG Name vg
LV UUID 63Oepd-akBS-2ISP-6trP-GYpx-f8HS-rfK4iR
LV Write Access read/write
LV Status available
# open 1
LV Size 889.51 GB
Current LE 227715
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

E.The Linux LVM configuration almost done , Now next step to format this logical volume lvol0 with a Linux supported file system, i.e. EXT2 , EXT3 file system etc.., You can use following command to format logical volumes with ext3 journalized ( -j =journaling support) file system .

Quote:
# mke2fs –j /dev/vg/lvol0 ( name of logical volume )

F.Once it formatted use following command to mount the created file system

Quote:
#mount /dev/vg/lvol0 /home

To confirm the LVM setup has been completed successfully, the df -h command should display the output same as below

Quote:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 4.9G 350M 4.3G 8% /
/dev/sda6 2.0G 41M 1.8G 3% /tmp
/dev/sda3 15G 678M 14G 5% /var
/dev/sda2 15G 2.2G 12G 16% /usr
tmpfs 1013M 0 1013M 0% /dev/shm
/dev/mapper/vg-lvol0 876G 199G 669G 23% /home

Also do not forget to add the corresponding line in the /etc/fstab file:
#File: /etc/fstab

Quote:
/dev/mapper/vg-lvol0 /home ext3 defaults 0 0