EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux LVM

By Alokananda GhoshalAlokananda Ghoshal

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux LVM

Linux LVM

Introduction to Linux LVM

In today’s world, when the entire world is going to be built on the data it becomes a daunting task for system admins to manage the disk space. In earlier times, when one used to run out of space, a long cumbersome process used to start in order to increase the space availability to a disk partition. Not only this the system had to be taken off-line. In Linux LVM or Logical Volume Manager, when introduced in Fedora Linux, was a savior as it was the first time some abstraction layer allowed flexible disk management. To formally define LVM, it is a device mapper framework that enables allocation of space on a mass storage device with a hint of flexibility.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In Linux, there are infinite possibilities of LVM and in this article, we will discuss the ones which are widely used when it comes to the utility of LVM. In this section we will come face to face with the syntax as in the next section we will take a dig at how LVM works.

1. Display Physical Volumes

Syntax:

pvs

OR

pvdisplay

2. Displaying Volume Groups

Syntax:

vgs

OR

vgdisplay <volume group name>

3. Creating Logical Volumes

Syntax:

lvcreate -L <size of logical volume> -n <Volume name> <VG name>

4. Listing the partition types in Linux

Syntax:

lsblk

5. Mount Logical Volumes

Syntax:

mount -t ext3 <Logical Volume path> <mount path>

6. Extending a Logical Volume

Syntax:

lvextend -L +<Size increase> <Logical volume path>

7. Removing a Logical Volume

Syntax:

lvremove <Logical Vol path name>

How LVM works in Linux?

Now that we syntactically have a brief idea of what a Logical Volume Manager looks like, it is time for us to understand how does LVM works in Linux. To begin with, LVM deals with management of disk allocation, stripping of disks, mirroring disks, and resizing the logical volumes. Now, if you look at the syntax carefully, you will find that the first 3, has just few alphabets been different or in other words, understanding each of the 3 different chronological portions of the architecture.

The first one is the Physical Volume. This has a LVM utility prefix pv. These are block devices or disk-like devices that act like raw material for LVM to build a higher abstraction layer. The next item on the architecture is Volume Group which has utility prefix vg. LVM helps in a combination of physical volumes into pools of storage. These layer abstracts the underlying devices characteristics. The third and the last is Logical Volume, which is prefixed as lv. This is analogous to partition on a physical disk, except having a bit more flexibility. All these three can be considered as a subset within the previous one, i.e. Logical Volume group is combined to Volume Group, Pool of volume groups make a physical volume.

Now that we have a complete understanding of LVM and its different components, let us start with some chronological order of steps. For using LVM, we would first need to create a partition on the unpartitioned disk. For the sake of this article, we will assume that the partition can be created on the single partitions. The other, by the way, is a raw and unpartitioned hard disk. For this, cfdisk command is used. Next is to have physical volumes created, for which pvcreate command is used. Once the physical volume is created it is time to create a volume group inside that, as this is the group which will act like a container for all of our storage. Now we need to create the most granular level of the architecture, i.e. Logical volume. It is like cutting smaller pieces of cake from a big piece of cake. This smaller logical volume can be of any number, but the net size of all these smaller pieces of cake should never exceed that of the volume group where these logical volumes are created.

At this point of time, our logical volume is ready to use. At this point, we can start creating file systems in our logical volumes. One should be aware of the fact that a small % of space is reserved for super-users (by default 5%).

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,008 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

Apart from this initial working of LVM, there are some advanced utilities of mounting, extending, removing local volumes as deemed fit for a use case. During mounting, one should be careful about creating a mount point before executing the mount command. One of the biggest advantages of extending the logical volume is to increase the space any time one runs out of space in the volume. When one runs lvextend only the size of the logical volume increases, whereas the size of the file system doesn’t and in order to do that, one needs to run the resize2fs command. Last but not the least, when a logical volume is removed, one should make sure that it doesn’t contain any valuable data, as this command can’t be undone and should be carefully executed!

In the next section, we will look at examples of the explained working of LVM.

Examples

Lets us discuss the examples of Linux LVM.

Example #1 – Display Physical Volumes

Syntax:

pvs

Output:

 linux LVM 1

Example #2 – Displaying Volume Groups

Syntax:

vgs

Output:

linux LVM 2

Example #3 – Creating Logical Volumes

Syntax:

lvcreate -L 5G -n EduCBAVol1 EduCBADemoGrp
lvcreate -L 2G -n EduCBAVol2 EduCBADemoGrp
lvcreate -L 1G -n EduCBAVol3 EduCBADemoGrp

Post creating of Logical Volume:

Syntax:

vgs -o +lv_size,lv_name

Output:

 linux LVM 3

Post creating of Logical Volume:

linux LVM 4

Example #4 – Listing the partition types in Linux

Syntax:

lsblk

Output:

linux LVM 5

Example #5 – Mount Logical Volumes

Syntax:

mount /dev/EduCBADemoGrp/EduCBAVol1 /mnt/EduCBAVol1
mount /dev/EduCBADemoGrp/EduCBAVol2 /mnt/EduCBAVol2
mount /dev/EduCBADemoGrp/EduCBAVol3 /mnt/EduCBAVol3
vi /etc/fstab

Output:

linux LVM 6

Example #6 – Extending a Logical Volume

Syntax:

lvextend -L +600 /dev/EduCBADemoGrp/EduCBAVol1

Output:

example 6

Example #7 – Removing a Logical Volume

Syntax:

lvremove /dev/EduCBADemoGrp/EduCBAVol2

Output:

 example 7

Conclusion

With the set of examples and explanation to working of how LVM works and what different utilities the command caters to in Linux. We encourage you to experiment more with different parameters and get acquainted with some failure mode which acts like a block for using LVM in some scenarios!

Recommended Articles

This is a guide to Linux LVM. Here we also discuss the definition and How LVM works in Linux? along with different examples and its syntax. You may also have a look at the following articles to learn more –

  • Vim Command in Linux
  • Linux Size
  • Linux Network Stack
  • Linux Automount

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More