How To Create Volume Group And File System With LVM2 In Linux?
LVM, shorts for Logical Volume Management, is available in most modern Linux distributions. If I recall correctly, the disk layout for file systems of Red Hat Enterprise Linux 4 default installation is based on Logical Volume Management.
As the name implies, LVM is a software technique to consolidate a group multiple block devices (hard disk or disk partition) and present them to OS as a single disk volume. In other words, system administrator can build or create a 500GB file system with 2 units of 250GB hard disk.
Another advantage of using LVM implementation is flexibility to perform on-the-fly resize for the file system that built on this virtual disk partition, by adding in more physical hard disks and disk partitions.

A visualized concept diagram of the Linux Logical Volume Manager or LVM
How to create a new volume group (VG) and file system on Logical Volume (LV)?
Base on RHEL4 and LVM2 as the platform, here is the summary of steps to build a new volume group (VG), create a Logical Volume (LV), followed by making new file system on it.
1) Use

2) With reference to lvmdiskscan output, the /dev/sda2 disk partition is not currently used for LVM. However, it might be used by Red Hat.
So, you’ve to verify or confirm which of the non-LVM block devices are not currently used by Red Hat with the df command. For example, this following

3) Now, let say I decides to create the new Volume Group (VG) with two unused SCSI hard disks, /dev/sdh and /dev/sdi. So, let’s use the pvcreate command to initialize these two SCSI hard disks for use by LVM:
The pvcreate command creates the VGDA, shorts of Volume Group Descriptor Area, for LVM to keep track Physical Extent (PE) allocation history, among other things. The initialized hard disk is known as Physical Volume (PV).
4) Now, use vgcreate command to create a new Volume Group called vg7, using the block devices (/dev/sdh and /dev/sdi) initialized by pvcreate command in previous step (you may run
A Volume Group can be thought of a container that house all the PV specified by
The -s option switches specify the physical extent size (PE size) of the volume group. If this is not specifying, the default PE size is 4MB, which is best for most applications.
Take note that the name of VG must not conflict with existing VG. To list existing VG in system, execute
5) Next, we proceed to partition Volume Group into Logical Volume. A file system can only be built on Logical Volume (LV) but not Volume Group (VG). Therefore, at least one LV must be created per VG. For example, this lvcreate command create a 400MB Logical Volume (virtual disk partition) called lvol3 in the Volume Group called vg7:
Similar to VG, the name of LV must not crash with the existing LV in the same VG. Again, this can be verified by executing
6) Now, with the new Logical Volume (lvol3), we can create file system on this virtual disk partition. For example, this mkfs command create the Linux EXT3 file system on Logical Volume /dev/vg7/lvol3, with -m 2 option switch to specify 2% of the file system blocks reserved for super-user.:
The full path of logical volume can be checked by executing
7) Once the mkfs successfully creates EXT3 file system, it’s ready to mount the new file system. First, create a directory as mount point, let say this:
8) Then execute the mount command to mount the new file system to /NewVGMnt:
To verify the mount point, just type

Another advantage of using LVM implementation is flexibility to perform on-the-fly resize for the file system that built on this virtual disk partition, by adding in more physical hard disks and disk partitions.

