unix

How do I create a LVM volume group on a Linux server?

To create a LVM file system on a Linux server, use the procedure listed below.

1. Login as root or run the commands with sudo.

2. Using the whole secondary hard disk for LVM partition:
fdisk /dev/sdb

At the Linux fdisk command prompt,
1. press n to create a new disk partition,
2. press p to create a primary disk partition,
3. press 1 to denote it as 1st disk partition,
4. press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,
5. press t (will automatically select the only partition – partition 1) to change the default Linux partition type (0×83) to LVM partition type (0x8e),
6. press L to list all the currently supported partition type,
7. press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
8. press p to display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/sdb1 in Linux,
9. press w to write the partition table and exit fdisk upon completion.

3. Next, this LVM command will create a LVM physical volume (PV) on a regular hard disk or partition:
pvcreate /dev/sdb1

4. Now, another LVM command to create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 4 MB:
vgcreate -s 4M vg0 /dev/sdb1

NOTE: Make sure you plan the PE size ahead when creating a volume group with vgcreate -s option.

5. Create a 5 GB logical volume (LV) called lvol0 on volume group vg0:
lvcreate -L 5120M -n lvol0 vg0

This lvcreate command will create a softlink /dev/vg0/lvol0 point to a correspondence block device file called /dev/mapper/vg0-lvol0.

6. The Linux LVM setup is almost done. Now is the time to format logical volume lvol0 to create a Red Hat Linux supported file system, i.e. EXT3 file system, with 1% reserved block count:
mkfs -t ext3 -m 1 -v /dev/vg0/lvol0

7. Create a mount point before mounting the new EXT3 file system:
mkdir /mnt/vfs

8. The last step of this LVM tutorial – mount the new EXT3 file system created on logical volume lvol0 of LVM to /mnt/vfs mount point:
mount -t ext3 /dev/vg0/lvol0 /mnt/vfs

To confirm the LVM setup has been completed successfully, the df -h command should display these similar message:

/dev/mapper/vg0-lvol0 388M 11M 374M 3% /mnt/vfs

3 Comments

3 Comments

  1. mesothelioma causes prevention

    December 7, 2010 at 3:20 pm

    you just solved our number 1 question! Thank you for doing work simple.

  2. UGGS Boots

    December 16, 2010 at 7:23 am

    Fantastic write-up, bookmarked for long run referrence

  3. Moncler Jackets

    December 16, 2010 at 2:18 pm

    wonderful post but including some pictures will make it improved.

Leave a Reply

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

To Top