Playing with LVM: Preparing for iSCSI Implementation

This is the first of two posts about how to set up a server for storage sharing using iSCSI, specifically running the CentOS Linux distribution.

Good Old Preparation

In order to do this properly, we’ll need a partition or volume that is going to be shared. CentOS 6 natively uses LVM (Logical Volume Management) which is an excellent tool. Because almost my entire harddrive was used by default for the home partition, I’m going to have to play with the LVM tools before I can begin any iSCSI setup.

1. Collect information

LVM is brilliant. First, the storage hardware is declared as a PV (Physical Volume) just to indicate that there is hardware to draw from. Then, Physical Volumes are assigned to a VG (Volume Grouping), which acts like a giant pool of storage space.

The distinctions between the actual physical devices disappear beyond this point, as the VG makes all it’s contained Physical Volumes act like one hard disk. So first I have to find out what PVs are on my machine. I do this as root at the command line:

# pvs

which returns

 PV         VG              Fmt  Attr PSize   PFree
 /dev/sda2  vg_box2senecacd lvm2 a--  465.27g    0
Important Info:

PV: Tells me the device file that LVM considers a physical volume.
VG: Tells me the name of the VG it is assigned to
PFree: Tells me how much of the space in the PV is free for allocation.

0 PFree? This means there’s nothing I can use for my iSCSI drive! Not good.

LVs (Logical Volumes) are the closest thing to a conservative partition that LVM offers. This is a volume that, on creation, requests space from a VG. If there’s some available, the LV is created with no problems.

So the fact that there’s no unallocated space in the VG means that there’s an LV on my machine (or possible more) that are hogging all the space!

To see what I have I run the following terminal command (again as root):

# lvs

which returns

 LV      VG              Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
 lv_home vg_box2senecacd -wi-ao-- 411.41g                                           
 lv_root vg_box2senecacd -wi-ao--  50.00g                                           
 lv_swap vg_box2senecacd -wi-ao--   3.86g

Hmm. So not one, not two but three LVs on my system already!

The culprit, clearly, is lv_home with 411gb of my 465gb harddisk. So now what?

2. Reduce an LV to Create Space

WARNING: This is dangerous. System files are scattered literally all over the LV, so even though the vast majority of it is unused, I have to understand what I’m doing in order to not break my (still a baby) system.

The terminal command will read:

# lvreduce /dev/vg_box2senecacd/lv_home -r -L 200g

This should (fingers crossed!) reduce my lv_home LV from 411gb to 200gb (-L 200g), while resizing the underlying filesystem before hand (-r).

This command requires that I unmount my /home/ directory.
In order to do this, I needto sign out of my user profile 
and into the root profile, then open a terminal window to
run this command.

It worked!  Now if I run

# lvs

It returns:

LV      VG              Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
lv_home vg_box2senecacd -wi-ao-- 200.00g                                           
lv_root vg_box2senecacd -wi-ao--  50.00g                                           
lv_swap vg_box2senecacd -wi-ao--   3.86g

And to check my unallocated space, I will again run

# pvs

which returns

PV         VG              Fmt  Attr PSize   PFree  
/dev/sda2  vg_box2senecacd lvm2 a--  465.27g 211.41g

And now I have free space.

3. Create a Dedicated LV for iSCSI Storage

This part is easy.  I’m going to create an LV that uses space from the VG vg_box2senecacd using this command:

# lvcreate -L 50g -n lv_scsiTest1 vg_box2senecacd

and because I wanna play around a bit more, I’m going to do the same thing again twice.


Now I’m ready to make the server… do server things! iSCSI is only a few steps, but that’s all the time we have for today folks, so expect part 2 soon.