In this post I want to show how we can create a new LVM Volume Group (VG) and Logical Volumes (LVs) in Linux.



Initialize physical Volumes (PVs)

Creating a new volume group requires to add disks (block devices) to the volume group as storage. Disks in LVM terminology are so called physical volumes (PVs).

In order to assign a disk (block device) to a volume group, we first need to initialize the disks as LVM physical volumes which will add some LVM metadata to the disks.

The following command initializes our new disks /dev/sdc and /dev/sdd as LVM physical volumes (PVs) which then can be assigned to a volume group.

# pvcreate /dev/sdc /dev/sdd


By executing the pvs command you will get a list of all initialized LVM physical volumes as shown below. The first physical volume /dev/sdb is already assigned to the existing volume group named system_vg.


We can now create our new volume group as shown below.



Create a new Volume Group (VG)

To create a new volume group we can use the vgcreate command. Below I will create a new volume group named data_vg. The vgcreate command needs at least one physical volume and a name.

I will assign both previously created physical volumes to the volume group.

# vgcreate data_vg /dev/sdc /dev/sdd


We can now create new logical volumes (LVs) within this new volume group.



Create new Logical Volumes (LVs)

Logical volumes are partitions which will finally contain the file system and gets mounted on the root file system.

To create a logical volume we can use the lvcreate command as shown below. Here I will create three new logical volumes, named data1, data2 & data3 within my new volume group named data_vg.

# lvcreate  -L 50G -n data1 data_vg
# lvcreate  -L 50G -n data2 data_vg
# lvcreate  -L 50G -n data3 data_vg


So far the logical volume doesn’t contain a file system, therefore we can use for the ext4 file system type the mkfs.ext4 command as shown below.

mkfs.ext2 -> ext2 file system
mkfs.ext3 -> ext3 file system
mkfs.ext4 -> ext4 file system
mkfs.btrfs -> btrfs file system
mkfs.xfs -> xfs file system


# mkfs.ext4 /dev/<volume group>/<logical volume>

# mkfs.ext4 /dev/data_vg/data1
# mkfs.ext4 /dev/data_vg/data2
# mkfs.ext4 /dev/data_vg/data3



Finally we can mount our logical volumes. Therefore I was first creating three new directories named data1, data2 & data3 on the root file system.






Links

How to create a volume group in Linux with LVM
https://www.redhat.com/sysadmin/create-volume-group

Removing Volume Groups
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/vg_remove

Removing Physical Volumes from a Volume Group
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/VG_remove_PV

Removing Physical Volumes
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/pv_remove

Physical Volume Administration
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/5/html/logical_volume_manager_administration/physvol_admin

How to create a physical volume in Linux using LVM
https://www.redhat.com/sysadmin/create-physical-volume?intcmp=701f20000012ngPAAQ

LVM Configuration Examples
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/lvm_examples#LVM_examples