Assignment: Topic:Lvm
Assignment: Topic:Lvm
Assignment: Topic:Lvm
TOPIC:LVM
Introduction
LVM, or Logical Volume Management, is a storage device management
technology that gives users the power to pool and abstract the physical layout of
component storage devices for easier and flexible administration. Utilizing the
device mapper Linux kernel framework, the current iteration, LVM2, can be used
to gather existing storage devices into groups and allocate logical units from the
combined space as needed.
The main advantages of LVM are increased abstraction, flexibility, and control.
Logical volumes can have meaningful names like "databases" or "root-backup".
Volumes can be resized dynamically as space requirements change and migrated
between physical devices within the pool on a running system or exported easily.
LVM also offers advanced features like snapshotting, striping, and mirroring.
In this guide, we will briefly discuss how LVM works and then demonstrate the
basic commands needed to get up and running quickly.
Physical Volumes:
Volume Groups:
Logical Volumes:
In summary, LVM can be used to combine physical volumes into volume groups to
unify the storage space available on a system. Afterwards, administrators can
segment the volume group into arbitrary logical volumes, which act as flexible
partitions.
The extents on a physical volume are called physical extents, while the extents of
a logical volume are called logical extents. A logical volume is simply a mapping
that LVM maintains between logical and physical extents. Because of this
relationship, the extent size represents the smallest amount of space that can be
allocated by LVM.
Extents are behind much of the flexibility and power of LVM. The logical extents
that are presented as a unified device by LVM do not have to map to continuous
physical extents. LVM can copy and reorganize the physical extents that compose a
logical volume without any interruption to users. Logical volumes can also be
easily expanded or shrunk by simply adding extents to or removing extents from
the volume.
sudo lvmdiskscan
The output will display all available block devices that LVM can interact with:
Output
/dev/ram0 [ 64.00 MiB]
/dev/sda [ 200.00 GiB]
/dev/ram1 [ 64.00 MiB]
...
Warning: Make sure that you double-check that the devices you intend to use with
LVM do not have any important data already written to them. Using these devices
within LVM will overwrite the current contents. If you already have important data
on your server, make backups before proceeding.
Now that we know the physical devices we want to use, we can mark them as
physical volumes within LVM using the pvcreate command:
Output
Physical volume "/dev/sda" successfully created
Physical volume "/dev/sdb" successfully created
This will write an LVM header to the devices to indicate that they are ready to be
added to a volume group.
You can quickly verify that LVM has registered the physical volumes by typing:
sudo pvs
Output
PV VG Fmt Attr PSize PFree
/dev/sda lvm2 --- 200.00g 200.00g
/dev/sdb lvm2 --- 100.00g 100.00g
As you can see, both of the devices are present under the PV column, which stands
for physical volume.
To create the volume group and add both of our physical volumes to it in a single
command, type:
Output
Volume group "LVMVolGroup" successfully created
If we check the pvs output again, we can see that our physical volumes are now
associated with new volume group:
sudo pvs
Output
PV VG Fmt Attr PSize PFree
/dev/sda LVMVolGroup lvm2 a-- 200.00g 200.00g
/dev/sdb LVMVolGroup lvm2 a-- 100.00g 100.00g
We can see a brief summary of the volume group itself by typing:
sudo vgs
Output
VG #PV #LV #SN Attr VSize VFree
LVMVolGroup 2 0 0 wz--n- 299.99g 299.99g
As you can see, our volume group currently has two physical volumes, zero logical
volumes, and has the combined capacity of the underlying devices.
We'll create four separate logical volumes out of our volume group:
To create logical volumes, we use the lvcreate command. We must pass in the
volume group to pull from, and can name the logical volume with the -n option. To
specify the size directly, you can use the -Loption. If, instead, you wish to specify
the size in terms of the number of extents, you can use the -loption.
We can create the first three logical volumes with the -L option like this:
Output
Logical volume "projects" created.
Logical volume "www" created.
Logical volume "db" created.
We can see the logical volumes and their relationship to the volume group by
selecting custom output from the vgs command:
Output
VG #PV #LV #SN Attr VSize VFree LSize LV
LVMVolGroup 2 3 0 wz--n- 299.99g 264.99g 10.00g projects
LVMVolGroup 2 3 0 wz--n- 299.99g 264.99g 5.00g www
LVMVolGroup 2 3 0 wz--n- 299.99g 264.99g 20.00g db
We have added the last two columns of output so that we can see the space
allocated to our logical volumes.
Now, we can allocate the rest of the space in the volume group to the "workspace"
volume using the -lflag, which works in extents. We can also provide a percentage
and a unit to better communicate our intentions. In our case, we wish to allocate
the remaining free space, so we can pass in 100%FREE:
Output
Logical volume "workspace" created.
If we recheck the volume group information, we can see that we have used up all
of the available space:
Output
VG #PV #LV #SN Attr VSize VFree LSize LV
LVMVolGroup 2 4 0 wz--n- 299.99g 0 10.00g projects
LVMVolGroup 2 4 0 wz--n- 299.99g 0 5.00g www
LVMVolGroup 2 4 0 wz--n- 299.99g 0 20.00g db
LVMVolGroup 2 4 0 wz--n- 299.99g 0 264.99g workspace
As you can see, the "workspace" volume has been created and the
"LVMVolGroup" volume group is completely allocated.
/dev/volume_group_name/logical_volume_name
/dev/mapper/volume_group_name-logical_volume_name
So to format our four logical volumes with the Ext4 filesystem, we can type:
Or we can type:
To make the mounts persistent, add them to /etc/fstab just like you would with
normal block devices:
/etc/fstab
...
Conclusion
Hopefully, by this point, you will have a fairly good understanding of the various
components that LVM manages to create a flexible storage system. You should also
have a basic understanding of how to get storage devices up and running in an
LVM setup.
Reference
www.digitalocean.com