- Login with root user ID
- Using the complete secondary hard disk for LVM partition: fdisk /dev/hdb at the Linux fdisk command prompt,
- press n to create a new disk partition,
- press p to create a primary disk partition,
- press 1 to denote it as 1st disk partition,
- press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,
- press t (will automatically select the only partition – partition 1) to change the default Linux partition type (0×83) to LVM partition type (0x8e),
- press L to list all the currently supported partition type,
- press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
- press p to display the secondary hard disk partition setup.
- press w to write the partition table and exit fdisk.
- Next, this LVM command will create a LVM physical volume (PV) on a regular hard disk or partition:
- create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 16MB:
vgcreate -s 16M vg0 /dev/hdb1
- Create a 400MB logical volume (LV) called lvol0 on volume group vg0:
lvcreate -L 400M -n lvol0 vg0 (this command also creates a softlink /dev/vg0/lvol0 to a corresponding block device file called /dev/mapper/vg0-lvol0).
- Next format logical volume lvol0 to create a supported file system, i.e. EXT3 file system, with 1% reserved block count:
mkfs -t ext3 -m 1 -v /dev/vg0/lvol0
- Create a mount point before mounting the new EXT3 file system:
- 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 check the LVM setup is successfull, the df -h command is used, the output as shown below
/dev/mapper/vg0-lvol0 388M 11M 374M 3% /mnt/vfs
Reference commands for Logical Volume Manager:
To 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.
To list all physical volumes (PV) created for volume group (VG) in the current system.
To dynamically add 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).