Logical Volume Management - What is LVM & how to use it (and WHY you should use it)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello it's dorian and today i'm going to cover logical volume management or lvms i'm going to cover what it is how to use it the basics and why you should use it so let's get started [Music] now i'm sure many of you have run into the dreaded low disk space notification and then you have to you know start going through your downloads delete all your large files delete your games or whatnot and then you have to think about expanding so are you going to add another hard drive and mount your home partition to it or start moving files over to there or are you going to buy a larger drive copy all your partitions over then extend the partitions lots of choices lots of decisions to make there but one of the things you could do is install your linux distribution on an lvm partition now when you first read about lvm it kind of sounds like a raid array where you have multiple disks and the data is spanned across that in a way yeah okay it can be but it doesn't provide any redundancy or anything but it does extend your partitions across multiple disks similar to raid and what you can do is just keep adding disks to continue to expand that partition on the fly so in the description down below i've got a link to a lvm cheat sheet and it basically goes through what i'm going to go through today step by step with the commands and you can follow along with that if you want watch the video at the same time whatever and i have it in three different formats so you can print it up and use it as a hard copy but to get started what is lvm well what it does is it'll take a group of physical disks and create a volume group and then from within that volume group you create logical volumes so you can have your swap partition your root partition and a home partition then once you start running out of room it's just a matter of adding another disk and then you can expand your volume group and then within the volume group you can expand your logical volumes so i'm going to go through that right now and show you what i have here is a basic install of ubuntu i didn't do anything other than add a couple of favorites and install g parted so you can see here this is the main hard drive it has an efi system partition and the lvm partition now i set this when i installed it it was the regular install just like any other install except you would click on the advanced button and then there's an option here to make it an lvm partition you can also encrypt it with a password that's up to you if you want to do that or not i don't do that because it complicates things and if you're trying to fix something and it can't access it it just causes another layer of issues but you can turn that on if you want to that's completely up to you and then you just go ahead and proceed with the install like you normally would if you're trying to convert an existing system into lvm there is a way to do it but it involves creating a lvm and copying your existing files over to it and then changing some configurations to make it boot properly and then deleting the old one it's not ideal it can get messy and confusing and sometimes it just won't work depending on how your system is set up so i would say just start fresh clean install with lvm from the beginning so this is a fresh install i mean there's a lot of free space and there isn't even a lot of stuff installed here but let's just say i'm starting to run out of room on my lvm partition it's full of games movies music and what have you so what i'm going to do is add another hard drive into my computer which i have done so if i go down here i have sdb so i have a 223 gig ssd in here and i added another 120 gig shows up as 111 but this is what i added into my system and it doesn't matter what's on it because you're going to wipe it and everything anyways so i just have two ext4 partitions in here so the first thing you're going to want to do is wipe everything out that's on it you could do it with fdisk but if you're already running a linux distribution you might as well just use g parted or some type of graphical application like this so basically i'm just going to delete both of these and i'm going to create a new partition take up all the space and it's going to be an lvm to pv as it shows up in g parted it might just say linux lvm and whatever um program you're using but the important thing is you're creating the lvm file system so add that apply get that done and then we can finally get started and start extending our space so the next thing you're going to do is open up a terminal window and i know a lot of people are going oh no not the terminal but it's not it's not that hard and you you can use that cheat sheet that i have and it's not a big deal i'll walk you through everything here so some of the commands you're going to use here are pvs and before i get started anything that you use here is going to be sudo so you can do sudo su to become root so you don't have to keep typing it but you do have to be root to be able to do it so now this is listing our physical volumes this is whatever disks that you have in your system that have an lvm partition so you can see sda2 is the partition that we're actually using for ubuntu and you can see here it's mounted as vg ubuntu which is here another command to show what's currently going on is you could do vg's and it's going to show you the vg ubuntu volume group and it is using one physical volume with one disk and it contains two logical volumes so let's go ahead and look at lvs logical volumes so the logical volumes the two that are listed up here are root and swap so i have the root partition which is 222 gigs and i have a swap partition which for some reason ubuntu only made one gig and i'm going to expand that there's actually a difference in expanding a swap partition than a regular partition so i'm going to go through those steps as well so now if you've used fdisk or another utility and it is not showing up here then the command you're going to want to use is pv create so physical volume create and you're basically just going to tell it which physical volume you want added now this isn't going to do anything because it was already successfully created so if i do sudo pvs you can see it's there it was there before it's not assigned to any volume group but if it didn't show up the first time it should now show up okay so at this point we have two physical volumes and we want to extend our volume group across both disks so now what you're going to do here is sudo vg extend vg ubuntu because that is the volume group we want to extend and then dev sdb1 because we want vg ubuntu to extend onto sdb1 so we'll do that and successfully extend it so we can go ahead and do pvs and now we can see that the volume group is on both physical hard drives so now at this point we haven't changed anything with the root and swap partitions they are the same size they are both still on sda2 the original hard drive what we have to do now is extend those into the new space that is available on the second hard drive now as i mentioned before i only had the one gig of swap partition which to me is is fine i actually don't use any but if you wanted to resize a swap partition this is how you're going to do it first thing you're going to do is turn the swap off so the command is swap off dash a which will turn off the swap all swap partitions because you could have more than one and now we can resize that swap partition so let's have a look at the logical volumes the lvs and you can see that swap one is one gig we need to extend that logical volume now that we have additional space on the second drive so now we're going to resize the logical volume of the swap partition but one thing that you're going to need to know is the path of where that volume is physically on the drive so i'll explain this here by running lv display so logical volume display shows you a lot of information about the logical volumes in your volume group now you can see here the swap partition is here so slash dev slash vg ubuntu so vg ubuntu is acting as a hard drive normally you'd have dev slash dev sda1 and whatnot well this is fiji ubuntu because it's a volume group and then swap one within that volume group if you found that confusing don't worry about it the biggest thing you need to know is you need to know this path in order to resize the partition so now we're going to do lv resize and the path of what you want to extend and you're going to do dash capital l and then you're going to use disk space here like gigabytes megabytes so i want an additional seven gigabytes so i do plus seven g you could do m if you want an extra seven megabytes for some reason but i'm using gigabytes so i want an extra seven gigabytes added to the current size of that swap partition so i'm going to do that and the logical volume of swap one successfully resized so you can see it went from 976 megs to 7.95 gigs close enough to eight gigs now because it's a swap partition you need to do make swap and you're going to put that same path again it's going to format it no it's not going to format it because you also need to be sudo all right so that's done and now we can do swap on again dash a and if we look at our system monitor our swap is now showing as eight gigs so perfect now that's small partitions that is not ext4 root partitions that's just something i wanted to cover because it's a different way to do it because you have to unmount recreate the swap file system and remount resizing the root partition is actually a little bit easier so again let's just do lv display and this is the one we want to resize so i'm just going to copy that and now here we're going to sudo lv resize just like before and just like before i could do dash l and 100 gigs and then the path now you'll notice before i put the options here after it doesn't really matter if you put it before or after it will understand so i just want to show you that it doesn't matter how you do it and this should actually be a plus 100 gigs but i'm not going to do this what i want to do is take up all the available remaining space on that drive because i took seven gigs of the new drive for the swap partition so now the rest of the space i want to take it all up so i'm going to change this to lowercase l and then i'm going to go plus 100 percent free this means i want to take 100 of the remaining free space on the new drive the the new volume group which is now extended onto the new drive which gave us extra free space so now i want to resize this root partition to take up all of it you can see what is available here also by doing a zuru pvs and you can see here there's 104 gigs free on the volume group because we've taken seven away for the swap partition so this command down here in the other window is going to add 104 gigs to our total free space so you can see here the size of root 218 gigs 202 gigs free so we're going to go ahead and run our resize command and you can see root has changed from 222 gigs to 326 gigs there's one thing that i forgot because i'm not reading my own notes on my cheat sheet is you have to resize the file system within the logical volume as well so there's a dash r that has to go in there as well so just run that and it will also resize the file system within the logical volume so now if we go ahead and run this again we can see here that root used to be 218 gigs with 202 free and it is now 321 gigs with 301 gigs free so now we have extended our partition for root and swap across two physical drives so now going back to g parted here when this drive fills up and it's out of space the data is just going to start spilling over into sdb1 the new hard drive that you just added you can see here the mount point for the lvm partition is vg ubuntu and if you look on sdb the mount point is also vg ubuntu and then after this if you fill this disk up you do the same thing and you just add another drive and extend onto that one as well however if that happens on the second drive you've added i would strongly consider getting a much larger hard drive if you're going to add a third one so that it doesn't happen again so this is very handy for if you're running a server and you're just collecting data if you have a lot of pictures and you have a computer that you just use for working on pictures or videos and you just keep you know collecting large files over and over and you just run out of space well throw in another hard drive and run out of space throw in another hard drive now the big downside to this is shrinking going going the opposite if you want to remove one of your physical disks it's a little more complicated and i'm not going to go through it because i have tried it and three out of four times the system wouldn't boot because you can shrink your volumes and you can move the data off the physical disks but there's still a really good chance that you're gonna lose data and something's gonna go wrong and three out of four times something went wrong and the system wouldn't boot so i just kept trying and trying and trying actually i did try it another time so three out of five times it failed two succeeded but it took some messing around with and i don't know it's not it's not something you want to do this is better for just expanding and expanding so all this in a nutshell well a long nutshell but i tried to keep it short and simple all this is how you would continue expanding your drives with lvm key points are start with an lvm to begin with right off the bat get a larger hard drive than you think you would need if you're adding one and remember that shrinking is not a good option and terrible things can happen and yeah i hope this helps you out so don't forget to subscribe don't forget to like the video share it on your social media and until next time bash on [Music] [Music]
Info
Channel: DorianDotSlash
Views: 8,292
Rating: 4.9766083 out of 5
Keywords: logical volume management, logical volume manager linux, logical volume management in linux, lvm, lvms, lvm's, how to use lvm, what is lvm, lvm explained, logical volume management explained, logical volume manager explained, what is logical volume management, resize lvm, how to resize lvm, how to expand lvm, how to grow lvm, logical volume manager, lvextend, how to extend lvm, extend lvm, lvm tutorial, linux lvm, lvm linux, swap lvm, learn lvm, learning lvm
Id: 214rUhQe7B4
Channel Id: undefined
Length: 16min 33sec (993 seconds)
Published: Sat Feb 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.