LVM made easy

Every time I need to setup a new template, add a disk or extend one I have to go back to LVM-HOWTO

I’m tired of finding out the bits I need, so I thought I would put in on a note and share

This document is for people with prior LVM experience, not an alternative to LVM-HOWTO and I strongly recommend to use each and every command with caution as they cause data loss beyond recovery

Assuming your Linux distribution supports LVM2

Added a new physical disk called


It we can do this with a few simple steps

After exporting the disk

  1. Initialize physical volume in the on the disk/partition as applicable
  2. Add the physical disk to a volume group and  activating the volume group
  3. Creating a logical volume out of the new volume group
  4. And finally initialize the logical volume and mount it for use

Before I start I usually make sure I got the right disk ID and it not in use using the following commands

[root@mail ~]# fdisk  -l

Part of my ourput contains

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table

I also execute

[root@mail ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
                      9.7G  1.4G  7.8G  16% /
/dev/sda1             99M   30M   65M  32% /boot
tmpfs                 2.0G  4.0K  2.0G   1% /dev/shm

This is to check the disk and make sure the disk I will work on is not in use.

First thing we need to do is create physical volume

1.     Initialize physical volume in the on the disk/partition as applicable

[root@mail ~]#  pvcreate /dev/sdb

Physical volume “/dev/xvdb” successfully created


You may alternatively use

[root@mail ~]#  pvcreate /dev/sdb1

If the disk has a partition and you would like only to add the partition of the disk in a logical volume. However I most of the time prefer the entire disk as I’m working on a SAN environment and they are all iSCSI exports

To show your physical volume

[root@mail ~]# pvscan


[root@mail ~]# pvdisplay /dev/sdb

2.     Add the physical disk to a volume group

Im creating a volume for my mail server and I would use the name “mail-storage-group” for the volume group

[root@mail ~]# vgcreate mail-storage-group /dev/sdb

Volume group “mail-storage-group” successfully created

[root@mail ~]# vgchange -a y mail-storage-group

0 logical volume(s) in volume group “mail-storage-group” now active

To show your volume group you may use

[root@mail ~]# vgscan


[root@mail ~]# vgdisplay mail-storage-group

3.     Creating a logical volume out of the new volume group

We would like to use all available disk space out of “mail-storage-group” to create a logical volume for mail storage called “mail-storage-lv”. We can optionally use part of the disk and extend them later on or even create more logical volume.

[root@mail ~]# lvcreate -l +100%FREE -n mail-storage-lv mail-storage-group

Logical volume “mail-storage-lv” created

to show your logical volume information you may use

[root@mail ~]# lvscan


[root@mail ~]# lvdisplay  mail-storage-group

4.     initialize the logical volume and mount it for use

[root@mail ~]# mkfs.ext3 /dev/mail-storage-group/mail-storage-lv

mke2fs 1.39 (29-May-2006)
Filesystem label=
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


Then can mount it

[root@mail ~]# mount /dev/mail-storage-group/mail-storage-lv  /mnt/

Or to keep it mounted over reboot at an entry to /etc/fstab file with an entry like

“/dev/mail-storage-group/mail-storage-lv /mnt ext3    defaults        1”

The df command shall show something like this

[root@mail ~]# df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00                      10093752   1447664   8125080  16% /
/dev/xvda1              101086     29754     66113  32% /boot
tmpfs                  2097152         4   2097148   1% /dev/shm
/dev/mapper/mail–storage–group-mail–storage–lv 10317112    154236   9638796   2% /mnt

So your new LVM file system is mounted and ready to go

All these commands are tested in redhat, and should work on redhat clones and probably other distributions of linux. Please try it on your own risk

Read more: How to extend an LVM

Tag: LVM, linux, redhat, creating lvm, howto, lvcreate, pvcreate, vgcreate


One thought on “LVM made easy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s