How to manage LVM in Linux

Quick How To Guide

Creating dynamic disc

We are going to create three discs on USB drive, each disc will have 512 MB. First verify if we have connected USB drive as /dev/sdc/:

 fdisk -l

If we have USB drive connected as /dev/sdc:

 fdisk /dev/sdc

Command d can remove existing logical volumes on the USB drive.

Enter commands n, p, 1-3, +512M to create 3 logical volumes. For example we create first volume /dev/sdc1:

Command (m for help): p
Command (m for help): n
Partition number (1-3): 1
First sector (34-41943006, default 41940992): 34
Last sector, +sectors or +size{K,M,G,T,P}: +512M
Command (m for help): p
		

Command w saves new partition table and changes can not be undone.

Reload partition table:

 partprobe

Format created discs:

 pvcreate /dev/sdc1
 pvcreate /dev/sdc2
 pvcreate /dev/sdc3

Verify:

 pvdisplay

Create volume group DATA:

 vgcreate DATA /dev/sdc1 /dev/sdc2 /dev/sdc3

To be sure verify group capacity:

 vgdisplay

Create physical volume from 100% of physical volume capacity.

 lvcreate -l +100%FREE -n new_volume DATA

Format the new volume:

 mkfs -t ext3 /dev/DATA/new_volume

Create directory for mount:

 mkdir /mnt/dynamic

Mount the new volume:

 mount /dev/DATA/new_volume /mnt/dynamic

Mount verification:

 df -hT

Mount verification using graphical interface:

 system-config-lvm

Dynamic resize dynamic disk

Create primary logical partition /dev/sdc4, that use the rest of USB drive:

 fdisk /dev/sdc
Command (m for help):n
Command (m for help):4
Command (m for help):p
<enter>
<enter>

Command w saves new partition table and it can not be undone.

Verify partition table:

 partprobe

Add new disk to physical LVL partition:

 pvcreate /dev/sdc4

Verify:

 pvdisplay

Extend volume group:

 vgextend DATA /dev/sdc4

Verify extended volume group:

 vgdisplay

Extend logical volume with 1 GB:

 lvextend -L+1G /dev/DATA/new_volume

Resize size of disk:

 resize2fs /dev/DATA/new_volume

Remount:

 mount -o remount /dev/DATA/new_volume

Verify:

 df -hT

Removing dynamic disc

Unmount logical volume:

 umount /dev/DATA/new_volume

Remove logical volume:

 lvremove /dev/DATA/new_volume

Remove volume group:

 vgremove /dev/DATA

Remove physical volumes:

 pvremove /dev/sdc1
 pvremove /dev/sdc2
 pvremove /dev/sdc3
 pvremove /dev/sdc4

Verification using graphical interface:

 system-config-lvm

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.