Skip to content

Category: Storage

How to setup LVM, dynamic partitions in Linux.

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:

Comments closed

How to add a new storage volume to Linux VM locally and on AWS EC2.

Sooner or later we all run out of space. Today I am going to demo how to add a new
storage to Linux VM. First we will look at how to do this on local VM with virtualbox and vagrant,
then in AWS.

1. Adding a new volume locally.
2. Splitting disk into partitions
3. Spinning AWS EC2 instance and adding a new volume manually.
4. Attaching new volume with AWS CLI.

So let’s assume you have vagrant and virtualbox installed, let’s spin up a new VM:

vagrant init ubuntu/trusty64 && vagrant up && vagrant ssh

You can pick up newer version of Ubuntu of course, Xenial or Zesty, or any other Linux distro even, I have ubuntu/trusty64 vagrant box already downloaded, so I will be using that one.

First let’s check what we have already got there with ‘list block devices’ command:

vagrant@sensuclient:~$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  40G  0 disk
`-sda1   8:1    0  40G  0 part /
vagrant@sensuclient:~$

Now let’s exit VM and stop it:


vagrant halt
==> sensuclient: Attempting graceful shutdown of VM...

Then we need to go to virtualbox and add new disk as shown below:

Once it is done, we can start VM and check devices again:

vagrant up  && vagrant ssh  

vagrant@sensuclient:~$ sudo lsblk -f
NAME   FSTYPE LABEL           MOUNTPOINT
sda
`-sda1 ext4   cloudimg-rootfs /
sdb

As you can see new disk, ‘sdb’ has been added to the list.

Next we need to crate a filesystem:

Comments closed