Skip to content

Instantly share code, notes, and snippets.

@JPalmerGithub
Forked from plembo/createkvmstoragepool.md
Created November 3, 2022 12:07
Show Gist options
  • Save JPalmerGithub/e32b0dc0ff2783278b6e1fcdd5f82c8c to your computer and use it in GitHub Desktop.
Save JPalmerGithub/e32b0dc0ff2783278b6e1fcdd5f82c8c to your computer and use it in GitHub Desktop.
Create the default KVM storage pool for images

Change the location of the default KVM storage pool for images

Some distributions create the defaut KVM (libvirt) storage pool for images when they install KVM, others do this upon the creation of the first KVM guest. Creating the default pool from scratch is pretty straightforward. Here's how to do it with virsh.

First verify there is no existing default pool:

$ virsh pool-list --all
 Name      State    Autostart
-----------------------------

Assuming you want the physical path of the new pool to be /data1/libvirt/images, create that directory (sudo mkdir -p /data1/libvirt/images) and run the following command:

$ virsh pool-define-as default dir --target /data1/libvirt/images

Check the configuration:

$ virsh pool-dumpxml default
<pool type='dir'>
  <name>default</name>
  <uuid>a93c414a-5380-4f53-8236-a28b6d1e2ee8</uuid>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <available unit='bytes'>0</available>
  <source>
  </source>
  <target>
    <path>/data1/libvirt/images</path>
  </target>
</pool>

Compare this with a pool definition generated on the creation of the first image on another machine:

<pool type='dir'>
  <name>default</name>
  <uuid>63eb0fa4-6b1e-40e2-92cf-41dced138fc7</uuid>
  <capacity unit='bytes'>3937758330880</capacity>
  <allocation unit='bytes'>836987985920</allocation>
  <available unit='bytes'>3100770344960</available>
  <source>
  </source>
  <target>
    <path>/data1/libvirt/images</path>
    <permissions>
      <mode>0711</mode>
      <owner>64055</owner>
      <group>108</group>
    </permissions>
  </target>
</pool>

You'll notice right away that there a few things missing here, like the capacity values and permissions for the directory. Things should work without these, but what I do is edit the definition to at least set up the permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment