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
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:
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:
Or by accessing the device through it’s multipath device name
Next we will create a volume group on this physical volume:
you can now display the physical characterstics of your PV and VG with the following commands
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:
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:
Now we can create a file system on our LV, allowing us to start using this device for writing files
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
Assuming we wish to have our mount point as /data-san
Add the following line to the file at the end
Write this information and execute the following command
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.
or
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:
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