top of page

how to create a logical volume

  • Writer: Sankalpa H.T.S
    Sankalpa H.T.S
  • Jun 20, 2018
  • 3 min read

ree

This document provides some basic LVM configuration examples: Here I’m gonna create an LVM logical volume called nagios on a disk, But we can create an LVM on many disks.


Update the server:

ree

Install the basic packages for the system:

ree

This document will relate to my <NAGIOS CONFIGURATION IN LINUX UBUNTU -16.04.3- server> document. So that I changed the machine’s host name into nagios_server:

ree

Reboot for apply changes:

ree

Here is my server machine:

ree

To use disks in a volume group, label them as LVM physical volumes with the pvcreate command. Before that check whether it has physical volumes already with pvdisplay command.

ree

Prompt returned nothing. There aren’t any physical volumes:

ree

In order to create an LVM let’s see required disks consists at using lsblk command:

ree

We have 20G disk at /dev/sdb. 20G disk at /dev/sda used for partitioned as sd1,sd2,sd5 in the server installation.

ree

Let’s make a physical volume with pvcreate command using 20G disk at /dev/sdb .

ree

ree

Let’s check the added physical volume with pvdisplay:

ree

Now we get our new physical volume details:

ree

Create the a volume group that consists of the LVM physical volumes you have created. The following command creates the volume group vg1.


Check for existing volume groups:

ree

Prompt return nothing as below. No volume groups exist

ree

Now create vg1 volume group with vgcreate:

ree

Let’s check the added physical volume with vgdisplay: We can use the vgs command to display the attributes of the new volume group.

ree

Now we get our new physical volume details as below:

ree

Check for existing logical volumes:

ree

Prompt return nothing as below. No logical volumes exist.

ree

Create the logical volume from the volume group we have created. The following command creates the logical volume nagios from the volume group vg1. This example creates a logical volume that uses 10GB of the volume group.

ree

ree

Let’s check the added physical volume with lvdisplay:

ree

Now we get our new physical volume details as below:

ree

We can check our created LVM using lsblk command:

ree

Above screen shot you can see the 10G size LVM we created.


Create an User for Mount the LVM


Create a password disabled user named nagios with a user directory in the home folder:

ree

Change to the home directory and check the user directory is created:

ree

We can find our user directory here by using ls command:

ree

Tail the /etc/passwd file for find our newly created user:

ree

We can find the user in the end line of the passwd file:

ree

Tail the /etc/shadow file for find our newly created user:

ree

We can find the user in the end line of the shadow file:

ree

Mount the LVM


Create a file system on the LVM we created with mkfs.ext4 command:

ree

The following command creates a EXT4 file system on the logical volume.

ree

Check whether our LVM has a MOUNTPOINT already:

ree

We can find it hasn’t a MOUNTPOINT.


Mount our LVM to /home/nagios/ directory which created when we creates our nagios user:

ree

See the mount point now:

ree

We can find it has mounted to the /home/nagios as below:

ree

Reboot the machine and see the mount point of the created LVM again:

ree

When we reboot the machine it has automatically unmounted. Let’s mount again with some configurations to mount the LVM statically:


mount the LVM statically


Mount our LVM to /home/nagios/ directory which created when we creates our nagios user:

ree

And run the command blkid to check the block ID for the LVM we created:

ree

Copy the block ID “/dev/mapper/vg1-nagios” from the output:

ree

And open the fstab file in the /etc/ directory

ree

The file looks like below:

ree

Add the copied block ID with the <mount point> <type> <options> <dump> and <pass> as pointed below:

ree

Now reboot the machine and run lsblk command and see:

ree

Run lsblk command:

ree

Now you can see our mounted point is not removed:


Also run the df -h command and see the output:

ree

We can clearly see where our created nagios LVM mounted on as below:

ree

References:


 
 
 

Comments


bottom of page