Logical Volume is a common way to manage multiple hard drives on Linux especially server. Using LVM, we can use multiple hard disks as one big space. We can easily add more disks to existing Volume Group to get more space without any downtime. So, LVM is an advanced way to manage disks and partitions on Linux system. Any Linux OS supports LVM including Arch Linux.
LVM (Logical Volume Management) on Arch Linux
On this tutorial, I will show you the following topics which you can expand to cover your own needs.
- Create Physical Volume
- Create Volume Group
- Create Logical Volume
First thing first is to backup all your data somewhere. This method could break your existing data and hard disk partitions, so backup is a must. On this tutorial, I am using two virtual disks with 5 GB and 10 GB in size. So lets get started.
A. Create Physical Volume
Open Terminal and login as root
Now we need to list all the connected hard drives on our Arch system.
[root@arch-pc ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
|-sda1 8:1 0 15G 0 part /
`-sda2 8:2 0 4G 0 part /home
sdb 8:16 0 5G 0 disk
sdc 8:32 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
As you can see in red, I have two disks sdb and sdc. I will use the entire disks for LVM layout. The following command is used to create new physical volume with sdb and sdc.
pvcreate /dev/sdb /dev/sdc
[root@arch-pc ~]# pvcreate /dev/sdb /dev/sdc
Physical volume “/dev/sdb” successfully created.
Physical volume “/dev/sdc” successfully created.
Now lets check our new PV with this command
Verify that LVM has registered the new physical volume
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 — 5.00g 5.00g
/dev/sdc lvm2 — 10.00g 10.00g
B. Create Volume Group
We have successfully created a new physical volume on the previous step. Now, we need to create a new volume group. I will use TestVolGroup for my new volume group. We will add /dev/sdb and /dev/sdc to the new volume group.
vgcreate TestVolGroup /dev/sdb /dev/sdc
Volume group “TestVolGroup” successfully created
Now check again using pvs command
PV VG Fmt Attr PSize PFree /dev/sdb TestVolGroup lvm2 a-- 5.00g 5.00g /dev/sdc TestVolGroup lvm2 a-- 10.00g 10.00g
--- Volume group --- VG Name TestVolGroup System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 14.99 GiB PE Size 4.00 MiB Total PE 3838 Alloc PE / Size 0 / 0 Free PE / Size 3838 / 14.99 GiB VG UUID cbo3vN-Zfil-a4hp-mAi7-44Fb-fJXe-pAFecW
C. Create Logical Volume
Now we have a new Volume Group called TestVolGroup with total size approximately 15 GB. Now we can start creating new Logical Volume with any size we want. For example we want to create two logical volumes with 2 GB in size for each logical volume. We will use lvcreate command to create new logical volume.
lvcreate -L 2G -n mydata TestVolGroup lvcreate -L 2G -n myproject TestVolGroup
Logical volume "mydata" created. Logical volume "myproject" created.
Now we can check our new logical volume with lvdisplay command
OK, now we have new logical volumes. We can now mount and format our new logical volume. Thank you for reading this post.