In the previous blog I showed how to add a new storage in Linux and split the disk into partitions. Today I will touch a bit more advanced topic and will show how to create logical volumes with LVM. There are plenty advantages of LVM:
- you can create/resize/delete partitions while your system is running, without reboot.
- merge multiple small disks space together, creating a bigger logical disk
- create distributed I/O across all disks, similar to RAID, but much easier to set up.
- create snapshots of the volume easily for disk backups. etc
Last time we used Ubuntu, this time we will use CentOS, as when it comes to storage management and commands and tools that we will use, they are pretty much similar:
[vagrant@centos ~]$ rpm -qa | grep lvm
lvm2-2.02.171-8.el7.x86_64
lvm2-libs-2.02.171-8.el7.x86_64
[vagrant@centos ~]$
ubuntu@zesty:~$ dpkg --list | grep lvm
ii liblvm2app2.2:amd64 2.02.167-1ubuntu5 amd64 LVM2 application library
ii liblvm2cmd2.02:amd64 2.02.167-1ubuntu5 amd64 LVM2 command library
ii lvm2 2.02.167-1ubuntu5 amd64 Linux Logical Volume Manager
ubuntu@zesty:~$
Let’s create a VM, make sure the directory you running the command is empty as vagrant is using rsync to synchronise contents of current directory with the VM, so if you have GBs of files, it might take a while without a reason:
vagrant init centos/7 && \
vagrant up && \
vagrant ssh
If you didn’t have centos previously it will download about 385MB:
➜ ~ du -sh ~/.vagrant.d/boxes/*
385M /Users/kayanazimov/.vagrant.d/boxes/centos-VAGRANTSLASH-7
425M /Users/kayanazimov/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64
269M /Users/kayanazimov/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64
290M /Users/kayanazimov/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-zesty64
Once inside, let’s check the existing storage devices:
[vagrant@centos ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
Now let’s exit,, halt the vm, add 2 new disks of size 1GB and then start the vm and logon again,
If you don’t know how to add new disks to vm you can read first part of previous blog about storages.
Now let’s check disks again:
[vagrant@centos ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
sdc 8:32 0 1G 0 disk
As you can see sdb and sdc have been added. Let’s ask LVM which devices available to it:
[vagrant@centos ~]$ sudo lvmscan
sudo: lvmscan: command not found
[vagrant@centos ~]$ sudo lvmdiscan
sudo: lvmdiscan: command not found
[vagrant@centos ~]$ sudo lvmdiskscan
/dev/VolGroup00/LogVol00 [ <37.47 GiB]
/dev/VolGroup00/LogVol01 [ 1.50 GiB]
/dev/sda2 [ 1.00 GiB]
/dev/sda3 [ <39.00 GiB] LVM physical volume
/dev/sdb [ 1.00 GiB]
/dev/sdc [ 1.00 GiB]
2 disks
3 partitions
0 LVM physical volume whole disks
1 LVM physical volume
First we need to initialise a physical volumes for use by LVM: