Last week, I covered online extension of file systems using Logical Volume Manager (LVM). This week looks at how to create physical volumes, volume groups, and logical volumes.The first step is to create the physical volumes. LVM on Linux is a little different to LVM on HP-UX in one aspect: LVM on Linux allows a whole disk or a partition on a disk to be used as a Physical Volume (PV). If partitions are being used, then the first step is to use the command fdisk to see what partitions exist on a disk, and to create a new LVM partition. Figure A shows the operation of fdisk. The red circles show the inputs required. Stepping through the options for fdisk, the first option is n, which will add a new partition. The defaults for the partition number and sector sizes are sufficient for most cases. The next step is to select the type of partition; here, the type is 8e for Linux LVM. Once this is done, typing in p will print out the partition table. One final step is required, which is to write the new partition table to disk. The w option does this and exits on completion. The partition is now ready for use.
One area to be mindful of is the group of settings for Physical Extent (PE) size. The default PE size is 4MB. Generally, there is no need to deviate from this size unless it is specifically requested. The PE size is configurable, but once the volume group is created the PE size cannot be changed easily. It can be changed, but the way this is done is to remove and recreate the volume group. This may not be desirable, particularly if the volume group has a number of logical volumes that are in use.
Creation of the volume group leads into creation of logical volumes. The command lvcreate is used to create logical volumes. There are a few options that can be used. The -L option allows specification of the logical volume size in Megabytes, Terabytes, Petabytes or Exabytes (using the suffixes M, T, P or E respectively). The default is Megabytes. The -l option specifies physical extents. One useful option from a System Administration perspective is the -n option, which is used to specify a name for the logical volume. If this is not specified, the logical volume name defaults to the next default logical volume number.
There are other options that lvcreate has, such as -m (mirror), -i (stripes) and -I (stripe size). A full examination of these options will be provided in a future post. They are mentioned here for information.Figure G shows the command string used for a simple lvcreate.
Successful creation of a logical volume leads to the final step: creation of a file system. The main file systems (ext2, ext3, ext4 or reiserfs) can be created by the mkfs command with a -t option to specify the type. In this example, an ext4 file system is created.
Summing up, LVM can provide flexibility in managing physical volumes. This discussion has mainly been about how to create a volume group and logical volumes, but there is potential for other options to be used, such as mirroring or striping.
Scott Reeves has worked for Hewlett Packard on HP-UX servers and SANs, and has worked in similar areas in the past at IBM. Currently he works as an independent IT consultant, specializing in Wi-Fi networks and SANs.