[Translated] Linux FAQs with Answers--How to change default location of libvirt VM images

This commit is contained in:
zhengsihua 2014-10-16 09:11:47 +08:00
parent d90b60c803
commit da421f0351
2 changed files with 90 additions and 92 deletions

View File

@ -1,92 +0,0 @@
Translating----geekpi
Linux FAQs with Answers--How to change default location of libvirt VM images
================================================================================
> **Question**: I am using libvirt and virt-manager to create VMs on my Linux system. I noticed that the VM images are stored in /var/lib/libvirt/images directory. Is there a way to change the default location of VM image directory to something else?
**libvirt** and its GUI front-end **virt-manager** can create and manage VMs using different hypervisors such as KVM and Xen. By default, all the VM images created via **libvirt** go to /var/lib/libvirt/images directory. However, this may not be desirable in some cases. For example, the disk partition where /var/lib/libvirt/images lives may have limited free space. Or you may want to store all VM images in a specific repository for management purposes.
In fact, you can easily change the default location of the libvirt image directory, or what they call a "storage pool."
There are two ways to change the default storage pool.
### Method One: Virt-Manager GUI ###
If you are using virt-manager GUI program, changing the default storage pool is very easy.
Go to "Edit" -> "Connection Details" in **virt-manager** menu GUI.
![](https://farm4.staticflickr.com/3935/15433062592_0d89a8d132_o.png)
You will see the default storage pool as shown below. On the left bottom of the window, click on the cross icon, which will stop the default storage pool. Once the pool is stopped, click on the trash bin icon on the right, which will delete the pool. Note that this action will NOT remove the VM images inside the pool.
Now click on the plus icon on the far left to add a new storage pool.
![](https://farm6.staticflickr.com/5600/15246703330_26884c8258_b.jpg)
Type in the name of a new storage pool (e.g., default), and choose the type of the pool. In this case, choose a "filesystem directory" type since we are simply changing a storage pool directory.
![](https://farm4.staticflickr.com/3928/15433416355_1a2f9f85ab_b.jpg)
Type in the path of a new storage pool (e.g., /storage).
![](https://farm6.staticflickr.com/5599/15433062732_195fa6701b_b.jpg)
At this point, the new storage pool should be started, and automatically used when you create a new VM.
![](https://farm4.staticflickr.com/3934/15430217721_b14c3a93fa_b.jpg)
### Method One: Virsh Command-Line ###
Another method to change the default storage pool directory is to use **virsh** command line utility which comes with **libvirt** package.
First, run the following command to dump XML definition of the default storage pool.
$ virsh pool-dumpxml default > pool.xml
Open this XML file with a text editor, and change <path> element from /var/lib/libvirt/images to a new location.
<pool type='dir'>
<name>default</name>
<uuid>0ec0e393-28a2-e975-feec-0c7356f38d08</uuid>
<capacity unit='bytes'>975762788352</capacity>
<allocation unit='bytes'>530052247552</allocation>
<available unit='bytes'>445710540800</available>
<source>
</source>
<target>
<path>/var/lib/libvirt/images</path>
<permissions>
<mode>0711</mode>
<owner>-1</owner>
<group>-1</group>
</permissions>
</target>
</pool>
Remove the current default pool.
$ virsh pool-destroy default
----------
Pool default destroyed
Now create a new storage pool based on the updated XML file.
$ virsh pool-create pool.xml
----------
Pool default created from pool.xml
At this point, a default pool has been changed to a new location, and is ready for use.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-default-location-libvirt-vm-images.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,90 @@
Linux 有问必答 -- 如何改变libvirt VM镜像的默认位置
================================================================================
> **提问** 我使用libvirt和virt-manager在我的Linux系统上创建虚拟机。我注意到虚拟机镜像位于/var/lib/libvirt/images目录。有没有办法改变虚拟机镜像的默认路径
**libvirt**和它的GUI前端**virt-manager**可以使用不同的虚拟机管理程序创建和管理VM例如LVM和Xen。默认上所有的虚拟机镜像通过**libvirt**创建到/var/lib/libvirt/images目录。然而这有时并不是我们希望的。比如/var/lib/libvirt/images此处的磁盘分区大小有限。或者你想要存储所有的虚拟机镜像到一个特定的用于管理的仓库中。
实际上你可以非常容易地改变libvirt镜像的默认目录或者称之为“存储池”。
有两种方法可以改变默认存储池。
### 方法一: Virt-Manager GUI ###
如果你正在使用virt-manager GUI程序改变默认存储池非常容易。
进入**virt-manager**的菜单GUI “编辑” -> "连接细节"。
![](https://farm4.staticflickr.com/3935/15433062592_0d89a8d132_o.png)
你可以看到如下所是的默认存储池。在窗口的左下角,点击叉形按钮,将会停止默认的存储池。存储池一旦停止后,点击右边的垃圾桶,将会删除存储池。注意这个动作不会删除池中的镜像。
现在点击左边的加号增加一个新的存储池。
![](https://farm6.staticflickr.com/5600/15246703330_26884c8258_b.jpg)
输入新的存储池的名字比如default并且选择存储池的类型。本例中因为我们只是改变存储池目录所以选择“文件系统目录”。
![](https://farm4.staticflickr.com/3928/15433416355_1a2f9f85ab_b.jpg)
输入新的存储池路径(比如,/storage
![](https://farm6.staticflickr.com/5599/15433062732_195fa6701b_b.jpg)
这时,新的存储池应该启动了,并且自动在你创建一个新的虚拟机的时候使用。
![](https://farm4.staticflickr.com/3934/15430217721_b14c3a93fa_b.jpg)
### 方法二: Virsh 命令行 ###
另外一个改变默认存储池目录的方法是使用来自**libvirt**包的**virsh** 命令行工具。
首先运行下面的命令来导出默认存储池的XML定义。
$ virsh pool-dumpxml default > pool.xml
用文本编辑器打开XML文件并且改变<path>节点中的/var/lib/libvirt/images改成新的地址。
<pool type='dir'>
<name>default</name>
<uuid>0ec0e393-28a2-e975-feec-0c7356f38d08</uuid>
<capacity unit='bytes'>975762788352</capacity>
<allocation unit='bytes'>530052247552</allocation>
<available unit='bytes'>445710540800</available>
<source>
</source>
<target>
<path>/var/lib/libvirt/images</path>
<permissions>
<mode>0711</mode>
<owner>-1</owner>
<group>-1</group>
</permissions>
</target>
</pool>
移除现在的默认池。
$ virsh pool-destroy default
----------
Pool default destroyed
现在创建一个基于更新后的XML文件的新存储池。
$ virsh pool-create pool.xml
----------
Pool default created from pool.xml
这时,默认池已经改变到新的地址了,并且可以使用了。
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-default-location-libvirt-vm-images.html
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出