找回密码
 注册
查看: 3874|回复: 3

使用virsh define使用xml文件启动虚拟机

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2019-9-5 09:36:11 | 显示全部楼层 |阅读模式
购买主题 本主题需向作者支付 2 金钱 才能浏览

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-9-5 10:10:11 | 显示全部楼层
<domain type='kvm' id='131'>3 x( l  P% Y1 P' B$ D+ D8 f
  <name>test</name>0 H5 r9 C% e8 ^3 t& Z/ K
  <uuid>0e91050a-8a6e-4db9-ab8e-a5ffe4215132</uuid># U; H- z, Q1 F9 m+ Y
  <description>Timos VM</description>
2 ~: o" C! ~( b) h$ N* n  <memory unit='KiB'>8388608</memory>5 R; v0 r0 h9 d+ `$ r
  <currentMemory unit='KiB'>8388608</currentMemory>8 X) C& A2 b. D+ k9 R" C
  <memoryBacking>0 e# l8 N4 \* q& A* k8 b
    <hugepages/>9 w. t7 Q: A' H$ @0 o1 R
    <nosharepages/>1 n( x8 j; `+ o) I4 a
  </memoryBacking>6 K) b: a1 K- Y3 ?9 i
  <vcpu placement='static'>2</vcpu>) z% X5 d: C0 n! @7 ~' ~
  <cputune>1 o- j% [' D7 |- G
    <vcpupin vcpu='0' cpuset='45'/>
0 Y0 E8 S9 T! X    <vcpupin vcpu='1' cpuset='44'/>( }- d* s3 f6 s& V5 U2 ]
  </cputune>
- ^  Z- h+ a; c2 q$ j6 v7 |  <numatune>
; ?) b2 @, q% o9 Y2 n    <memory mode='preferred' nodeset='0'/>8 `) V- A% Z0 o- D- m; ^, K
  </numatune>9 n* }! d: O+ m
  <resource>  a. V/ Q: x2 W4 H* }7 o
    <partition>/machine</partition>7 n1 Z9 e3 m4 n5 l
  </resource>, f7 a5 ~3 S* o
  <sysinfo type='smbios'>
$ ^( c3 Y! p4 u: Z5 S& W    <bios>
9 }0 G. C' W* w% t, y( P1 x      <entry name='vendor'>KVM</entry>
2 u( [( U6 A" a7 q+ {    </bios>
. g; v6 P- h; i& Z9 x    <system>
9 }8 Q/ [& V, V4 L      <entry name='manufacturer'>alcatel-lucent.com</entry>9 j  B: s3 U- G5 S4 H( r' ~& I5 }" p
      <entry name='product'>TIMOS:slot=A chassis=VSR-I card=cpm-v mda/1=m20-v
9 P& d. T3 O7 m* }1 |7 h        address=192.168.0.12/24@active ; H# z  i9 w. H$ A% w- {
     </entry># J7 w8 m" |$ {  \& g: w1 H
    </system>1 }; s0 Y8 w# H" E- x
  </sysinfo>2 @- [: L  c0 n
  <os>
3 i$ j5 v6 i) k' n    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>$ c" X& @5 t6 F5 ~8 g9 i. w3 n+ }
    <boot dev='hd'/>
" A/ t+ @3 N) x) V0 J. i7 X! M    <smbios mode='sysinfo'/>+ C" T$ n1 Y; |
  </os>1 a; d3 [% T. o, ~
  <cpu mode='host-model'>7 y0 D  }1 F' q: Y
    <model fallback='allow'/>
$ Y. W1 D* U4 s( P! p  </cpu>
4 s6 `' `3 [7 P+ @! ~, W% N  <clock offset='utc'>
3 d2 B1 P/ s4 N( w, l    <timer name='rtc' tickpolicy='delay'/>
3 q# R+ x) z  D; `    <timer name='pit' tickpolicy='delay'/>
" m( q7 D; [8 {3 ]$ `    <timer name='hpet' present='no'/>, y( e- n2 J' R; W
  </clock>! W8 j. i+ }7 B7 e5 u' i3 O1 B
  <on_poweroff>destroy</on_poweroff>6 O3 O" W# E% s5 W
  <on_reboot>restart</on_reboot>3 q, }4 I$ Z) t6 U
  <on_crash>restart</on_crash>
. _! w2 t' L9 V, e  <pm>" w7 q# r; T! K4 P2 I
    <suspend-to-mem enabled='no'/>2 p4 W2 y* x/ Z8 N4 x4 h) x! a
    <suspend-to-disk enabled='no'/>
7 u# s! c: |6 }/ I1 y  </pm>
. X; I; S, D4 k9 r" x' m. ~+ d- A  <devices>0 ~! }% N: q. M4 l& p
    <emulator>/usr/libexec/qemu-kvm</emulator>0 r- T/ {2 g+ D2 r5 j* j- ^8 e
    <disk type='file' device='disk'>
4 X0 w! n  k+ v0 y' a      <driver name='qemu' type='qcow2' cache='none'/>
9 v2 n: l) z# j! C% A* R' i      <source file='/var/lib/libvirt/images/test.qcow2'/>2 S! k2 W$ s8 u/ i
      <backingStore/>
& J6 \& T' S& y& i, g0 W; y. j- k9 X      <target dev='hda' bus='virtio'/>
- ]: |5 P  p+ Z- T  b      <alias name='virtio-disk0'/>3 c, F  ^! j8 d9 j0 J! t0 D
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>! b% C* {! D, a  V: o# t5 _9 C
    </disk>. i, X8 z8 L% S7 b8 J7 m
    <controller type='pci' index='0' model='pci-root'>
! ?4 K! |" D' v, a" E# Y' }- j      <alias name='pci.0'/>6 K, Q5 f$ k$ ^; v( K
    </controller># U5 m! q, D8 B8 ?3 Y- T2 m
    <controller type='usb' index='0'>9 a1 [& \/ Q; _' ?" }" D" e
      <alias name='usb'/>6 N+ H  Z  @% I$ J
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>) n- r/ J. A4 W, i9 u
    </controller>
' `' p  v' L8 W4 S( Y- f5 l    <interface type='bridge'>2 @! p# {1 o. ]3 Z
      <mac address='50:54:00:59:e9:02'/>7 S& W, m" ~! F! ?  {8 r
      <source bridge='br2455'/>
  l0 n  r" T% r4 P0 K# y      <target dev='vnet2'/># ~# i1 T* y! e5 @; y, d% V
      <model type='virtio'/>/ D/ ?/ H' W) k, t0 B# w2 Q
      <alias name='net0'/>
- I; D0 N/ s9 I7 y      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>, }8 m; v$ n& A4 n7 A$ z% _0 M3 ~
    </interface># S# a: l# A: X9 P0 x: u
    <interface type='bridge'>
