Red Hat Enterprise Linux 6 Logical Volume Manager Administration LVM Administrator Guide
Logical Volume Manager Administration Red Hat Enterprise Linux 6 Logical Volume Manager Administration LVM Administrator Guide Edition 1 Copyright © 2011 Red Hat, Inc. and others. The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/.
Introduction vii 1. About This Guide .......................................................................................................... vii 2. Audience ....................................................................................................................... vii 3. Software Versions .......................................................................................................... vii 4. Related Documentation .......................................................................
Logical Volume Manager Administration 4.3.9. Removing Volume Groups ................................................................................ 4.3.10. Splitting a Volume Group ............................................................................... 4.3.11. Combining Volume Groups ............................................................................. 4.3.12. Backing Up Volume Group Metadata .............................................................. 4.3.13. Renaming a Volume Group ....
6.2. 6.3. 6.4. 6.5. 6.6. 6.7. Displaying Information on Failed Devices ..................................................................... Recovering from LVM Mirror Failure ............................................................................ Recovering Physical Volume Metadata ........................................................................ Replacing a Missing Physical Volume ..........................................................................
vi
Introduction 1. About This Guide This book describes the Logical Volume Manager (LVM), including information on running LVM in a clustered environment. 2. Audience This book is intended to be used by system administrators managing systems running the Linux operating system. It requires familiarity with Red Hat Enterprise Linux 6 and GFS2 file system administration. 3. Software Versions Table 1.
Introduction • Release Notes — Provides information about the current release of Red Hat products. High Availability Add-On documentation and other Red Hat documents are available in HTML, PDF, and RPM versions on the Red Hat Enterprise Linux Documentation CD and online at http:// docs.redhat.com/docs/en-US/index.html. 5.
Typographic Conventions Press Ctrl+Alt+F2 to switch to the first virtual terminal. Press Ctrl+Alt+F1 to return to your X-Windows session. The first paragraph highlights the particular keycap to press. The second highlights two key combinations (each a set of three keycaps with each set pressed simultaneously). If source code is discussed, class names, methods, functions, variable names and returned values mentioned within a paragraph will be presented as above, in mono-spaced bold.
Introduction Publican is a DocBook publishing system. 6.2. Pull-quote Conventions Terminal output and source code listings are set off visually from the surrounding text. Output sent to a terminal is set in mono-spaced roman and presented thus: books books_tests Desktop Desktop1 documentation downloads drafts images mss notes photos scripts stuff svgs svn Source-code listings are also set in mono-spaced roman but add syntax highlighting as follows: package org.jboss.book.jca.ex1; import javax.
Notes and Warnings Warning Warnings should not be ignored. Ignoring warnings will most likely cause data loss.
xii
Chapter 1. The LVM Logical Volume Manager This chapter provides a summary of the features of the LVM logical volume manager that are new for the initial and subsequent releases of Red Hat Enterprise Linux 6. Following that, this chapter provides a high-level overview of the components of the Logical Volume Manager (LVM). 1.1.
Chapter 1. The LVM Logical Volume Manager • You can now create a mirror log for a mirrored logical device that is itself mirrored by using the -mirrorlog mirrored argument of the lvcreate command when creating a mirrored logical device. For information on using this option, see Section 4.4.3, “Creating Mirrored Volumes”. 1.1.2. New and Changed Features for Red Hat Enterprise Linux 6.1 Red Hat Enterprise Linux 6.1 includes the following documentation and feature updates and changes.
LVM Architecture Overview Volume management creates a layer of abstraction over physical storage, allowing you to create logical storage volumes. This provides much greater flexibility in a number of ways than using physical storage directly. With a logical volume, you are not restricted to physical disk sizes. In addition, the hardware storage configuration is hidden from the software so it can be resized and moved without stopping applications or unmounting file systems. This can reduce operational costs.
Chapter 1. The LVM Logical Volume Manager • atomic changes to metadata • redundant copies of metadata LVM2 is backwards compatible with LVM1, with the exception of snapshot and cluster support. You can convert a volume group from LVM1 format to LVM2 format with the vgconvert command. For information on converting LVM metadata format, see the vgconvert(8) man page. The underlying physical storage unit of an LVM logical volume is a block device such as a partition or whole disk.
The Clustered Logical Volume Manager (CLVM) • If you are using a clustered system for failover where only a single node that accesses the storage is active at any one time, you should use High Availability Logical Volume Management agents (HALVM). • If more than one node of your cluster will require access to your storage which is then shared among the active nodes, then you must use CLVM.
Chapter 1. The LVM Logical Volume Manager Figure 1.2. CLVM Overview Note CLVM requires changes to the lvm.conf file for cluster-wide locking. Information on configuring the lvm.conf file to support clustered locking is provided within the lvm.conf file itself. For information about the lvm.conf file, see Appendix B, The LVM Configuration Files. 1.5.
Document Overview • Chapter 3, LVM Administration Overview provides an overview of the basic steps you perform to configure LVM logical volumes, whether you are using the LVM Command Line Interface (CLI) commands or the LVM Graphical User Interface (GUI). • Chapter 4, LVM Administration with CLI Commands summarizes the individual administrative tasks you can perform with the LVM CLI commands to create and maintain logical volumes.
8
Chapter 2. LVM Components This chapter describes the components of an LVM Logical volume. 2.1. Physical Volumes The underlying physical storage unit of an LVM logical volume is a block device such as a partition or whole disk. To use the device for an LVM logical volume the device must be initialized as a physical volume (PV). Initializing a block device as a physical volume places a label near the start of the device. By default, the LVM label is placed in the second 512-byte sector.
Chapter 2. LVM Components Figure 2.1. Physical Volume layout 2.1.2. Multiple Partitions on a Disk LVM allows you to create physical volumes out of disk partitions. It is generally recommended that you create a single partition that covers the whole disk to label as an LVM physical volume for the following reasons: • Administrative convenience It is easier to keep track of the hardware in a system if each real disk only appears once. This becomes particularly true if a disk fails.
LVM Logical Volumes A logical volume is allocated into logical extents of the same size as the physical extents. The extent size is thus the same for all logical volumes in the volume group. The volume group maps the logical extents to physical extents. 2.3. LVM Logical Volumes In LVM, a volume group is divided up into logical volumes. There are three types of LVM logical volumes: linear volumes, striped volumes, and mirrored volumes. These are described in the following sections. 2.3.1.
Chapter 2. LVM Components of 4MB. This volume group includes 2 physical volumes named PV1 and PV2. The physical volumes are divided into 4MB units, since that is the extent size. In this example, PV1 is 100 extents in size (400MB) and PV2 is 200 extents in size (800MB). You can create a linear volume any size between 1 and 300 extents (4MB to 1200MB). In this example, the linear volume named LV1 is 300 extents in size. Figure 2.3.
Mirrored Logical Volumes striped logical volume. For large sequential reads and writes, this can improve the efficiency of the data I/O. Striping enhances performance by writing data to a predetermined number of physical volumes in round-robin fashion. With striping, I/O can be done in parallel. In some situations, this can result in near-linear performance gain for each additional physical volume in the stripe. The following illustration shows data being striped across three physical volumes.
Chapter 2. LVM Components A mirror maintains identical copies of data on different devices. When data is written to one device, it is written to a second device as well, mirroring the data. This provides protection for device failures. When one leg of a mirror fails, the logical volume becomes a linear volume and can still be accessed. LVM supports mirrored volumes.
Snapshot Volumes Note LVM snapshots are not supported for LVM mirrored logical volumes. Because a snapshot copies only the data areas that change after the snapshot is created, the snapshot feature requires a minimal amount of storage. For example, with a rarely updated origin, 3-5 % of the origin's capacity is sufficient to maintain the snapshot. Note Snapshot copies of a file system are virtual copies, not actual media backup for a file system.
Chapter 2. LVM Components As of the Red Hat Enterprise Linux 6 release, you can use the --merge option of the lvconvert command to merge a snapshot into its origin volume. One use for this feature is to perform system rollback if you have lost data or files or otherwise need to restore your system to a previous state. After you merge the snapshot volume, the resulting logical volume will have the origin volume's name, minor number, and UUID and the merged snapshot is removed.
Chapter 3. LVM Administration Overview This chapter provides an overview of the administrative procedures you use to configure LVM logical volumes. This chapter is intended to provide a general understanding of the steps involved. For specific step-by-step examples of common LVM configuration procedures, see Chapter 5, LVM Configuration Examples. For descriptions of the CLI commands you can use to perform LVM administration, see Chapter 4, LVM Administration with CLI Commands.
Chapter 3. LVM Administration 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. The examples in this document use GFS2 file systems.
Logging in the /etc/lvm/backup file and the metadata archives are stored in the /etc/lvm/archive file. How long the metadata archives stored in the /etc/lvm/archive file are kept and how many archive files are kept is determined by parameters you can set in the lvm.conf file. A daily system backup should include the contents of the /etc/lvm directory in the backup. Note that a metadata backup does not back up the user and system data contained in the logical volumes.
20
Chapter 4. LVM Administration with CLI Commands This chapter summarizes the individual administrative tasks you can perform with the LVM Command Line Interface (CLI) commands to create and maintain logical volumes. Note If you are creating or modifying an LVM volume for a clustered environment, you must ensure that you are running the clvmd daemon. For information, see Section 3.1, “Creating LVM Volumes in a Cluster”. 4.1. Using CLI Commands There are several general features of all LVM CLI commands.
Chapter 4. LVM Administration with CLI Commands Found volume group "new_vg" Creating new_vg-lvol0 Loading new_vg-lvol0 table Resuming new_vg-lvol0 (253:2) Clearing start of logical volume "lvol0" Creating volume group backup "/etc/lvm/backup/new_vg" (seqno 5). Logical volume "lvol0" created You could also have used the -vv, -vvv or the -vvvv argument to display increasingly more details about the command execution. The -vvvv argument provides the maximum amount of information at this time.
Creating Physical Volumes The following subsections describe the commands used for creating physical volumes. 4.2.1.1. Setting the Partition Type If you are using a whole disk device for your physical volume, the disk must have no partition table. For DOS disk partitions, the partition id should be set to 0x8e using the fdisk or cfdisk command or an equivalent. For whole disk devices only the partition table must be erased, which will effectively destroy all data on that disk.
Chapter 4. LVM Administration with CLI Commands /dev/ram8 [ /dev/ram9 [ /dev/ram10 [ /dev/ram11 [ /dev/ram12 [ /dev/ram13 [ /dev/ram14 [ /dev/ram15 [ /dev/sdb [ /dev/sdb1 [ /dev/sdc [ /dev/sdc1 [ /dev/sdd [ /dev/sdd1 [ 7 disks 17 partitions 0 LVM physical volume whole disks 4 LVM physical volumes 16.00 16.00 16.00 16.00 16.00 16.00 16.00 16.00 17.15 17.14 17.15 17.14 17.15 17.14 MB] MB] MB] MB] MB] MB] MB] MB] GB] GB] LVM physical volume GB] GB] LVM physical volume GB] GB] LVM physical volume 4.2.2.
Preventing Allocation on a Physical Volume You can define a filter in the lvm.conf so that this command will avoid scanning specific physical volumes. For information on using filters to control which devices are scanned, see Section 4.5, “Controlling LVM Device Scans with Filters”. 4.2.3. 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.
Chapter 4. LVM Administration with CLI Commands # 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.
Adding Physical Volumes to a Volume Group You create volume groups in a cluster environment with the vgcreate command, just as you create them on a single node. By default, volume groups created with CLVM on shared storage are visible to all computers that have access to the shared storage. It is possible, however, to create volume groups that are local, visible only to one node in the cluster, by using the -c n of the vgcreate command.
Chapter 4. LVM Administration with CLI Commands For information on using the vgs command to customize your output, see Section 4.8, “Customized Reporting for LVM”. 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.
Removing Physical Volumes from a Volume Group # vgscan Reading all physical volumes. This may take a while... Found volume group "new_vg" using metadata type lvm2 Found volume group "officevg" using metadata type lvm2 4.3.6. 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.
Chapter 4. LVM Administration with CLI Commands 4.3.8. Activating and Deactivating Volume Groups When you create a volume group it is, by default, activated. This means that the logical volumes in that group are accessible and subject to change. There are various circumstances for which you need to make a volume group inactive and thus unknown to the kernel. To deactivate or activate a volume group, use the -a (--available) argument of the vgchange command.
Backing Up Volume Group Metadata extent sizes of the volume are equal and the physical and logical volume summaries of both volume groups fit into the destination volume groups limits. The following command merges the inactive volume group my_vg into the active or inactive volume group databases giving verbose runtime information. # vgmerge -v databases my_vg 4.3.12.
Chapter 4. LVM Administration with CLI Commands 3. Use the vgexport command to export the volume group. This prevents it from being accessed by the system from which you are removing it. After you export the volume group, the physical volume will show up as being in an exported volume group when you execute the pvscan command, as in the following example. [root@tng3-1]# pvscan PV /dev/sda1 is in exported VG myvg [17.15 GB / 7.15 GB free] PV /dev/sdc1 is in exported VG myvg [17.15 GB / 15.
Creating Linear Logical Volumes The following command creates a 1500 MB linear logical volume named testlv in the volume group testvg, creating the block device /dev/testvg/testlv. # lvcreate -L1500 -n testlv testvg The following command creates a 50 gigabyte logical volume named gfslv from the free extents in volume group vg0. # lvcreate -L 50G -n gfslv vg0 You can use the -l argument of the lvcreate command to specify the size of the logical volume in extents.
Chapter 4. LVM Administration with CLI Commands You can specify which extents of a physical volume are to be used for a logical volume. The following example creates a linear logical volume out of extents 0 through 24 of physical volume /dev/sda1 and extents 50 through 124 of physical volume /dev/sdb1 in volume group testvg.
Creating Mirrored Volumes Mirrored LVM Logical Volumes in a Cluster Creating a mirrored LVM logical volume in a cluster requires the same commands and procedures as creating a mirrored LVM logical volume on a single node. However, in order to create a mirrored LVM volume in a cluster the cluster and cluster mirror infrastructure must be running, the cluster must be quorate, and the locking type in the lvm.conf file must be set correctly to enable cluster locking.
Chapter 4. LVM Administration with CLI Commands LVM maintains a small log which it uses to keep track of which regions are in sync with the mirror or mirrors. By default, this log is kept on disk, which keeps it persistent across reboots and ensures that the mirror does not need to be re-synced every time a machine reboots or crashes.
Creating Mirrored Volumes When a mirror is created, the mirror regions are synchronized. For large mirror components, the sync process may take a long time. When you are creating a new mirror that does not need to be revived, you can specify the --nosync argument to indicate that an initial synchronization from the first device is not required. You can specify which devices to use for the mirror legs and log, and which extents of the devices to use.
Chapter 4. LVM Administration with CLI Commands By default, the mirror_image_fault_policy parameter is set to remove. With this policy, if a mirror image fails the mirror will convert to a non-mirrored device if there is only one remaining good copy. Setting this policy to allocate for a mirror device requires the mirror to resynchronize the devices; this is a slow process, but it preserves the mirror characteristic of the device.
Creating Snapshot Volumes specified by the mirror_log_fault_policy and mirror_device_fault_policy parameters in the lvm.conf file. 4.4.3.4. Changing Mirrored Volume Configuration You can convert a logical volume from a mirrored volume to a linear volume or from a linear volume to a mirrored volume with the lvconvert command. You can also use this command to reconfigure other mirror parameters of an existing logical volume, such as corelog.
Chapter 4. LVM Administration with CLI Commands Note As of the Red Hat Enterprise Linux 6.1 release, LVM snapshots are supported for mirrored logical volumes. The following command creates a snapshot logical volume that is 100 MB in size named /dev/ vg00/snap. This creates a snapshot of the origin logical volume named /dev/vg00/lvol1.
Merging Snapshot Volumes Warning Because the snapshot increases in size as the origin volume changes, it is important to monitor the percentage of the snapshot volume regularly with the lvs command to be sure it does not fill. A snapshot that is 100% full is lost completely, as a write to unchanged parts of the origin would be unable to succeed without corrupting the snapshot. 4.4.5.
Chapter 4. LVM Administration with CLI Commands 4.4.7. Resizing Logical Volumes To reduce the size of a logical volume, use the lvreduce command. If the logical volume contains a file system, be sure to reduce the file system first (or use the LVM GUI) so that the logical volume is always at least as large as the file system expects it to be. The following command reduces the size of logical volume lvol1 in volume group vg00 by 3 logical extents. # lvreduce -l -3 vg00/lvol1 4.4.8.
Displaying Logical Volumes [root@tng3-1 lvm]# lvremove /dev/testvg/testlv Do you really want to remove active logical volume "testlv"? [y/n]: y Logical volume "testlv" successfully removed You could explicitly deactivate the logical volume before removing it with the lvchange -an command, in which case you would not see the prompt verifying whether you want to remove an active logical volume. 4.4.11.
Chapter 4. LVM Administration with CLI Commands # lvextend -L+1G /dev/myvg/homevol lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB lvextend -- doing automatic backup of volume group "myvg" lvextend -- logical volume "/dev/myvg/homevol" successfully extended As with the lvcreate command, you can use the -l argument of the lvextend command to specify the number of extents by which to increase the size of the logical volume.
Growing Logical Volumes The following command adds another physical volume to the volume group, which then has 135G of additional space. # vgextend vg /dev/sdc1 Volume group "vg" successfully extended # vgs VG #PV #LV #SN Attr VSize VFree vg 3 1 0 wz--n- 406.97G 135.66G At this point you cannot extend the striped logical volume to the full size of the volume group, because two underlying devices are needed in order to stripe the data. # lvextend vg/stripe1 -L 406G Using stripesize of last segment 64.
Chapter 4. LVM Administration with CLI Commands For example, if you have logical volumes that are mirrored between two sites within a single volume group, you can tag the physical volumes according to where they are situated by tagging the physical volumes with @site1 and @site2 tags and specify the following line in the lvm.conf file: cling_tag_list = [ "@site1", "@site2" ] For information on tagging physical volumes, see Appendix C, LVM Object Tags. In the following example, the lvm.
Shrinking Logical Volumes [root@taft-03 ~]# lvs -a -o +devices LV VG Attr LSize Log Copy% mirror taft Mwi-a- 200.00g mirror_mlog 50.16 mirror_mimage_0(0),mirror_mimage_1(0) [mirror_mimage_0] taft Iwi-ao 200.00g [mirror_mimage_0] taft Iwi-ao 200.00g [mirror_mimage_1] taft Iwi-ao 200.00g [mirror_mimage_1] taft Iwi-ao 200.00g [mirror_mlog] taft lwi-ao 4.00m Devices /dev/sdb1(0) /dev/sdg1(0) /dev/sdc1(0) /dev/sdd1(0) /dev/sdh1(0) 4.4.13.
Chapter 4. LVM Administration with CLI Commands filter = [ "a/.*/" ] The following filter removes the cdrom device in order to avoid delays if the drive contains no media: filter = [ "r|/dev/cdrom|" ] The following filter adds all loop and removes all other block devices: filter = [ "a/loop.*/", "r/.*/" ] The following filter adds all loop and IDE and removes all other block devices: filter =[ "a|loop.*|", "a|/dev/hd.*|", "r|.
Activating Logical Volumes on Individual Nodes in a Cluster # pvmove -i5 /dev/sdd1 4.7. Activating Logical Volumes on Individual Nodes in a Cluster If you have LVM installed in a cluster environment, you may at times need to activate logical volumes exclusively on one node. To activate logical volumes exclusively on one node, use the lvchange -aey command. Alternatively, you can use lvchange -aly command to activate logical volumes only on the local node but not exclusively.
Chapter 4. LVM Administration with CLI Commands /dev/sdb1 /dev/sdc1 /dev/sdd1 17.14G 17.14G 17.14G • You can append a field to the output with the plus sign (+), which is used in combination with the -o argument. The following example displays the UUID of the physical volume in addition to the default fields. # pvs -o +pv_uuid PV VG /dev/sdb1 new_vg /dev/sdc1 new_vg /dev/sdd1 new_vg Fmt lvm2 lvm2 lvm2 Attr aaa- PSize 17.14G 17.14G 17.14G PFree 17.14G 17.09G 17.
Object Selection /dev/sdd1 =new_vg=lvm2=a- =17.14G=17.14G You can use the -P argument of the lvs or vgs command to display information about a failed volume that would otherwise not appear in the output. For information on the output this argument yields, see Section 6.2, “Displaying Information on Failed Devices”. For a full listing of display arguments, see the pvs(8), vgs(8) and lvs(8) man pages.
Chapter 4.
Object Selection /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 vg vg vg vg vg vg lvm2 lvm2 lvm2 lvm2 lvm2 lvm2 aaaaaa- 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 17.14G 0 0 0 0 0 0 4389 4389 4389 4389 4389 4389 You can use the pvs -a command to see devices detected by LVM that have not been initialized as LVM physical volumes.
Chapter 4.
Object Selection Argument Header Description Bit 3: Allocation policy: (c)ontiguous, (n)ormal, (a)nywhere, (i)nherited. This is capitalized if the volume is currently locked against allocation changes, for example while executing the pvmove command.
Chapter 4. LVM Administration with CLI Commands # lvs LV VG Attr LSize Origin Snap% Move Log Copy% lvol0 new_vg owi-a- 52.00M newvgsnap1 new_vg swi-a- 8.00M lvol0 0.20 Convert Using the -v argument with the lvs command adds the following fields to the default display: seg_count, lv_major, lv_minor, lv_kernel_major, lv_kernel_minor, lv_uuid. # lvs -v Finding all logical volumes LV VG #Seg Attr LSize Maj Min KMaj KMin Origin Snap% Move Copy% Convert LV UUID lvol0 new_vg 1 owi-a- 52.
Sorting LVM Reports 4.8.3. Sorting LVM Reports Normally the entire output of the lvs, vgs, or pvs command has to be generated and stored internally before it can be sorted and columns aligned correctly. You can specify the --unbuffered argument to display unsorted output as soon as it is generated. To specify an alternative ordered list of columns to sort on, use the -O argument of any of the reporting commands. It is not necessary to include these fields within the output itself.
Chapter 4. LVM Administration with CLI Commands # pvs --units m PV VG /dev/sda1 /dev/sdb1 new_vg /dev/sdc1 new_vg /dev/sdd1 new_vg Fmt lvm2 lvm2 lvm2 lvm2 Attr -aaa- PSize 17555.40M 17552.00M 17552.00M 17552.00M PFree 17555.40M 17552.00M 17500.00M 17552.00M By default, units are displayed in powers of 2 (multiples of 1024). You can specify that units be displayed in multiples of 1000 by capitalizing the unit specification (B, K, M, G, T, H).
Chapter 5. LVM Configuration Examples This chapter provides some basic LVM configuration examples. 5.1. Creating an LVM Logical Volume on Three Disks This example creates an LVM logical volume called new_logical_volume that consists of the disks at /dev/sda1, /dev/sdb1, and /dev/sdc1. 5.1.1. Creating the Physical Volumes To use disks in a volume group, you label them as LVM physical volumes. Warning This command destroys any data on /dev/sda1, /dev/sdb1, and /dev/sdc1.
Chapter 5. LVM Configuration Examples [root@tng3-1 ~]# mkfs.gfs2 -plock_nolock -j 1 /dev/new_vol_group/new_logical_volume This will destroy any data on /dev/new_vol_group/new_logical_volume. Are you sure you want to proceed? [y/n] y Device: Blocksize: Filesystem Size: Journals: Resource Groups: Locking Protocol: Lock Table: /dev/new_vol_group/new_logical_volume 4096 491460 1 8 lock_nolock Syncing... All Done The following commands mount the logical volume and report the file system disk space usage.
Creating the Logical Volume You can use the vgs command to display the attributes of the new volume group. [root@tng3-1 ~]# vgs VG #PV #LV #SN Attr VSize VFree volgroup01 3 0 0 wz--n- 51.45G 51.45G 5.2.3. Creating the Logical Volume The following command creates the striped logical volume striped_logical_volume from the volume group volgroup01. This example creates a logical volume that is 2 gigabytes in size, with three stripes and a stripe size of 4 kilobytes.
Chapter 5. LVM Configuration Examples In the initial set up, the logical volume mylv is carved from the volume group myvol, which in turn consists of the three physical volumes, /dev/sda1, /dev/sdb1, and /dev/sdc1. After completing this procedure, the volume group myvg will consist of /dev/sda1 and /dev/sdb1. A second volume group, yourvg, will consist of /dev/sdc1. 5.3.1. Determining Free Space You can use the pvscan command to determine how much free space is currently available in the volume group.
Creating the New Logical Volume Volume group "yourvg" successfully split from "myvg" You can use the vgs command to see the attributes of the two volume groups. [root@tng3-1 ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 2 1 0 wz--n- 34.30G 10.80G yourvg 1 0 0 wz--n- 17.15G 17.15G 5.3.4. Creating the New Logical Volume After creating the new volume group, you can create the new logical volume yourlv. [root@tng3-1 ~]# lvcreate -L5G -n yourlv yourvg Logical volume "yourlv" created 5.3.5.
Chapter 5. LVM Configuration Examples This example shows how you can remove a disk from an existing logical volume, either to replace the disk or to use the disk as part of a different volume. In order to remove a disk, you must first move the extents on the LVM physical volume to a different disk or set of disks. 5.4.1. Moving Extents to Existing Physical Volumes In this example, the logical volume is distributed across four physical volumes in the volume group myvg.
Moving Extents to a New Disk [root@tng3-1]# pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda1 myvg lvm2 a17.15G 7.15G 10.00G /dev/sdb1 myvg lvm2 a17.15G 15.15G 2.00G /dev/sdc1 myvg lvm2 a17.15G 15.15G 2.00G We want to move the extents of /dev/sdb1 to a new device, /dev/sdd1. 5.4.2.1. Creating the New Physical Volume Create a new physical volume from /dev/sdd1. [root@tng3-1 ~]# pvcreate /dev/sdd1 Physical volume "/dev/sdd1" successfully created 5.4.2.2.
Chapter 5. LVM Configuration Examples 5.5. Creating a Mirrored LVM Logical Volume in a Cluster Creating a mirrored LVM logical volume in a cluster requires the same commands and procedures as creating a mirrored LVM logical volume on a single node. However, in order to create a mirrored LVM volume in a cluster the cluster and cluster mirror infrastructure must be running, the cluster must be quorate, and the locking type in the lvm.
Creating a Mirrored LVM Logical Volume in a Cluster 5. Create the mirror. The first step is creating the physical volumes. The following commands create three physical volumes. Two of the physical volumes will be used for the legs of the mirror, and the third physical volume will contain the mirror log.
Chapter 5. LVM Configuration Examples May 10 14:55:00 doc-07 lvm[19402]: vg001-mirrorlv is now in-sync 8. You can use the lvs with the -o +devices options to display the configuration of the mirror, including which devices make up the mirror legs. You can see that the logical volume in this example is composed of two linear images and one log. [root@doc-07 ~]# lvs -a -o +devices LV VG Attr LSize Origin Snap% Convert Devices mirrorlv vg001 mwi-a- 3.
Chapter 6. LVM Troubleshooting This chapter provide instructions for troubleshooting a variety of LVM issues. 6.1. Troubleshooting Diagnostics If a command is not working as expected, you can gather diagnostics in the following ways: • Use the -v, -vv, -vvv, or -vvvv argument of any command for increasingly verbose levels of output. • If the problem is related to the logical volume activation, set 'activation = 1' in the 'log' section of the configuration file and run the command with the -vvvv argument.
Chapter 6. LVM Troubleshooting [root@link-07 tmp]# lvs -a -o +devices Volume group "vg" not found Using the -P argument shows the logical volumes that have failed. [root@link-07 tmp]# lvs -P -a -o +devices Partial mode. Incomplete volume groups will be activated read-only. LV VG Attr LSize Origin Snap% Move Log Copy% Devices linear vg -wi-a- 20.00G unknown device(0) stripe vg -wi-a- 20.
Recovering from LVM Mirror Failure Physical Physical Physical Physical Physical Physical Physical Physical Physical Physical Physical Physical volume volume volume volume volume volume volume volume volume volume volume volume "/dev/sdc1" "/dev/sdc2" "/dev/sdd1" "/dev/sdd2" "/dev/sde1" "/dev/sde2" "/dev/sdf1" "/dev/sdf2" "/dev/sdg1" "/dev/sdg2" "/dev/sdh1" "/dev/sdh2" successfully successfully successfully successfully successfully successfully successfully successfully successfully successfully successf
Chapter 6. LVM Troubleshooting groupfs vg -wi-a- 752.00M /dev/sdb1(0) At this point you should still be able to use the logical volume, but there will be no mirror redundancy. To rebuild the mirrored volume, you replace the broken drive and recreate the physical volume. If you use the same disk rather than replacing it with a new one, you will see "inconsistent" warnings when you run the pvcreate command. You can prevent that warning from appearing by executing the vgreduce --removemissing command.
Recovering Physical Volume Metadata Logical volume mirror converted. You can use the lvs command to verify that the mirror is restored. [root@link-08 ~]# lvs -a -o +devices LV VG Attr LSize Origin Snap% groupfs vg mwi-a- 752.00M groupfs_mimage_0(0),groupfs_mimage_1(0) [groupfs_mimage_0] vg iwi-ao 752.00M [groupfs_mimage_1] vg iwi-ao 752.00M [groupfs_mlog] vg lwi-ao 4.00M Move Log Copy% Devices groupfs_mlog 68.62 /dev/sdb1(0) /dev/sdi1(0) /dev/sdc1(0) 6.4.
Chapter 6. LVM Troubleshooting indicated above, FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk. This command restores the physical volume label with the metadata information contained in VG_00050.vg, the most recent good archived metadata for the volume group.
Removing Lost Physical Volumes from a Volume Group 6.6. Removing Lost Physical Volumes from a Volume Group If you lose a physical volume, you can activate the remaining physical volumes in the volume group with the --partial argument of the vgchange command. You can remove all the logical volumes that used that physical volume from the volume group with the --removemissing argument of the vgreduce command.
Chapter 6. LVM Troubleshooting Alternately, you can extend the logical volume to use a percentage of the remaining free space in the volume group by using the -l argument of the lvcreate command. For information, see Section 4.4.1, “Creating Linear Logical Volumes”.
Chapter 7. LVM Administration with the LVM GUI In addition to the Command Line Interface (CLI), LVM provides a Graphical User Interface (GUI) which you can use to configure LVM logical volumes. You can bring up this utility by typing systemconfig-lvm. The LVM chapter of the Storage Administration Guide provides step-by-step instructions for configuring an LVM logical volume using this utility.
78
Appendix A. The Device Mapper The Device Mapper is a kernel driver that provides a framework for volume management. It provides a generic way of creating mapped devices, which may be used as logical volumes. It does not specifically know about volume groups or metadata formats. The Device Mapper provides the foundation for a number of higher-level technologies. In addition to LVM, Device-Mapper multipath and the dmraid command use the Device Mapper.
Appendix A. The Device Mapper • mirror • snapshot and snapshot-origin • error • zero • multipath • crypt A.1.1. The linear Mapping Target A linear mapping target maps a continuous range of blocks onto another block device.
The striped Mapping Target start starting block in virtual device length length of this segment #stripes number of stripes for the virtual device chunk_size number of sectors written to each stripe before switching to the next; must be power of 2 at least as big as the kernel page size device block device, referenced by the device name in the filesystem or by the major and minor numbers in the format major:minor.
Appendix A. The Device Mapper 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0 A.1.3. The mirror Mapping Target The mirror mapping target supports the mapping of a mirrored logical device. The format of a mirrored target is as follows: start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ...
The snapshot and snapshot-origin Mapping Targets logargs the log arguments for the mirror; the number of log arguments provided is specified by the #logargs parameter and the valid log arguments are determined by the log_type parameter. #devs the number of legs in the mirror; a device and an offset is specified for each leg device block device for each mirror leg, referenced by the device name in the filesystem or by the major and minor numbers in the format major:minor.
Appendix A. The Device Mapper 1. A device with a linear mapping containing the original mapping table of the source volume. 2. A device with a linear mapping used as the copy-on-write (COW) device for the source volume; for each write, the original data is saved in the COW device of each snapshot to keep its visible content unchanged (until the COW device fills up). 3. A device with a snapshot mapping combining #1 and #2, which is the visible snapshot volume. 4.
The error Mapping Target start starting block in virtual device length length of this segment origin base volume of snapshot COW-device Device on which changed chunks of data are stored P|N P (Persistent) or N (Not persistent); indicates whether snapshot will survive after reboot. For transient snapshots (N) less metadata must be saved on disk; they can be kept in memory by the kernel.
Appendix A. The Device Mapper The zero mapping target takes no additional parameters besides the start and length parameters. The following example shows a zero target for a 16Tb Device. 0 65536 zero A.1.7. The multipath Mapping Target The multipath mapping target supports the mapping of a multipathed device. The format for the multipath target is as follows: start length multipath #features [feature1 ... featureN] #handlerargs [handlerarg1 ... handlerargN] #pathgroups pathgroup pathgroupargs1 ...
The multipath Mapping Target pathgroup The next path group to try. pathgroupsargs Each path group consists of the following arguments: pathselector #selectorargs #paths #pathargs device1 ioreqs1 ... deviceN ioreqsN There is one set of path arguments for each path in the path group. pathselector Specifies the algorithm in use to determine what path in this path group to use for the next I/O operation. #selectorargs The number of path selector arguments which follow this argument in the multipath mapping.
Appendix A. The Device Mapper The following example shows a pure failover target definition for the same multipath device. In this target there are four path groups, with only one open path per path group so that the multipathed device will use only one path at a time.
The dmsetup Command device block device, referenced by the device name in the filesystem or by the major and minor numbers in the format major:minor offset starting offset of the mapping on the device The following is an example of a crypt target. 0 2097152 crypt aes-plain 0123456789abcdef0123456789abcdef 0 /dev/hda 0 A.2. The dmsetup Command The dmsetup command is a command line wrapper for communication with the Device Mapper.
Appendix A. The Device Mapper Event number The current number of events received. Issuing a dmsetup wait n command allows the user to wait for the n'th event, blocking the call until it is received. Major, minor Major and minor device number Number of targets The number of fragments that make up a device. For example, a linear device spanning 3 disks would have 3 targets. A linear device composed of the beginning and end of a disk, but not the middle would have 2 targets. UUID UUID of the device.
The dmsetup status Command [root@grant-01 ~]# dmsetup ls --target mirror lock_stress-grant--02.1722 (253, 34) lock_stress-grant--01.1720 (253, 18) lock_stress-grant--03.1718 (253, 52) lock_stress-grant--02.1716 (253, 40) lock_stress-grant--03.1713 (253, 47) lock_stress-grant--02.1709 (253, 23) lock_stress-grant--01.1707 (253, 8) lock_stress-grant--01.1724 (253, 14) lock_stress-grant--03.
Appendix A. The Device Mapper The following example shows the command to list the dependencies of all currently configured mapped devices. [root@ask-07 ~]# dmsetup deps testgfsvg-testgfslv3: 1 dependencies testgfsvg-testgfslv2: 1 dependencies testgfsvg-testgfslv1: 1 dependencies VolGroup00-LogVol01: 1 dependencies VolGroup00-LogVol00: 1 dependencies : : : : : (8, (8, (8, (8, (8, 16) 16) 16) 2) 2) The following example shows the command to list the dependencies only of the device lock_stress-grant--02.
udev Integration with the Device Mapper and LVM). Without this support, it was a common problem for a user to try to remove a device that was still open and processed by udev rules as a result of a previous change event; this was particularly common when there was a very short time between changes for that device. The Red Hat Enterprise Linux 6 release provides officially supported udev rules for Device Mapper devices in general and for LVM as well. Table A.
Appendix A. The Device Mapper • DM_SUSPENDED: the suspended state of Device Mapper device • DM_UDEV_RULES_VSN: udev rules version (this is primarily for all other rules to check that previously mentioned variables are set directly by official Device Mapper rules) The following variables are set in 11-dm-lvm.rules: • DM_LV_NAME: logical volume name • DM_VG_NAME: volume group name • DM_LV_LAYER: LVM layer name All these variables can be used in the 12-dm-permissions.
Commands and Interfaces that Support udev dmsetup command ... ... dmsetup command ... --noudevrules Disables udev rules. Nodes/symlinks will be created by libdevmapper itself (the old way). This option is for debugging purposes, if udev does not work correctly. --noudevsync Disables udev synchronization. This is also for debugging purposes. For more information on the dmsetup and its options, see the dmsetup(8) man page.
96
Appendix B. The LVM Configuration Files LVM supports multiple configuration files. At system startup, the lvm.conf configuration file is loaded from the directory specified by the environment variable LVM_SYSTEM_DIR, which is set to /etc/lvm by default. The lvm.conf file can specify additional configuration files to load. Settings in later files override settings from earlier ones. To display the settings in use after loading all the configuration files, execute the lvm dumpconfig command.
Appendix B. The LVM Configuration Files # the environment variable LVM_SYSTEM_DIR before running the tools. # # N.B. Take care that each setting only appears once if uncommenting # example settings in this file. # This section allows you to configure which block devices should # be used by the LVM system. devices { # Where do you want your volume groups to appear ? dir = "/dev" # An array of directories that contain the device nodes you wish # to use with LVM2.
Sample lvm.conf File # filter =[ "a|loop|", "r|/dev/hdc|", "a|/dev/ide|", "r|.*|" ] # Use anchors if you want to be really specific # filter = [ "a|^/dev/hda8$|", "r/.*/" ] # The results of the filtering are cached on disk to avoid # rescanning dud devices (which can take a very long time). # By default this cache is stored in the /etc/lvm/cache directory # in a file called '.cache'. # It is safe to delete the contents: the tools regenerate it.
Appendix B. The LVM Configuration Files # But note that pvcreate --dataalignmentoffset will skip this detection. # 1 enables; 0 disables. data_alignment_offset_detection = 1 # If, while scanning the system for PVs, LVM2 encounters a device-mapper # device that has its I/O suspended, it waits for it to become accessible. # Set this to 1 to skip such devices. This should only be needed # in recovery situations.
Sample lvm.conf File # # # # # #} Set to 1 to guarantee that mirror logs will always be placed on different PVs from the mirror images. This was the default until version 2.02.85. mirror_logs_require_separate_pvs = 0 # This section that allows you to configure the nature of the # information that LVM2 reports. log { # Controls the messages sent to stdout or stderr. # There are three levels of verbosity, 3 being the most verbose.
Appendix B. The LVM Configuration Files backup_dir = "/etc/lvm/backup" # Should we maintain an archive of old metadata configurations. # Use 1 for Yes; 0 for No. # On by default. Think very hard before turning this off.
Sample lvm.conf File # # # # The default metadata format that commands should use - "lvm1" or "lvm2". The command line override is -M1 or -M2. Defaults to "lvm2". format = "lvm2" # Location of proc filesystem proc = "/proc" # Type of locking to use. Defaults to local file-based locking (1). # Turn locking off by setting to 0 (dangerous: risks metadata corruption # if LVM2 commands get run concurrently). # Type 2 uses the external shared library locking_library. # Type 3 uses built-in clustered locking.
Appendix B. The LVM Configuration Files # If set to 1, no operations that change on-disk metadata will be permitted. # Additionally, read-only commands that encounter metadata in need of repair # will still be allowed to proceed exactly as if the repair had been # performed (except for the unchanged vg_seqno).
Sample lvm.conf File reserved_stack = 256 # How much memory (in KB) to reserve for use while devices suspended reserved_memory = 8192 # Nice value used while devices suspended process_priority = -18 # If volume_list is defined, each LV is only activated if there is a # match against the list. # "vgname" and "vgname/lvname" are matched exactly. # "@tag" matches any tag set in the LV or VG.
Appendix B. The LVM Configuration Files # # # # # # # # # # # # # snapshot should be extended: when its space usage exceeds this many percent. The latter defines how much extra space should be allocated for the snapshot, in percent of its current size. For example, if you set snapshot_autoextend_threshold to 70 and snapshot_autoextend_percent to 20, whenever a snapshot exceeds 70% usage, it will be extended by another 20%. For a 1G snapshot, using up 700M will trigger a resize to 1.2G.
Sample lvm.conf File # are used at the individual PV level using 'pvchange # --metadataignore y/n'. # vgmetadatacopies = 0 # Approximate default size of on-disk metadata areas in sectors. # You should increase this if you have large volume groups or # you want to retain a large on-disk history of your metadata changes. # pvmetadatasize = 255 # # # # # # # # # # # # List of directories holding live copies of text format metadata.
108
Appendix C. LVM Object Tags An LVM tag is a word that can be used to group LVM2 objects of the same type together. Tags can be attached to objects such as physical volumes, volume groups, and logical volumes. Tags can be attached to hosts in a cluster configuration. Snapshots cannot be tagged. Tags can be given on the command line in place of PV, VG or LV arguments. Tags should be prefixed with @ to avoid ambiguity.
Appendix C. LVM Object Tags For example, the following entry in the configuration file always defines tag1, and defines tag2 if the hostname is host1. tags { tag1 { } tag2 { host_list = ["host1"] } } C.3. Controlling Activation with Tags You can specify in the configuration file that only certain logical volumes should be activated on that host.
Appendix D. LVM Volume Group Metadata The configuration details of a volume group are referred to as the metadata. By default, an identical copy of the metadata is maintained in every metadata area in every physical volume within the volume group. LVM volume group metadata is stored as ASCII. If a volume group contains many physical volumes, having many redundant copies of the metadata is inefficient.
Appendix D.
Sample Metadata status = dev_size pe_start pe_count ["ALLOCATABLE"] = 35964301 # 17.1491 Gigabytes = 384 = 4390 # 17.1484 Gigabytes } pv2 { id = "wCoG4p-55Ui-9tbp-VTEA-jO6s-RAVx-UREW0G" device = "/dev/sdc" # Hint only status = dev_size pe_start pe_count ["ALLOCATABLE"] = 35964301 # 17.1491 Gigabytes = 384 = 4390 # 17.1484 Gigabytes } pv3 { id = "hGlUwi-zsBg-39FF-do88-pHxY-8XA2-9WKIiA" device = "/dev/sdd" # Hint only status = dev_size pe_start pe_count ["ALLOCATABLE"] = 35964301 # 17.
114
Appendix E. Revision History Revision 3.0-5 Thu Dec 1 2011 Steven Levine slevine@redhat.com Release for GA of Red Hat Enterprise Linux 6.2 Revision 3.0-4 Mon Nov 21 2011 Resolves: #755371, #755373, #755374 Documentation QE review Steven Levine slevine@redhat.com Revision 3.0-3 Mon Nov 07 2011 Resolves: #749487 Clarifies pvcreate example for a whole disk. Steven Levine slevine@redhat.com Revision 3.0-2 Wed Oct 12 2011 Resolves: #744999 Fixes small typographical errors. Steven Levine slevine@redhat.
Appendix E. Revision History Documents support for including multiple --addtag and --deltag arguments on a single command line. Resolves: #694604 Documents support for expanded character list in tags. Resolves: #694611 Documents support for mirrored stripes. Resolves: #694616 Documents support for snapshots of mirrored volumes. Resolves: #694618 Documents support for snapshots of exclusively-activated cluster volumes.
Index Symbols /lib/udev/rules.
Index displaying, 43, 49, 54 exclusive access, 49 extending, 43 growing, 43 linear, 32 local access, 49 lvs display arguments, 54 mirrored, 34 reducing, 47 removing, 42 renaming, 42 resizing, 42 shrinking, 47 snapshot, 39 striped, 34 lvchange command, 42 lvconvert command, 39 lvcreate command, 32 lvdisplay command, 43 lvextend command, 43 LVM architecture overview, 3 clustered, 4 components, 4, custom report format, 49 directory structure, 26 help, 22 history, 3 label, 9 logging, 19 logical volume administr
report format, LVM devices, 49 resizing logical volume, 42 physical volume, 25 rules.
120