Categories
Linux

Logical Volume Creation

In one of my current projects I have to attach a (virtual) disk to a (cloud) server.

Gather information

To get an overview of the system I used this commands:

pvs
pvdisplay

vgs
vgdisplay

lvs
lvdisplay

fdisk -c -l /dev/sdb

Interpretation of information

Physical Volume Partition Volume Group Logical Volumes Size
/dev/sda 107 GB
/dev/sda /dev/sda1 0,5 GB
/dev/sda /dev/sda2 106,5 GB
/dev/sda /dev/sda2 vg00 <99.50g
/dev/sda /dev/sda2 vg00 lv_home 2 GB
/dev/sda /dev/sda2 vg00 lv_usr 2 GB
/dev/sda /dev/sda2 vg00 "free" <76.50g
/dev/sdb 107 GB

Technically it is possible to create a new logical volume inside volume group vg00, because there are > 76,5 GB unassigned and free storage.

But the vg00 is reserved for the Operating System and should not used for data from application.

Therefore the additional disk is needed for applicatin data.

Volume creation

Physical Volume with ~ 100 GB is attached to the server and added as /dev/sdb.

A volume group "vg_app" will be created with two logical volumes. One logical volume for logfiles, named "lv_logs" with 20 GB and the other with remaining free space, named "lv_app", for application data.

# create volume group
vgcreate -s 32M vg_app /dev/sdb

# create logical volume for logfiles
lvcreate -L 20G -n lv_log vg_app

# create logical volume for application data
lvcreate -l 100%VG -n lv_app vg_app

# show information
vgdisplay -v /dev/vg_app

mount -a
Physical Volume Volume Group Logical Volume Size
/dev/sdb 107 GB
/dev/sdb vg_app 107 GB
/dev/sdb vg_app lv_log 20 GB
/dev/sdb vg_app lv_app > 79 GB

Create File system

mkfs -t ext4 /dev/vg_app/lv_app
mkfs -t ext4 /dev/vg_app/lv_log

Mount logical volumes

mkdir /app
mkdir /app/log

mount /dev/mapper/vg_app-lv_log /app/log
mount /dev/mapper/vg_app-lv_app /app

mount -a
vi /etc/fstab
mount -a
# /etc/fstab
# [...] existing files code [...]
/dev/mapper/vg_app-lv_app /app     ext4 defaults 0 0
/dev/mapper/vg_app-lv_log /app/log ext4 defaults 0 0

Test

Reboot and doublecheck that mounted volumes are still there.

reboot now
##########
df -h
Filesystem                 Size  Used Avail Use% Mounted on
[...]
/dev/mapper/vg_app-lv_app   79G   57M   75G   1% /app
/dev/mapper/vg_app-lv_log   20G   45M   19G   1% /app/log

-> Both logical volumes are mounted --> Success!

Leave a Reply

Your email address will not be published. Required fields are marked *