Logical Volume Creation Overview
The following is a summary of the steps to perform to create an LVM logical volume.
1. Initialize the partitions you will use for the LVM volume as physical volumes (this labels them).
2. Create a volume group.
3. Create a logical volume.
After creating the logical volume you can create and mount the file system.
Removing Physical Volumes from a Volume Group
DESCRIPTION
vgreduce allows you to remove one or more unused 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.
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
It’s a good idea to run this option with –test first to find out what it would remove before running it for real.
Scanning Disks for Volume Groups to Build the Cache File
The vgscan command scans all supported disk devices in the system looking for LVM physical volumes and volume groups. This builds the LVM cache in the /etc/lvm/.cache file, which maintains a listing of current LVM devices.
LVM runs the vgscan command automatically at system startup and at other times during LVM operation, such as when you execute a vgcreate command or when LVM detects an inconsistency. You may need to run the vgscan command manually when you change your hardware configuration, causing new devices to be visible to the system that were not present at system bootup. This may be necessary, for example, when you add new disks to the system on a SAN or hotplug a new disk that has been labeled as a physical volume.
You can define a filter in the lvm.conf file to restrict the scan to avoid specific devices.
SYNOPSIS
DESCRIPTION
lvm.conf is loaded during the initialisation phase of lvm (8). This file can in turn lead to other files being loaded - settings read in later override earlier settings. File timestamps are checked between commands and if any have changed, all the files are reloaded.
Use lvm dumpconfig to check what settings are in use.
# lvm dumpconfig
devices {
dir=”/dev”
scan=”/dev”
preferred_names=[]
filter=”a/.*/”
cache_dir=”/etc/lvm/cache”
cache_file_prefix=”"
write_cache_state=1
sysfs_scan=1
md_component_detection=1
ignore_suspended_devices=0
}
Displaying Volume Groups
There are two commands you can use to display properties of LVM volume groups: vgs and vgdisplay.
The vgscan command, which scans all the disks for volume groups and rebuilds the LVM cache file, also displays the volume groups.
The vgs command provides volume group information in a configurable form, displaying one line per volume group. The vgs command provides a great deal of format control, and is useful for scripting.
The vgdisplay command displays volume group properties (such as size, extents, number of physical volumes, etc.) in a fixed form. The following example shows the output of a vgdisplay command for the volume group new_vg. If you do not specify a volume group, all existing volume groups are displayed.
# vgdisplay new_vg
— Volume group —
VG Name new_vg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 11
VG Access read/write
VG Status resizable
DESCRIPTION
vgdisplay allows you to see the attributes of VolumeGroupName (or all volume groups if none is given) with it’s physical and logical volumes and their sizes etc.
vgs (8) is an alternative that provides the same information in the style of ps (1).
Adding Physical Volumes to a Volume Group
To add additional physical volumes to an existing volume group, use the vgextend command. The vgextend command increases a volume group’s capacity by adding one or more free physical volumes.
The following command adds the physical volume /dev/sdf1 to the volume group vg1
DESCRIPTION
vgextend allows you to add one or more initialized physical volumes ( see pvcreate(8) ) to an existing volume group to extend it in size.
Examples
“vgextend vg00 /dev/sda4 /dev/sdn1″ tries to extend the existing volume group “vg00″ by the new physical volumes (see pvcreate(8) ) “/dev/sdn1″ and /dev/sda4″.