22

I'm trying to use a different Storage Pool on KVM in order to store the virtual disks of my VMs and also the ISOs from the operating systems which I'm using.

For example: I want to use the directory /media/work/kvm which is mounted over /dev/sda5, as the default Storage Pool for all future situations

To configure, create and start a new storage pool, it is pretty easy, but a least in Ubuntu, it doesn't matter if I'm selecting and ISO from a different storage pool, Virtual Machine Manager always points me to the default Storage Pool (/var/cache/libvirt) as the storage where the virtual disks from my VMs will be created.

How can I avoid this?

ivanleoncz
  • 1,433
  • 4
  • 18
  • 32

4 Answers4

39

Before following the steps, be sure that you are running these commands as normal user and that your user belongs to the group libvirtd (on some systems libvirt).

Here are the following commands which I used:

Listing current pools:

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

Destroying pool:

$ virsh pool-destroy default
Pool default destroyed

Undefine pool:

$ virsh pool-undefine default
Pool default has been undefined

Creating a directory to host the new pool (if it does not exist):

$ sudo mkdir /media/work/kvm

Defining a new pool with name "default":

$ virsh pool-define-as --name default --type dir --target /media/work/kvm
Pool default defined

Set pool to be started when libvirt daemons starts:

$ virsh pool-autostart default
Pool default marked as autostarted

Start pool:

$ virsh pool-start default
Pool default started

Checking pool state:

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

From now, when creating virtual machines, Virtual Machine Manager will inform you that the *.img file (virtual disk of your VM), will be saved at /media/work/kvm.

ivanleoncz
  • 1,433
  • 4
  • 18
  • 32
  • `virsh pool-destroy default` results in `error: Storage pool not found: no storage pool with matching name 'default'` – Vince Jun 25 '21 at 21:40
7

If you just want to change the image path, you can also edit the storage path in the default pool by running:

$ virsh pool-edit default

The above command will open the default pool xml in an editor (vim/nano), now:

  1. edit the path
  2. save the changes and
  3. restart libvirt service
Junaid
  • 201
  • 2
  • 5
  • `virsh pool-edit default` results in `error: Storage pool not found: no storage pool with matching name 'default'` – Vince Jun 25 '21 at 21:40
  • @Vince that means your default storage pool doesn't exist, what version of libvirt are you using? – Junaid Jun 28 '21 at 08:58
  • you can create a default pool as mentioned in @ivanleoncz 's answer: https://serverfault.com/a/840520/398346 – Junaid Jun 28 '21 at 09:00
  • Using `dpkg -l | grep libvirt` shows 6.0.0-0ubuntu8.10. The pools are there, but I can't see them unless I use `sudo`. I haven't run virt-manager with `sudo`. – Vince Jun 28 '21 at 09:25
  • @Vince then that's a permission issue. Google 'virsh without sudo' and you should get some results to fix that. – Junaid Jun 28 '21 at 09:44
  • I followed your advice. Apparently, it's by design. From the [virsh man page](https://libvirt.org/manpages/virsh.html#notes): "Most virsh commands require root privileges to run due to the communications channels used to talk to the hypervisor." So, I don't exactly have an issue. You're supposed to run `virsh` with `sudo`. – Vince Jun 28 '21 at 11:39
3

Aside from the reply above showing how todo it from the command line, you can also change this from virt-manager directly. In the main virt-manager window, go to the menu 'Edit -> Host Details'. In the dialog box that appears, switch to the 'Storage' tab. You can now delete the 'default' storage pool and create a new storage pool to replace it.

DanielB
  • 1,510
  • 6
  • 7
  • I don't know why, Daniel, but I tried this solution before, and unfortunately, it didn't worked here on Virtual Machine Manager (Ubuntu Trusty Tahr - 14.04)... – ivanleoncz Apr 18 '17 at 18:01
  • The Edit menu doesn't have a "Host Details" option. It has a "Preferences" option, but there's no "Storage" tab. Virtual Machine Manager 2.2.1. – Vince Jun 25 '21 at 21:44
  • It is called "Connection details" these days. – DanielB Jun 28 '21 at 09:55
1

From the GUI, there doesn't seem to be a way to do it without an existing VM.

  1. Select a VM
  2. Select "Connection Details" from the Edit menu
  3. Click the Storage tab
  4. Select the default pool
  5. Click the Stop Pool button
    • It looks like a horizontal line inside a broken circle
  6. Click the Delete Pool button
    • It looks like a trash can
  7. Click the pool you want to make your default or add a new pool you want to use as your default
  8. If the pool was in use, you'll have to click the Stop Pool button again
  9. Change the name of the pool to "default"
  10. Click Apply

From the command line, the procedure described by ivanleoncz should work, but you'll need to run the commands with sudo in order for virsh to show any pools.

Update: It's apparently by design that you can't get the list of pools without sudo. According to the virsh man page:

Most virsh commands require root privileges to run due to the communications channels used to talk to the hypervisor.

Vince
  • 133
  • 5