CentOS Logical Volume Manager (LVM)
How to Install and Configure LVM on CentOS
LVM (Logical Volume Manager) in CentOS can be used to:
- create easy to maintain logical volumes
- manage disk quotas
- online resize of logical volumes
- create software RAIDs
- combine multiple hard drives into a big storage pool
The advantage of using LVM is that space can be added to or removed from logical volumes as needed without the need to spread data over multiple file systems.
As an example, without LVM, the root (/) file system of a CentOS based server would be created with a certain fixed size when the operating system is installed.
At a later stage if a new disk drive is installed, there is no way to allocate any of this new space to the root (/) file system. An option would be to create new file systems on the new disk and mount them at particular mount points. In this scenario you would have plenty of space on the new file system but the root (/) file system would still be nearly full. To create space on the root filesystem, files would have to be moved to the new filesystem. With LVM, the new disk (or part thereof) can be assigned to the logical volume containing the root file system thereby dynamically extending the space available.
Logical Volume Manager (LVM) provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes, onto which fixed size filesystems are created, LVM allows for grouping together disk space into logical volumes which can be easily resized and moved.
In addition, LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted, the administrator can simply add more space without having to move the user files to a different file system.
Components of LVM are as follows:
VG – Volume Group: high level container that holds one or more physical or logical volumes.
PV – Physical Volume: represents a storage device such as a disk drive or storage media.
PE – Physical Extent: each physical volume is divided into equal size blocks called physical extents.
LV – Logical Volume: eqivalent to a disk partition and can contain a filesystem.
LE – Logical Extent: Each logical volume (LV) is divided into equal size blocks called logical extents.
- Assume we are creating a new volume group called
VolGroup_01
. - This volume group needs physical disk space in order to function.
- This can be achieved by allocating some disk partitions (say
/dev/sda1
,/dev/sdb1
,/dev/sdb2
) to the volume group. - These become physical volumes in
VolGroup_01
. - We then create a logical volume called, say,
LogVol_01
within the volume group made up of the three physical volumes. When space runs out onLogVol_01
, just add more disk partitions as physical volumes and assign them to the volume group and logical volume.
Gather information on a Logical Volume setup
Command | Descriprion |
---|---|
mount | displays filesystem mount information |
vgdisplay | displays volume group information |
lvdisplay | displays logical volume information |
pvdisplay | displays physical volume information (devices that provide actual physical space) |
yum install system-config-lvm | graphical Logical Volume Manager tool |
Add space to CentOS Volume Group using command line
Assuming that a new disk (no previous partitions exist or any existing partitions have been deleted using fdisk
utility) has been added to a CentOS 6 system and is recognised by the OS as /dev/sdb
.
The following steps will accomplish this task:
Command | Description |
---|---|
pvcreate /dev/sdb | Create physical volume |
vgextend VolGroup_01 | xtend the Volume group VolGroup_01 with the physical volume |
lvextend -L+30G /dev/VolGroup_01/lv_root | Add 30GB (change this to match your requirements) of the physical volume to logical volume (lv_root) |
resize2fs /dev/VolGroup_01/lv_root | Resize the filesystem residing on physical volume to use the new additional logical volume space |
Summary:
- The above steps have effectively added new space to logical volume
lv_root
. - This has been done while the server was online and a rebbot was also not required.
- The users would see the new additional space though!
Recent Posts
- Enable http/2 in Apache 16th Jan 2021
- MySQL Shell 8.x 16th Jan 2021
- vi/vim tricks 30th Dec 2020
- SELinux on CentOS 29th Dec 2020
- ssh-copy-id (password less ssh login) 26th Dec 2020
- MySQL auto_increment capacity calculation 26th Dec 2020
- Using UUID as a Primary Key 24th Dec 2020
- Keycloak and InnoDB Cluster 29th Nov 2020
- How to create Column in MySQL only if one does not exist? 19th Mar 2019
- Inject empty transactions in MySQL 5.6 GTID based Replication 25th Dec 2018
- Adding a new disk to CentOS 26th Aug 2018
- mysqldump extended inserts 26th Jun 2018
- CentOS Logical Volume Manager (LVM) 26th Oct 2017
- How to prepare SD Card for Raspberry Pi on a MAC 26th Jun 2017
- Convert .dmg file on a MAC to .iso 26th Apr 2017
Categories
- CentOS (4)
- CentOS 8 (2)
- InnoDB cluster (1)
- mysql (7)
- Raspberry Pi (1)
- ssh (1)
- Technical (3)
Tag cloud
Archives
- January 2021 (2)
- December 2020 (5)
- November 2020 (1)
- March 2019 (1)
- December 2018 (1)
- August 2018 (1)
- June 2018 (1)
- October 2017 (1)
- June 2017 (1)
- April 2017 (1)
- February 2016 (1)