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



Logical Volumes

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:

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.