unix

How do I set up LVM on my Linux server?

LVM allows users to dynamically extend or shrink Linux “partition” or file system while it is online. The LVM can resize volume groups (VG) that are online by adding new physical volumes (PV) or rejecting those existing PVs attached to the VG.

1. Login to the Linux server as root.

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

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

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

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

NOTE: It is important to plan the PE size before creating a volume group with vgcreate -s option!

6. Create a 400GB logical volume (LV) called lvol0 on volume group vg0:
lvcreate -L 400G -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.

7. 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

8. Create a mount point before mounting the new EXT3 file system:
mkdir /applications

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

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

/dev/mapper/vg0-lvol0 388G 11M 374G 3% /applications

Some of the useful LVM commands reference:

vgdisplay vg0

To check or display volume group setting, such as physical size (PE Size), volume group name (VG name), maximum logical volumes (Max LV), maximum physical volume (Max PV), etc.

pvscan

To check or list all physical volumes (PV) created for volume group (VG) in the current system.

vgextend

To dynamically adding more physical volume (PV), i.e. through new hard disk or disk partition, to an existing volume group (VG) in online mode. You’ll have to manually execute vgextend after pvcreate command that create LVM physical volume (PV).

Click to comment

Leave a Reply

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

To Top