0

I want to create a storage pool for virt-manager's qcow2 images in my home directory but I get a strange error:

Error creating pool: Could not define storage pool: XML error: name /home/matthias/virtual-guests/virt-manager cannot contain '/'

Error creating pool

questions

  • Is it even possible to have the storage pool in my home directory?
  • Do I need special permissions for virt-manager to access the directory?

full error traceback

Traceback (most recent call last): File "/usr/share/virt-manager/virtManager/asyncjob.py", line 89, in cb_wrapper callback(asyncjob, *args, **kwargs) File "/usr/share/virt-manager/virtManager/createpool.py", line 442, in _async_pool_create poolobj = self._pool.install(create=True, meter=meter, build=build) File "/usr/share/virt-manager/virtinst/storage.py", line 531, in install raise RuntimeError(_("Could not define storage pool: %s") % str(e)) RuntimeErError creating pool: Could not define storage poror: Could not define storage pool: XML error: name /home/matthias/virtual-guests/virt-manager cannot contain '/'

4 Answers 4

2

You can create pools, but there are a few things to consider.

  1. The "name" really has to be without a set of special characters, like '/'. If you want to create a /tmp/test pool you might name it "test" (on step 1 of 2) and give it the path "/tmp/test" (on step 2 of 2) and it will work.

  2. apparmor will stop you if you go too uncommon There is a limited set of paths that are allowed by default, if you go out of these at some point virt-aa-helper will no more able to access the files. But that would be needed so that it can allow the access for the per-guest custom profile. See the existing rules in /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper and add custom ones via /etc/apparmor.d/local/usr.lib.libvirt.virt-aa-helper See /etc/apparmor.d/local/README for more on this.

  3. Some pool types are yet unable to be handled by apparmor. The default pool type of virt-manager will be "dir" and that will be fine. But there are more advanced types like "lvm groups", for those types apparmor rules can not be created for the guest on the fly (see bug on this), in these cases you'll need to allow the extra paths you need via changing /etc/apparmor.d/abstractions/libvirt-qemu.

1

Yes, you can create a pool for your home directory. You probably tried to create a pool named "/home/matthias/virtual-guests/virt-manager" which contains the "/" symbols. In the future, when creating a pool, enter a name without the "/" symbol.

You may need to create a QCOW2 file (disk image file) on another partition in the future, see the STEPS from this GUIDE.
Also You may find useful this GUIDE.

1

Creating a qcow2 disk image file on another partition

This guide was tested on Ubuntu 22.04 LTS, 22.10, 23.04, 23.10.

Automatically linking a directory to a block (automatic partition mounting)

1. Make new directories

$ sudo mkdir /media/username
$ sudo mkdir /media/username/Shared
$ sudo mkdir /media/username/Shared/kvm

Important! Directory name kvm with lower case letters.

2. Run blkid command to display information about available block devices. You will need universally unique identifier (UUID)

$ sudo blkid

The result should look something like:

/dev/sda1: LABEL="Ubuntu" UUID="azazazaz-azaz-azaz-azaz-azazazazazaz" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Ubuntu" PARTUUID="a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1"
/dev/sda2: LABEL="Shared" UUID="abababab-abab-abab-abab-abababababab" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Shared" PARTUUID="a2a2a2a2-a2a2-a2a2-a2a2-a2a2a2a2a2a2"

3. Edit the fstab file.

$ sudo nano /etc/fstab

Add the following two lines with the correct UUID in fstab file:

# Shared
UUID=abababab-abab-abab-abab-abababababab       /media/username/Shared        ext4    defaults        0       2

The end result should look something like:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p3 during installation
UUID=azazazaz-azaz-azaz-azaz-azazazazazaz /               ext4    errors=remount-ro 0       1
# Shared
UUID=abababab-abab-abab-abab-abababababab       /media/username/Shared        ext4    defaults        0       2

4. Run mount -a command

$ sudo mount -a

Possible issues:

  1. The emulator may not have search permissions for the path '/media/username/Shared/kvm/Disk.qcow2'
  2. Error starting domain: Cannot access storage file '/media/username/Shared/kvm/Disk.qcow2' (as uid:10101, gid:101): Permission denied

5. Fix permission issues

$ sudo chown root:root '/media'
$ sudo chmod 775 '/media'

$ sudo chown root:root '/media/username'
$ sudo chmod 775 '/media/username'

$ sudo chown username:username '/media/username/Shared'
$ sudo chmod 775 '/media/username/Shared'

$ sudo chown username:username '/media/username/Shared/kvm'
$ sudo chmod 777 '/media/username/Shared/kvm'

Changing the default storage pool for libvirt

6. List the current pools

$ virsh pool-list

You should get the following text:

Name                 State      Autostart 
-------------------------------------------
default              active     yes 

7. Destroy the default pool.

$ virsh pool-destroy default

You should get the following text: Pool default destroyed

8. Undefine the pool

$ virsh pool-undefine default

You should get the following text: Pool default has been undefined

9. Define a new pool named "default"

$ virsh pool-define-as --name default --type dir --target /media/username/Shared/kvm

You should get the following text: Pool default defined

10. Set the pool to start when the libvirt daemons start

$ virsh pool-autostart default

You should get the following text: Pool default marked as autostarted

11. Start the pool

$ virsh pool-start default

You should get the following text: Pool default started

12. Check the state of the pool

$ virsh pool-list

You should get the following text:

Name                 State      Autostart 
-------------------------------------------
default              active     yes 

Now, when creating virtual machines, Virtual Machine Manager will save qcow2 files to the /media/username/Shared/kvm directory.

Creating a new guest machine or qcow2 file

13. Run virt-manager

$ virt-manager

14. Create a disk image for the virtual machine or create a new machine.

0

In my case it was a mistake - not particulary obvious. I was trying to create storage pool in directory, so dir:Filesystem Directory

There are 2 steps:

  1. You specify type and name, but here name isn't path. Example: test
  2. Next step, Target Path, this will give you suggested path /var/lib/libvirt/images/**test**. Simple **change**/var/lib/libvirt/imagesto whatever you want. Example:/libvirt-images-pool2/(which will result in/libvirt-images-pool2/test```

Note: you might need to fiddle with ownership and permission, but I think libvirt fixes them once you click finish.

Hope it will help somebody.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .