What is the Logical Volume Manager (LVM)?

Physical Volumes have limited storage and controllability. Volume Groups allow physical volumes to be combined into a large single volume which allows users to have greater control over their storage. Volume Groups can then be broken into Logical Volumes which allow system administrators to dynamically size and mirror logical partitions. LVM also facilitates the use of snapshots which are images of current Logical Volume partitions. Snapshots can then be backed up onto external storage. 

Advantages of logical volumes

  • Use any number of disks as one big disk.
  • Have logical volumes stretched over several disks.
  • Create small logical volumes and resize them “dynamically” as they get filled.
  • Resize logical volumes regardless of their order on disk. It does not depend on the position of the LV within VG, there is no need to ensure surrounding available space.
  • Resize/create/delete logical and physical volumes online. File systems on them still need to be resized, but some support online resizing.
  • Online/live migration of LV being used by services to different disks without having to restart services.
  • Snapshots allow you to backup a frozen copy of the file system, while keeping service downtime to a minimum.

Logical Volume Process:

  • Physical Volume – Partitions on the physical storage drives
  • Volume Group – More than one physical volume combined into a single large logical storage
  • Logical Volume – Logical partitions (mount points) created on the volume group
  • Logical Extent – Logical volumes are split into chunks of data called Logical Extents which are mapped to physical extents (blocksize). Logical Extents are responsible for the multi storage functionality due to their ability to map across storage drives. root, boot, primary swap and dump have to be contiguous (all on the same drive).

 Logical Volume Manager Process

Common LVM commands
Commands Description
lvdisplay lvdisplay allows you to see the attributes of a logical volume like size, read/write status, snapshot information etc.
lvcreate lvcreate creates a new logical volume in a volume group by allocating logical extents from the free physical extent pool of that volume group.
lvrename lvrename renames an existing logical volume from OldLogicalVolume{Name|Path} to NewLogicalVolume{Name|Path}.
lvremove lvremove removes one or more logical volumes. Confirmation will be requested before deactivating any active logical volume prior to removal. Logical volumes cannot be deactivated or removed while they are open (e.g. if they contain a mounted filesystem). Removing an origin logical volume will also remove all dependent snapshots.
lvextend lvextend allows you to extend the size of a logical volume.

 

Creating LVM Snapshots
Commands Description
lvdisplay -v /dev/vg00/lv_root Display the Logical Volume you wish to snapshot. Note the Logical Extent (LE).
lvcreate -l 125 -s /dev/vg00/lv_root -n lv_root_snap Create the snapshot replacing “125” with LE.

 

Restoring LVM Snapshots
Commands Description
lvrename /dev/vg00/lv_root /dev/vg00/lv_root_old Assuming the current LV is creating issues the first step is to rename the corrupt LV. “Lv_root_old” for example.
lvcreate -l 125 -n lv_root /dev/vg00 Create a blank LV of the same size. Replacing 125 with LE
dd if=/dev/vg00/lv_root_snap of=/dev/vg00/lv_root Copy the contents of the snapshot into the newly created LV.
shutdown -r now Restart the server
lvremove /dev/vg00/lv_root_old If everything is working correctly, remove the old corrupt LV.

Sources:

https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-lvm.html

https://www.howtoforge.com/linux_lvm_snapshots

http://tldp.org/HOWTO/LVM-HOWTO/benefitsoflvmsmall.html

http://askubuntu.com/questions/417642/logical-volume-physical-volume-and-volume-groups

http://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-lvm/

http://docstore.mik.ua/manuals/hp-ux/en/5992-4589/ch01s03.html

https://fritshoogland.wordpress.com/2012/08/11/using-lvm-snapshots-for-backup-and-restore-of-filesystems/

Leave a Reply

Your email address will not be published. Required fields are marked *

Post navigation