|
|
virsh 在线添加设备cdrom或者iso镜像
( ^3 a1 }4 v' Gvirsh domblklist Windows2019_x86 3 F: V8 `& T" ]
Target Source9 N& K9 |7 w9 E2 y; T; k
----------------------------------------------------------------9 w: E/ a$ i; o) x
vda /usr/src/Windows2019-x86.qcow2
' M7 E6 c0 d5 u' Z sda /usr/src/cn_windows_server_2019_x64_dvd_2d80e042.iso3 S' g% Z) a x( k3 B
q# f% h5 a2 |7 @% a2 B) S
" A. y+ T, F) m0 ^
% {' F+ T1 ~( _7 `
virsh attach-disk Windows2019_x86 --target sdb --type cdrom /usr/src/virtio-win-0.1.225.iso --mode readonly
3 I# I7 K8 W; a2 [ X: p Terror: Failed to attach disk
) J& k3 h* N6 f4 x% X1 }, Oerror: Operation not supported: cdrom/floppy device hotplug isn't supported& t0 d/ T! p' M8 o: r, i& ^7 c
1 w$ O2 p7 {! ~4 W, X1 f, l
$ g. Y* n. x0 s- S/ Y) F( [
! `2 c3 x& q7 T* M8 L" z- ]
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver cdrom --config --persistent . b; ~ h) \- X
error: Failed to attach disk( x; N! u2 A7 `
error: unsupported configuration: unknown driver format value 'cdrom'3 S3 Z: z9 R7 v# j6 ~
& u0 t8 q' J% f$ G9 V% {7 H
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver qcow2 --config --persistent % \9 n2 L3 [: @1 w" B
error: Failed to attach disk# a+ R( B' b8 X: q3 W/ ?/ h
error: internal error: No more available PCI slots
$ u F j. b2 q% o P9 [8 J+ f% a7 f) h9 \. i# A1 I. |
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso vdc --cache none --subdriver qcow2 --config --persistent
# F9 H4 i4 u3 k+ r3 @( N7 U( Q& gerror: Failed to attach disk
# ?* s& h" Z9 o; Merror: internal error: unable to execute QEMU command 'blockdev-add': Image is not in qcow2 format
- C1 W! `/ Y- H) k5 P! Q ]; Q" f4 ?& i' r! }. K" r2 j n
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso vdc --cache none --subdriver raw --config --persistent ; z) i. g5 ~2 l$ `$ }+ `" @
Disk attached successfully
4 T4 T5 d0 e: V, h+ m
5 K1 A s9 p9 y f1 [3 {1 e. {! a
! Q, G5 {7 P1 E7 }4 e# D
root@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
9 ?- h/ k, |0 k1 l e+ i7 w+ x' |2 Q5 X! q/ d( `
Starting install...
7 c: s6 ^1 b( l1 R1 _ERROR Cannot get interface MTU on 'br0': No such device
3 N: I/ X4 \# ~+ h3 C) }) }3 yDomain installation does not appear to have been successful.6 K1 s: `- t$ ^7 F- r5 B
If it was, you can restart your domain by running:
0 m1 ^% l' G2 Q. C5 Z8 H& m1 ~6 q6 i virsh --connect qemu:///system start Windows2019_x86( R' x/ L1 c) |4 ]5 ^% s: j& l' |+ k
otherwise, please restart your installation.
5 R( s, o7 o/ H7 Q" o' @6 t+ {, wroot@compute01:/usr/src#
3 v2 H) ~; h) [( z7 a$ B, ^root@compute01:/usr/src# \6 T0 C- K& k; e0 Z" l* r' `
root@compute01:/usr/src# netplan apply 2 k$ l! V7 N0 m5 s
! h: P9 E& n$ U. [** (generate:8799): WARNING **: 13:35:59.651: `gateway4` has been deprecated, use default routes instead.
0 ^# V Z8 ~+ i+ f. ]5 }See the 'Default routes' section of the documentation for more details.
- M1 N( m0 b; q" n0 |% N$ d6 z1 v- M# Z1 G
** (process:8797): WARNING **: 13:36:01.040: `gateway4` has been deprecated, use default routes instead.$ U. R x' d. @2 D3 V( m; K J
See the 'Default routes' section of the documentation for more details.
9 _& G6 ~/ \, P" h9 Q# j5 O# T2 S" d5 h' w2 u5 m
** (process:8797): WARNING **: 13:36:01.052: `gateway4` has been deprecated, use default routes instead.% ^7 ]$ g+ T" J u( A3 O6 e, X5 i: u
See the 'Default routes' section of the documentation for more details.) ^- j( v* o0 S' c
* C& d# z( z# u9 I) P8 m9 l7 m. I% C** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.
% l3 \/ Z& ~; ?8 u; D1 }See the 'Default routes' section of the documentation for more details.$ X0 d- m4 ~: ^7 z/ b" L
0 R: ~- W1 H4 g7 ]** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.
! i: N( b8 [1 e, }; LSee the 'Default routes' section of the documentation for more details.+ I/ f1 v) M" J2 `- W
root@compute01:/usr/src# ( u, o/ H) ]( |
root@compute01:/usr/src#
8 c/ X7 x% B9 ~$ {/ @root@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
" K3 }0 _5 z2 d/ x% o" k
8 M0 a; Z' [7 t* NStarting install...4 M' J6 [9 q3 S# x4 g/ m4 n& ~+ U
Creating domain... | 0 B 00:00:00
8 v: r- C& t& G( `( B. H* l
8 b0 [& v$ t, a8 KDomain is still running. Installation may be in progress.
; b+ j" b1 c( P" ^, YYou can reconnect to the console to complete the installation process.+ n. U! G, ~" Z7 `( w* z) d
root@compute01:/usr/src# - T# O8 V6 L# k1 }, p
' q9 J( T, A6 F! H
在线添加光盘- b+ r% G. T7 `; ]4 H9 `7 j* K6 }
virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso/ vdd
; t ?1 h; U4 k& t9 a8 J; e X; Y8 A" Y) r9 Y8 R) d3 r5 o
其他方法:; c1 V4 `: M! [0 B
s$ ~2 X, i, ]3 i! B% V; C
: y9 `- t; k7 ]
再次使用 virsh dumpxml sles12-sp3 可以看到iso文件加载:
% P# S, x4 O0 q: s- _* o! b. [, N/ t1 b0 T7 z9 D. W
<disk type='file' device='cdrom'>
, Q' Q2 M7 w1 [# ] <driver name='qemu' type='raw'/>1 j. s& N4 y1 r9 H
<source file='/var/lib/libvirt/images/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso' index='3'/>
& }; N: F% Y5 U6 f: c <backingStore/>
: _& l8 m) t, h, G9 d$ T# ^( b <target dev='sda' bus='sata'/>3 K6 l7 G# x; }. N& }" z
<readonly/>
0 p: y5 K8 h$ H/ c `( ~ <alias name='sata0-0-0'/>( `6 _9 f9 F% z3 ^! }
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
. d& a- y S3 G" ^$ E* ^</disk>3 I. O# d8 L" C- o9 t- ?5 s5 ^9 z& X* d
如果要卸载这个iso文件,则创建一个相同结构的xml文件 detach_iso.xml ,但是保持 <source/> 行删除:6 v& X3 E; Y* h! j. b* D
" d* R+ o) Y6 ~" ]<disk type='file' device='cdrom'>
# K. r- ~7 z3 J1 L9 h/ p <driver name='qemu' type='raw'/>
5 `* ~, I1 h* q q; Z* P, v) i <backingStore/>
% u+ g) f/ v1 ?3 u <target dev='sda' bus='sata'/>% c9 c9 a% M- y$ Q
<readonly/>
4 U% m. u7 {, g, K+ n0 E: ] <alias name='sata0-0-0'/>1 W( C l( O8 `3 X4 X8 W3 z2 i i
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
1 S( o) k: C4 I, M+ @) ]</disk>9 Q0 d/ r/ E. ~7 Z
然后执行设备更新:
/ u# ?1 m- z; J; v- c: ~
, Y1 i% _% z- t/ g" rvirsh update-device sles12-sp3 detach_iso.xml% P9 _6 v2 q; u5 x
此时提示:
! E$ u5 X, b$ o$ C' {
5 z; u9 J. H* Z j: XDevice updated successfully
8 H o* D! ]" B2 t" d2 w( m0 x5 o再检查虚拟机配置,就看到iso文件已经卸载了。
2 w" i3 p$ G( f' N
1 \: U+ A0 S9 }0 f, Y1 r( W/ v |
|