Showing posts with label lvdisplay. Show all posts
Showing posts with label lvdisplay. Show all posts

Tuesday, June 17, 2008

LVM Quick Command Reference For Linux And Unix

Hello again,

Today, as promised in yesterday's post (where we came full circle from getting started with LVM, and using monitoring and display commands to removing those same LVM devices), today we've got a little quick command reference of the most commonly used LVM commands.

You may have noticed that I named Linux and Unix in the title of this post. That's because HP-UX's implementation of LVM is very similar to Linux's, and this reference basically works for both of them :) If you're interested in specifics on most of these commands, please refer to our previous posts. We'll note commands in this reference that we "haven't" covered yet.

And, off we go. Hopefully this will help out if you ever need a one-stop-shop for that LVM command you've been looking for. In future posts, we'll definitely be looking at more advanced LVM concepts. For instance, we haven't even begun to look at things like setting up RAID or any form of advanced manipulation of the physical volumes, logical volumes and volume groups we created. You have our promise that posts on theses subjects will be forthcoming. Just maybe not tomorrow ;)

1. LVM Basic relationships. A quick run-down on how the different parts are related

Physical volume - This consists of one, or many, partitions (or physical extent groups) on a physical drive.
Volume group - This is composed of one or more physical volumes and contains one or more logical volumes.
Logical volume - This is contained within a volume group.

2. LVM creation commands (These commands are used to initialize, or create, new logical objects) - Note that we have yet to explore these fully, as they can be used to do much more than we've demonstrated so far in our simple setup.

pvcreate - Used to create physical volumes.
vgcreate - Used to create volume groups.
lvcreate - Used to create logical volumes.

3. LVM monitoring and display commands (These commands are used to discover, and display the properties of, existing logical objects). Note that some of these commands include cross-referenced information. For instance, pvdisplay includes information about volume groups associated with the physical volume.

pvscan - Used to scan the OS for physical volumes.
vgscan - Used to scan the OS for volume groups.
lvscan - Used to scan the OS for logical volumes.
pvdisplay - Used to display information about physical volumes.
vgdisplay - Used to display information about volume groups.
lvdisplay - Used to display information about logical volumes.

4. LVM destruction or removal commands (These commands are used to ensure that logical objects are not allocable anymore and/or remove them entirely) Note, again, that we haven't fully explored the possibilities with these commands either. The "change" commands in particular are good for a lot more than just prepping a logical object for destruction.

pvchange - Used to change the status of a physical volume.
vgchange - Used to change the status of a volume group.
lvchange - Used to change the status of a logical volume.
pvremove - Used to wipe the disk label of a physical drive so that LVM does not recognize it as a physical volume.
vgremove - Used to remove a volume group.
lvremove - Used to remove a logical volume.

5. Manipulation commands (These commands allow you to play around with your existing logical objects. We haven't posted on "any" of these commands yet - Some of them can be extremely dangerous to goof with for no reason)

pvextend - Used to add physical devices (or partition(s) of same) to a physical volume.
pvreduce - Used to remove physical devices (or partition(s) of same) from a physical volume.
vgextend - Used to add new physical disk (or partition(s) of same) to a volume group.
vgreduce - Used to remove physical disk (or partition(s) of same) from a volume group.
lvextend - Used to increase the size of a logical volume.
lvreduce - Used to decrease the size of a logical volume.

You may note that some of these commands vary slightly from LVM1 to LVM2 and also between the pure Linux implementation and HP-UX's Unix version. We'll be looking at the differences, and similarities, between all of these in future posts, for sure.

Until then. Enjoy :)

, Mike

Monday, June 16, 2008

Removing Logical Devices Using LVM On Linux And Unix

Hey there,

A long weekend of getting confused over factorials and prime numbers is finally over, so today, we're going to finish one part of what we started in our previous posts regarding getting started with LVM logical volume management and making use of LVM's monitoring and display commands, and close this little circle by using those same monitoring commands to aid in disk removal with LVM.

Refer back to those two initial posts for any additional details, if you'd like them, but, for today's purposes, we're just going to use their outcome as the assumed setup which we'll be removing.

In a nutshell, we have one physical volume composed of one volume group which, in turn, contains only one logical volume (or you could think of it the other way around). Hopefully this is all coming back to us (including me ;)

Note: Based on your particular vendor distribution , or version, of LVM, the output of these commands may be slightly different. You shouldn't notice any significant difference, though.

The first thing we'll want to do, to undo all the hard work we've put into creating this little setup, is to remove the logical volume (lvol01) from the volume group (vg01). This is done easily with the lvchange command, like so:

host # lvchange -a n /dev/vg01/lvol01

lvchange doesn't spit any output to the terminal by default, if everything goes well. But, if we double-check that the return code from the above command is 0, then we've successfully made the lvol01 logical volume unavailable (-a for availability status with n following it to indicate that we want that status set to no).

Next, we'll remove the logical volume, allowing the naturally occuring backup of the volume group, from vg01:

host # lvremove -f /dev/vg01/lvol01
...
lvremove -- doing automatic backup of volume group "vg01"
lvremove -- logical volume "/dev/vg01/lvol01" successfully removed


The next two things to do will be to change the volume group's status and remove the volume group using (yes, it's true ;) vgchange and vgremove, like this:

host # vgchange -a n /dev/vg01
vgchange -- volume group "vg01" successfully deactivated


host # vgremove /dev/vg01
vgremove -- volume group "vg01" successfully removed


