top of page

how to create a logical volume

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

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:

Install the basic packages for the system:

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:

Reboot for apply changes:

Here is my server machine:

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.

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

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

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

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


Let’s check the added physical volume with pvdisplay:

Now we get our new physical volume details:

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:

Prompt return nothing as below. No volume groups exist

Now create vg1 volume group with vgcreate:

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

Now we get our new physical volume details as below:

Check for existing logical volumes:

Prompt return nothing as below. No logical volumes exist.

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.


Let’s check the added physical volume with lvdisplay:

Now we get our new physical volume details as below:

We can check our created LVM using lsblk command:

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:

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

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

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

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

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

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

Mount the LVM


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

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

Check whether our LVM has a MOUNTPOINT already:

We can find it hasn’t a MOUNTPOINT.


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

See the mount point now:

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

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

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:

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

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


And open the fstab file in the /etc/ directory

The file looks like below:

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

Now reboot the machine and run lsblk command and see:

Run lsblk command:

Now you can see our mounted point is not removed:


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

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

References:


 
 
 

Comentarios


bottom of page