无法启动使用 virt-clone 克隆的域

无法启动使用 virt-clone 克隆的域

底部有最终更新

我有一个已配置的 KVM 域,想将其用作其他来宾的“模板”。因此,我的流程大致如下:

  1. 关闭“源”域(07xQBuild
  2. 跑步virt-clone --original 07xQBuild --name 07x2 --file ./07x2.qcow2
  3. 07x2.qcow2使用挂载新创建的图像guestmount,并编辑网络配置等内容(/etc/netplan/01-config.yaml/etc/hostname等)
  4. 卸载映像并开始virsh start 07x2

但这总是以以下方式结束:

error: Failed to start domain 07x2
error: Cannot open log file: '/usr/local/var/log/libvirt/qemu/07x2-fs0-virtiofsd.log': Device or resource busy

没有07x2-fs0-virtiofsd.log文件,07x2.log文件只包含:

2020-07-28 13:42:29.400+0000: shutting down, reason=failed

我尝试运行LIBVIRT_DEBUG=1 virsh start 07x2,但在 400 多行输出中,我看到的所有错误就是这个:

2020-07-28 13:15:00.954+0000: 40737: info : virObjectNew:250 : OBJECT_NEW: obj=0x56440bb29480 classname=virDomain
2020-07-28 13:15:00.954+0000: 40737: info : virObjectRef:385 : OBJECT_REF: obj=0x56440bb25be0
2020-07-28 13:15:00.954+0000: 40737: debug : virDomainGetID:1721 : dom=0x56440bb29480, (VM: name=07x2, uuid=761c9104-b8de-474a-a5d6-31be46b50562)
2020-07-28 13:15:00.955+0000: 40737: debug : virDomainCreate:6544 : dom=0x56440bb29480, (VM: name=07x2, uuid=761c9104-b8de-474a-a5d6-31be46b50562)
2020-07-28 13:15:00.955+0000: 40737: debug : virNetMessageNew:45 : msg=0x56440bb27df0 tracked=0
2020-07-28 13:15:00.955+0000: 40737: debug : virNetMessageEncodePayload:388 : Encode length as 60
2020-07-28 13:15:00.955+0000: 40737: info : virNetClientSendInternal:2108 : RPC_CLIENT_MSG_TX_QUEUE: client=0x56440bb26f60 len=60 prog=536903814 vers=1 proc=9 type=0 status=0 serial=7
2020-07-28 13:15:00.955+0000: 40737: debug : virNetClientCallNew:2061 : New call 0x56440bb39290: msg=0x56440bb27df0, expectReply=1, nonBlock=0
2020-07-28 13:15:00.955+0000: 40737: debug : virNetClientIO:1879 : Outgoing message prog=536903814 version=1 serial=7 proc=9 type=0 length=60 dispatch=(nil)
2020-07-28 13:15:00.955+0000: 40737: debug : virNetClientIO:1931 : We have the buck head=0x56440bb39290 call=0x56440bb39290
2020-07-28 13:15:00.955+0000: 40737: info : virEventGLibHandleUpdate:196 : EVENT_GLIB_UPDATE_HANDLE: watch=1 events=0
2020-07-28 13:15:00.955+0000: 40737: debug : virEventGLibHandleUpdate:206 : Update handle data=0x56440bb27420 watch=1 fd=4 events=0
2020-07-28 13:15:00.955+0000: 40737: debug : virEventGLibHandleUpdate:227 : Removed old handle watch=15
2020-07-28 13:15:00.955+0000: 40738: debug : virEventRunDefaultImpl:340 : running default event implementation
2020-07-28 13:15:00.955+0000: 40737: info : virEventGLibTimeoutUpdate:381 : EVENT_GLIB_UPDATE_TIMEOUT: timer=2 interval=5000
2020-07-28 13:15:00.955+0000: 40737: debug : virEventGLibTimeoutUpdate:390 : Update timeout data=0x56440bb27dc0 timer=2 interval=5000 ms
2020-07-28 13:15:00.955+0000: 40738: debug : virEventRunDefaultImpl:340 : running default event implementation
2020-07-28 13:15:02.363+0000: 40737: info : virEventGLibTimeoutUpdate:381 : EVENT_GLIB_UPDATE_TIMEOUT: timer=2 interval=3000
2020-07-28 13:15:02.363+0000: 40737: debug : virEventGLibTimeoutUpdate:390 : Update timeout data=0x56440bb27dc0 timer=2 interval=3000 ms
2020-07-28 13:15:02.363+0000: 40737: debug : virNetMessageDecodeLength:160 : Got length, now need 304 total (300 more)
2020-07-28 13:15:02.363+0000: 40737: info : virNetClientCallDispatch:1263 : RPC_CLIENT_MSG_RX: client=0x56440bb26f60 len=304 prog=536903814 vers=1 proc=9 type=1 status=1 serial=7
2020-07-28 13:15:02.363+0000: 40737: debug : virKeepAliveCheckMessage:369 : ka=0x56440bb28bb0, client=0x56440bb26f60, msg=0x56440bb26fc8
2020-07-28 13:15:02.363+0000: 40737: info : virEventGLibTimeoutUpdate:381 : EVENT_GLIB_UPDATE_TIMEOUT: timer=2 interval=5000
2020-07-28 13:15:02.363+0000: 40737: debug : virEventGLibTimeoutUpdate:390 : Update timeout data=0x56440bb27dc0 timer=2 interval=5000 ms
2020-07-28 13:15:02.363+0000: 40737: debug : virNetMessageClear:73 : msg=0x56440bb26fc8 nfds=0
2020-07-28 13:15:02.363+0000: 40738: debug : virEventRunDefaultImpl:340 : running default event implementation
2020-07-28 13:15:02.363+0000: 40737: debug : virNetClientIOEventLoopPassTheBuck:1559 : Giving up the buck 0x56440bb39290
2020-07-28 13:15:02.363+0000: 40737: debug : virNetClientIOEventLoopPassTheBuck:1573 : No thread to pass the buck to
2020-07-28 13:15:02.363+0000: 40737: info : virEventGLibHandleUpdate:196 : EVENT_GLIB_UPDATE_HANDLE: watch=1 events=1
2020-07-28 13:15:02.363+0000: 40737: debug : virEventGLibHandleUpdate:206 : Update handle data=0x56440bb27420 watch=1 fd=4 events=1
2020-07-28 13:15:02.363+0000: 40737: debug : virEventGLibHandleUpdate:222 : Added new handle watch=19
2020-07-28 13:15:02.363+0000: 40737: debug : virNetClientIO:1956 : All done with our call head=(nil) call=0x56440bb39290 rv=0
2020-07-28 13:15:02.363+0000: 40737: debug : virNetMessageFree:86 : msg=0x56440bb27df0 nfds=0 cb=(nil)
2020-07-28 13:15:02.363+0000: 40738: debug : virEventRunDefaultImpl:340 : running default event implementation
2020-07-28 13:15:02.363+0000: 40737: debug : virDomainGetName:1642 : domain=0x56440bb29480
error: Failed to start domain 07x2
2020-07-28 13:15:02.363+0000: 40737: debug : virDomainFree:562 : dom=0x56440bb29480, (VM: name=07x2, uuid=761c9104-b8de-474a-a5d6-31be46b50562)
2020-07-28 13:15:02.364+0000: 40737: info : virObjectUnref:347 : OBJECT_UNREF: obj=0x56440bb29480
2020-07-28 13:15:02.364+0000: 40737: info : virObjectUnref:349 : OBJECT_DISPOSE: obj=0x56440bb29480
2020-07-28 13:15:02.364+0000: 40737: debug : virDomainDispose:323 : release domain 0x56440bb29480 07x2 761c9104-b8de-474a-a5d6-31be46b50562
2020-07-28 13:15:02.364+0000: 40737: info : virObjectUnref:347 : OBJECT_UNREF: obj=0x56440bb25be0
error: Cannot open log file: '/usr/local/var/log/libvirt/qemu/07x2-fs0-virtiofsd.log': Device or resource busy

我尝试转储源域的 XML(可行)和克隆域的 XML(不可行),唯一的 4 个区别是名称、uuid、源文件和 mac 地址:

# diff 07xQBuild.xml 07x2.xml
2,3c2,3
<   <name>07xQBuild</name>
<   <uuid>24ed7962-518e-4151-8635-84cb72a8a9b4</uuid>
---
>   <name>07x2</name>
>   <uuid>761c9104-b8de-474a-a5d6-31be46b50562</uuid>
45c45
<       <source file='/fast_data/kvm/images/07xQBuild.qcow2'/>
---
>       <source file='/fast_data/kvm/images/07x2.qcow2'/>
83c83
<       <mac address='52:54:00:01:7c:fc'/>
---
>       <mac address='52:54:00:c6:4a:e4'/>

克隆域后还需要其他东西吗virt-clone

2020-07-28 17:10 BST 更新

好吧,这看起来很简单——我创建一个名为 07x3 的新客户,一切正常。由于我已经重建并测试了 07x2 几次,所以看起来有些问题。要删除并重新创建域,我一直在这样做:

# virsh destroy 07x2
# virsh undefine 07x2
# rm 07x2.qcow2

这对所有其他域都有效,但 07x2 总是会导致该错误。所以我想新的问题是如何找出在能够重新创建它之前我还需要删除/清除/清除什么?

2020-08-14 11:31 BST 更新

根据@gediz-gÜrsu 的回答,我尝试了这个:

  1. # cp -a /fast_data/kvm/images/07xTemplate.qcow2 /fast_data/kvm/images/07x2.qcow2
  2. # cp -a /usr/local/etc/libvirt/qemu/07xTemplate.xml /usr/local/etc/libvirt/qemu/07x2.xml
  3. 编辑该 xml,替换名称、uuid、磁盘源和 mac 地址
  4. # virsh define /usr/local/etc/libvirt/qemu/07x2.xml
  5. 用于guestmount更新磁盘映像设置(IP 地址等)
  6. # virsh start 07x2

我得到了完全相同的错误,并且没有名为 的日志文件07x2-fs0-virtiofsd.log07x2.log看起来与原始问题完全一样。所以我想我们可以排除virt-clone问题的原因。

然而,运行lsof | grep virtiofsd.log结果如下:

virtlogd   3255                   root   15w      REG              253,1           0    5773534 /usr/local/var/log/libvirt/qemu/07x1-fs0-virtiofsd.log
virtlogd   3255                   root   17w      REG              253,1           0    5773535 /usr/local/var/log/libvirt/qemu/07x1-fs1-virtiofsd.log
virtlogd   3255                   root   19w      REG              253,1           0    5773536 /usr/local/var/log/libvirt/qemu/07x1-fs2-virtiofsd.log
virtlogd   3255                   root   21w      REG              253,1           0    5773537 /usr/local/var/log/libvirt/qemu/07x1-fs3-virtiofsd.log
virtlogd   3255                   root   23w      REG              253,1           0    5773538 /usr/local/var/log/libvirt/qemu/07x1-fs4-virtiofsd.log
virtlogd   3255                   root   27w      REG              253,1           0    5767384 /usr/local/var/log/libvirt/qemu/07x2-fs0-virtiofsd.log (deleted)
virtlogd   3255                   root   29w      REG              253,1           0    5767385 /usr/local/var/log/libvirt/qemu/07x2-fs1-virtiofsd.log (deleted)
virtlogd   3255                   root   31w      REG              253,1           0    5773542 /usr/local/var/log/libvirt/qemu/07x3-fs0-virtiofsd.log
virtlogd   3255                   root   33w      REG              253,1           0    5773543 /usr/local/var/log/libvirt/qemu/07x3-fs1-virtiofsd.log
virtlogd   3255                   root   35w      REG              253,1           0    5773807 /usr/local/var/log/libvirt/qemu/07x3-fs2-virtiofsd.log
virtlogd   3255                   root   37w      REG              253,1           0    5773808 /usr/local/var/log/libvirt/qemu/07x3-fs3-virtiofsd.log
virtlogd   3255                   root   39w      REG              253,1           0    5774205 /usr/local/var/log/libvirt/qemu/07x3-fs4-virtiofsd.log

抱歉,它太宽了——请滚动查看(deleted)我猜测是问题原因的 2 个条目。因此,解决方案似乎很简单service virtlogd restart。我现在可以成功启动该域了!

答案1

如果它不是自动化的并且再次发生,下次不要使用 virt-clone,而是尝试使用virsh editwith cp -ar

将 uuid 名称更改为 mac 以及复制驱动器的新名称。

您还可以使用它virt-manager来添加和删除驱动器并更改名称,与一起使用时非常实用ssh -X or -Y

如果 lsof 没有提供有关此文件的任何信息,则“资源繁忙无法打开文件”可能是权限问题...

lsof |grep virtiofsd.log

相关内容