how to change kvm default storage position.

本文介绍如何通过两种方法更改Libvirt虚拟机映像的默认存储位置:使用virt-manager图形界面工具轻松修改默认存储池;或者通过virsh命令行工具编辑XML配置文件来实现。适用于希望调整VM映像存放位置的Linux系统管理员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

copy from this site
兄Die,写代码太累了?孤独寂寞冷?还没有女朋友吧?
关注微信公众号(瓠悠笑软件部落),送知识!送知识!送温暖!送工作!送女朋友!插科打诨哟!
huyouxiao.com
#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.
Connection Details
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.
storage

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.
path of new storage
Type in the path of a new storage pool (e.g., /storage).
add a new storage
At this point, the new storage pool should be started, and automatically used when you create a new VM.
create a new VM
##Method Two: 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 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值