Wednesday, April 20, 2016

Week 23: Day 060 - Managing Logical Volumes


This blog post will be dedicated to logical volumes. The main reason for using this is if for example, you ran out of space on your logical volume, you take available disk space from the volume group. If there's no space on the volume group, get a new physical volume. In essence this is like if you lost space on your hard drive, you take space from something else, and if there is none, buy and use a new hard drive.

In a LVM architecture, there are several layers. They can range from disks to partitions, logical units, and yadda yadda. The storage devices can be flagged as physical volumes, which makes them usable in LVM. Here's the hierarchy: Physical Disks, Volume Group, Logical Volumes, and File Systems. This will work on both EXT4 and XFS. Data can be moved to the volume group using "pvmove". If a hard disk is failing, it can be removed from the volume group.

To create logical volumes you need to take care of physical volume (PV) and the volume group (VG), while assigning physical volumes to it. Finally the logical volume (LV) itself will have to be created. The only commands I need to remember are: "pv", "vg", and "lv".

------------------------------------------------------------------------------------------------------------
One of the great benefits of LVM is that you can resize it. The "vgextend" command is used to add storage to a volume group, and the "vgreduce" command is used to take physical volumes out of a volume group (which can lead to some additional complications). For the RHCSA test, you need to know how to extend the available storage in volume groups. This procedure is relatively easy:

1. Make sure that a physical volume or device is available to be added to the volume group.

2. Use vgextend to extend the volume group. The new disk space will show immediately in the volume group.

Logical volumes can be extended with the "lvextend" command.To grow the logical volume size, use lvresize, followed by the -r option to resize the file system used on it. 

Perfect example of its use:
  • lvresize -L +1G -r /dev/vgdata/lvdata.
  •  lvresize -r -l 75%VG /dev/vgdata/lvdata This resizes the logical volume so that it will take 75% of the total disk space in the volume group.
  • lvresize -r -l +75%VG /dev/vgdata/lvdata This tries to add 75% of the total size of the volume group to the logical volume. (Notice the difference with the previous command.)
  •  lvresize -r -l +75%FREE /dev/vgdata/lvdata This adds 75% of all free disk space to the logical volume.
  • lvresize -r -l 75%FREE /dev/vgdata/lvdata This resizes the logical volume to a total size that equals 75% of the amount of free disk space. (Notice the difference with the previous command.)

No comments:

Post a Comment