How to Setup LVM Partition to New Logical Volume Manager (Drive).

  1. What is LVM and it’s example
  2. Advantage of LVM
  3. Possibilities of LVM
  4. Real-time LVM Example
  5. Adding New Space/disk using LVM
  6. Extending the space using LVM
  7. Creating a partition using fdisk command
  • LVM is used to manage volume and assign disk on the linux server.
  • Logical volume manage allows disk to be combined together

Example of LVM

  • Like Partition of disk in Windows c, d drive similarly we can do the same in the Linux.
  • Single disk can be divided into different partiton.
  • Multiple disks combined and group them into one change it into different partition

My Server Setup- Requirements:-

  • Operating System:- RHEL 9
  • Server IP Address:- 192.168.180.106
  • Disk – 1 Disk with 8GB

Requirement:-

We need to deploy two new applications app1 and app2 on our server and need a separate partitions and space for each applications.

Advantage of LVM:-

In case of disk Is running out of space, you can add new disk without breaking partitions of your file system.

Step of LVM for adding new space:-

  1. Install a new Hard disk drive
  2. Make a partition to use it
  3. Designate physical volume(pv)
  4. Manage volume Group (vG)
  5. Manage Logical volume (Lv)
  6. Apply a filesystem
  7. Set a mount point

Install a new Hard disk drive

# fdisk -l

Make a partition to using 'fdisk':-

Before using a new disk, we need to partition the disk using the fdisk command as shown.

# fdisk -l
# fdisk /dev/sda

Follow the below steps to create new partition.

  1. Choose n to create new.
  2. Choose p to create a primary.
  3. Choose which number of partition we need to create.
  4. Press Enter twice to use the full space of the Disk.
  5. We need to change the type of newly created partition type t.
  6. Which number of partition need to change, choose the number which we created its 1.
  7. Here we need to change the type, we need to create LVM so we going to use the type code of LVM as 8e, if we do not know the type code press L to list all type codes.

Designate physical volume (pv) so that it will be available to LVM as storage capacity.

Then create the new physical disks. The below command.

# pvcreate /dev/sda1

Display PV capacity and additional information:

Manage Volume Groups (VGs)

VG must have at least one member (VG is our group name and other are our PVs.)

# vgcreate vgapps /dev/sdb1

To display information for a VG named VG00

# vgdisplay vgapps

Manage Logical Volume (LVs)

To create a Logical volume. The below command.

# lvcreate -L 4000MB -n app1-lv vgapps
# lvcreate -L 4000MB -n app2-lv vgapps

To display information for a LV below command.

# lvdisplay /dev/vgapps/app1-lv
# lvdisplay /dev/vgapps/app2-lv

Apply a File System:-

For using the logical volumes we need to format.
Run the mkfs.ex4 command on the LV

# mkfs.ext4 /dev/vgapps/app1-lv
# mkfs.ext4 /dev/vgapps/app2-lv

Set a mount point:-

Here I am using the ext4 file-system to create the volumes and going to mount them under.
Create a mount point by using mkdir. The below command.

# mkdir /data1
# mkdir /data2
# mount /dev/vgapps/app1-lv /data1/
# mount /dev/vgapps/app2-lv /data2/

List and confirm the Mount point using.

# df -TH
# df -h
# lsblk

Permanent Mounting of Logical Volumes:-

 It’s now temporarily mounted, for permanent mount, we need to add the entry in fstab, for that let us get the mount entry from mtab using

Manually mount the volume using the mount command, or edit the /etc/fstab file to mount the volume automatically when the system boots.

# cat /etc/mtab

We need to make slight changes in the fstab entry while entering the mount entry contents copies from mtab, we need to change the rw to defaults

# vim /etc/fstab
#our fstab entries
/dev/mapper/vgapps-app1--lv /data1 ext4 defaults 0 0 /dev/mapper/vgapps-app2--lv /data2 ext4 defaults 0 0

Save the file by pressing :wq and Entering press

Finally, run the command mount -a to check for the fstab entry before restarting.

# mount -av

Question:-

Fstab: – The /etc/fstab file in Linux controls how disk drives and partitions are mounted and used by the system.

Leave a Reply

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