Showing posts with label lvremove. Show all posts
Showing posts with label lvremove. 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