Using Thinly-Provisioned Logical Volumes

Thinly provisioned logical volumes have virtual sizes that are typically greater than the physical storage on which you create them. You create thinly provisioned logical volumes from storage that you have assigned to a special type of logical volume called a thin pool. LVM assigns storage on demand from a thin pool to a thinly-provisioned logical volume as required by the applications that access the volume. You need to use the lvs command to monitor the usage of the thin pool so that you can increase its size if its available storage is in danger of being exhausted.

Configuring and Managing Thinly-Provisioned Logical Volumes

Creating thinly provisioned logical volumes involves two steps:

  1. Create a thin pool.

    sudo lvcreate --size size --thin vol_group/pool_name
  2. Create a thinly provisioned logical volume.

    sudo lvcreate --virtualsize size --thin vol_group/thin_pool_name --name logical_vol

In the following example, the thin pool mytp of size 1 GB is first created from the volume group myvg:

sudo lvcreate --size 1g --thin myvg/mytp
Logical volume "mytp" created

Then, the thinly provisioned logical volume mytv is created with a virtual size of 2 GB:

sudo lvcreate --virtualsize 2g --thin myvg/mytp --name mytv
Logical volume "mytv" created

Note that the size of mytp is less than that of mytv.

To create a snapshot of mytv, don't specify the size of the snapshot. Otherwise, its storage would not be provisioned from mytp, for example:

sudo lvcreate --snapshot --name mytv-snapshot myvg/mytv
Logical volume “mytv-snapshot” created

If the volume group has sufficient space, use the lvresize command as needed to increase the size of a thin pool, for example:

sudo lvresize -L+1G myvg/mytp
Extending logical volume mytp to 2 GiB
Logical volume mytp successfully resized

For more information, see the lvcreate(8) and lvresize(8) manual pages.

Using snapper With Thinly-Provisioned Logical Volumes

The snapper utility is another tool for creating and maintaining thin snapshots of thinly-provisioned logical volumes.

To set up the snapper configuration for an existing mounted volume:

sudo snapper -c config_name create-config -f "lvm(fs_type)" fs_name
config_name

Name of the configuration

fs_type

File system type (ext4 or xfs)

fs_name

Path of the file system.

The command adds an entry for config_name to /etc/sysconfig/snapper, creates the configuration file /etc/snapper/configs/config_name , and sets up a .snapshots subdirectory for the snapshots.

By default, snapper sets up a cron.hourly job to create snapshots in the .snapshot subdirectory of the volume and a cron.daily job to clean up old snapshots. You can edit the configuration file to disable or change this behavior. For more information, see the snapper-configs(5) manual page.

With snapper, you can create 3 types of snapshots:

post

A post snapshot records the state of a volume after a modification. A post snapshot should always be paired with a pre snapshot that you take immediately before you make the modification.

pre

A pre snapshot records the state of a volume immediately before a modification. A pre snapshot should always be paired with a post snapshot that you take immediately after you have completed the modification.

single

A single snapshot records the state of a volume but does not have any association with other snapshots of the volume.

For example, the following commands create a pre snapshot and a post snapshots of a volume:

sudo snapper -c config_name create -t pre -p N
... Modify the volume's contents ...
sudo snapper -c config_name create -t post --pre-num N -p N'

The -p option causes snapper to display the number of the snapshot so that you can reference it when you create the post snapshot or when you compare the contents of the pre and post snapshots.

To display the files and directories that have been added, removed, or modified between the pre and post snapshots, use the status subcommand:

sudo snapper -c config_name status N .. ..

To display the differences between the contents of the files in the pre and post snapshots, use the diff subcommand:

sudo snapper -c config_name diff .. N'

To list the snapshots that exist for a volume:

sudo snapper -c config_name list

To delete a snapshot, specify its number to the delete subcommand:

sudo snapper -c config_name delete N''

To undo the changes in the volume from post snapshot N' to pre snapshot N:

sudo snapper -c config_name undochange N .. N'

For more information, see the snapper(8) manual page.