Categories

  • linux

At this point I am assuming that you have properly configured your fibre channel adapters/HBA’s, provisioned the ports on the switch, configured proper zoning, and configured multipathing. Possibly I will add that config to a separate post. Assuming all of this, after you have created a LUN on your storage device and presented it to your server, you can follow these steps to create a functional device using LVM commands.

List the devices currently attached to the system using

# multipath -l
mpath7 (360050768028180a83400000000000021) dm-0 IBM,2145
[size=1000G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=0][active]
\_ 5:0:2:0 sde 8:64 [active][undef]
\_ 5:0:3:0 sdf 8:80 [active][undef]
\_ 6:0:2:0 sdi 8:128 [active][undef]
\_ 6:0:3:0 sdj 8:144 [active][undef]
\_ round-robin 0 [prio=0][enabled]
\_ 5:0:0:0 sdc 8:32 [active][undef]
\_ 5:0:1:0 sdd 8:48 [active][undef]
\_ 6:0:0:0 sdg 8:96 [active][undef]
\_ 6:0:1:0 sdh 8:112 [active][undef]

The number of paths listed under this command will vary depending on the number of fibre connections configured on your HBA’s.

Here we can see that the multipath device is named mpath7 and it is on device dm-0.

You can also look at the device using the following:

# fdisk -l /dev/dm-0

Disk /dev/dm-0: 1073.7 GB, 1073741824000 bytes
255 heads, 63 sectors/track, 130541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

In my case this LUN is a 1TB drive. You will likely find that fdisk does not give you accurate information regarding the configuration of the device.

Next we will use some of the LVM based commands to create a physical volume (PV), a volume group (VG) on that physical volume , and a logical volume (LV) within the volume group. First create a physical volume on the physical device with the following command:

pvcreate /dev/dm-0

Or by accessing the device through it’s multipath device name

pvcreate /dev/mapper/mpath7

Next we will create a volume group on this physical volume:

# vgcreate vol_grp_name /dev/dm-0
Volume group "vol_grp_name" successfully created

you can now display the physical characterstics of your PV and VG with the following commands

# pvdisplay
"/dev/mpath/360050768028180a83400000000000021" is a new physical volume of "1000.00 GB"
--- NEW Physical volume ---
PV Name /dev/mpath/360050768028180a83400000000000021
VG Name
PV Size 1000.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX
# vgdisplay
--- Volume group ---
VG Name vol_grp_name
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1000.00 GB
PE Size 4.00 MB
Total PE 255999
Alloc PE / Size 0 / 0
Free PE / Size 255999 / 1000.00 GB
VG UUID af68Kj-oD2i-TKRI-jBpU-YKky-owSD-gwlSdp

Here we can see the VG size, the size of each PE, the total number of PE’s  along with allocated/free PE information.

Next we will create a LV on this VG using the following command:

lvcreate -l 20 -n my_lv_name vol_grp_name

Here we have specified that the drive will consist of 20 PE’s

  • Note: from the vgdisplay command we know there are a total of 255999 PE's with a size of 4MB each so we will have 20x4MB or a 80MB LV

The following command will display the information in your LV:

# lvdisplay
--- Logical volume ---
LV Name /dev/vol_grp_name/my_lv_name
VG Name vol_grp_name
LV UUID XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX
LV Write Access read/write
LV Status available
# open 0
LV Size 80.00 MB
Current LE 20
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

Now we can create a file system on our LV, allowing us to start using this device for writing files

#mkfs.ext3 /dev/vol_grp_name/my_lv_name

This command will make an EXT3 filesystem using all available space on the LV.

Next we can setup this device for mounting. We will do this by adding a mount point to the system and then adding the required information to the /etc/fstab file

# mkdir /data-san

Assuming we wish to have our mount point as /data-san

# vi /etc/fstab

Add the following line to the file at the end

/dev/vol_grp_name/my_lv_name /data-san ext3 defaults 1 1

Write this information and execute the following command

# mount /data-san

You can run df -h or your favorate command to check the size of each mount point on the system, you should now see your 80MB volume mounted on /data-san, ready to roll.

Extending the Volume

But now we have reached the point where we have a LUN that is 1TB in size that has a LV consisting of only 20 PE’s totalling 80MB in size that has a EXT3 filesystem sitting on it and is mounted to a directory that could be in use. What do we do if we want to increase the size of this device to provide additional storage? Easy, lets resize and extend this device:

You can add additional PE’s to a LV using the following command.

# lvextend -L +100M/dev/vol_grp_name/my_lv_name

or

# lvextend -l +100%FREE /dev/vol_grp_name/my_lv_name

The first command will add 100MB to the LV and the second will add 100% of the Free space available in the VG. The VG will now be extended to include the additional space you have specified.

But if you were to run df you would see that the mounted drive is still at it’s original size of 80MB. This is due to the fact that you have extended the logical volume the file system sits on, but not the file system itself.

In order to extend the EXT3 filesystem, we will execute the following:

resize2fs /dev/vol_grp_name/my_lv_name

If the drive is mounted this will take much longer, and may not be the safest operation if there are large amounts of reads/writes occurring. The safest method is to unmount /dev/data-san, execute the resize2fs command, and then mount /dev/data-san.

After this command completes you will have a resized, usable amount of space that you have specified.

 

If you would like to expand the size of an existing LUN from the storage side, and then have these changes take effect please look at my post Expanding a LUN on RedHat