Showing posts with label logical. Show all posts
Showing posts with label logical. Show all posts

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

Tuesday, June 10, 2008

How To Get Started With Logical Volume Management In Linux

Hey again,

Today, since past posts regarding disk management software have mostly been limited to Veritas Volume Manager, I thought we'd look at LVM on Linux (In a future post, we'll check out the differences between LVM 1 and 2, but for now I figured we could keep it simple and broad).

If you use any of the "major player" Linux flavours out there, you've probably noticed (over the last year or so) that standard installs show all your disks listed out in df, like:

/dev/mapper/vg01-lvol01 246M 75.2M 158M 32% /dir


rather than the old-style:

/dev/hdd1 246M 75.2M 158M 32% /dir


that you've (if you're anything like me and only have two hard drives on the home PC you're running Linux on ;) grown to love.

And, while I think it's fantastic that Linux has grown into a mostly-user-friendly operating system with GUI's to make all of the extended partitioning and volume management more accessible, I also think there's something to be said for knowing how to be able to set all that stuff up on your own. You never know when your main display (or X-windows session) will die on you and, at some point, you may end up having to do some disk repair on the lonely old command line.

With that in mind, we'll step through the most basic LVM setup: Getting from /dev/hdd to /dev/mapper/vg01-lvol01 from the command prompt.

Our basic (and huge assumption) here is that we've got a primary drive to work from (although we could do this just as easily from a rescue, or live, CD-ROM if we needed to perform this work on our primary disk during the Linux installation process or a freakish-nightmare of a fix)

First, we'll want to use fdisk to create a "new" "primary" partition that consists of the entire disk (512Mb in size). Barring a primer on fdisk, we'll want to set up our disk to have one primary partition that consists of all cylinders (first and last should be the default start and end values) and is set to the "Linux LVM" partition type.

Once we're done with the stuff we'd "normally" do (for the most part) to set up any other type of partition table on our /dev/hdd disk, we can begin to play around with the LVM commands. Note that if you chose any partition type other than LVM when setting up your partition, using the following commands will, at best, result in error messages and accomplish nothing :)

If you've ever used HP-UX before, a lot of these commands will seem familiar. There's a reason, but the legalities of discussing it (and possibly getting bits of it wrong) fall outside the scope of my pocketbook ;)

The first thing we'll do is create a "physical volume," like so:

host # pvcreate /dev/hdd1

Yes, it was a physical volume already. The logical-physical relationship sometimes doesn't hold up to scrutiny outside of the "rules" ;)

Next, well create a "volume group." This is necessary, because "logical volumes" run in packs... pardon my lack of propriety ;) We could use the "-s" option here to define the "physical extent" size, but we'll leave that alone. To say the least, specifying this requires some research and planning. If you get that number wrong, things can go South later, and you'll have to do some ugly backtracking. We just want to define a "volume group" so we have something to work with. We'll call it vg01, for lack of a more original name.

host # vgcreate vg01 /dev/hdd1

Next, we'll create a "logical volume" (we'll name this one "lvol01" to keep things consistent) of 246 Megabytes size. That should fit nicely inside vg01 (which we're basically using to represent the entire partition /dev/hdd1). We could make our "logical volume" as large as the entire partition and/or "volume group", but that would defeat the purpose of this whole exercise. The aim, of course, is to end up with flexible volumes so we can resize them later if we need to.

host # lvcreate -L 246M -n lvol01 vg01

This is where the /dev/mapper stuff comes into play (it never made sense to me the first time I saw it... really. It's because of my past experience with HP-UX ;) The "lvcreate" command creates a symlink between /dev/vg01/lvol01 and the character device /dev/mapper/vg01-lvol01.

And, next, all we have to do is format that bad boy:

host # mkfs -t ext3 /dev/vg01/lvol01

Note that, above, you can set a reserved block count (based on percentage) using the -m flag. I would usually set this to "-m 5" so that 5% of the allocated space would be reserved for root (although you can set it as low as 1). This way, if someone jams your filesystem up to 100% and no one can get any work done, you can still log in as root and fix the issue. -v is another useful flag if you want to see verbose output. You can insert these two flags anywhere in the above command line except at the very end (after the logical device name) or in between the -t flag and its argument. Common sense, I know, but I feel compelled to over-explain ;)

Now, we'll make a mount point, or, really, just make a new directory off of the root filesystem (although you can do overlays if you wanna get creative ;)

host # mkdir /dir

and then we'll mount our logical volume up and check it out with df:

host # mount -t ext3 /dev/vg01/lvol01 /dir

host # df -h /dir
...
/dev/mapper/vg0-lvol0 246M 75.2M 158M 32% /dir


Tomorrow, or maybe the day after that, we'll take a look at some more ways to manipulate your existing volumes, add more volumes, do mirroring and lots of other fun stuff that LVM allows you to do.

For now, we'll just thank our deity-of-choice that this all worked out ;)

Cheers,

, Mike