Logical Volume Management (LVM) - Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lesson we're going to discuss something that's really cool it's called logical volume management which most folks just call LVM LVM provides an alternative that you can use when you're partitioning the hardness drives in your Linux system basically what it does is create an alternative to the traditional process of creating disk partitions and mounting them in the Linux file system instead of defining and creating partitions instead what you do is define volume groups from all the various storage devices in your system then from the volume group we allocate space to specific logical volumes which are managed by the logical volume manager then instead of mounting a partition in the filesystem and what you do is instead mount logical volumes at the various mount points in your filesystem the great thing about LVM is the fact that it provides you with a huge degree of flexibility when you're allocating space on your system let's take a look at an example here on this Linux system I have two LVM volumes the first one is mounted in /opt where various applications are installed and the other one is mounted at /var where i store my mail queues where i store my log files where i store my print queues and so on now because of the type of data that's stored in /var it's very possible that the logical volume that I have mounted in /var is going to start running out of disk space at some point maybe I have a ton of users on the system they send a lot of email they send a lot of print jobs and my log files are growing so the size required for this volume is going to increase over time on the other hand my /opt directory really doesn't need a whole lot of space once I've got my applications installed I only need a little bit of space for a few minor changes I don't need a ton of space here what we can do using LVM is we can actually take some of the space those allocated to the logical volume mounted at /opt and move it to the logical volume mounted at /var and the whole process can be done seamlessly transparently while the system remains running and servicing use now could you do this with traditional disk partitions yes but would it be difficult yes it'd be a pain in the neck because basically what I would have to do to reallocate space from one partition to another is back up both partitions and then cross my fingers say a prayer and resize the partitions and then restore the data from back up and hopefully none of the data would get mangled during the process in addition LVM also allows you to dynamically add space to this system for example suppose I have a logical volume and I have mounted it at the /home directory this is where all of my end users home directories reside for example let's suppose that on my Linux system I have a logical volume defined with LEM and I've mounted it in the /home directory that means all of my end users home directories are stored inside of this logical volume and let's suppose that we are now starting to run out of space this is a very common occurrence as users download and create very large files now to add capacity to this logical volume all I have to do is install a new hard to strive in the system and then allocate all the space on that hard drive to the logical volume mount of that slash home and when I do the size of that volume is instantly increased I didn't have to backup the data I didn't have to resize partitions I didn't have to restore data from backup as I would have if I needed to increase the size of a traditional partition that would have been mounted at /home basically LVM makes life a lot easier for the system administrator so with this in mind let's take a look at the various components that are required to create these logical volumes we've been talking about now understand that LEM creates a pool of storage space called a volume group from the space contained in the volume group we can allocate logical volumes we define the volume and we assign them a certain amount of space so the structure of LVM uses the components that you see here first of all we have our physical volumes now a physical volume could be one of two different things it could be a part tition on a hard disk drive or it could even be an entire hard disk drive all the space on the drive either way works the key thing to remember is that the storage space available on these physical volumes is then assigned and pooled together into the volume group and this is where things get really cool with LVM because once we assign storage space to the volume group we are no longer concerned about physical partition or disk boundaries that's all just available storage space basically the volume group consists of all the space available on these physical volumes group together the key thing to remember here is the fact that the storage space within the volume group can come from many different physical volumes on many different storage devices and what this means is you can add additional hard disks or additional partitions to the volume group whenever you decide you need additional storage space and then as we said earlier we take the space in the volume group and we allocate it to individual logical volumes now these logical volumes are really kind of analogous to physical partitions that you might be used to with either grid or MBR you can format a logical volume and add a filesystem to it you can create a filesystem on logical volume such as ext3 ext4 rise or whatever it is you want to use and then you can then mount the logical volume in a directory in your filesystem and store data on it just like you would a partition so the process for creating a logical volume is shown here the first thing you have to do is create your physical volumes and then you need to assign those physical volumes to a volume group and once you've done that you create your logical volumes out of the volume group so let's look at the first step in the process where you define your LVM physical volumes now it's important at this point that you don't confuse physical volumes with logical volumes the physical volumes are composed of the disk partitions or even the entire hard disk drives if you want to that we define as physical LVM volumes that are then allocated to a volume group now if you decide to use an existing partition as a physical volume for your volume group then you need to set its partition type to Linux LVM which I believe the type code is 8e now I have tried it with just standard Linux partitions type 83 and it works just fine now in most of the time when I setup LVM I actually use partitions but if you want to you could use the entire hard disk itself without creating any partitions on it you can use the entire hard disk as a physical volume but be aware that if you decide to do this the hard disk cannot contain a partition table and if you've ever created a partition at all ever on that hard disk drive that it's going to have a partition table even if there are no partitions in it so if the disk you want to use already does have an existing partition table you need to clear it out and you can use the DD command as shown here to do just that in this example we're going to clear out the partition table for an MBR disk to do this we just have to overwrite the first 512 kilobytes on the hard disk drive because this is where the Master Boot Record resides in this example we're going to take just junk characters from the slash dev slash zero file and we're going to write them to the hard disk itself / - /s dB we're going to copy 512 kilobytes and we're only going to do it once so we're essentially overriding the first 512 K block on the hard disk drive with nothing and once you've decided which disks or partitions you want to use you then use the PV create command at the shell prompt to define these disks or partitions as physical volumes in the syntax is really easy just IPV create followed by the device file name of the device that you want to add in this case we are adding an entire hard disk drive first I define s DB as a physical volume then I define SDC is a physical volume and then define s DD is a physical volume once you've done that you can use the PV scan - V command to view all the physical volumes that are currently defined on the system along with their size and here you can see that I have SD d SD c and SD b it also shows their size over here and notice they're not the same size SD d and SD c or 16 gigs in size SD b is 20 gigs in size and LVM does not care so once we've got our physical volumes defined we then need to assign those physical volumes to the volume group this basically takes the space on those physical volumes and allocates it to the volume group that can then be later on assigned to a logical volume to create a volume group you use the VG create command now the process for allocating physical volumes to a volume group is a little bit tricky if the volume group doesn't already exist so in order to create the volume group we first specify the VG a create command followed by the name of the volume group we want to create and then the name of the first physical volume that we want to assign to that volume group so in this case I'm creating a volume group named research and then I'm assigning the SDB physical volume to that volume group now in this case I want to add two more physical volumes to the group as well but I could not do that from the VGA create command on some distributions you can but most distributions you cannot you can only specify one physical volume with a VGA create command therefore what you have to do is run a second command called VG extend followed by the volume name and then you can list out the rest of the physical volumes that you want to add to the volume group run the PV scan command and then you can see that s DB C and D are all added to the same volume group called research now once we have our volume group defined we can then use the space that we've allocated to that volume group to define our logical volumes our LVS to do this you use the LV create command the syntax is shown here you enter LV create then use the - L option to specify the size of the volume that you want to create then you use the - and option to specify the name of the volume and then at the end of the command you specify which volume group you want to steal that space from to create the volume in question so in this case I am creating a 10 gigabyte volume named res underscore vol and then the space is going to come from the research volume group and I did the same thing a second time to create a second volume within that same volume group named dev underscore vol this is really cool essentially what we just did is to find two logical volumes within a single volume group which itself was created by pooling together all of the storage space from the three hard disk drives the cool thing about it is if I ended up needing more space for any one of these volumes duvall or reservoir all I would have to do is install a new storage device in the system define it as a physical volume allocate a space to the volume group and then run the LV extend command to increase the size of the volume I didn't have to back up any data I didn't have to resize any partitions I just dynamically add the new storage space in the volume group do the appropriate logical volume so once we have the logical volumes created we then need to treat them basically like we would an MBR or GPT partition in order to store data on an MBR GPT partition I have to create a file system on it and then mount it in the file system and the same holds true for logical volumes the first thing I need to do is create a file system on it just like I would a partition and use the exact same command to do so I enter make FS - T followed by the type of file system that I want to create and then instead of specifying a partition that I want to create the filesystem on I instead specified the device file for the logical volume which uses a slightly different syntax than a partition we enter / - slash followed by the the volume group that the logical volume resides in and then the name of the logical volume itself once the file system is created on the logical volume I can mount it in the file system and I use the mount command just like I would with a MBR or GPT disk partition and I specify Dashti followed by the type of file system that I just created on the logical volume and then once again I specify the device file for the logical volume using the exact same syntax that I did before and then I end the command with where I want to mount it in the file system that's it for this lesson in this lesson we talked about how to use LVM on a Linux system we first talked about how LVM works we talked about the components that are required within an l vm implementation and then we ended this lesson by reviewing the process for creating a logical l vm volume
Info
Channel: The Linux Man
Views: 70,841
Rating: 4.974359 out of 5
Keywords: Linux
Id: fadQX2e_PGk
Channel Id: undefined
Length: 13min 32sec (812 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.