Archive for February, 2012

Removing Physical Volumes from a Volume Group

To remove unused physical volumes from a volume group, use the vgreduce command. The vgreduce command shrinks a volume group’s capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.

Before removing a physical volume from a volume group, you can make sure that the physical volume is not used by any logical volumes by using the pvdisplay command.

# pvdisplay /dev/hda1

If the physical volume is still being used you will have to migrate the data to another physical volume using the pvmove command. Then use the vgreduce command to remove the physical volume:

The following command removes the physical volume /dev/hda1 from the volume group my_volume_group.

# vgreduce my_volume_group /dev/hda1
SBDavid

Creating Volume Groups

Creating Volume Groups

To create a volume group from one or more physical volumes, use the vgcreate command. The vgcreate command creates a new volume group by name and adds at least one physical volume to it.

The following command creates a volume group named vg1 that contains physical volumes /dev/sdd1 and /dev/sde1.

# vgcreate vg1 /dev/sdd1 /dev/sde1

When physical volumes are used to create a volume group, its disk space is divided into 4MB extents, by default. This extent is the minimum amount by which the logical volume may be increased or decreased in size. Large numbers of extents will have no impact on I/O performance of the logical volume.

You can specify the extent size with the -s option to the vgcreate command if the default extent size is not suitable.

SBDavid

Resizing & Removing Physical Volumes

Resizing & Removing Physical Volumes

If you need to change the size of an underlying block device for any reason, use the pvresizecommand to update LVM with the new size. You can execute this command while LVM is using the physical volume.

If a device is no longer required for use by LVM, you can remove the LVM label with the pvremovecommand. Executing the pvremove command zeroes the LVM metadata on an empty physical volume. If the physical volume you want to remove is currently part of a volume group, you must remove it from the volume group with the vgreduce command.

# pvremove /dev/sdd5

Preventing Allocation on a Physical Volume

You can prevent allocation of physical extents on the free space of one or more physical volumes with the pvchange command. This may be necessary if there are disk errors, or if you will be removing the physical volume.

The following command disallows the allocation of physical extents on /dev/sdk1.

# pvchange -x n /dev/sdk1

We can also use the -xy arguments of the pvchange command to allow allocation where it had previously been disallowed.

SBDavid

Displaying Physical Volumes

Displaying Physical Volumes

There are three commands you can use to display properties of LVM physical volumes: pvs,pvdisplay, and pvscan.

The pvs command provides physical volume information in a configurable form, displaying one line per physical volume. The pvs command provides a great deal of format control, and is useful for scripting.

The pvdisplay command provides a verbose multi-line output for each physical volume. It displays physical properties (size, extents, volume group, etc.) in a fixed format.

The following example shows the output of the pvdisplay command for a single physical volume.

# pvdisplay

Next »