These commands show how you can create a new LVM pool in an existing volume group. Virsh from libvirt is used for the task.
I’ve tested everything on a fresh Ubuntu Server 14.04 (Trusty Tahr).
How we start
During the installation of this server, I created 1 large volume group which spanned almost the whole disk ( except for /boot which sits on its own primary partition ). That single volume group lives in partition 2.
root@flipflop ~ # sgdisk -p /dev/sda
Disk /dev/sda: 5860533168 sectors, 2.7 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): D09D3D4B-01CE-4A1F-8ED0-4E68253A85D6
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 4096 1052671 512.0 MiB FD00
2 1052672 5860533134 2.7 TiB FD00
3 2048 4095 1024.0 KiB EF02
root@flipflop ~ #
The installer of Ubuntu created this partition table. Note that we’re using a Guid Partition Table (GPT). A normal MBR is not possible anymore since the disk is over 2TB in size. In this partition, a Logical Volume Group (LVM) has been created.
root@flipflop ~ # vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 1
Act PV 1
VG Size 2.73 TiB
PE Size 4.00 MiB
Total PE 715236
Alloc PE / Size 143872 / 562.00 GiB
Free PE / Size 571364 / 2.18 TiB
VG UUID YOVLIn-I0bX-0bND-JhuX-EnxI-YuO8-5ux86P
root@flipflop ~ #
Defining the new storage pool
To define the storage pool, I’m using the virsh command from libvirt with the pool-define-as option.
If you want to see all options, issue this command.
root@flipflop ~ # virsh help pool-define-as
To define the actual pool, I’ve run this command.
root@flipflop ~ # virsh pool-define-as mylvmpool logical - - /dev/sda2 vg0 /dev/vg0
This command defines the pool. There is no need to run ‘virsh pool-create’ because the pool already exists.
If you want to autostart the storage pool.
root@flipflop ~ # virsh pool-autostart mylvmpool
Checking the storage pool
Right now we can manipulate the vg using the virsh command. A couple of examples:
Listing all storage pools
root@flipflop ~ # virsh pool-list
Name State Autostart
-------------------------------------------
mylvmpool active yes
Getting detailed info about a storage pool
root@flipflop ~ # virsh pool-info mylvmpool
Name: mylvmpool
UUID: cf2438fa-eeb7-457d-ae48-7c05f3cc8dc8
State: running
Persistent: yes
Autostart: yes
Capacity: 2.73 TiB
Allocation: 562.00 GiB
Available: 2.18 TiB
Listing all volumes in the storage pool
root@flipflop ~ # virsh vol-list mylvmpool
Name Path
------------------------------------------------------------------------------
home /dev/vg0/home
root /dev/vg0/root
swap /dev/vg0/swap
Creating a new volume
root@flipflop ~ # virsh vol-create-as mylvmpool newvol 100G
Vol newvol created
Checking if the volume has been created
root@flipflop ~ # virsh vol-list mylvmpool
Name Path
------------------------------------------------------------------------------
home /dev/vg0/home
newvol /dev/vg0/newvol
root /dev/vg0/root
swap /dev/vg0/swap
Listing the details of the new volume
root@flipflop ~ # virsh vol-info newvol --pool mylvmpool
Name: newvol
Type: block
Capacity: 100.00 GiB
Allocation: 100.00 GiB
Deleting the new volume
root@flipflop ~ # virsh vol-delete newvol --pool mylvmpool
Vol newvol deleted
This post explained how to create a new LVM storage pool in an existing Logical Volume Group. It also show how volumes can be listed, created and deleted.