LVM snapshots allow us to freeze a volume in time so we can analyze the data. A common use for this technology is for system backups. By freezing a view of a volume we can take our time backing up the data without invalidating our backups. Without snapshots our backup software may be backing up data that's currently being changed.
- [Teacher] The roll forward type of snapshot is probably the most common type in system administration. We create these to freeze the file systems so we can back it up. In this example we'll create a snapshot of the origin volume and then when we're done we'll delete the snapshot. We need to make sure that our volume group has enough free space to hold the snapshot. Lets start by typing in sudo space vgs and hit enter. Type in your password if prompted. Our VG data volume group only has 24 megabytes of space.
So we'll need to increase this if we want to snapshot larger than 24 megabytes. Let's look at what we have available in the way of other physical volumes. Type in sudo space pvs and hit enter. Our slash dev slash STC1 physical volume has 476 megabytes of free space. Let's add this back into our volume group. Type in clear then type in sudo space vgextend space vgdata space slash dev slash sdc1 and hit enter.
And verify it was vgs. Type in sudo space vgs and hit enter again. And how we have 496 megabytes of free space in the volume group. Before we create a snapshot of our LV data physical volume let's make sure it's mounted and we'll add a few files to it. Type in df space dash h and hit enter. It's mounted on slash media slash LV data. If yours is not mounted then mount it before continuing. Let's cd there. Type in clear and then type in cd space slash media slash lvdata and hit enter.
And then let's list the directory. Type in ls space dash l and hit enter again. There are no files currently. Let's create three files. Type in sudo space touch space file left curly bracket one comma two comma three. Right curly bracket dot txt and hit enter and we'll verify again by typing in ls space dash l. Now that we have some files in the origin volume let's create a snapshot. Type in clear and then type in sudo space lvcreate space dash dash snapshot.
Space dash dash size space 100 capital m. Space dash name, space lvdata snap space and then the origin volume. Which will be slash dev slash vgdata slash lvdata and hit enter. And we'll verify with lvs. Type in sudo space lvs and hit enter. We can see our new volume named lvdata snap is 100 megabytes in size. This is the snapshot of our origin volume which is slash dev slash vg data slash lvdata.
If you leave out the size you will be creating a thin provision snapshot. We won't go into specifics here. Now let's mount this snapshot to get access to it. We'll create another mount point in slash media called lvdata snap. Type in clear then type in sudo space mkdir space slash media slash lvdata snap and hit enter. Now let's mount it. Type in sudo space mount space slash dev slash vgdata slash lvdata snap space slash media slash lvdata snap and hit enter.
We can verify with df. Type in df space dash h and hit enter. Notice that df says the snapshot is not 100 megabytes in size it's 1.5 gigabytes. This is because it shows all files in the snapshotted state so it will say it's 1.5 gigabytes in size just like the original volume. Now let's cd to the lvdata mount point and look around. Type in clear and type in cd space slash media slash lvdata and hit enter and then type in ls.
We see our three files. Let's create three more. Type in sudo space touch space file left curly bracket a comma b comma c right curly bracket dot txt and hit enter. And we'll type in ls again. Now let's cd to our snapshot mount point. Type in cd space slash media slash lvdata snap and hit enter and we'll list it with ls. File a file b and file c that we created earlier are not in this volume because they did not exist when we made the snapshot.
This snapshot is a frozen in time view of our origin volume when we created it. To delete a snapshot we treat it just like any other logical volume. Let's unmount it first also make sure you're not in it when you do this. Type in cd space tilda and hit enter and type in sudo space umount space slash media slash lvdata snap and hit enter. And then delete it with lv remove. Type in sudo space lv remove space slash dev slash vgdata slash lvdata snap.
Then press y to continue and we'll verify with sudo space lvs and hit enter. The snapshot is gone and the space used by it has been freed.
Note: This course also helps you study to pass the Red Hat Certified Engineer (RHCE) exam—the benchmark certification for Red Hat Enterprise Linux.
- Create partitions
- Backing up the partition table
- Resize partitions
- Managing LVM volumes
- Creating LVM rollback and roll-forward snapshots
- Extending and shrinking LVM volume groups
- Replacing physical volumes in LVM volume groups
- Creating Linux file systems
- Managing swap
- Creating RAID arrays using LVM
- Backing up and restoring files and file systems