Creating an LVM snapshot gives an administrator a point-in-time view of a logical volume before a backup, risky change, or data check. The origin LV can keep running while the snapshot preserves older blocks, but the snapshot needs enough copy-on-write space for changes made after it is created.
The lvcreate –snapshot command creates a snapshot LV in the same volume group as the origin. For a standard thick LV, the snapshot size is the amount of VG free space reserved for changed blocks, not a full copy of the origin volume.
Snapshot space fills as the origin changes, and a full snapshot becomes invalid. Keep snapshots short-lived, monitor Data%, and use application-aware quiescing or backups for databases and other write-heavy services because an LVM snapshot is block-consistent rather than application-consistent.
Related: How to create an LVM logical volume
Related: How to restore an LVM snapshot
Steps to create an LVM snapshot:
- List the origin logical volume.
$ sudo lvs --options lv_name,vg_name,lv_size,lv_attr /dev/vgdata/projects LV VG LSize Attr projects vgdata 20.00g -wi-ao----
Replace /dev/vgdata/projects with the VG and LV that should be captured. The o flag in Attr means the origin device is open, commonly because it is mounted or used by a process.
- Check free space in the volume group.
$ sudo vgs vgdata VG #PV #LV #SN Attr VSize VFree vgdata 2 1 0 wz--n- 200.00g 80.00g
The snapshot size for a standard copy-on-write snapshot is allocated from VFree in the origin volume group.
- Create the snapshot logical volume.
$ sudo lvcreate --snapshot --size 5G --name projects_snap /dev/vgdata/projects Logical volume "projects_snap" created.
Choose a size that can hold changed blocks for the snapshot's lifetime. If Data% reaches 100%, the snapshot becomes invalid.
- List the snapshot and its origin.
$ sudo lvs --options lv_name,origin,lv_size,data_percent,lv_attr /dev/vgdata/projects_snap LV Origin LSize Data% Attr projects_snap projects 5.00g 0.01 swi-a-s---
The s target flag shows a classic snapshot. Origin should match the source LV, and Data% shows snapshot space already used.
- Create a temporary mount point when the snapshot contains a filesystem.
$ sudo mkdir -p /mnt/projects-snapshot
- Mount an ext4 snapshot read-only for inspection.
$ sudo mount -o ro,noload /dev/vgdata/projects_snap /mnt/projects-snapshot
For XFS snapshots mounted beside the origin, use sudo mount -o ro,nouuid,norecovery /dev/vgdata/projects_snap /mnt/projects-snapshot. Skip mounting when the LV contains swap, a database device, a virtual machine disk, or another raw consumer.
- Inspect a known file from the snapshot.
$ sudo cat /mnt/projects-snapshot/app.conf release config
- Unmount the snapshot after inspection.
$ sudo umount /mnt/projects-snapshot
- Monitor snapshot usage while it is kept.
$ sudo lvs --options lv_name,origin,lv_size,data_percent,lv_attr /dev/vgdata/projects_snap LV Origin LSize Data% Attr projects_snap projects 5.00g 1.42 swi-a-s---
Extend or remove the snapshot before Data% reaches 100%. A snapshot kept longer than needed consumes VG space and can slow write-heavy origins.
Related: How to increase the size of an LVM logical volume
Related: How to remove an LVM logical volume
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.