The most assured way to finish this (unless your flavour of Linux doesn't allow it) would be to run pvchange and then pvremove to finish off the process.

host # pvchange -x n /dev/hdd1 <-- This will tell LVM not to allow allocation of any physical extents from this physical volume (See our original post on getting started with LVM for a slightly more in-depth explanation of these).

host # pvremove -f /dev/hdd1 <-- This will wipe the label on the physical drive so that LVM will no longer recognize it as a physical volume.

And you're all set! Your monitoring and display commands (pvscan, pvdisplay, vgscan, vgdisplay, lvscan and lvdisplay) will now show you disheartening results (that's assuming you didn't want to do this, which goes contrary to the intent of the post ;)

Tomorrow, we'll put a together a quick command reference for LVM, including (of course) a few extra commands so it's not "all" fluff ;)

Cheers,

Mike

Wednesday, June 11, 2008

Monitoring and Display Commands For LVM On Linux And Unix

Hey there,

Today, we're going to follow up on our previous post regarding getting started with LVM logical volume management and go over a few (perhaps) boring but essential commands you'll want to know in order to keep tabs on your setup both in good times and in bad.

Refer back to our initial post on getting started with LVM for any additional details, if you'd like them, but, for today's purposes, we're just going to use the outcome of that post as the simple setup that we'll be monitoring/displaying today. In a nutshell, we have one physical volume composed of one volume group which, in turn, contains only one logical volume (or you could think of it the other way around). Unless I'm completely off-center here today, our output from today should be extremely reminiscent of yesterday's ;)

Note: Based on your particular version, or vendor distribution of LVM, the output of these commands may be slightly different. Not so much so that it should make a significant difference.

Basically, our monitoring and displaying commands are broken down into three groups: Those dealing with "physical volumes," those dealing with "logical volumes" and those dealing with "volume groups." We'll step through them (not over and/or around them, even though that would be more polite ;) one by one (in twos):

Physical Volumes:

The two commands we'll be using here are pvscan and pvdisplay.

pvscan, as with all of the following commands, pretty much does what the name implies. It scans your system for LVM physical volumes. When used straight-up, it will list out all the physical volumes it can find on the system, including those "not" associated with volume groups (output truncated to save on space):

host # pvscan
pvscan
pvscan -- reading all physical volumes (this may take a while...)
...
pvscan -- ACTIVE PV "/dev/hda1" is in no VG [512 MB]
...
pvscan -- ACTIVE PV "/dev/hdd1" of VG "vg01"[512 MB / 266 MB free]
...


Next, we'll use pvdisplay to display our only physical volume:

host # pvdisplay /dev/hdd1 <-- Note that you can leave the /dev/hdd1, or any specification, off of the command line if you want to display all of your physical volumes. We just happen to know we only have one and are being particular ;)
...
PV Name /dev/hdd1
VG Name vg01
PV Size 512 MB
...


Other output should include whether or not the physical volume is allocatable (or "can be used" ;), total physical extents (see our post on getting started with LVM for a little more information on PE's), free physical extents, allocated physical extents and the physical volume's UUID (Identifier).

Volume Groups:

The two commands we'll be using here are vgscan and vgdisplay.

vgscan will report on all existing volume groups, as well as create a file (generally) called /etc/lvmtab (Some versions will create an /etc/lvmtab.d directory as well):

host # vgscan
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- found active volume group "vg01"
...


vgdisplay can be used to check on the state and condition of our volume group(s). Again, we're specifying our volume group on the command line, but this is not necessary:

host # vgdisplay vg01
...
VG Name vg01
...
VG Size 246 MB
...


this command gives even more effusive output. Everything from the maximum logical volumes the volume group can contain (including how many it currently does and how many of those are open), separate (yet similar) information with regards to the physical volumes it can encompass, all of the information you've come to expect about the physical extents and, of course, each volume's UUID.

Logical volumes:

The two commands we'll be using here are (you guessed it ;) lvscan and lvdisplay.

lvscan will give us a report on all of our logical volumes, and their state (ACTIVE/INACTIVE or possibly in ERROR) on our system, like so:

host # lvscan
...
lvscan -- ACTIVE "/dev/vg01/lvol01" [246 MB]
lvscan -- 1 logical volumes with 246 MB total in 1 volume group
lvscan -- 1 active logical volume


Once this step has been completed (and it should be completed at least once!), we can use lvdisplay to check out our logical volume(s). We'll be specifically looking at lvol01:

host # lvdisplay lvol01
...
LV Name /dev/vg01/lvol01
VG Name vg01
...


and we'll get our standard UUID information, read/write access, availability status and information on the logical volume size (among other useful information, hopefully including the block device the logical volume is associated with :)

It should be noted that the logical volume size is one of the areas we generally look at first. If, for some reason, the output from "df" seems less than what you intended, this will give you a confident indication of whether or not your logical volume is too small, or you just need to grow the filesystem, resident on it, to use all of the logical volume's space!

...And that about wraps up the "information gathering" section of this series of posts on LVM. In future posts we'll be looking at ways to manipulate volumes (both in groups and individually in their physical and logical aspects; although the physical volume is actually a logical representation of a logical representation of a physical device... but I think we went into too much detail about that gordian knot in our previous post, and, even then, haven't begun to scratch the surface ;). In future posts we'll also be looking at LVM on Unix and Linux and the relationship between the two, which is becoming less complex every day!

Cheers,

, Mike