A visualized concept diagram of the Linux Logical Volume Manager or LVM
How to create a new volume group (VG) and file system on Logical Volume (LV)?
Base on RHEL4 and LVM2 as the platform, here is the summary of steps to build a new volume group (VG), create a Logical Volume (LV), followed by making new file system on it.
As with most Linux commands, the LVM and file system related commands come with number of option switches to extend or overwrite the command default behaviour.
Obviously, this general guide doesn’t cover detail of all option switches. For your own good sake, just vet through the command manual page to see if any of those option switches applicable to your environment.
1) Use
lvmdiskscan to find out how many block devices (hard disks or disk partitions) seen by OS are currently used for LVM:
2) With reference to lvmdiskscan output, the /dev/sda2 disk partition is not currently used for LVM. However, it might be used by Red Hat.
So, you’ve to verify or confirm which of the non-LVM block devices are not currently used by Red Hat with the df command. For example, this following
df -h output clearly indicates that /dev/sda2 and /dev/sda3 are actually mounted as root and boot file system respectively:
3) Now, let say I decides to create the new Volume Group (VG) with two unused SCSI hard disks, /dev/sdh and /dev/sdi. So, let’s use the pvcreate command to initialize these two SCSI hard disks for use by LVM:
pvcreate /dev/sdh /dev/sdi
The pvcreate command creates the VGDA, shorts of Volume Group Descriptor Area, for LVM to keep track Physical Extent (PE) allocation history, among other things. The initialized hard disk is known as Physical Volume (PV).
The manual page suggests setting a DOS disk partition to Linux LVM partition type (0x8e) prior to execute pvcreate command. But, why not to keep a standard by explicitly creating or changing non-LVM partition to LVM partition type?
1) To change existing, non-LVM disk partition to LVM partition type (0x8e) by using fdisk command:
2) To use the entire hard disk for LVM, simply proceed with fdisk to create one primary partition to take up whole hard disk space and then set the partition type to 0x8e.
The pvcreate manual page, however, suggest a faster approach by destroying the existing partition table, with this dd command:
dd if=/dev/zero of=/dev/sdi bs=512 count=1
4) Now, use vgcreate command to create a new Volume Group called vg7, using the block devices (/dev/sdh and /dev/sdi) initialized by pvcreate command in previous step (you may run
pvdisplay to see difference of before and after executing vgcreate command):vgcreate -s 16M vg7 /dev/sdh /dev/sdi
A Volume Group can be thought of a container that house all the PV specified by
vgcreate or vgextend command. Conceptually, you should regard Volume Group as a virtual hard disk, as you can see later that it’s possible to “partition” the Volume Group into Logical Volume (LV).The -s option switches specify the physical extent size (PE size) of the volume group. If this is not specifying, the default PE size is 4MB, which is best for most applications.
The maximum number of PE per Logical Volume (LV) is not applicable in LVM2. However, high number of PE could affect LVM tool performance.
As such, set a bigger PE size could effectively reducing number of PE per VG and LV (if the VG is big enough).
Take note that the name of VG must not conflict with existing VG. To list existing VG in system, execute
vgscan5) Next, we proceed to partition Volume Group into Logical Volume. A file system can only be built on Logical Volume (LV) but not Volume Group (VG). Therefore, at least one LV must be created per VG. For example, this lvcreate command create a 400MB Logical Volume (virtual disk partition) called lvol3 in the Volume Group called vg7:
lvcreate -L 400M -n lvol3 vg7
Similar to VG, the name of LV must not crash with the existing LV in the same VG. Again, this can be verified by executing
lvscan
To use all free Physical Extent in Volume Group for Logical Volume, you can use -l option switch to specify the number of PE to create the LV. The number of free PE in Volume Group vg7 can be checked by executingvgdisplay vg7
6) Now, with the new Logical Volume (lvol3), we can create file system on this virtual disk partition. For example, this mkfs command create the Linux EXT3 file system on Logical Volume /dev/vg7/lvol3, with -m 2 option switch to specify 2% of the file system blocks reserved for super-user.:
mkfs -t ext3 -m 2 -v /dev/vg7/lvol3
The full path of logical volume can be checked by executing
lvscan command.7) Once the mkfs successfully creates EXT3 file system, it’s ready to mount the new file system. First, create a directory as mount point, let say this:
mkdir /NewVGMnt
8) Then execute the mount command to mount the new file system to /NewVGMnt:
mount -t ext3 /dev/vg7/lvol3 /mnt/NewVGMnt
To verify the mount point, just type
df -h command to confirm it’s done successfully. To enable Linux automatically mount the new file system during boot-up, include this new file system to /etc/fstab system file.
Custom Search










2010 •
Good straight forward article. I’m amazed how many admins don’t use the -m switch with mkfs.
Excellent. Exactly what I was looking for. Thanks!
Pros work, i like that way …. keep it up and try to put an illustrated installation process
Hello,
Thank you for this article : I was always afraid of using LVM but your article showed it was easy.
thank you again for the good work.
cheers
Hello,
Thank you for this article : I was always afraid of using LVM but your article showed it was easy.
thank you again for the good work.
cheers