Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Logical Volumes

To create an LVM logical volume, the physical volumes are combined into a volume
group (VG). This creates a pool of disk space out of which LVM logical volumes (LVs)
can be allocated. This process is analogous to the way in which disks are divided into
partitions. A logical volume is used by file systems and applications (such as databases).

“LVM Logical Volume Components” shows the components of a simple LVM logical


volume:

lvcreate

vgcreate vg01 /dev/sdb /dev/sdc /dev/sdd

pvcreate /dev/sdb /dev/sdc /dev/sdd

LVM Logical Volume Components

CREATING AN LVM LOGICAL VOLUME ON THREE DISKS

This example procedure creates an LVM logical volume called new_logical_volume that


consists of the disks at /dev/sda1, /dev/sdb1, and /dev/sdc1.
1. To use disks in a volume group, label them as LVM physical volumes with
the pvcreate command.
WARNING

This command destroys any data on /dev/sda1, /dev/sdb1, and /dev/sdc1.

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

Physical volume "/dev/sda1" successfully created


Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created

2. Create the volume group that consists of the LVM physical volumes you have
created. The following command creates the volume group new_vol_group.
# vgcreate new_vol_group /dev/sda1 /dev/sdb1 /dev/sdc1

Volume group "new_vol_group" successfully created

3. Create the logical volume from the volume group you have created. The
following command creates the logical volume new_logical_volume from the volume
group new_vol_group. This example creates a logical volume that uses 2 gigabytes of the
volume group.
# lvcreate -L 2G -n new_logical_volume new_vol_group

Logical volume "new_logical_volume" created

4. Create a file system on the logical volume. The following command creates ext4
file system on the logical volume.
# mkfs.xfs /dev/new_vol_group/new_logical_volume

This will destroy any data on /dev/new_vol_group/new_logical_volume.

Are you sure you want to proceed? [y/n] y

The following commands mount the logical volume and report the file system disk space
usage.
# mount /dev/new_vol_group/new_logical_volume /mnt
# df –h

To Monitor the physical, volume group and logical volumes

# pvdisplay
# vgdisplay
# lvdisplay

Extend the volume group


# vgextend vg01 /dev/vdb3
Reducing a Volume Group
# pvmove /dev/vdb3 # move data from disk
# vgreduce vg01 /dev/vdb3

Extend the logical volume online


# lvextend -L +300M /dev/vg01/lv01
# xfs_growfs /mnt/data # for XFS file system
# resize2fs /dev/vg01/lv01 # for EXT4

Removing logical volume

# lvremove /dev/vg01/lv01

# vgremove vg01

# pvremove /dev/vdb2 /dev/vdb1

You might also like