LVM Basics (Logical Volume Manager)

in #linux7 years ago (edited)

I have been trying to get my head around the basic features of LVM for my LPIC-1 Exam 101. I thought I would share my revision notes with the Steemit community, I have been working with Centos 7.

Physical Volumes


pvdisplay – displays physical volumes

pvcreate – creates a physical volume

lsblk – lists block devices

Begin by using lsblk to show physical devices.

lsblk

In this example, we’ll say sda and sdb are listed. The below command will create a physical volume.

pvcreate /dev/sdb

Next, you want to display the physical volumes to see if it has been created successfully.

pvdisplay

Now you should see the new physical volume 'sdb'.


Volume Groups


vgdisplay – displays volume groups

vgcreate – creates a volume group

Next, you want to display the volume groups to see if it has been created successfully.

vgdisplay

Now you should see the new volume group 'testvg'.


Logical Volumes


lvdisplay – displays logical volumes

lvcreate – creates a logical volume

I ran the below command to create a logical volume called ‘mylv’ which is located in the volume group ‘testvg’. I used the -l 100% to use 100% of the volume group.

lvcreate -l 100%VG -n mylv testvg

Next, you want to display the logical volumes to see if it has been created successfully.

lvdisplay

Now you should see the new volume group 'mylv'.


Creating a filesystem and mounting


The below command will create a file system using ext4 on the logical volume ‘mylv’ that was created previously.

mkfs.ext4 /dev/testvg/mylv

Next, I made a directory to mount the logical volume with the below command.

mkdir /mnt/media

I then mounted the logical volume to /mnt/media

mount /dev/testvg/mylv /mnt/media


Editing fstab


For the volume to automount on reboot you will need to edit fstab.

cd /etc/

vi fstab

Within ‘fstab’ you will need to specify some options regarding the new logical volume and it’s mount point. For this example, I added the below.

/dev/testvg/mylv /mnt/media ext4 defaults 0 0

You can read more about ‘fstab’ at the below link;

https://community.linuxmint.com/tutorial/view/1513

I hope this is of use to some people, it certainly helped me break down the LVM hierarchy and how to create a file system in Linux.

Liam AKA Gadgie

Sort:  

Great post dude @orginalworks should verify this for you.

Thanks dude, much appericated!

yes it is help information

Thank you for taking time to comment, I'm glad you found it useful.

Surely not the best LVM guide, but you've made it so simple to understand.

Congratulations @gadgie! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @gadgie! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.038
BTC 97252.23
ETH 3609.35
USDT 1.00
SBD 3.85