logical volumes. Use either the –T option, or the --thin option, or the --thinpool option when creating a thin pool. The following example creates a thin pool named mythinpool from the myvolg volume group that is 100m in size:
# lvcreate –L 100m –T myvolg/mythinpool
This command creates a logical volume as shown by the following command: # lvs
LV VG Attr LSize Pool Origin Data%... mythinpool myvolg twi-a-tz-- 100.00m 0.00 The “Data%” column shows the allocated pool data. The example shows 0.00% because virtual thin volumes have not yet been created in this thin-pool. You can also use the lvdisplaycommand to show the “Allocated pool data” percentage.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
LVM Thin Provisioning
•
LVM thin provisioning allows you to over-commit the
physical storage.
•
You can create file systems which are larger than the
available physical storage.
•
Use the lvcreate command to create a thin pool:
•
Use the lvcreate command to create a thin volume.
–
A thin volume is a virtual disk inside a thin pool.
–
The size of the virtual disk can be greater than the size of the
thin pool.
•
Use the lvs command to monitor the allocated pool data
and add more capacity when it starts to become full.
# lvcreate –L 100m –T myvolg/mythinpool
# lvcreate –V 1g –T myvolg/mythinpool –n mythinvol
The thin pool logical volume is not mountable. That is, there is no entry in the /dev directory: # ls /dev/myvolg*
ls: cannot access /dev/myvolg*: No such file or directory
Use the lvcreate command with the –V option to create a thin volume (a virtual disk) from a thin pool. The following example creates a 1 GB thin volume named mythinvol in the
myvolg/mythinpoolthin pool. Note that the size of the thin volume is larger than the size of the thin pool that contains it.
# lvcreate –V 1g –T myvolg/mythinpool –n mythinvol This command creates a thin volume as shown by the following command:
# lvs
LV VG Attr LSize Pool Origin Data%... mythinpool myvolg twi-a-tz-- 100.00m 0.00 mythinvol myvolg Vwi-a-tz-- 1.00g mythinpool 0.00 Note the difference in attributes. The thin volume has a ‘V’ attribute for virtual disk. The Data% column shows 0.00 until you create a file system on the thin volume.
The virtual disk thin volume has a /dev entry shown as follows. In this example, the entry is a symbolic link to the dm-4 block device.
# ls –l /dev/myvolg*
lrwxrwxrwx ... mythinvol -> ../dm-4
You can create a file system on this thin volume and mount it. For example: # mkfs.ext4 /dev/myvolg/mythinvol
# mkdir /myvol
# mount /dev/myvolg/mythinvol /myvol
Output of the df command shows the size of the file system is 976M, which is an over- allocation of the available storage in the thin pool.
# df –h
Filesystem Size Used Avail Use% Mounted on ...
/dev/mapper/myvolg-mythinvol
976M 2.6M 907M 1% /myvol
Copy some data to /myvol then run the lvs command to show the allocated pool data. # cp /boot/vmlinuz* /myvol
# lvs
LV VG Attr LSize Pool Origin Data%... mythinpool myvolg twi-a-tz-- 100.00m 49.00 mythinvol myvolg Vwi-a-tz-- 1.00g mythinpool 4.79 This shows you have used 49% of the allocated pool data. This also shows that the thin volume has used 4.79% of 1 GB. You can use the lvextend command to add space to a thin pool logical volume.
Oracle Linux 7: System Administration 14 - 15
Snapper is a command-line utility in Oracle Linux 7 used to create and manage snapshots of LVM thin volumes. It can create, delete, and compare snapshots and revert changes done between snapshots. Snapper also allows for the easy creation and management of snapshots for Btrfs. Use the following command to install the snapper software package:
# yum install snapper
The snapper software package includes a cron.hourly file to create snapshots and a cron.dailyfile to clean up old snapshots.
# ls –l /etc/cron*/snapper
-rwxr-xr-x ... /etc/cron.daily/snapper -rwxr-xr-x ... /etc/cron.hourly/snapper
To create a snapshot using snapper, a configuration file is required for the LVM thin volume or Btrfs subvolume. The LVM and Btrfs volumes must also have a mounted file system. Use the create-configcommand to create the configuration file. The following example creates a configuration file named myvol_snap for an LVM ext4 file system mounted on /myvol1:
# snapper –c myvol1_snap create-config –f “lvm(ext4)” /myvol1 This command adds an entry to /etc/sysconfig/snapper, creates a .snapshots directory in the /myvol1 directory, and creates the configuration file, myvol1_snap, in the
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Snapper
•
Command-line utility in Oracle Linux 7 to create and
manage snapshots
•
Supports Btrfs and LVM thin volumes
•
Requires a configuration file for each Btrfs and LVM
volume
–
To create myvol1_snap configuration file for ext4 file
system on LVM thin volume mounted on /myvol1:
–
Entry is added to /etc/sysconfig/snapper.
–
.snapshots directory is created in the /myvol1 directory.
–
Configuration file, myvol1_snap, is created in the
/etc/snapper/configs/
directory.
# snapper –c myvol1_snap create-config –f “lvm(ext4)” /myvol1
Each /etc/snapper/configs/* file describes a snapper configuration. See the snapper-configs(5)man page for a description of the parameters in the snapper configuration file.
The hourly cron job performs automatic snapshot creation but you can also create snapshots manually. There are three types of snapshots that you can create by using snapper:
• pre: Use to record the state of a volume before a modification. Pre snapshots should
always have a corresponding post snapshot.
• post: Use to record the state of a volume after a modification.
• single: These snapshots have no special relationship to other snapshots.
Use the create -t command to specify the type of snapshot to create. Possible values are single, pre, and post.
The following example creates a pre snapshot of the /myvol1 volume. The –p option causes snapper to display the number of the snapshot. In this example, the number is 4.
# snapper –c myvol1_snap create –t pre –p 4
The snapshots are stored by snapshot number in the .snapshots subdirectory of the volume.
Oracle Linux 7: System Administration 14 - 17
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.