Creating LVM Volume Group

How to create a LVM group from two hard disk partitions is introduced in this post.

Assume we have installed two hard disks /dev/sdb and /dev/sdc to the server, our task now is to create one LVM volume group vg_xen for installing LVM backed Xen DomUs from these two disks. We will do this by several steps: create partitions on the hard disks, initialize disk partitions and create a volume group.

Create partitions on the hard disks

We can use fdisk to create partitions:

# fdisk /dev/sdb

Add a new partition by command: n

Select primary partition by: p

Select partition number 1: 1

Then select from the first section to the last one.

Write table to disk and exit by command: w

We can find out the new partition in /dev/ directory:

$ ls /dev/sd*

We can find:

/dev/sdb1

Follow the same procedure to create partition /dev/sdc1

Initialize disk partitions

Create volume group descriptors at the starts of partitions:

    # pvcreate /dev/sdb1
    # pvcreate /dev/sdc1

Create a volume group

We create LVM volume group vg_xen that contains /dev/sdb1 and /dev/sdc1:

# vgcreate vg_xen /dev/sdb1 /dev/sdc1

Activate the new added volume group

We can activeate it by scan the volume groups:

# vgscan

Add new physical volumes to the volume group

If we installed another hard disk /dev/sdd afterwards, we can create partition /dev/sdd1 on it and initialize it as introduced above. Then we can add the new physical volume to the volume group:

# vgextend vg_xen /dev/sdd1

A more detailed tutorial of extending a LVM volume group can be found here: Extending a LVM Volume Group.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

5 comments:

  1. Dear Zhiqiang Ma,

    I have small doubt, I have created Volume group(vg) and mount the vg(volume group) in /mnt and stored the some file.

    It is possible to move the Vg partition to another server, Please let me know ?

    Thanks for advance.

    BY

    Mike

Leave a Reply

Your email address will not be published. Required fields are marked *