Thu, March 29, 2018 ยท 2 min read

KVM custom storage pool on LVM partition

KVM custom storage pool on LVM partition

Libvirtd by default has a storage pool called default, we can create additional storage pools from a simple XML file.

Pool XML definition

<pool type="logical">
  <name>store</name>
  <source>
    <device path="/dev/sda1"/>
  </source>
  <target>
    <path>/dev/store</path>
  </target>
</pool>

Define and start the pool

$ virsh pool-define store.xml
Pool store defined from store.xml

$ virsh pool-start store
Pool store started

$ virsh pool-list
 Name                 State      Autostart
-------------------------------------------
 cipher               active     yes
 default              active     no
 store                active     no

$ virsh pool-autostart store
Pool store marked as autostarted

$ virsh pool-autostart default
Pool default marked as autostarted

$ virsh pool-list
 Name                 State      Autostart
-------------------------------------------
 cipher               active     yes
 default              active     yes
 store                active     yes

Creating volumes with virsh

$ virsh vol-create-as store linux2 25G
Vol linux2 created

$ virsh vol-list store
 Name                 Path
------------------------------------------------------------------------------
 linux1               /dev/store/linux1
 linux2               /dev/store/linux2

Check LVM information

$ lvdisplay /dev/store/linux2
  --- Logical volume ---
  LV Path                /dev/store/linux2
  LV Name                linux2
  VG Name                store
  LV Size                25.00 GiB

Installing OS on the newly created LVM volume

$ virt-install \
  --name linux2 \
  --ram 512 \
  --disk path=/dev/store/linux2 \
  --vcpus 2 \
  --os-type linux \
  --os-variant rhel7 \
  --network network=default \
  --graphics none \
  --console pty,target_type=serial \
  --location '/home/cipher/CentOS-7-x86_64-Minimal-1708.iso' \
  --extra-args 'console=ttyS0,115200n8 serial'

Installation with kickstart

$ virt-install \
  --name linux2 \
  --ram 512 \
  --disk path=/dev/store/linux2 \
  --vcpus 2 \
  --os-type linux \
  --os-variant rhel7 \
  --network network=default \
  --graphics none \
  --console pty,target_type=serial \
  --location '/home/cipher/CentOS-7-x86_64-Minimal-1708.iso' \
  --initrd-inject '/var/www/html/pub/ks.cfg' \
  --extra-args 'console=ttyS0,115200n8 serial' \
  --extra-args 'ks=file:/ks.cfg' \
  --accelerate