Linux Notes: LVM (logical volume manager)

  1. The information presented here is intended for educational use by qualified computer technologists.
  2. The information presented here is provided free of charge, as-is, with no warranty of any kind.
Edit: 2020-09-04
back to: my Linux Notes (index)
jump to: HP/HPE RAID hardware



  • If you think about it from a very high level, partitioning employs software to alter a hard-disk (or block-structured tape, or USB stick) in such a way that the storage medium can be broken up into smaller functional pieces.
  • After this activity, compatible software is employed to detect/read the partitioning tables (usually stored just after the boot block) to support the partitioning paradigm
  • The resulting partitions can host different file system formats which may include different operating systems (or none)
  • Once set up, these partitions can be read by any compatible software and/or firmware
  • Partitioning is a much older concept and requires that the associated medium be offline because "partitioning changes" are destructive (no attempt is ever made to look inside)

Logical Volumes

  • Logical volume management employs software to break up hard-disks into logical volumes (think: volume partitioning)
  • just as in disk partitioning, volume partitions can host different file system formats
  • the advantage to logical volumes is that almost every file system can be extended or shrunk on the fly (eg. while the system is running)
  • xfs is one file system that cannot be shrunk on the fly here is an example work-around

Stating the Obvious

LVM (Logical Volume Manager)

Anyone who has moved to CentOS-7 will notice that the primary Linux volume has been mounted using LVM (Logical Volume Manager)

My System

Here is an example from one of my CentOS-7 systems:
  • 8-drives contribute to one RAID-60 volume with a resultant size of 1-TB (raid is implemented in HP hardware)
  • poking around as root
    	<ur> = user response
    	<sr> = system response
    <sr>	[root@kawc0f]#
    <ur>	ls -la /dev/sd*
    <sr>	brw-rw----. 1 root disk 8, 0 Aug 24 08:02 /dev/sda
    	brw-rw----. 1 root disk 8, 0 Aug 24 08:02 /dev/sda1
    	brw-rw----. 1 root disk 8, 0 Aug 24 08:02 /dev/sda2
    <ur>	df -h
    <sr>	Filesystem               Size  Used Avail Use% Mounted on
    	/dev/sda1               1016M  231M  785M  23% /boot
    	/dev/mapper/centos-root  500G   40G  461G   8% /
    	/dev/mapper/centos-home  400G  5.7G  395G   2% /home
    <ur>	pvdisplay
    <sr>	--- Physical volume ---
    	PV Name		/dev/sda2
    	VG Name		centos
    	PV Size		1.09 TiB / not usable 4.00 MiB
  • Notes:
    • /dev/sda is the raw physical drive
    • /dev/sda1 is the first partition
    • /dev/sda2 is the second partition which is used to implement two logical volumes (centos-root and centos-home)
      • the current view, where LVM volumes centos-root and centos-home are almost evenly split, is the result of this procedure

Database Maintenance Hacks

Here are two procedures for dealing with systems where the database appears to be filling its host volume. The first procedure will allow you to fix the problem without taking your database offline

  1. If your MySQL or MariaDB databases are growing too quickly, and now you are worried that you might fill up your host LVM, then click here for a verified work around
  2. Here is a tiny stub (sent by a friend) to move MariaDB-10 data files from their default location to a new secondary disk (sdb)
    (LVM commands in red; SELinux in green)
    systemctl stop mariadb               # stop the MariaDB server
    fdisk /dev/sdb                       # create partition sdb1 on device /dev/sdb
    pvcreate /dev/sdb1                   # associate partition with the LVM physical layer
    vgcreate database /dev/sdb1          # associate LVM physical layer the LVM group layer 
    lvcreate -l 100%FREE -n db database  # associate LVM group layer with the LVM logical layer
    mkfs.ext4 /dev/database/db           # create a new file system on the logical device
    mkdir /database                      # create a mount point
    mount /database                      # mount LVM logical layer as if it was a physical partition
    mkdir /database/db                   #
    chcon -Rt mysqld_db_t   /database/db #
    chcon -Ru system_u      /database/db #
    chown -R mysql:mysql    /database/db #
    cp -R -p /var/lib/mysql /database/db # recursively copy files to the new location ("rsync -aX" might be a better choice) 
    mv /var/lib/mysql /var/lib/mysql.old # rename old folder (just being paranoid here)
    vi /etc/mysql.cnf.d/server.cnf       # create or modify symbol "datadir"
    systemctl start mariadb              # start the MariaDB server

    No secondary disk? If your primary disk has some free space which is not yet allocated to any LVM then skip the "pvcreate" and "vgcreate" commands and just create a new LVM via "lvcreate"

 Back to Home
Neil Rieck
Waterloo, Ontario, Canada.