|
|
virsh 在线添加设备cdrom或者iso镜像
) a5 D9 q+ X- u) Pvirsh domblklist Windows2019_x86
1 r, l& h! H4 g# q) A6 P/ G Target Source
1 w8 P/ R" v- }----------------------------------------------------------------
$ ]( g1 n& F' L/ ^5 O, M vda /usr/src/Windows2019-x86.qcow2. [# X a! T+ v, b
sda /usr/src/cn_windows_server_2019_x64_dvd_2d80e042.iso& s$ r& ~8 Q' Y5 J+ {
6 S% c' r* l `8 m# E
; v, h9 d: K) w: m8 t' {
1 W1 S O& p+ `& L- h% Qvirsh attach-disk Windows2019_x86 --target sdb --type cdrom /usr/src/virtio-win-0.1.225.iso --mode readonly : ~2 I* P+ H. l
error: Failed to attach disk
/ H t% {6 _" Uerror: Operation not supported: cdrom/floppy device hotplug isn't supported
3 d$ V/ i4 a: _# Q+ p3 N* i" I, ? b6 R$ q
1 \/ J3 O9 J3 V% G! v/ I! o4 K, w! `3 r! c6 t+ c7 X# n
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver cdrom --config --persistent 6 t$ H$ b. s/ g& z; F
error: Failed to attach disk
4 U& L" r8 Y! y) eerror: unsupported configuration: unknown driver format value 'cdrom'
8 \0 E; u; e+ `% `! w* n. R
$ E6 M, s- w3 o# Uroot@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso sdb --cache none --subdriver qcow2 --config --persistent ' ~0 p" \; l' q1 n
error: Failed to attach disk
' i* U% z2 V8 s6 F$ Derror: internal error: No more available PCI slots6 p5 \& f( |. f' j# H, b: Z3 C
5 J3 ?: G3 R, X; i) r8 {; S) 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 % {' f/ m1 S) ? i
error: Failed to attach disk0 x* R; f: r p# p: U5 L5 D1 I
error: internal error: unable to execute QEMU command 'blockdev-add': Image is not in qcow2 format
9 o/ N1 l4 q1 a7 Y" Y: K! e+ J9 X3 ?; l2 b# S7 v- ~( L' W* F$ R$ n/ e, g
root@compute01:/usr/src# virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso vdc --cache none --subdriver raw --config --persistent
, L7 I- _6 G1 DDisk attached successfully
: y. b/ M# M! s. `$ b: d9 r5 L6 s/ V
4 @3 E& z+ @6 f* j1 x+ O
E, Q- G8 o( o9 p! E, J& P
+ w3 V( f+ J8 j8 v/ d# I+ iroot@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
3 _3 f; O& J- V+ K6 f% f f8 t+ u
) u* D/ Q+ G9 k% C J) KStarting install...
8 v2 c/ P/ C8 P# X) cERROR Cannot get interface MTU on 'br0': No such device
+ I' Q% r q2 z; b( a% k: j7 NDomain installation does not appear to have been successful.6 C3 W! a+ H7 G
If it was, you can restart your domain by running:
& R; N; K- i3 ]& f virsh --connect qemu:///system start Windows2019_x86# n- [0 G# J9 b$ O6 g7 L
otherwise, please restart your installation.' v( {$ ]9 w# [- O% Y; z
root@compute01:/usr/src#
, N: M& E* Q) ~# X/ lroot@compute01:/usr/src#
& P- I! u9 {( n- Nroot@compute01:/usr/src# netplan apply
+ N% K3 {( `4 u4 O) K# k' q2 y' `' \8 S# {6 \0 v, \
** (generate:8799): WARNING **: 13:35:59.651: `gateway4` has been deprecated, use default routes instead." l, C( _% c- u0 K1 U' r* M
See the 'Default routes' section of the documentation for more details.
9 _, d7 E) `4 |7 ~
) I) G6 ^9 D1 ?) d8 k" C** (process:8797): WARNING **: 13:36:01.040: `gateway4` has been deprecated, use default routes instead.- u4 \ S# O" t+ P `
See the 'Default routes' section of the documentation for more details.6 M* e. P; y3 N! X
5 x" l" d4 ~1 M! K- O** (process:8797): WARNING **: 13:36:01.052: `gateway4` has been deprecated, use default routes instead.
$ l/ o1 L. m6 I3 HSee the 'Default routes' section of the documentation for more details.% f) {- Q0 o, q+ k* B8 u& u6 b
1 ^ Q ^8 ^/ Q0 C8 ^4 W- U** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.7 K: p2 P D$ N/ `& y
See the 'Default routes' section of the documentation for more details.( j7 |+ t" T$ Q! n
$ L% J* |" V1 S% Z0 p6 L2 X& X
** (process:8797): WARNING **: 13:36:01.589: `gateway4` has been deprecated, use default routes instead.1 o% q: j+ W0 Q
See the 'Default routes' section of the documentation for more details.
8 U3 F# U, G! s( \root@compute01:/usr/src#
% c& w7 W3 }" W( P1 ^ Droot@compute01:/usr/src#
) R! Y& {5 Y4 w% l/ h+ g/ sroot@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 {; W! c3 k0 `5 W+ B: ?4 R
2 E5 S. P; k V+ ZStarting install...- `+ r8 K+ r" y; T; L
Creating domain... | 0 B 00:00:00 % _* Q1 F/ K/ D; [$ I
# j- s' O* ~5 ^+ D% s6 V- XDomain is still running. Installation may be in progress.' b6 f; l" e0 U Q# C; _/ h- T
You can reconnect to the console to complete the installation process.
% a3 C9 I( v& w j& qroot@compute01:/usr/src#
9 [$ o! W$ |8 c$ }& Z. U; B/ t' T
在线添加光盘+ C7 s8 o7 D) L2 s
virsh attach-disk Windows2019_x86 /usr/src/virtio-win-0.1.225.iso/ vdd
4 K! Q) I, E4 g8 M! R
& C8 \; i/ d1 L9 v% {. j其他方法:# N) p+ w2 U, }" g8 c1 O- v! \
* u/ j' n( z o
$ L( f6 J' K& A: m
再次使用 virsh dumpxml sles12-sp3 可以看到iso文件加载:, X$ f1 i1 H/ X% H, n
' H; y- q r) A
<disk type='file' device='cdrom'>
" I0 y' P5 j: N) `6 h <driver name='qemu' type='raw'/>
3 y: X7 o6 _- k5 N; W <source file='/var/lib/libvirt/images/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso' index='3'/>- O- x$ Q7 }) @3 I( U' y
<backingStore/>! I. v6 Y9 T0 m" [9 z" A% I
<target dev='sda' bus='sata'/>0 n5 X$ l* g2 N3 \$ j% o
<readonly/>
8 Z; {; R6 Q+ l8 c% Q <alias name='sata0-0-0'/>- p* `& f4 ^3 j
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ C D- R5 U- E6 U</disk>
. j5 `/ v7 M9 W+ t! D' W# K如果要卸载这个iso文件,则创建一个相同结构的xml文件 detach_iso.xml ,但是保持 <source/> 行删除:2 S7 ]& @' q3 \) L
" P( P1 C+ F" C& M3 f1 u7 C* `- G<disk type='file' device='cdrom'>) q/ }2 V! }, r% ? b. A2 j& q
<driver name='qemu' type='raw'/>/ [& X' `0 H) j( g" z. l6 O+ w. E! ]8 C, a
<backingStore/>
1 @2 e" g! _ g+ c0 J) T <target dev='sda' bus='sata'/>: V3 t; G' u# i$ a" d( d
<readonly/>
! @% T6 y' [7 t( I <alias name='sata0-0-0'/>( i& J U$ _/ ]
<address type='drive' controller='0' bus='0' target='0' unit='0'/>- F" A, V2 j% Y/ p8 \
</disk>
; O6 q7 z1 G+ K5 O/ \9 T然后执行设备更新:) l6 I9 D; j5 d* S9 [
. v# ]- z+ l9 V5 d7 j
virsh update-device sles12-sp3 detach_iso.xml
* p, }# M4 v6 ~3 n' b+ Y此时提示:' G* w Z( b" T7 X( Q* z. o
) O6 x7 L/ \# H w5 P" s0 }8 v
Device updated successfully
, L/ q1 f) O! Y" ^& J& V% y: f ?$ U: N0 ^再检查虚拟机配置,就看到iso文件已经卸载了。! w4 v0 E7 \7 v3 b, R' R
+ T7 P- S0 \6 Q% E! g6 ] |
|