lvm cheatsheet
16 Mar 2019
There are certain technical things I keep forgetting no matter how many times
I try them, ln
usage, git
parameters and the reason for this post, LVM
.
So, here goes a quick how-to for my future me.
Basics
In order to understand LVM it’s required to grasp its components.
Physical Volume (PV)
A PV is any block device that can be used as storage
Volume Group (VG)
A VG is a group of at least one PV, commonly contains many thought.
Logical Volume (LV)
A LV is a portion (partition) of a VG.
How to set up multiple hard drives as one volume?
Define /dev/sda, /dev/sdb2 and /dev/sdc3 as PVs
$ sudo pvcreate /dev/sda /dev/sdb2 /dev/sdc3
Create a Volume Group (VG) out of three just defined PVs
$ sudo vgcreate vg_name /dev/sda /dev/sdb2 /dev/sdc3
Create a Logical Volume (LV) out of the just defined VG
$ sudo lvcreate -l 100%FREE -n lv_name vg_name
Done!, now it can be formated and mounted as a normal HD, eg:
$ sudo mkfs.ext4 /dev/vg_name/lv_name
$ echo '/dev/vg_name/lv_name /mount_point ext4 defaults 0 0' | sudo tee -a /etc/fstab
$ sudo mount -a
How to mount a previously defined LVM volume
Recreate /dev/ LVM partitions
$ sudo vgchange -ay
Done!, now it can be formated and mounted as a normal HD, eg:
$ sudo mkfs.ext4 /dev/vg_name/lv_name
$ echo '/dev/vg_name/lv_name /mount_point ext4 defaults 0 0' | sudo tee -a /etc/fstab
$ sudo mount -a
That’s it!, I’ll keep adding LVM recipes as I find fit, happy storing, 😊