4 ]( t1 U. U) Z  e5 E9 \      <mac address='50:54:08:68:1f:c0'/>
+ s5 E  V, j. p& g! P1 h/ C- D      <source bridge='br2083'/>
# K0 I$ K( l% X/ q2 f      <target dev='vnet3'/>4 n9 f1 @$ K. Y1 i! z
      <model type='virtio'/>2 B( \* Q# _  T/ @9 D' X: J1 F2 w" U
      <alias name='net1'/>
: Q, I, z6 x1 [4 [0 L8 U/ C      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>. b' ?8 E; k7 F) s; ]
    </interface>
6 _6 A7 X- q$ a9 S7 }$ d    <serial type='pty'>
, j8 K6 g  t) L( \! ~      <source path='/dev/pts/2'/>
* f* h! n) |5 g, ^  b2 K      <target port='0'/>
0 \6 K' t2 u& C+ Q* w0 ]0 _4 t. k      <alias name='serial0'/>6 T( }) F% f6 q) L" w
    </serial>
/ k% s! ?' g8 |7 a1 ~    <console type='pty' tty='/dev/pts/2'>
4 N, V7 J. ]+ {* c( B/ b      <source path='/dev/pts/2'/>: q# K3 v% g3 f: ?3 [* {
      <target type='serial' port='0'/>5 F' y) j/ U  f9 ~: J' r
      <alias name='serial0'/>, T) |2 y/ d: G; ^' L
    </console>
7 Q" E) h! w' d, `. O. I. s6 ~- Y    <input type='mouse' bus='ps2'/>0 P7 G$ e( M, I8 ~& [: T
    <input type='keyboard' bus='ps2'/>" Y: I) n- l6 t" F; a/ y) ~3 V. w
    <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0'>& j. w  q% [/ _& I
      <listen type='address' address='0.0.0.0'/>
