libvirt – adding storage pools manually

libvirt – adding storage pools manually

I use direct disk pass-through for several of my KVM guests. I usually use Virt-Manager to set these up, but a bug in the latest version (1.2.1) made that impossible.

Fortunately it’s pretty easy to add drives using virsh. First check the existing storage pools:

$ virsh pool-list --all
Name State Autostart
-------------------------------------------
Backup active yes
BigParity inactive yes
default active yes
Parity active yes

Create a storage pool xml file. Look at the existing pools in  /etc/libvirt/storage/ for reference. Create the file locally:

$ cat Parity5TB.xml
<pool type='disk'>
<name>Parity5TB</name>
<uuid>8a4550e0-3bcf-4351-ad36-496b51737c</uuid>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<available unit='bytes'>0</available>
<source>
<device path='/dev/disk/by-id/ata-TOSHIBA_MD04ACA500_55F'/>
<format type='unknown'/>
</source>
<target>
<path>/dev/disk/by-id</path>
<permissions>
<mode>0711</mode>
<owner>-1</owner>
<group>-1</group>
</permissions>
</target>
</pool>

 

Note that I use /dev/disk/by-id. You can use any /dev/disk/by-* reference, but NEVER use /dev/sd* (you’ll undestand why after the first time you add or remove a drive).

Assuming it’s already formatted (I find it easiest to format on the host with gparted and pass through the pre-formatted disk) you can quickly get the uuid with blkid. Then either use /dev/disk/by-uuid, or lookup the symbolic links in the /dev/disk/by-X directory.

Add the pool to your definitions:

$ virsh pool-define Parity5TB.xml
$ virsh pool-list --all
Name State Autostart
-------------------------------------------
Backup active yes
BigParity inactive yes
default active yes
Parity active yes
Parity5TB active no

That’s it. This does not autostart the drive, or attach it to any guests, but you can still do this through virt-manager.

Leave a Reply

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