Hello, and welcome to today's video about Logical Volume Management, also known as LVM.
So what is LVM?
LVM is a storage solution that provides a way to combine any number of disks or partitions
into a single file system or multiple file systems.
These file systems are flexible in their layout and allow the dynamic resizing of the allocated
space.
The resizing allows an administrator to shrink a volume when space is no longer needed (returning
it to the free pool) or grow the volume to increase storage for a user's home directory,
writing to logs, or other necessities.
What about mounting these file systems?
We can mount a file system created on top of LVM nearly anywhere, except at /boot.
Although GRUB2 supports LVM on Oracle Linux, for systems running the AMD, Intel, and ARM
architecture, the boot loader cannot read LVM volumes.
This limitation requires a non-LVM disk partition for the /boot partition.
The last feature to highlight is LVM snapshots.
A snapshot provides a point-in-time copy of the logical volume, which can be mounted and
then used to make a backup of a live system.
Well, that's a good introduction to LVM, but how's LVM laid out?
LVM consists of four layers.
At the bottom layer, you have the physical volumes (PV) such as /dev/sda, /dev/sdb, and
/sdc.
These are the physical disks attached to the system.
Above the physical volumes is the volume group (VG).
The volume group encompasses all the physical volumes in the LVM layout, whether a single
disk or multiple.
In our diagram, we show it includes all the physical disks.
On top of the volume group is the logical volumes (LV), which function similar to partitions
carving up the volume group.
And lastly, you have the file system.
The file system can be EXT4, XFS, ReiserFS, or whatever and contains the directory for
mounting logical volumes.
Great, looks easy, right?
Let's jump onto a running Oracle Linux system to demonstrate some of the details we just
covered.
We'll use Oracle Linux 8 deployed in Oracle Cloud Infrastructure, where we've added several
additional block volumes.
This demo aims to increase the available space for files and logs on the root file system.
Start by reporting any existing physical volumes by running `sudo pvs`.
This command shows we have a physical volume, a partition, which is `/dev/sda3` associated
with the volume group `ocivolume`.
Then report summary details about the volume groups by running `sudo vgs`, which shows
the volume group name of `ocivolume` with a size of 45G and no free space.
To increase the available capacity on the root file system, we'll add to the free space
in the volume group and then expand our logical volume.
Increasing free space, in this case, requires another physical volume by adding another
disk or partition.
Let's see what disks or partitions are available by running `sudo lsblk`.
The output shows three available disks, `/dev/sdb`, `/dev/sdc`, and `/dev/sdd`.
If we wanted only to use part of the disk, then use `fdisk` or `parted` to partition
it.
To keep it simple, we'll use the entire disk.
Create the new LVM physical volume on `/dev/sdb` by running `sudo pvcreate /dev/sdb`.
Then show the newly created physical volume using `sudo pvs`.
Next, extend the volume group by running `sudo vgextend` and passing the volume group name
`ocivolume` and the physical volume name `/dev/sdb`.
With the volume group extension complete, we should examine the detailed information
for our volume group by running `sudo vgdisplay`.
The terminal shows the VG Size has increased, and there is 50G free.
So far, things are going well.
We can now work with our logical volumes.
Get a listing of the existing logical volumes by running `sudo lvs`.
The results show one called `oled` and the other called `root`.
We want to increase the capacity on `root`, which contains our home and var directories.
When extending `root`, we'll need to pass the full logical volume path, which we get
by running `sudo lvdisplay`.
The command results show that the full path for `root` is `/dev/ocivolume/root`.
Now extend the `root` logical volume by running `sudo lvextend` passing the increased size
`-L 50G` and the path `/dev/ocivolume/root`.
Verify our success by running `sudo lvdisplay /dev/ocivolume/root`.
Outstanding, we increased the size of our logical volume.
So all that space is now usable, correct?
Not quite yet.
We still have to expand the file system.
Before performing that step, we first need to know what file system exists on the logical
volume.
Running `sudo lsblk -f` shows that `/dev/sdb` is an LVM2_member and uses the `xfs` file
system.
Next, let's do a quick disk space check with `df -h` to have a reference point before the
file system grows.
The output shows that the LV `/dev/mapper/ocivolume-root` mounted at `/` has 28G.
Now grow the file system with `sudo xfs_growfs /`.
That didn't take long.
Running `df -h` again now shows 42G available.
We have successfully grown our usable space for files, applications, or logs.
I hope you enjoyed this introduction to LVM, as there is so much more we can do with it.
If looking for more practice, check out our free tutorials and labs by clicking the card
above or reviewing the links in the description of this video.
Thank you for watching.
For additional information on Oracle Linux, access the Oracle Linux Documentation or Oracle
Linux Learning Library.