$ U6 J6 M) |( _& _$ w    </graphics>" Y6 L/ |& x6 }! q% d+ J
    <video>* Q, w$ [9 _- I. N6 j; w
      <model type='vga' vram='16384' heads='1'/>
. F% r4 X' T, l. t      <alias name='video0'/>; e0 a7 ^, s0 }3 C
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>" f+ Q$ N2 B3 \4 E
    </video>
) {4 r7 u, R& v$ W7 V$ _) V    <memballoon model='virtio'>; k& i' G' L6 w8 K: h! F" g
      <alias name='balloon0'/>- B- Z! W& f- ~( r
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>  h! j  [* f8 P7 S0 P
    </memballoon>8 h* M+ a8 S% c) o' d# k
  </devices>/ P# I1 W! h( `8 L: v$ n
  <seclabel type='none' model='none'/>' i( o# d. B, ]
</domain>

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-9-5 10:33:17 | 显示全部楼层
<domain type='kvm' id='192'>
6 g! ~1 s8 g" d- d  <name>test</name>( L0 J: s+ M8 ^! V! b: }0 I9 W
  <uuid></uuid>$ v$ f* s- |0 _8 i& `) W
  <memory unit='KiB'>25165824</memory>9 \4 H- H# ]# w* j: w; r( p
  <currentMemory unit='KiB'>25165824</currentMemory>
" I4 z% b  J0 R1 j8 R% E' C1 e- G# t  <vcpu placement='static'>6</vcpu>$ v" V; `6 U0 q2 ~; c! y# D
  <resource>& c. F, |, G3 u: [) n1 v6 F
    <partition>/machine</partition>. h& T7 w2 D; o8 g# \! a4 c
  </resource>, f" T% I2 \( [1 E
  <os>
5 l* ?1 }. G, ^# T3 J( }5 b    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>; i' s; f1 a1 {9 h2 A
    <boot dev='hd'/>9 C# v/ o4 s( g/ {" ^3 B+ M1 H4 }
  </os>
2 f5 s& t' F/ T4 r7 {- R+ C) h  <features># h" N8 G1 h* I6 s5 `5 E5 z
    <acpi/>
& }7 R' ]9 A4 F' z  s" \    <apic/>
4 C+ u# x% ^) ^# n* s1 m6 K& k! H- j  </features>* Y2 U  y2 p% }) O1 x4 Z  o' R, _
  <cpu mode='custom' match='exact'>
& F3 L& u$ b& D6 r1 u5 I/ {    <model fallback='allow'>Haswell-noTSX</model>4 i& f& {3 i0 y+ u- ], f( }" u
  </cpu>" O7 M9 r  }* L
  <clock offset='utc'>; r0 y' a  Z' W
    <timer name='rtc' tickpolicy='catchup'/>
) r3 {. z5 q! i) b4 t6 n    <timer name='pit' tickpolicy='delay'/>
8 f' d! a' G: t2 g- M+ U9 {! [    <timer name='hpet' present='no'/>
  P) P  {+ W. O+ S  </clock>
0 l3 L1 _9 L* i% ~  <on_poweroff>destroy</on_poweroff>& t  U- j+ ^6 X; x+ ^
  <on_reboot>restart</on_reboot>. w% d) k0 l9 J" |
  <on_crash>restart</on_crash>
  ^$ K( v/ H: b  s' n  <pm>+ p  k: O& s5 @  }: a3 C
    <suspend-to-mem enabled='no'/>
0 ]$ d6 l/ [" e! L' K; q  W    <suspend-to-disk enabled='no'/>
4 ?' U& N8 i  s  T  </pm>
1 Y+ @& Z: \9 @  <devices>
! ^- ?9 E. M4 ~* Q+ S' W    <emulator>/usr/libexec/qemu-kvm</emulator>+ }, W7 S  B1 I, b) M
    <disk type='file' device='disk'>
/ ~3 Q2 i; w$ x1 z" t      <driver name='qemu' type='qcow2'/>
; \2 j- n: f1 q4 W8 i* f      <source file='/var/lib/libvirt/images/VSD-4.0.10_272.4.qcow2'/>
. J8 _$ A! M2 V/ W      <backingStore/>, g; u( K9 |  \8 u3 G
      <target dev='vda' bus='virtio'/>% h, @( A1 l9 ^; E1 `
      <alias name='virtio-disk0'/>
- \5 y* @* m  }% Y5 ~& H1 ?! Y7 ~      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
# l, {4 E) ]4 U: T. a0 S    </disk>2 v0 [2 L8 K2 F: u1 h, R- @
    <controller type='usb' index='0' model='ich9-ehci1'>
4 |7 L* R) o1 ]# V! c      <alias name='usb'/>
1 N% e7 q  Q( A7 l9 S1 U  I' O# b; W      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>7 E% i. D' S# \) J" }* n" U
    </controller>6 z1 E5 S8 W- [9 I7 F) c; B7 ~
    <controller type='usb' index='0' model='ich9-uhci1'>
  E0 H. `1 J/ C6 W9 i# p. @      <alias name='usb'/>3 J: v# ^2 i) o8 P0 z: C
      <master startport='0'/>
; x" U" z! e4 C* t6 \      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>2 b. U1 h% ^: y. }+ V) O, ]
    </controller>7 P# E$ d( ?# x, I
    <controller type='usb' index='0' model='ich9-uhci2'>
* v1 ~& A- k5 q# R; |( h      <alias name='usb'/>
+ R  @! c6 [6 t5 Z" `4 w; ~! ]" P      <master startport='2'/>
6 a. x) @2 s* X7 d( ]2 f2 Y4 Z! T      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
  i5 k* c9 Y, `" C. \8 `6 ]2 G    </controller>
