5.4.5. Creating Snapshot Volumes
Note
As of the Red Hat Enterprise Linux 6.4 release, LVM supports thinly-provisioned snapshots. For information on creating thinly provisioned snapshot volumes, see Section 5.4.6, “Creating Thinly-Provisioned Snapshot Volumes”.
Use the
-s
argument of the lvcreate
command to create a snapshot volume. A snapshot volume is writable.
Note
LVM snapshots are not supported across the nodes in a cluster. You cannot create a snapshot volume in a clustered volume group. As of the Red Hat Enterprise Linux 6.1 release, however, if you need to create a consistent backup of data on a clustered logical volume you can activate the volume exclusively and then create the snapshot. For information on activating logical volumes exclusively on one node, see Section 5.7, “Activating Logical Volumes on Individual Nodes in a Cluster”.
Note
As of the Red Hat Enterprise Linux 6.1 release, LVM snapshots are supported for mirrored logical volumes.
As of the Red Hat Enterprise Linux 6.3 release, snapshots are supported for RAID logical volumes. For information on RAID logical volumes, see Section 5.4.16, “RAID Logical Volumes”.
As of the Red Hat Enterprise Linux 6.5 release, LVM does not allow you to create a snapshot volume that is larger than the size of the origin volume plus needed metadata for the volume. If you specify a snapshot volume that is larger than this, the system will create a snapshot volume that is only as large as will be needed for the size of the origin.
By default, a snapshot volume is skipped during normal activation commands. For information on controlling the activation of a snapshot volume, see Section 5.4.17, “Controlling Logical Volume Activation”.
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
. If the original logical volume contains a file system, you can mount the snapshot logical volume on an arbitrary directory in order to access the contents of the file system to run a backup while the original file system continues to get updated.
# lvcreate --size 100M --snapshot --name snap /dev/vg00/lvol1
After you create a snapshot logical volume, specifying the origin volume on the
lvdisplay
command yields output that includes a list of all snapshot logical volumes and their status (active or inactive).
The following example shows the status of the logical volume
/dev/new_vg/lvol0
, for which a snapshot volume /dev/new_vg/newvgsnap
has been created.
# lvdisplay /dev/new_vg/lvol0
--- Logical volume ---
LV Name /dev/new_vg/lvol0
VG Name new_vg
LV UUID LBy1Tz-sr23-OjsI-LT03-nHLC-y8XW-EhCl78
LV Write Access read/write
LV snapshot status source of
/dev/new_vg/newvgsnap1 [active]
LV Status available
# open 0
LV Size 52.00 MB
Current LE 13
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:2
The
lvs
command, by default, displays the origin volume and the current percentage of the snapshot volume being used for each snapshot volume. The following example shows the default output for the lvs
command for a system that includes the logical volume /dev/new_vg/lvol0
, for which a snapshot volume /dev/new_vg/newvgsnap
has been created.
# 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
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.
As of the Red Hat Enterprise Linux 6.2 release, there are two new features related to snapshots. First, in addition to the snapshot itself being invalidated when full, any mounted file systems on that snapshot device are forcibly unmounted, avoiding the inevitable file system errors upon access to the mount point. Second, you can specify the
snapshot_autoextend_threshold
option in the lvm.conf
file. This option allows automatic extension of a snapshot whenever the remaining snapshot space drops below the threshold you set. This feature requires that there be unallocated space in the volume group.
As of the Red Hat Enterprise Linux 6.5 release, LVM does not allow you to create a snapshot volume that is larger than the size of the origin volume plus needed metadata for the volume. Similarly, automatic extension of a snapshot will not increase the size of a snapshot volume beyond the maximum calculated size that is necessary for the snapshot. Once a snapshot has grown large enough to cover the origin, it is no longer monitored for automatic extension.
Information on setting
snapshot_autoextend_threshold
and snapshot_autoextend_percent
is provided in the lvm.conf
file itself. For information about the lvm.conf
file, see Appendix B, The LVM Configuration Files.