15.12.2023

How to mount LVM disk on the Debian?

Why we use LVM?

LVM (Logical Volume Manager) is primarily intended for storage pool management and is therefore suitable wherever storage space must be optimally utilized, such as in high-traffic environments and where multiple servers or workloads share a set of disks. It provides flexible storage solutions that are more scalable than conventional physical volumes, allowing administrators to extend the capacity of volume groups without needing to perform additional offline operations on member disks.

Additionally, LVM enables easy disk migration, including adding/removing drives and switching between mirrored or striped RAID configurations. Consequently, its use is advantageous in situations where data storage demand may fluctuate over time or when the need for redundant backup solutions arises (e.g. for disaster recovery purposes). In that instruction we will consider how to mount exist disk to system!

Mounting a disk

First of all, we need to connect physically or virtuality disk to our system and check them by the command below:

lsblk

Screenshot №1 — Check disk

Now we can see printed map info about our disks system with various details, initially we have only vda physical and connect vdb virtual. But what type of disk you choose doesn't matter. Take a look at the last column with name MOUNTPOINTS that literally mean mount on the filesystem. If your disk doesn't display like this or in the filed type you see value none, then install needed utility for our manipulation:

apt install lvm2

Screenshot №2 — Installation

Alright! Not every time system search lvm disk automatically, for manual process we will use command:

vgscan

Additionally, after utility installation we can see disk space through the command with more detailed info about created volume:

lvs

Screenshot №3 — Scan

Go ahead, commonly lvm disk activate automatically, but if in your case that doesn't work properly try to use command:

vgchange -ay /dev/vgb

And also for logical volume we need to type command:

lvchange -ay /dev/vgb/target_disk

Screenshot №4 — Activation

Highlight! You need to change every name of device, virtual group and logical volume for yours. Another one significant step, if you have data with already exist filesystem then you can skip that step. For others in that block we will make filesystem on the raw disk, by the command:

mkfs /dev/vgb/targert_disk

Screenshot №5 — Make filesystem

In the result we can see summary printed info. For temporary connect we can use command mount, for automatic load we will see below. At the first create or use currently existed folder in my case that /mnt/tmp:

mkdir /mnt/tmp

And then mount disk:

mount /dev/vgb/targert_disk /mnt/tmp

For check result of our manipulations type:

lsblk

Screenshot №6 — Mount

Last column indicate our point connection of disk /mnt/tmp! But what if we need to mount automatically disk with startup system? For that in the Debian we can use fstab. That file literally mount all disks contain in them, we just add specified row and system will work. But we need to know some details of disk:

blkid /dev/vgb/targert_disk

They will print UUID of the needed device and filesystem type, we will use them next.

echo 'UUID=34e1e481-6c35-472b-a8f2-97bc4f3190a2 /mnt/tmp ext2 defaults 0 0' >> /etc/fstab

For make sure that all work properly print last row in the file:

tail -n 1

Screenshot №7 — Fstab

Change UUID, folder where you want mount disk, filesystem and leave without changes defaults with 0 0. Command above allow to add entering values in the file.

For update map disk without restarting we will use:

mount -a

Make sure that we do everything right:

lsblk

Screenshot №8 — Mount-point

Also take look at the last column!

 

Mounting LVM disks on Debian involves connecting the disk, scanning for LVM disks, activating volumes, creating filesystems, mounting, and configuring /etc/fstab. These steps ensure efficient utilization and automated mounting at system startup.