LVM Tools Using the LVM Commands

Instead of using system-config-lvm, you can use a collection of LVM tools to manage your LVM volumes, adding new LVM physical partitions and removing current ones. The system-config-lvm system tool is actually a GUI interface for the LVM tools. You can either use LVM tools directly or use the lvm command to generate an interactive shell from which you can run LVM commands. There are Man pages for all the LVM commands. LVM maintains configuration information in the /etc/lvm/lvm.conf directory, where you can configure LVM options such as the log file or the directory for LVM devices (see the lvm.conf Man page for more details).

Displaying LVM Information

You can use the pvdisplay, vgdisplay, and lvdisplay commands to show detailed information about a physical partition, volume groups, and logical volumes. pvscan, vgscan, and lvscan list your physical, group, and logical volumes.

Managing LVM Physical Volumes with the LVM Commands

A physical volume can be any hard disk partition or RAID device. A RAID device is seen as a single physical volume. You can create physical volumes either from a single hard disk or from partitions on a hard disk. On very large systems with many hard disks, you would more likely use an entire hard disk for each physical volume.

To initialize a physical volume on an entire hard disk, you use the hard disk device name, as shown here:

pvcreate /dev/sdc

If you are using a single partition for an entire drive, you create a new physical volume using the partition's device name, as shown here:

pvcreate /dev/sdcl

This will create one physical partition, pv, called sdcl on the sdc hard drive (the third Serial ATA drive, drive c).

To initialize several drives, just list them. The following creates two physical partitions, sdc1 and sdd1.

pvcreate /dev/sdcl /dev/sddl

You could also use several partitions on different hard drives. This is a situation in which your hard drives each hold several partitions. This condition occurs often when you are using some partitions on your hard drive for different purposes like different operating systems, or if you want to distribute your logical group across several hard drives. To initialize these partitions at once, you simply list them.

pvcreate /dev/hda3 /dev/hdbl /dev/hdb2

Once you have initialized your partitions, you have to create LVM groups on them.

Managing LVM Groups

Physical LVM partitions are used to make up a volume group. You can manually create a volume group using the vgcreate command and the name of the group along with a list of physical partitions you want in the group.

If you are then creating a new volume group to place these partitions in, you can include them in the group when you create the volume group with the vgcreate command. The volume group can use one or more physical partitions. The default install configuration described previously used only one physical partition for the VolGroupOO. In the following example, a volume group called mymedia is made up two physical volumes, sdbl and sdcl.

vgcreate mymedia /dev/sdbl /dev/sdcl

The previous example sets up a logical group on two serial ATA hard drives, each with its own single partition. Alternatively, you can set up a volume group to span partitions on several hard drives. If you are using partitions for different functions, this approach gives you the flexibility for using all the space available across multiple hard drives.

The following example creates a group called rabbit consisting of three physical partitions, /dev/hda3, /dev/hdb4, and /dev/hdb4:

vgcreate rabbit /dev/hda3 /dev/hdb2 /dev/hdb4

If you to later want to add a physical volume to a volume group, you use the vgextend command. The vgextend command adds a new partition to a logical group. In the following example, the partition /dev/hda3 is added to the volume group rabbit. In effect, you are extending the size of the logical group by adding a new physical partition.

vgextend rabbit /dev/hda3

To add an entire new drive to a volume group, you would follow a similar procedure. The following example adds a fifth serial ATA hard drive, sde, first creating a physical volume on it and then adding that volume, sdel, to the mymedia volume group.

pvcreate /dev/sde1 vgextend mymedia /dev/sde1

To remove a physical partition, first remove it from its logical group. You may have to use the pmove command to move any data off the physical partition. Then use the vgreduce command to remove it from its logical group.

You can, in turn, remove a entire volume group by first deactivating it with vgchange -a n and then using the vgremove command.

Activating Volume Groups

Whereas in a standard file system structure, you mount and unmount hard disk partitions, with an LVM structure, you activate and deactivate entire volume groups. The group volumes are inaccessible until you activate them with the vgchange command with the -a option. To activate a group, first reboot your system, and then enter the vgchange command with the -a option and the y argument to activate the logical group (an n argument will deactivate the group).

vgchange -a y rabbit

Managing LVM Logical Volumes

To create logical volumes, you use the lvcreate command and then format your logical volume using the standard formatting command like mkfs.ext3. Keep in mind that all these actions can be performed at once by system-config-lvm (see Figure 31-3).

With the -n option you specify the volume's name, which functions like a hard disk partition's label. You use the -L option to specify the size of the volume. There are other options for implementing features such as whether to implement a linear, striped, or mirrored volume, or to specify the size of the extents to use. Usually the defaults work well. The following example creates a logical volume named projects on the rabbit logical group with a size of 20GB.

lvcreate -n projects -L 20GB rabbit

The following example sets up a logical volume on the mymedia volume group that is 540 GB in size. The mymedia volume group is made up of two physical volumes, each on 320 GB hard drives. In effect the two hard drives are logically seen as one.

lvcreate -n myvideos -L 540GB mymedia

Once you have created your logical volume, you then have to create a file system to use on it. The following creates an ext3 file system on the myvideos logical volume.

mkfs.ext3 myvideos

You can remove a logical volume with the lvremove command. With lvextend, you can increase the size of the logical volume, and lvreduce will reduce its size.

0 0

Post a comment