How to create LVM Disk on Ubuntu 17.04

LVM (Logical Volume Management) is a great system to manage local volumes, filesystems. It comes with many modern features you need, much better than traditional disk partitioning systems. On this tutorial, I am going to show you how I manage my Ubuntu 17.04 with LVM. I choose LVM partitioning during initial Ubuntu 17.04 installation. For the Ubuntu official wiki about LVM, please visit this page: https://wiki.ubuntu.com/Lvm.

In LVM, we will manage the following three items:

  • Volume Group (VG)
  • Physical Volume (PV)
  • Logical Volume (LV)

First we need to display current LVM that exist on our Ubuntu 17.04. This command below will display information about current LVM volumes.

sudo lvmdiskscan

Output:

root@pydio:~# lvmdiskscan
  /dev/pydio-vg/root   [       9.26 GiB] 
  /dev/pydio-vg/swap_1 [     512.00 MiB] 
  /dev/vda1            [     243.00 MiB] 
  /dev/vda5            [       9.76 GiB] LVM physical volume
  /dev/vdb             [      10.00 GiB] 
  2 disks
  2 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

On the example above, I am currently have 1 active LVM physical volume and I have another 2 disks which can be used to extend this current Volume Group or create a new one.

Display existing Volume Group

sudo vgdisplay

Output:

root@pydio:~# vgdisplay
  --- Volume group ---
  VG Name               pydio-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.76 GiB
  PE Size               4.00 MiB
  Total PE              2498
  Alloc PE / Size       2498 / 9.76 GiB
  Free  PE / Size       0 / 0   
  VG UUID               P4isRq-HvDS-WbKy-Fn6t-8j4d-lWKE-awfQQQ
   

As you can see, my current VG name is: pydio-vg and it size would be: 10.0 GB.

Display Existing Physical Volume

Use this command to display the physical volume on the system

sudo pvdisplay

Output:

root@pydio:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda5
  VG Name               pydio-vg
  PV Size               9.76 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2498
  Free PE               0
  Allocated PE          2498
  PV UUID               eV4XNN-8Lfb-WfJZ-gcwC-wQfI-Ind6-a2kqbz

Current Volume Group has only 1 physical volume which is /dev/vda1.

Display Existing Logical Volume

To display current Logical Volume, use lvdisplay command as follow

sudo lvdisplay

Example:

root@pydio:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/pydio-vg/root
  LV Name                root
  VG Name                pydio-vg
  LV UUID                BlC44o-ERzj-BVR9-tfQE-MYxA-1fAC-kKEf3s
  LV Write Access        read/write
  LV Creation host, time pydio, 2016-05-13 21:19:55 +0700
  LV Status              available
  # open                 1
  LV Size                9.26 GiB
  Current LE             2370
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/pydio-vg/swap_1
  LV Name                swap_1
  VG Name                pydio-vg
  LV UUID                mydJPo-F1oH-PU0O-nmO4-i5gh-o4dn-hlWuYH
  LV Write Access        read/write
  LV Creation host, time pydio, 2016-05-13 21:19:55 +0700
  LV Status              available
  # open                 2
  LV Size                512.00 MiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

OK now we have any information we need. We are going to create a new LVM volume. First, we need to create a physical volume.

Create new Physical Volume

From the lvmdiskscan command, we can see that there are two disks that currently not used (/dev/vdb). I want to create a new physical volume using /dev/vdb. The following command will use the whole /dev/vdb disk as a new physical volume.

sudo pvcreate /dev/vdb

Output:

root@pydio:~# pvcreate /dev/vdb
  Physical volume "/dev/vdb" successfully created

Make sure that the new physical volume is listed using pvdisplay command

root@pydio:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda5
  VG Name               pydio-vg
  PV Size               9.76 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2498
  Free PE               0
  Allocated PE          2498
  PV UUID               eV4XNN-8Lfb-WfJZ-gcwC-wQfI-Ind6-a2kqbz
   
  "/dev/vdb" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdb
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               HiUSon-EtEO-zM3L-wG91-lucp-BpRw-3IBNTt

Please notice that the /dev/vdb is now listed in new Physical Volume.

Create New Volume Group

Now we can create a new Volume Group (VG) using the newly created PV from the step before.

sudo vgcreate gamblisfx-vg /dev/vdb

The command will create a new VG called gamblisfx-vg which contains /dev/vdb device.

Output:

root@pydio:~# vgcreate gamblisfx-vg /dev/vdb
  Volume group "gamblisfx-vg" successfully created

Check the new VG

vgdisplay

Output:

root@pydio:~# vgdisplay
  --- Volume group ---
  VG Name               pydio-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.76 GiB
  PE Size               4.00 MiB
  Total PE              2498
  Alloc PE / Size       2498 / 9.76 GiB
  Free  PE / Size       0 / 0   
  VG UUID               P4isRq-HvDS-WbKy-Fn6t-8j4d-lWKE-awfQQQ
   
  --- Volume group ---
  VG Name               gamblisfx-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               10.00 GiB
  PE Size               4.00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / 10.00 GiB
  VG UUID               G3N9s6-QlXX-wirT-DTFu-gzx6-Q5nV-yMdigb

OK now basically I have two vg’s in my Ubuntu system. The first one was created during Ubuntu installation (pydio-vg) and the second one (gamblisfx-vg) is the one we’ve just created.

Create a new Logical Volume 

Now we have a new Volume Group so next we can create a new LV. For example I want to create a new LV with 5GB in size.

sudo lvcreate -n lv01 -L 5g gamblisfx-vg

Output:

root@pydio:~# lvcreate -n lv01 -L 5g gamblisfx-vg
  Logical volume "lv01" created.

Check using lvdisplay command

root@pydio:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/pydio-vg/root
  LV Name                root
  VG Name                pydio-vg
  LV UUID                BlC44o-ERzj-BVR9-tfQE-MYxA-1fAC-kKEf3s
  LV Write Access        read/write
  LV Creation host, time pydio, 2016-05-13 21:19:55 +0700
  LV Status              available
  # open                 1
  LV Size                9.26 GiB
  Current LE             2370
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/pydio-vg/swap_1
  LV Name                swap_1
  VG Name                pydio-vg
  LV UUID                mydJPo-F1oH-PU0O-nmO4-i5gh-o4dn-hlWuYH
  LV Write Access        read/write
  LV Creation host, time pydio, 2016-05-13 21:19:55 +0700
  LV Status              available
  # open                 2
  LV Size                512.00 MiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
   
  --- Logical volume ---
  LV Path                /dev/gamblisfx-vg/lv01
  LV Name                lv01
  VG Name                gamblisfx-vg
  LV UUID                NNvi5F-aBbU-5gWl-hiS1-T1xW-xnoq-YrfgCy
  LV Write Access        read/write
  LV Creation host, time pydio, 2017-04-28 11:41:48 +0700
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

As you can see, my new LV called lv01 is listed and now I can use it for other purposes, format it, mount it to store data etc.

Admin

Leave a Reply

Your email address will not be published. Required fields are marked *