This section briefly describes the principles behind Logical Volume Manager (LVM) and its basic features that make it useful under many circumstances. The YaST LVM configuration can be reached from the YaST Expert Partitioner. This partitioning tool enables you to edit and delete existing partitions and create new ones that should be used with LVM.
Using LVM might be associated with increased risk, such as data loss. Risks also include application crashes, power failures, and faulty commands. Save your data before implementing LVM or reconfiguring volumes. Never work without a backup.
LVM enables flexible distribution of hard disk space over several file systems. It was developed because the need to change the segmentation of hard disk space might arise only after the initial partitioning has already been done during installation. Because it is difficult to modify partitions on a running system, LVM provides a virtual pool (volume group or VG) of memory space from which logical volumes (LVs) can be created as needed. The operating system accesses these LVs instead of the physical partitions. Volume groups can span more than one disk, so that several disks or parts of them can constitute one single VG. In this way, LVM provides a kind of abstraction from the physical disk space that allows its segmentation to be changed in a much easier and safer way than through physical repartitioning.
Figure 4.1, “Physical Partitioning versus LVM” compares physical partitioning (left) with LVM segmentation (right). On the left side, one single disk has been divided into three physical partitions (PART), each with a mount point (MP) assigned so that the operating system can access them. On the right side, two disks have been divided into two and three physical partitions each. Two LVM volume groups (VG 1 and VG 2) have been defined. VG 1 contains two partitions from DISK 1 and one from DISK 2. VG 2 contains the remaining two partitions from DISK 2.
In LVM, the physical disk partitions that are incorporated in a volume group are called physical volumes (PVs). Within the volume groups in Figure 4.1, “Physical Partitioning versus LVM”, four logical volumes (LV 1 through LV 4) have been defined, which can be used by the operating system via the associated mount points. The border between different logical volumes need not be aligned with any partition border. See the border between LV 1 and LV 2 in this example.
LVM features:
Several hard disks or partitions can be combined in a large logical volume.
Provided the configuration is suitable, an LV (such as
/usr) can be enlarged when the free space is
exhausted.
Using LVM, it is possible to add hard disks or LVs in a running system. However, this requires hot-swappable hardware that is capable of such actions.
It is possible to activate a striping mode that distributes the data stream of a logical volume over several physical volumes. If these physical volumes reside on different disks, this can improve the reading and writing performance like RAID 0.
The snapshot feature enables consistent backups (especially for servers) in the running system.
With these features, using LVM already makes sense for heavily used home PCs or small servers. If you have a growing data stock, as in the case of databases, music archives, or user directories, LVM is especially useful. It allows file systems that are larger than the physical hard disk. Another advantage of LVM is that up to 256 LVs can be added. However, keep in mind that working with LVM is different from working with conventional partitions.
Starting from kernel version 2.6, LVM version 2 is available, which is downward-compatible with the previous LVM and enables the continued management of old volume groups. When creating new volume groups, decide whether to use the new format or the downward-compatible version. LVM 2 does not require any kernel patches. It makes use of the device mapper integrated in kernel 2.6. This kernel only supports LVM version 2. Therefore, when talking about LVM, this section always refers to LVM version 2.
You can manage new or existing LVM storage objects by using the YaST Partitioner. Instructions and further information about configuring LVM is available in the official LVM HOWTO (http://tldp.org/HOWTO/LVM-HOWTO/).
If you add multipath support after you have configured LVM, you must
modify the /etc/lvm/lvm.conf file to scan only the
multipath device names in the /dev/disk/by-id
directory as described in
Section 7.2.4, “Using LVM2 on Multipath Devices”, then reboot
the server.
For each disk, partition the free space that you want to use for LVM as
0x8E Linux LVM. You can create one or multiple LVM
partitions on a single device. It is not necessary for all of the
partitions on a device to be LVM partitions.
You can use the Volume Group function to group one or more LVM partitions into a logical pool of space called a volume group, then carve out one or more logical volumes from the space in the volume group.
In the YaST Partitioner, only the free space on the disk is made available to you as you are creating LVM partitions. If you want to use the entire disk for a single LVM partition and other partitions already exists on the disk, you must first remove all of the existing partitions to free the space before you can use that space in an LVM partition.
Deleting a partition destroys all of the data in the partition.
Launch YaST as the root user.
In YaST, open the .
(Optional) Remove one or more existing partitions to free that space and make it available for the LVM partition you want to create.
For information, see Section 4.12, “Deleting an LVM Partition (Physical Volume)”.
On the Partitions page, click .
Under , select or, then click .
Specify the , then click .
Configure the partition format:
Click .
The partitions are not actually created until you click and to exit the partitioner.
Repeat Step 4 through Step 8 for each Linux LVM partition you want to add.
Click , verify that the new Linux LVM partitions are listed, then click to exit the partitioner.
(Optional) Continue with the Volume Group configuration as described in Section 4.3, “Creating Volume Groups”.
An LVM volume group organizes the Linux LVM partitions into a logical pool of space. You can carve out logical volumes from the available space in the group. The Linux LVM partitions in a group can be on the same or different disks. You can add LVM partitions from the same or different disks to expand the size of the group. Assign all partitions reserved for LVM to a volume group. Otherwise, the space on the partition remains unused.
Launch YaST as the root user.
In YaST, open the .
In the left panel, click .
A list of existing Volume Groups are listed in the right panel.
At the lower left of the Volume Management page, click .
Specify the .
If you are creating a volume group at install time, the name
system is suggested for a volume group that will
contain the SUSE Linux Enterprise Server system files.
Specify the .
The defines the size of a physical block in the volume group. All the disk space in a volume group is handled in chunks of this size. Values can be from 1 KB to 16 GB in powers of 2. This value is normally set to 4 MB.
In LVM1, a 4 MB physical extent allowed a maximum LV size of 256 GB because it supports only up to 65534 extents per LV. VM2 does not restrict the number of physical extents. Having a large number of extents has no impact on I/O performance to the logical volume, but it slows down the LVM tools.
Different physical extent sizes should not be mixed in a single VG. The extent should not be modified after the initial setup.
In the list, select the Linux LVM partitions that you want to make part of this volume group, then click to move them to the list.
Click .
The new group appears in the list.
On the Volume Management page, click , verify that the new volume group is listed, then click .
When the Linux LVM partitions are assigned to a volume group, the partitions are then referred to as a physical volumes.
To add more physical volumes to an existing volume group:
Launch YaST as the root user.
In YaST, open the .
In the left panel, select Volume Management and expand the list of groups.
Under Volume Management, select the volume group, then click the tab.
At the bottom of the page, click .
Select a physical volume (LVM partitions) from the list then click Add to move it to the list.
Click .
Click , verify that the changes are listed, then click .
After a volume group has been filled with physical volumes, use the Logical Volumes dialog box (see Figure 4.3, “Logical Volume Management”) to define and manage the logical volumes that the operating system should use. This dialog lists all of the logical volumes in that volume group. You can use , , and options to manage the logical volumes. Assign at least one logical volume to each volume group. You can create new logical volumes as needed until all free space in the volume group has been exhausted.
Beginning in SLES 11 SP3, an LVM logical volume can be thinly provisioned. Thin provisioning allows you to create logical volumes with sizes that overbook the available free space. You create a thin pool that contains unused space reserved for use with an arbitrary number of thin volumes. A thin volume is created as a sparse volume and space is allocated from a thin pool as needed. The thin pool can be expanded dynamically when needed for cost-effective allocation of storage space.
To use thinly provisioned volumes in a cluster, the thin pool and the thin volumes that use it must be managed in a single cluster resource. This allows the thin volumes and thin pool to always be mounted exclusively on the same node.
It is possible to distribute the data stream in the logical volume among
several physical volumes (striping). If these physical volumes reside on
different hard disks, this generally results in a better reading and
writing performance (like RAID 0). However, a striping LV with
n stripes can only be created correctly if the hard
disk space required by the LV can be distributed evenly to
n physical volumes. For example, if only two physical
volumes are available, a logical volume with three stripes is
impossible.
Launch YaST as the root user.
In YaST, open the .
In the left panel, select Volume Management and expand it to see the list of volume groups.
Under Volume Management, select the volume group, then click the tab.
In the lower left, click to open the Add Logical Volume dialog box.
Specify the for the logical volume, then click .
Specify the type of LVM volume:
Normal volume: (Default) The volume’s space is allocated immediately.
Thin pool: The logical volume is a pool of space that is reserved for use with thin volumes. The thin volumes can allocate their needed space from it on demand.
Thin volume: The volume is created as a sparse volume. The volume allocates needed space on demand from a thin pool.
Specify the size of the volume and whether to use multiple stripes.
|
Specify the formatting options for the logical volume:
Click .
Click , verify that the changes are listed, then click .
Activation behavior for non-root LVM volume groups is controlled by
parameter settings in the /etc/sysconfig/lvm file.
By default, non-root LVM volume groups are automatically activated on
system restart by /etc/rc.d/boot.lvm, according to
the setting for the LVM_VGS_ACTIVATED_ON_BOOT
parameter in the /etc/sysconfig/lvm file. This
parameter allows you to activate all volume groups on system restart, or
to activate only specified non-root LVM volume groups.
To activate all non-root LVM volume groups on system restart, ensure
that the value for the LVM_VGS_ACTIVATED_ON_BOOT
parameter in the /etc/sysconfig/lvm file is empty
(""). This is the default setting. For almost all
standard LVM installations, it can safely stay empty.
LVM_VGS_ACTIVATED_ON_BOOT=""
To activate only a specified non-root LVM volume group on system
restart, specify the volume group name as the value for the
LVM_VGS_ACTIVATED_ON_BOOT parameter:
LVM_VGS_ACTIVATED_ON_BOOT="vg1"
By default, newly discovered LVM volume groups are not automatically
activated. The LVM_ACTIVATED_ON_DISCOVERED parameter
is disabled in the /etc/sysconfig/lvm file:
LVM_ACTIVATED_ON_DISCOVERED="disable"
You can enable the LVM_ACTIVATED_ON_DISCOVERED
parameter to allow newly discovered LVM volume groups to be activated
via udev rules:
LVM_ACTIVATED_ON_DISCOVERED="enable"
A tag is an unordered keyword or term assigned to the metadata of a storage object. Tagging allows you to classify collections of LVM storage objects in ways that you find useful by attaching an unordered list of tags to their metadata.
After you tag the LVM2 storage objects, you can use the tags in commands to accomplish the following tasks:
Select LVM objects for processing according to the presence or absence of specific tags.
Use tags in the configuration file to control which volume groups and logical volumes are activated on a server.
Override settings in a global configuration file by specifying tags in the command.
A tag can be used in place of any command line LVM object reference that accepts:
a list of objects
a single object as long as the tag expands to a single object
Replacing the object name with a tag is not supported everywhere yet. After the arguments are expanded, duplicate arguments in a list are resolved by removing the duplicate arguments, and retaining the first instance of each argument.
Wherever there might be ambiguity of argument type, you must prefix a
tag with the commercial at sign (@) character, such as
@mytag. Elsewhere, using the “@” prefix
is optional.
Consider the following requirements when using tags with LVM:
An LVM tag word can contain the ASCII uppercase characters A to Z, lowercase characters a to z, numbers 0 to 9, underscore (_), plus (+), hyphen (-), and period (.). The word cannot begin with a hyphen. The maximum length is 128 characters.
You can tag LVM2 physical volumes, volume groups, logical volumes, and logical volume segments. PV tags are stored in its volume group’s metadata. Deleting a volume group also deletes the tags in the orphaned physical volume. Snapshots cannot be tagged, but their origin can be tagged.
LVM1 objects cannot be tagged because the disk format does not support it.
Add a tag to (or tag) an LVM2 storage object.
Example.
vgchange --addtag @db1 vg1
Remove a tag from (or untag) an LVM2 storage object.
Example.
vgchange --deltag @db1 vg1
Specify the tag to use to narrow the list of volume groups or logical volumes to be activated or deactivated.
Example.
Enter the following to activate it the volume if it has a tag that matches the tag provided:
lvchange -ay --tag @db1 vg1/vol2
Add the following code to the /etc/lvm/lvm.conf
file to enable host tags that are defined separately on host in a
/etc/lvm/lvm_<hostname>.conf
file.
tags {
# Enable hostname tags
hosttags = 1
}
You place the activation code in the
/etc/lvm/lvm_<hostname>.conf
file on the host. See
Section 4.7.4.3, “Defining Activation”.
tags {
tag1 { }
# Tag does not require a match to be set.
tag2 {
# If no exact match, tag is not set.
host_list = [ "hostname1", "hostname2" ]
}
}
You can modify the /etc/lvm/lvm.conf file to
activate LVM logical volumes based on tags.
In a text editor, add the following code to the file:
activation {
volume_list = [ "vg1/lvol0", "@database" ]
}
Replace @database with the your tag. Use
"@*" to match the tag against any tag set on the
host.
The activation command matches against vgname, vgname/lvname, or @tag set in the metadata of volume groups and logical volumes. A volume group or logical volume is activated only if a metadata tag matches. The default if there is no match is not to activate.
If volume_list is not present and any tags are
defined on the host, then it activates the volume group or logical
volumes only if a host tag matches a metadata tag.
If volume_list is not present and no tags are
defined on the host, then it does activate.
You can use the activation code in a host’s configuration file
(/etc/lvm/lvm_<host_tag>.conf)
when host tags are enabled in the lvm.conf file.
For example, a server has two configuration files in the
/etc/lvm/ folder:
lvm.conf
|
lvm_<host_tag>.conf
|
At startup, load the /etc/lvm/lvm.conf file, and
process any tag settings in the file. If any host tags were defined,
it loads the related
/etc/lvm/lvm_<host_tag>.conf
file.When it searches for a specific configuration file entry, it
searches the host tag file first, then the lvm.conf
file, and stops at the first match.Within the
lvm_<host_tag>.conf
file, use the reverse order that tags were set. This allows the file
for the last tag set to be searched first. New tags set in the host
tag file will trigger additional configuration file loads.
You can set up a simple hostname activation control by enabling the
hostname_tags option in a the
/etc/lvm/lvm.conf file. Use the same file on every
machine in a cluster so that it is a global setting.
In a text editor, add the following code to the
/etc/lvm/lvm.conf file:
tags {
hostname_tags = 1
}
Replicate the file to all hosts in the cluster.
From any machine in the cluster, add db1 to the
list of machines that activate vg1/lvol2:
lvchange --addtag @db1 vg1/lvol2
On the db1 server, enter the following to
activate it:
lvchange -ay vg1/vol2
The examples in this section demonstrate two methods to accomplish the following:
Activate volume group vg1 only on the database
hosts db1 and db2.
Activate volume group vg2 only on the file
server host fs1.
Activate nothing initially on the file server backup host
fsb1, but be prepared for it to take over from
the file server host fs1.
In the following solution, the single configuration file is replicated among multiple hosts.
Add the @database tag to the metadata of volume
group vg1. In a terminal console, enter
vgchange --addtag @database vg1
Add the @fileserver tag to the metadata of volume
group vg2. In a terminal console, enter
vgchange --addtag @fileserver vg2
In a text editor, modify the /etc/lvm/lvm.conf
file with the following code to define the
@database, @fileserver,
@fileserverbackup tags.
tags {
database {
host_list = [ "db1", "db2" ]
}
fileserver {
host_list = [ "fs1" ]
}
fileserverbackup {
host_list = [ "fsb1" ]
}
}
activation {
# Activate only if host has a tag that matches a metadata tag
volume_list = [ "@*" ]
}
Replicate the modified /etc/lvm/lvm.conf file
to the four hosts: db1,
db2, fs1, and
fsb1.
If the file server host goes down, vg2 can be
brought up on fsb1 by entering the following
commands in a terminal console on any node:
vgchange --addtag @fileserverbackup vg2 vgchange -ay vg2
In the following solution, each host holds locally the information about which classes of volume to activate.
Add the @database tag to the metadata of volume
group vg1. In a terminal console, enter
vgchange --addtag @database vg1
Add the @fileserver tag to the metadata of volume
group vg2. In a terminal console, enter
vgchange --addtag @fileserver vg2
Enable host tags in the /etc/lvm/lvm.conf file:
In a text editor, modify the
/etc/lvm/lvm.conf file with the following
code to enable host tag configuration files.
tags {
hosttags = 1
}
Replicate the modified /etc/lvm/lvm.conf file
to the four hosts: db1,
db2, fs1, and
fsb1.
On host db1, create an activation configuration
file for the database host db1. In a text
editor, create a /etc/lvm/lvm_db1.conf file and
add the following code:
activation {
volume_list = [ "@database" ]
}
On host db2, create an activation configuration
file for the database host db2. In a text
editor, create a /etc/lvm/lvm_db2.conf file and
add the following code:
activation {
volume_list = [ "@database" ]
}
On host fs1, create an activation configuration file for the file
server host fs1.In a text editor, create
a /etc/lvm/lvm_fs1.conf file and add the
following code:
activation {
volume_list = [ "@fileserver" ]
}
If the file server host fs1 goes down, to bring
up a spare file server host fsb1 as a file server:
On host fsb1, create an activation
configuration file for the host fsb1. In a
text editor, create a /etc/lvm/lvm_fsb1.conf
file and add the following code:
activation {
volume_list = [ "@fileserver" ]
}
In a terminal console, enter one of the following commands:
vgchange -ay vg2 vgchange -ay @fileserver
You can add and remove Linux LVM partitions from a volume group to expand or reduce its size.
Removing a partition can result in data loss if the partition is in use by a logical volume.
Launch YaST as the root user.
In YaST, open the .
In the left panel, select Volume Management and expand it to see the list of volume groups.
Under Volume Management, select the volume group, then click the tab.
At the bottom of the page, click .
Do one of the following:
Add: Expand the size of the volume group by moving one or more physical volumes (LVM partitions) from the list to the list.
Remove: Reduce the size of the volume group by moving Lone or more physical volumes (LVM partitions) from the list to the list.
Click .
Click , verify that the changes are listed, then click .
Launch YaST as the root user.
In YaST, open the .
In the left panel, select Volume Management and expand it to see the list of volume groups.
Under Volume Management, select the volume group, then click the tab.
At the bottom of the page, click to open the Resize Logical Volume dialog box.
Use the slider to expand or reduce the size of the logical volume.
Reducing the size of a logical volume that contains data can cause data corruption.
Click .
Click , verify that the change is listed, then click .
The lvresize, lvextend, and
lvreduce commands are used to resize logical volumes.
See the man pages for each of these commands for syntax and options
information.
You can also increase the size of a logical volume by using the YaST
Partitioner. YaST uses parted(8) to grow the
partition.
To extend an LV there must be enough unallocated space available on the VG.
LVs can be extended or shrunk while they are being used, but this may not be true for a file system on them. Extending or shrinking the LV does not automatically modify the size of file systems in the volume. You must use a different command to grow the file system afterwards. For information about resizing file systems, see Chapter 5, Resizing File Systems.
Ensure that you use the right sequence:
If you extend an LV, you must extend the LV before you attempt to grow the file system.
If you shrink an LV, you must shrink the file system before you attempt to shrink the LV.
To extend the size of a logical volume:
Open a terminal console, log in as the root
user.
If the logical volume contains file systems that are hosted for a virtual machine (such as a Xen VM), shut down the VM.
Dismount the file systems on the logical volume.
At the terminal console prompt, enter the following command to grow the size of the logical volume:
lvextend -L +size /dev/vgname/lvname
For size, specify the amount of space you
want to add to the logical volume, such as 10GB. Replace
/dev/vgname/lvname
with the Linux path to the logical volume, such as
/dev/vg1/v1. For example:
lvextend -L +10GB /dev/vg1/v1
For example, to extend an LV with a (mounted and active) ReiserFS on it by 10GB:
lvextend −L +10G /dev/vgname/lvname resize_reiserfs −s +10GB −f /dev/vg−name/lv−name
For example, to shrink an LV with a ReiserFS on it by 5GB:
umount /mountpoint−of−LV resize_reiserfs −s −5GB /dev/vgname/lvname lvreduce /dev/vgname/lvname mount /dev/vgname/lvname /mountpoint−of−LV
Deleting a volume group destroys all of the data in each of its member partitions.
Launch YaST as the root user.
In YaST, open the .
In the left panel, select Volume Management and expand the list of groups.
Under Volume Management, select the volume group, then click the tab.
At the bottom of the page, click , then click to confirm the deletion.
Click , verify that the deleted volume group is listed (deletion is indicated by a red colored font), then click .
Deleting a partition destroys all of the data in the partition.
Launch YaST as the root user.
In YaST, open the .
If the Linux LVM partition is in use as a member of a volume group, remove the partition from the volume group, or delete the volume group.
In the YaST Partitioner under , select
the device (such as sdc).
On the Partitions page, select a partition that you want to remove, click , then click to confirm the deletion.
Click , verify that the deleted partition is listed (deletion is indicated by a red colored font), then click .
For information about using LVM commands, see the man pages for the
commands described in Table 4.1, “LVM Commands”.
Perform the commands as the root user.
|
Command |
Description |
|---|---|
pvcreate <device> |
Initializes a device (such as |
pvdisplay <device> |
Displays information about the LVM physical volume, such as whether it is currently being used in a logical volume. |
vgcreate -c y <vg_name> <dev1> [dev2...] |
Creates a clustered volume group with one or more specified devices. |
vgchange -a [ey | n] <vg_name> |
Activates ( Important
Ensure that you use the |
vgremove <vg_name> |
Removes a volume group. Before using this command, remove the logical volumes, then deactivate the volume group. |
vgdisplay <vg_name> |
Displays information about a specified volume group. To find the total physical extent of a volume group, enter vgdisplay vg_name | grep "Total PE" |
lvcreate -L size -n <lv_name> <vg_name> |
Creates a logical volume of the specified size. |
lvcreate -L <size> <-T|--thinpool> <vg_name/thin_pool_name> lvcreate -virtualsize <size> <-T|--thin> <vg_name/thin_pool_name> -n <thin_lv_name> lvcreate -L <size> -T <vg_name/thin_pool_name> -virtualsize <size> -n <thin_lv_name> |
Creates a thin logical volume or a thin pool of the specified size. Creates thin pool or thin logical volume or both. Specifying the optional argument --size will cause the creation of the thin pool logical volume. Specifying the optional argument --virtualsize will cause the creation of the thin logical volume from given thin pool volume. Specifying both arguments will cause the creation of both thin pool and thin volume using this pool. |
lvcreate -s [-L size] -n <snap_volume> <source_volume_path> |
Creates a snapshot volume for the specified logical volume. If the size option (-L, --size) is not included, the snapshot is created as a thin snapshot. |
lvremove</dev/vg_name/lv_name> |
Removes a logical volume, such as
Before using this command, close the logical volume by dismounting
it with the |
lvremove snap_volume_path |
Removes a snapshot volume. |
lvconvert --merge [-b] [-i <seconds>] [<snap_volume_path>[...<snapN>]|@<volume_tag>] |
Reverts (rolls back or merges) the snapshot data into the original volume. |
vgextend <vg_name><device> |
Adds a specified physical volume to an existing volume group |
vgreduce <vg_name> <device> |
Removes a specified physical volume from an existing volume group. Important
Ensure that the physical volume is not currently being used by a
logical volume. If it is, you must move the data to another
physical volume by using the |
lvextend -L size</dev/vg_name/lv_name> |
Extends the size of a specified logical volume. Afterwards, you must also expand the file system to take advantage of the newly available space. |
lvreduce -L size </dev/vg_name/lv_name> |
Reduces the size of a specified logical volume. ImportantEnsure that you reduce the size of the file system first before shrinking the volume, otherwise you risk losing data. |
lvrename </dev/vg_name/old_lv_name> </dev/vg_name/new_lv_name> |
Renames an existing LVM logical volume in a volume group from the old volume name to the new volume name. It does not change the volume group name. |