|
|
virsh 在线添加设备cdrom或者iso镜像
# }( X( f5 \: `* Kvirsh domblklist Windows2019_x86 * Q( @7 d k: V& ~/ D$ n. x9 N! F$ {" z
Target Source
% U$ z/ Y' s q, ?----------------------------------------------------------------2 o+ S2 {. c# } o
vda /usr/src/Windows2019-x86.qcow2
( k# I( v- _8 E6 M7 Z- L* z sda /usr/src/cn_windows_server_2019_x64_dvd_2d80e042.iso
$ B3 B& `8 b; F9 R% T7 t Q
- P0 g( \6 y* g. N5 N
1 q8 K v5 P; U3 t7 q0 l4 L( ~0 r
. z9 A% ^6 x! p; ~/ Svirsh attach-disk Windows2019_x86 --target sdb --type cdrom /usr/src/virtio-win-0.1.225.iso --mode readonly % p. _ v w+ D; E# G- U
error: Failed to attach disk5 U/ I. Y4 r5 r
error: Operation not supported: cdrom/floppy device hotplug isn't supported. ?0 I. O( S) l5 X0 a
$ A% X |1 c, [
$ H6 x( E/ c2 z: Y9 U1 @' V" a) |
( d) S* i' w4 P! p. N% J8 H, }2 Vroot@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver cdrom --config --persistent : @, `- `- u: z9 N& z, j( L
error: Failed to attach disk! E0 v+ a$ a$ V7 R! M) P
error: unsupported configuration: unknown driver format value 'cdrom'" B+ H' D3 c7 l; n7 v
& X2 v# ~: N. L# b
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver qcow2 --config --persistent 5 `1 d- s, i& Q8 q+ L' Y
error: Failed to attach disk/ _( }& ~6 B# H3 m: t. K" x, ~
error: internal error: No more available PCI slots
2 B+ O' w/ Z4 O, L2 x9 R" q7 @: f1 k* e8 s: a
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso vdc --cache none --subdriver qcow2 --config --persistent - X7 g/ U3 M/ V* ?3 l3 m( u
error: Failed to attach disk6 R$ W( x' _- o# n" x5 C2 V& p! _: y" M
error: internal error: unable to execute QEMU command 'blockdev-add': Image is not in qcow2 format8 X5 Y8 _6 |' a1 q1 ^( C
8 Z: M% e+ J* w- j0 K3 zroot@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso vdc --cache none --subdriver raw --config --persistent 6 ]% K+ v9 H- I8 Y5 V+ I
Disk attached successfully
$ a. |! G- A& G3 o S& x7 i; C+ I
2 D1 F$ K t* L! T* E
5 T$ o+ j) f3 s' s$ \, a
4 H6 n) [) t& A2 Oroot@compute01:/usr/src# virt-install --name=Windows2019_x86 --ram 8192 --vcpus=4 --disk path=/usr/src/Windows2019-x86.qcow2,format=qcow2,size=15,bus=virtio --accelerate --cdrom /usr/src/cn_windows_server_2019_x64_dvd_2d80e042.iso --vnc --vncport=5906 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole --disk path=/usr/src/virtio-win-0.1.225.iso,device=cdrom$ Q8 V8 y; p! j; H7 Z1 G* V" O4 ~
8 Q; m( a" n3 \+ t1 KStarting install...% \+ F; K4 P: o \. ~
ERROR Cannot get interface MTU on 'br0': No such device7 x+ B/ s. V' B5 l* \
Domain installation does not appear to have been successful., @0 s9 e: \; }; T( }4 w% X
If it was, you can restart your domain by running:/ T$ E6 w( J8 Q/ }: p) Y. Z
virsh --connect qemu:///system start Windows2019_x86+ U2 D8 F& [( M( A
otherwise, please restart your installation.
* u1 O) v; y0 d, J# Zroot@compute01:/usr/src# 0 d5 C6 A9 Z; {+ ^8 W! e3 H* c
root@compute01:/usr/src# % U8 v+ y9 ?; _2 u+ Z8 @0 G
root@compute01:/usr/src# netplan apply ( O6 R' j: R+ B( y5 e6 W
+ F+ j& J d+ H4 d% T0 Q0 @& D** (generate:8799): WARNING **: 13:35:59.651: `gateway4` has been deprecated, use default routes instead./ M( y+ `6 I9 A) ^0 k4 r
See the 'Default routes' section of the documentation for more details./ ]1 i" P* U7 M$ D
8 n: H: a R9 f; H3 p2 R) v
** (process:8797): WARNING **: 13:36:01.040: `gateway4` has been deprecated, use default routes instead.& o5 t( m) y9 C" O
See the 'Default routes' section of the documentation for more details.
, o4 W; d; J6 V' V0 ^# n6 J! q$ T$ R9 c k0 j
** (process:8797): WARNING **: 13:36:01.052: `gateway4` has been deprecated, use default routes instead.1 P) G& n1 K6 s9 |( }! P M$ M
See the 'Default routes' section of the documentation for more details.' h3 b2 r# v: ?/ Z
2 \7 A$ H7 {0 P9 T+ c) Z5 P Y
** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.
4 M- x% Z& m; v" x3 bSee the 'Default routes' section of the documentation for more details.2 X! f! w6 @/ j* U1 ^. h+ R
. P5 ~# A6 u* }& B* U3 D
** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.6 Z7 [1 z9 D7 e# ^
See the 'Default routes' section of the documentation for more details.
# c/ i& S) I$ d1 ^& Kroot@compute01:/usr/src# ; z; f' l- X" |
root@compute01:/usr/src#
9 h# x. {* f( _: {1 Hroot@compute01:/usr/src# virt-install --name=Windows2019_x86 --ram 8192 --vcpus=4 --disk path=/usr/src/Windows2019-x86.qcow2,format=qcow2,size=15,bus=virtio --accelerate --cdrom /usr/src/cn_windows_server_2019_x64_dvd_2d80e042.iso --vnc --vncport=5906 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole --disk path=/usr/src/virtio-win-0.1.225.iso,device=cdrom0 X# W |& ?/ x2 B8 x# {
/ d. A% r* }/ b$ jStarting install...
8 p9 m- v) [4 f/ o- ~+ P% SCreating domain... | 0 B 00:00:00
8 k3 r/ k3 s) {# p" {$ p
$ |4 X k2 M0 i2 ~5 GDomain is still running. Installation may be in progress.5 u" c- n9 q& E, E5 R
You can reconnect to the console to complete the installation process.# @1 ~1 Z! _) F4 M, P# S
root@compute01:/usr/src#
. G- S1 z2 w* G( N7 {" n/ K
7 J: W. H8 ? t8 ~* k0 h在线添加光盘" u' J b, e" |3 y( u4 I6 X
virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso/ vdd
# m, O$ s& G9 U- h
; J( y. B* e7 w& ]" l: K其他方法:
! @8 C- i! T8 e: {9 C, F. b/ \- U5 Q1 w' z
) _# U! }, n" c/ f: }
再次使用 virsh dumpxml sles12-sp3 可以看到iso文件加载: y5 y3 J* l$ W' P" X% y
+ V9 g! e# z; I4 R0 c* N7 \<disk type='file' device='cdrom'>
2 U9 o; m6 V2 u/ u, F <driver name='qemu' type='raw'/>0 w- g' W7 k+ P& ?
<source file='/var/lib/libvirt/images/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso' index='3'/>
! V% l! b& g. ^- u# m# Z/ l# w <backingStore/>
. a2 Y$ `. J% T, c <target dev='sda' bus='sata'/>
1 c& G- Q" @# f8 m4 b <readonly/>
7 n6 x. w: d0 Y } <alias name='sata0-0-0'/>) r; k, i& G% e3 A* t
<address type='drive' controller='0' bus='0' target='0' unit='0'/>: e9 v2 O$ V- [0 H F7 k1 v6 [; z
</disk>
' m' \: J. \; x( Y如果要卸载这个iso文件,则创建一个相同结构的xml文件 detach_iso.xml ,但是保持 <source/> 行删除:- K: t: w* B4 Z# `# ^* t! _$ A
7 C" F' v8 U- ^* f- e8 B! a+ [
<disk type='file' device='cdrom'>7 ?$ o" w- \# y- |5 K M- g+ v9 x
<driver name='qemu' type='raw'/>& S2 |, \4 B2 q2 N* _
<backingStore/>) P5 b' R/ r6 w- Y o
<target dev='sda' bus='sata'/>/ @/ b2 Z- S3 [
<readonly/>
Q9 r0 ^$ t& w7 y <alias name='sata0-0-0'/>: ]3 H8 c% w0 K2 v9 \& Q* Q
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
$ S7 o. y* K) } d& s6 L7 Z, W: o</disk>; k+ O+ q7 I7 ^9 D/ D* Q
然后执行设备更新:0 Z% |& C0 C" c' _0 W
. y# B4 Z+ x. a0 S5 S' fvirsh update-device sles12-sp3 detach_iso.xml
$ H& D" t- L1 y. c此时提示:
$ z' F& _7 h, D! p$ n9 g [7 Q" v! M ^7 j* e
Device updated successfully, Y3 f+ |! P9 C0 w. F) b, I% N
再检查虚拟机配置,就看到iso文件已经卸载了。( P# E- U& X/ E5 R
; r! T# `' w& z, S* \) u/ n1 k- s
|
|