Logical Volume Management in Linux?

Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
For eg: this tutorial

I'm unable to continue from here.

From the above output we can see that there is a physical volume (PV) named /dev/sda2 and the PV is a partition of the first disk drive. We can also see that there is a volume group (VG) named centos on this physical volume.

Now we want to add another Hard Disk Drive to increase our volume group. The new HDD will be the second Disk Drive and the device location will be /dev/sdb. To find your newly added drive location, issue the following command.

I'm wondering what're the preriquisites to start a LVM tutorial.

Can you share a step by step guide to use set up LVM and test some cases?

It includes prerequisites as:

Raw disk attached to Linux system

What does this mean? How do I do it in my system? I can't attach a totally new disk as I don't have money for that at the moment.

How do I do it?


I'm on centos in a vmware workstation pro.
 
Last edited:


All you need in order to use lvm is a disk which you can use to setup lvm with, on most Linux distributions the needed packages already installed unless you are running something like Arch or Gentoo or so something similar.
 
All you need in order to use lvm is a disk which you can use to setup lvm with, on most Linux distributions the needed packages already installed unless you are running something like Arch or Gentoo or so something similar.
could you please elaborate? This thing isn't getting inside my head.
Currently, this is the output of various commands that I am entering in my brand new virtual machine. How do I proceed from here?
Code:
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               5v7X0x-FQxK-zDf3-qUTh-IWtV-yEIZ-R429oS

[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c680d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
Your output of "pvdisplay" shows that /dev/sda2 is already a physical volume(pv) part of the volume group(vg) centos. So if you wanted to add more space to the volume group(vg) centos you would have to do the following:
1. Add another disk to your system.
2. Partition the disk with fdisk
3. Create a physical volume(pv) of that disk: pvcreate /dev/sdb1
4. Add that new physical volume(pv) to the volume group(vg) centos: vgextend centos /dev/sdb1
After words you could then extend a logical volume that needs extending.

So in short you need:
1. a partitioned disk.
2. from the disk you create physical volume(pv).
3. from the physical volume you create or extend a volume group(vg): vgcreate/vgextend vgname /dev/sdb1
4. from the volume group you can then create or extend logical volumes:
- lvcreate: lvcreate -n mylv -L 10G centos (When creating a new lv you still have to create a filesystem on it using mkfs.xfs or another filesystem in order to mount and use it)
- lvextend: lvextend -L +5G /dev/vgname/centos -r

That's that give you a better understanding of how it works?
 
i followed this tutorial (completed btw). but I didn't do by partitioning a disk at first. I just created a disk from vmware workstation pro and yet it worked. Do you know why?
 
i followed this tutorial (completed btw). but I didn't do by partitioning a disk at first. I just created a disk from vmware workstation pro and yet it worked. Do you know why?
Yeah I know why, I forgot if add that if you add the whole disk you don't have to partition the disk, the partitioning is in case you have are going to have more partitions on one disk. So you can also just do pvcreate on the disk without partitioning it.
Code:
pvcreate /dev/sdb
vgextend vgname /dev/sdb
 

Staff online


Latest posts

Top