Skip to main content

What is Logical Volume manager in Linux?






Topics to be covered in this blogpost:


What is LVM and its examples .

Advantage of LVM

Posssibilities of LVM

Realtime LVM Examples

Adding new Space /Disk using LVM 

What is LVM ?

LVM is used to manage volume and disk on the linux Server.

LVM allows disks to be combined together.


Example of LVM:

Like partition of disk in windows C,D drive similarly we can do the same in Linux.

Single disk can be divided into different partitions.


Multiple disks can be combined and grouped into one.

LVM can be understood using the image below:




Advantage of LVM:

In case of disk is running out of space ,you can add new disk without breaking partitions of your 

file system.


Possibilities of LVM:

1.New space can be created on server for new project

2.In case of the low disk space we can increase the space.

3.In case of the extra space allocated to the partition, capacity can be reallocated (reduce capacity in one volume group and add it to another.)

4. Possibilities and different combinations of LVM can be explained using the image below:



Working on LVM : 

Requirement:

We need to deploy 2 applications(app1 and app2) on the single Linux Server. We need separate partitions and space for both the applications. How can we do that ?

We can do it using LVM .I have Explained below how we doing it using LVM.

 
Steps of LVM for adding new Space :

1.Install a new Hard disk drive.

2. Make Partition to use it.

3.Create physical volume.

4.Create Volume group.

5.Create Logical Volume.

6.Apply the filesystem.

7.Set mountpoint.


1. Install the new Hard disk drive :

 We can add this hard disk drive from vCenter /Oracle virtual manager /Oracle Cloud wherever this server is deployed .


2.Make partition: 

a. Login to server using putty .to check if the disk you have added is reflecting in the server or not ,use the command fdisk -l. As you can see that disk /dev/sdb is added to the server .



b. use fdisk command to create partition.

command: fdisk diskname.




c. Type n for creating new partition and type p for primary partition. if you are creating 1 partition then type 1.Select first sector and last sector as default .



d. Above steps will create the new partition of type 'Linux'. but we need partition of type Linux LVM.

Type t and type 8e hexcode to change the partition type.




e. Type w to write the table to disk and exit.


f. if you want to check if the partition has been  created or not , type the command fdisk -l.

you can see in the below snip that /dev/sdb1 partition has been created from /dev/sdb disk.

3. Create the Physical Volume:

Command to create phyical volume: pvcreate partition (example: pvcreate /dev/sdb1)

command to display physical volumes: pvdisplay.


a. create the physical volume from partition /dev/sdb1

pvcreate /dev/sdb1


b. pvdisplay will show you your physical volume details . size of physical volume we have created is 2 gb.

4. Create the Volume Group:

We can create volume group from single physical volume or multiple physical volumes.

command to create VG: vgcreate VGname PV1 PV2 PV3 ....

command to display VG  : vgdisplay 

a. Create VG named vgapps from physical volume /dev/sdb1 as shown below :

vgcreate vgapps /dev/sdb1



5.Create the logical volume : 

Here is the tricky part . we have to create 2 logical volumes of size 1 gb  for 2 applications. because that is our requirement.

command to create logical volume : 

lvcreate -L size(1G or 1T) -n lvname vgname


command to display logical volumes: 

lvdisplay


a. create 2 logical volumes app1-lv and app2-lv for 2 applications from volume group vgapps.

commands :

lvcreate -L 1000M -n app1-lv vgapps

lvcreate -L 1000M -n app2-lv vgapps



b. lvdisplay will show the following info.




6. Apply the FileSystem.

Run the mkfs.ext4 command on LV.

command : mkfs.ext4 LVpath

a. Create file system : mkfs.ext4 /dev/vgapps/app1-lv





7. create the mount point:

a. Create two directories for app1 and app2 .


b. mount LV path on the 2 directories we have created.


c. Use command df -hT to check if the file systems are reflecting or not.

Comments

Popular posts from this blog

Linux basic commands

 Linux basic commands: du  -sh  *  |  sort  -h  -r   |  head  -n  40  :    list out first 40 files in the directory that are taking more space in the directory.  cd : change directory Is-l listing the items in long listing format  pwd : print working directory Is-I format: type :no of links:owner : group:size :month :day :time :name cd/: go to/directory whoami: tells us by which username we are logged in. touch jerry: creates the file named jerry in present working directory. cp jerry lex: copy the content of jerry file and paste it to lex file. vi text1: creates the file text1 and open it in vi editor mkdir superman: creates the directory called superman mkdir abc def  : creates 2 folder in one command. touch filename wont work in /etc/ folder if logged in by normal account. man cp: shows manual for cp command. echo "india is my country"> file1 puts the text in file1. rm filename: remove the filename  mv lex luther renames the file from lex to luther  mv luther /h

patching tasks

 Patching a Linux system is a critical task to ensure that the system remains secure, stable, and up-to-date with the latest features and fixes. Here’s a comprehensive guide to the tasks involved in Linux patching: 1. Pre-Patching Preparation Backup System : Ensure you have a full system backup, including critical data, configuration files, and applications. Test the backup to verify its integrity. Check Disk Space : Verify that you have enough disk space, particularly on /var , /tmp , and /boot partitions. Review Current Patch Level : Determine the current patch level and installed packages using package management tools like yum , apt , dpkg , or rpm . Check System Logs : Review system logs to identify any issues that might affect the patching process. Test in a Staging Environment : If possible, apply patches in a staging environment that mirrors production to identify potential issues. Notify Stakeholders : Inform stakeholders about the scheduled maintenance window and expected do