" N1 B3 e& k9 O1 [% u' R/ ], `    <controller type='usb' index='0' model='ich9-uhci3'>* h. ~1 \! i  k8 E. w5 X% D8 y
      <alias name='usb'/>3 S! n% d8 M5 v0 l' t! b2 W
      <master startport='4'/>: b0 w. j2 Z0 ^4 j3 |, b
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
' {3 Y! |) w) R# E# D* y; \# l    </controller>
/ t- D, u. O; x0 t    <controller type='pci' index='0' model='pci-root'>, J! i0 I- k  y  S/ E
      <alias name='pci.0'/>
8 }1 y' I/ h" S: C; M    </controller>
' I8 C2 ?" q/ r1 `+ `    <controller type='virtio-serial' index='0'>; D6 J# t# n. V8 S. w1 E* \$ r
      <alias name='virtio-serial0'/>
% ~$ w( z! K* [      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>) D$ w6 t" p8 o" q
    </controller>
/ I  e& t( j+ k/ ?( z8 ?9 \' q    <interface type='bridge'>  _8 s9 c2 \, p) B
      <source bridge='br2455'/>) ?2 N1 V9 B, y- Y
      <target dev=''/>
( L. q$ W: b( z6 G) w1 b& u      <model type='virtio'/>
6 L- t/ m% d' O. L      <alias name='net0'/>& v/ ^  `5 K* N8 P- B' z) m0 Y! C
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
: Q2 P& ~) H& H$ W+ ^- B    </interface>, m' l1 N6 W  @6 z
    <serial type='pty'>
" f* J  [$ R# I' }  p! v      <source path='/dev/pts/4'/>/ ^6 l3 J7 ?' e* K
      <target port='0'/>
" a# F; M  H( {  X      <alias name='serial0'/>
: s' C0 ]' {3 }! v    </serial>& @: d) H0 j6 H( I% A5 A
    <console type='pty' tty='/dev/pts/4'>
% a1 N7 Z% W$ N; X0 X      <source path='/dev/pts/4'/>6 d1 J4 D0 G( Z) a1 ^
      <target type='serial' port='0'/>
- O/ W; d; l) u      <alias name='serial0'/>
& G; Y& _  m% Z; D8 {: I; I$ O+ D    </console>
! S6 b) K4 U; o: I; q& f( p    <channel type='unix'># C( S3 F. U# x: R' p1 X7 E0 g; N$ u
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-vsd4/org.qemu.guest_agent.0'/>1 n. a3 b9 K. j  s$ o) J8 N+ e
      <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
8 i4 P1 K/ V1 f. R3 x' M      <alias name='channel0'/>; ~. a9 Q  m3 h$ u
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
7 N& \6 W! Z2 g* d    </channel>% N: L& e/ U" |8 P. ^/ r
    <input type='tablet' bus='usb'>! R& N4 ?0 Q$ V: Y, R1 J6 r
      <alias name='input0'/>
9 a$ M7 B8 b2 n/ I& K' L    </input>; ?0 n; j! J7 e$ D2 L& u' F) t9 k: H
    <input type='mouse' bus='ps2'/>
) k  C2 m( \% ?) X    <input type='keyboard' bus='ps2'/>
1 Q: @  i8 t( {' E8 d9 O    <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0'>6 S% n7 \+ [2 A
      <listen type='address' address='0.0.0.0'/>( [- k  R% R( q) A- r3 l: r
    </graphics>
; ]- Z8 W$ O% L    <video>
& _+ F+ u$ W/ A      <model type='cirrus' vram='16384' heads='1'/>% f/ `! a" x' X- Q5 }7 q% l
      <alias name='video0'/>3 i: F* d# @7 [9 v3 v3 T, }0 p
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
2 w" H( W* K" _; B2 X  L    </video>
1 F' h" l' R) ~+ ?2 b# x    <memballoon model='virtio'>
+ `' K% S2 t, |2 b( Y! @      <alias name='balloon0'/>
/ r: G  D1 S% F4 P      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>5 a1 v6 P) m! |; {; V/ M
    </memballoon>2 n( _& K( B0 e9 G+ x1 F' v" ?
  </devices>
) {$ T9 j: `8 ?( W4 c, [  i</domain>

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-9-5 14:15:51 | 显示全部楼层
kvm使用xml文件创建全过程,注意几点,在楼上的xml文件,5 v& Y* G- S/ g+ S& H
<domain type='kvm' id='1'  <name>centos</name>      //虚拟机名称唯一  7 w- @# ?5 ^$ H9 F; ?
5 r3 z1 l% p/ g, d+ y
8 U$ q3 m2 D- {5 D- U! y: ?
   <memory unit='KiB'>102400</memory>
, g: L5 h& E+ l   <currentMemory unit='KiB'>102400</currentMemory>
; k, z4 J+ t$ M5 _  B<vcpu placement='static'>1</vcpu>6 K3 r4 ^9 i% ~3 q1 o' J$ H
   <os>9 Z+ j& r2 s/ u
     <type arch='x86_64' machine='rhel6.6.0'>hvm</type>  //arch指出系统架构类型,machine 则是机器类型,查看机器类型:qemu-system-x86_64
: I3 _  D5 `3 {0 ~; u5 f     <boot dev='hd'/>         //启动介质,第一次需要装系统可以选择cdrom光盘启动
2 Z. v4 _$ j% l7 u2 l: ]  </os>" g2 t0 L" }  ~- o9 ^+ P
   <features>
! F1 s. |% h' t5 ^) `! c     <acpi/>                 //Advanced Configuration and Power Interface,高级配置与电源接口
8 h/ L# q" f+ Z/ ]% s    <apic/>                 //Advanced Programmable Interrupt Controller,高级可编程中断控制器% G2 _% t% V6 I& M9 A# e& o
    <pae/>                 //Physical Address Extension,物理地址扩展
0 J- Q6 o3 I* K  </features>
& [: j/ G$ r' L  i& H' y2 U9 ~! |8 T   <clock offset='utc'/>      //虚拟机时钟设置,这里表示本地本机时间, ^! ?- i  S% F, e
  <on_poweroff>destroy</on_poweroff>       //突发事件动作
+ j# p& h( G" o" u0 ~3 p, F- e) j7 r4 k* Y2 b. G. f5 k
  <on_reboot>restart</on_reboot>' H) {2 }0 F! R4 I

6 |3 c, ^. g7 c. k7 v& u/ M" m' e   <on_crash>restart</on_crash>
7 r+ ?  Y; u0 S. m( l" z$ }5 X   <devices>
1 l3 l" _, p& s; c     <emulator>/usr/libexec/qemu-kvm</emulator>       //kvm 默认
, L$ A( F& f" a$ p/ _1 w9 n    <disk type='file' device='disk'>
; R) F( r# r) W; `       <driver name='qemu' type='qcow2' cache='none'/>    //镜像类型
/ L2 t0 H  R* |8 }      <source file='/var/lib/libvirt/images/cirros-0.3.3-x86_64-disk.img'/>    //镜像位置7 \. [* n0 ?' q, s* ~+ d  |
      <target dev='hda' bus='ide'/>        
4 c" @8 J: ~* c: U     </disk>
9 C" e8 {0 l: f     <interface type='bridge'>    //虚拟机网卡类型1 Z! ^& \) h0 G& L' Y. s# ~2 l
      <source bridge='br0'/>   
9 n$ {9 I% p  H8 J; K# n7 l; i* G0 M       <target dev='vnet0'/>      //宿主机设备名称, X( X5 S! H# n1 H* L3 l
    </interface>
( `0 f; T2 o* V; r/ k     <console type='pty' tty='/dev/pts/2'>   //控制台登录设置' O  ]6 o: ?5 T5 A7 N/ j# w
      <source path='/dev/pts/2'/>3 f# I, l1 E- w4 T+ R2 C5 ?
       <target type='serial' port='0'/>
0 b4 \& G5 n8 L& n; [1 w     </console>
6 n4 y7 G0 o( q$ I% |' D+ f! c     <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>   //配置VNC 设置
6 e7 V( J% ?  _9 K( F9 p0 C      <listen type='address' address='0.0.0.0'/>
  X$ F2 Q1 G& l& p2 r* K" T     </graphics>( g* Q- @! ]/ M* v& @1 `1 Y
   </devices>
6 M4 _1 b) h/ f* S2 X4 M </domain>
0 i  W- \! N  @% t% r
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 04:53 , Processed in 0.048807 second(s), 24 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表