找回密码
 注册
查看: 3873|回复: 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'>
. ?- Y. B4 J) B  <name>test</name>
& O. g" y- ]) S* j. H  <uuid>0e91050a-8a6e-4db9-ab8e-a5ffe4215132</uuid>
( {- z  t) F. n) _( H4 y: P  <description>Timos VM</description>
. N  k/ [% q( O- `1 L2 c  <memory unit='KiB'>8388608</memory>
1 n) q7 l$ T0 [  <currentMemory unit='KiB'>8388608</currentMemory>
0 I, V: f. q5 S1 g3 X  <memoryBacking>
1 l2 K3 s4 j9 G- y6 E+ J    <hugepages/>$ Z( a& s( M, K
    <nosharepages/>
9 T- g# f/ X! N4 ^4 I; F  </memoryBacking>
7 c9 t8 s) m# w' I  <vcpu placement='static'>2</vcpu>
# g) _* Y- W, A8 C9 ^/ X  <cputune>
8 i& t7 q2 g7 P& o: V) O    <vcpupin vcpu='0' cpuset='45'/>
4 G3 _- v2 V1 }# C    <vcpupin vcpu='1' cpuset='44'/>1 U2 e2 n9 H) S
  </cputune>
/ U* u& z6 j' u  <numatune>- i9 Q  {- Q7 r- u6 z' {
    <memory mode='preferred' nodeset='0'/>1 R4 O4 F! W3 j/ f
  </numatune>
" i/ V! V0 T* l6 D  <resource>
! _8 g, o5 d" D) O    <partition>/machine</partition>
; X# U4 G: F+ B) G/ o( A) o  </resource>
9 R1 q: [7 m; T$ p7 t  <sysinfo type='smbios'>: V3 _5 @0 j" L* d4 y4 ]! q$ b! ]
    <bios>3 x4 Z7 T; M+ \! ^+ h3 ?. b; a( S
      <entry name='vendor'>KVM</entry>$ j& y9 {8 A& C2 g5 u
    </bios>
* Y5 ]# }, p2 Y7 S% a    <system>9 t+ _) _( S+ T6 P( y5 v9 B
      <entry name='manufacturer'>alcatel-lucent.com</entry>
2 w$ @  G3 b3 i3 }+ H  R      <entry name='product'>TIMOS:slot=A chassis=VSR-I card=cpm-v mda/1=m20-v- E+ G2 a% M0 y# i
        address=192.168.0.12/24@active % v- Q# s- ^4 j, @
     </entry>; \9 @- j/ L/ ?( Y9 _/ N! e
    </system>
4 S$ T2 U) S, k# L/ c, _- r  </sysinfo>% G+ O6 }; J( Y
  <os>
4 K: i3 ~1 y# a  k" A    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
6 V: j9 S5 ]: Q  e/ B- I- d# G$ W0 P    <boot dev='hd'/>. ^8 i' z) {- [) F. b. \: B) r& x
    <smbios mode='sysinfo'/>
3 Y7 X( C9 Z7 c. J4 S" {  </os>" o; \; u8 ^9 f! g8 P: ~
  <cpu mode='host-model'>
3 o+ V7 T; j1 D. q) V; P    <model fallback='allow'/>
4 O; c# L$ z6 ]( D# t' L* \8 Z2 k  </cpu>
  }" T" f9 ?" {% y7 K  <clock offset='utc'>: b- _1 S7 t5 V
    <timer name='rtc' tickpolicy='delay'/>
/ d. K0 j3 {; C' E! Z8 c) o    <timer name='pit' tickpolicy='delay'/>* ~/ n9 u0 C+ ?! J! Q# p# p
    <timer name='hpet' present='no'/>
& X1 p/ C+ o' S* k  </clock>, V% B0 Z( l0 _, ]  H0 j
  <on_poweroff>destroy</on_poweroff>- T, Y+ o% T$ ~0 L9 M
  <on_reboot>restart</on_reboot>' W% K$ G6 m- @  ^
  <on_crash>restart</on_crash>
3 \# O: p/ R% P* x" ~0 |  <pm>- u2 a  U7 s, i3 o
    <suspend-to-mem enabled='no'/>$ I0 k: Q& r, B
    <suspend-to-disk enabled='no'/>8 C% J5 _: x0 w
  </pm>
$ Y) x4 P+ M. F5 N2 N  <devices>
+ p) l5 Q1 O7 T" k4 v" E2 \    <emulator>/usr/libexec/qemu-kvm</emulator>
& ^) [, H7 q& d, m    <disk type='file' device='disk'>4 K  z- Z# k* i
      <driver name='qemu' type='qcow2' cache='none'/>. r- u& y# l; @' T
      <source file='/var/lib/libvirt/images/test.qcow2'/>" ~: y# B2 g( V. y4 }
      <backingStore/>+ [3 e& Z- X; {: c/ v  {
      <target dev='hda' bus='virtio'/>. g# e2 k( E( W6 L+ ^, x
      <alias name='virtio-disk0'/>' f9 O( G9 ]2 B: i: v
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
# V9 x1 }* Q3 P" g; _    </disk>
% O. b6 I9 ^2 ~! E8 I4 D, J    <controller type='pci' index='0' model='pci-root'>
' O. |. i8 H: J* r  Z; t2 ~: }7 s# z      <alias name='pci.0'/>0 P( k$ r# \! G
    </controller>8 J+ @8 I: w: {- {: S  Y  @+ ]1 v
    <controller type='usb' index='0'>" ?/ s' Y( B+ t
      <alias name='usb'/>4 G: ~+ _5 q% \  J, a" h# m$ Y/ I
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ S  o  z# Y5 U( r9 V& ^    </controller>- X1 O' V- V' F% {# B- g1 u
    <interface type='bridge'>
% T2 I9 p# H1 r- A* U7 P# O5 X      <mac address='50:54:00:59:e9:02'/>
; p2 H4 {9 H! e  X  Q; [: I* j9 |& s      <source bridge='br2455'/>+ X( L/ c5 Q4 H& F
      <target dev='vnet2'/>. Y6 v  ~& _# Z' f* \
      <model type='virtio'/>  |' F: Z9 L1 a: {' ]/ I# @
      <alias name='net0'/># r/ z* G+ ?  e& p, l# |, s
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>% T8 l) Z# m7 [' \- O
    </interface>; P2 M3 H9 t9 l, T$ n
    <interface type='bridge'>0 z1 T/ D5 D& S3 k- G1 W
      <mac address='50:54:08:68:1f:c0'/>
5 x- k% k* F; W6 j& s; x6 C      <source bridge='br2083'/>
( K  H6 C: L0 V$ g: V6 l      <target dev='vnet3'/>
6 I2 x) k! ^) l1 D. ]      <model type='virtio'/>
+ t+ j/ u- Z8 \      <alias name='net1'/>
; D0 `4 S! }6 b% g( R- |" `! o) K      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>$ f& [& _; d6 p0 T+ M
    </interface>9 {; l' @' V0 z& C, N: H% m2 U
    <serial type='pty'>
4 T' {4 z2 `. l3 V$ ~      <source path='/dev/pts/2'/># }% T3 z& J% c8 l. y) `
      <target port='0'/>- F7 D) K! c6 e. u5 Y8 w; f' ]
      <alias name='serial0'/>
7 M9 l- f; q, h1 s' k    </serial>" r/ V# X' ]) a( Y+ ^8 b3 ]
    <console type='pty' tty='/dev/pts/2'>: q! u. d9 r# g+ G' q
      <source path='/dev/pts/2'/>' D& [) j7 c2 M2 h4 e
      <target type='serial' port='0'/>
$ x( ?" ~$ e7 ?4 @: [- A: M      <alias name='serial0'/>
  s! |# ~& w& Q$ F- U* h- @' f    </console>, q6 K. F. z' p5 n, U2 G- H
    <input type='mouse' bus='ps2'/>
! B* r) b% ]1 j( J9 O+ b) @    <input type='keyboard' bus='ps2'/>
1 H& o5 Q  D5 L' L7 h! P0 R0 S    <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0'>5 L. G2 e# u0 |, z- E. w
      <listen type='address' address='0.0.0.0'/>. w& @$ h! W4 U2 F% H) Z
    </graphics>. |: ^# I! s, i7 E: c& |
    <video>
- I+ h1 ~& M6 L      <model type='vga' vram='16384' heads='1'/>
5 N2 T& G! |8 j6 s      <alias name='video0'/>; u' o$ b2 N; P
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
/ b- }- r/ ?* W/ h. g2 y" B8 L& A    </video>
  }" M! \+ ?& J# \    <memballoon model='virtio'>
" [' H* _9 a1 Q      <alias name='balloon0'/>
/ y: J+ ^" B7 K      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>1 Q, p& [/ J0 _2 J
    </memballoon>
% Y! N4 `. J3 k0 \( h" \( J  </devices>! q3 v+ k$ v7 b" W( L" Y
  <seclabel type='none' model='none'/>
! R, w* T5 a1 s+ G+ j" Z</domain>

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-9-5 10:33:17 | 显示全部楼层
<domain type='kvm' id='192'>$ p8 F6 d5 u. O& V: |8 b* R" B
  <name>test</name>3 \  g& c' K% ?1 o0 x7 H
  <uuid></uuid>
3 U8 I+ X9 A8 p; Y/ F  <memory unit='KiB'>25165824</memory>
# ]- ?5 ?( B+ A9 k+ o) O  <currentMemory unit='KiB'>25165824</currentMemory>9 J3 U) }  J" ^
  <vcpu placement='static'>6</vcpu>
+ G) Y0 F3 I+ p+ g' k2 h  <resource>$ |3 \! B4 `) {. F- Z* U& w
    <partition>/machine</partition>6 P1 j2 H, V: e4 W; b
  </resource>
1 H6 O9 L) k# ~- Z2 `  <os>- |$ M" M4 P3 j4 H1 L& A' u
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
+ P. h0 `+ x# H: j1 B    <boot dev='hd'/>
9 M. f/ S% C  b* _; o  </os>
0 K2 s" g% F, [# C3 ~  <features>: Z; H( H8 n' V4 H' X
    <acpi/>
7 _, O- i  N# B    <apic/>
5 E- X  Y7 u1 p7 C; ?: ?$ b( c  </features>+ ]  u) t& F5 V+ z3 r7 ^: m, U
  <cpu mode='custom' match='exact'>
6 `1 v& |6 r* C8 Z  q' A1 r8 V4 S' w    <model fallback='allow'>Haswell-noTSX</model>
) H/ _) g7 _& S2 C! k/ s/ T  </cpu>2 M+ O2 R, r5 o* e4 |1 @# \: R# R
  <clock offset='utc'>2 f# x. Y4 e+ `; X
    <timer name='rtc' tickpolicy='catchup'/># h; [" u# _) f$ |' X$ q
    <timer name='pit' tickpolicy='delay'/>: K$ ?8 p4 H) D
    <timer name='hpet' present='no'/>
# @) C) M! r9 \$ K  </clock>
0 W0 R( r2 B; E* ?" t  <on_poweroff>destroy</on_poweroff>4 X0 X- w% {8 c: s
  <on_reboot>restart</on_reboot>
1 D3 A# w6 V0 S+ X2 f( c  <on_crash>restart</on_crash>
$ v2 p) l6 Y5 ]: _  <pm>
7 a1 v+ Y1 w1 L. m* T    <suspend-to-mem enabled='no'/>
- O8 b! b/ X. K# u2 x    <suspend-to-disk enabled='no'/>
- r9 M8 f9 @% X& C  </pm>
# n. N. _9 P3 _2 B! c  <devices>. t! P/ a  [; C7 S% E  {3 Y
    <emulator>/usr/libexec/qemu-kvm</emulator>$ g) @: D* {  F) d, G) y
    <disk type='file' device='disk'>
5 \7 i; l( B+ Z, ^      <driver name='qemu' type='qcow2'/>) ]* ]) k6 S3 \% u% J- A6 C
      <source file='/var/lib/libvirt/images/VSD-4.0.10_272.4.qcow2'/>+ t% y# @9 b6 o/ G4 V  |7 L/ b
      <backingStore/>
4 h) u" L5 p$ {- t  o0 o      <target dev='vda' bus='virtio'/>
" @* E8 c  E% m- F! \+ Q      <alias name='virtio-disk0'/>. H, C* q" M& v$ L* S: W5 F& l0 D: E
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
$ g4 b: c, k, p7 a$ w    </disk># o8 [. X5 Z0 n! S
    <controller type='usb' index='0' model='ich9-ehci1'>1 ]/ q7 W% V. B5 M3 }& F
      <alias name='usb'/>
3 O1 W! M( {& N' k+ F      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
- p+ R/ D0 D$ D6 `+ ~    </controller>, q8 h- A4 X# [" g0 N$ J
    <controller type='usb' index='0' model='ich9-uhci1'>
  F  l+ v9 x# `1 l- \" U( k      <alias name='usb'/>' i6 G: K  d5 x' e% s$ x. E, W$ o
      <master startport='0'/>
5 m& s+ M) n/ v/ ~" k3 c      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>2 L& A+ q2 M! a0 d# a( J
    </controller>* l& f/ R& \5 ?1 j5 T7 b% A8 Q
    <controller type='usb' index='0' model='ich9-uhci2'>
7 r0 n# @9 j3 x9 y" s! F' K2 ^      <alias name='usb'/>+ E( e: a3 }) O& }( D0 A
      <master startport='2'/>; x. B9 T9 e* ^- G
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
4 J; H% L7 {" ?% i: Z. S7 |    </controller>
# K* B2 a6 M/ _' p* w! M    <controller type='usb' index='0' model='ich9-uhci3'>
  x- e) Y( n/ a  T      <alias name='usb'/>% [. ~% e" Z6 D
      <master startport='4'/>; ^; \0 n* H7 E9 d1 s
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>  i1 w/ B, D' N! k
    </controller>& N2 O; ~/ d5 c
    <controller type='pci' index='0' model='pci-root'>$ P2 v* g* {9 `4 H5 X
      <alias name='pci.0'/>% {, N% w( n/ {- g
    </controller>1 ^. P6 Q0 f. J# X  ~
    <controller type='virtio-serial' index='0'>
2 n( d1 l9 ]& }4 b/ ?- Q& N  I      <alias name='virtio-serial0'/>5 [1 L* S. n0 @. c' d0 m* {; ?
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>1 h  b+ l6 G2 k1 l+ w+ z
    </controller>3 L0 c5 X) p- N3 v
    <interface type='bridge'>: R7 m- N) D6 [( X
      <source bridge='br2455'/>
# M3 a# u! x4 _      <target dev=''/>
8 h% K) F# l* F9 ~* e, }      <model type='virtio'/>' L# Y7 W$ v( X0 U/ F
      <alias name='net0'/>0 }+ X( T; H" O3 q
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
: u3 t9 s1 C+ k  ?    </interface>
  \% M9 g/ I% K! J4 m5 P    <serial type='pty'>: H) v, D! @( r
      <source path='/dev/pts/4'/>
' P8 ]* S- r8 N6 A* Z      <target port='0'/>8 K* }; q/ M* `" y' s
      <alias name='serial0'/>: H0 ]1 x& H' m! m$ p
    </serial>
  |3 J" B9 w4 m! y5 f6 l8 {    <console type='pty' tty='/dev/pts/4'>
8 r! }  J* E& I6 W      <source path='/dev/pts/4'/>9 O& n' s8 H% ~% q% p
      <target type='serial' port='0'/>+ Q, f: \: C( k3 f( n2 n; y
      <alias name='serial0'/>
5 V( Y' A. c, p2 j3 d    </console>! ^3 G% ^  R+ S2 c+ @4 Z+ E
    <channel type='unix'>
+ d3 ^: C9 r- D      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-vsd4/org.qemu.guest_agent.0'/>4 _( r9 t, e, ^. ^) Z
      <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/># t; W$ F" A: L1 H: ^1 b
      <alias name='channel0'/>
# q* w0 J6 l# n      <address type='virtio-serial' controller='0' bus='0' port='1'/>* j3 Z0 L* A4 d# }: H3 T3 E$ F
    </channel>
+ d3 F0 M( h2 j5 @- D% |    <input type='tablet' bus='usb'>: N4 U6 h5 N% ^* E
      <alias name='input0'/>
# }4 y# l" p9 z' K6 ], f" v    </input>
7 T! j+ q( z9 |+ x+ p0 p3 n! m    <input type='mouse' bus='ps2'/>2 U5 Z* H! @2 ?1 M4 y9 H8 J3 T
    <input type='keyboard' bus='ps2'/>
0 S9 F1 s# |) v) i$ G    <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0'>
0 v; @+ H- O  W* H      <listen type='address' address='0.0.0.0'/>
1 Z2 L4 ]8 g! K+ {% O# k    </graphics>
/ ~/ ~$ b5 F/ D    <video>
! F. o5 E  X, L7 F# o      <model type='cirrus' vram='16384' heads='1'/>8 t/ y6 M  Y' l# n8 [- F
      <alias name='video0'/>; z( |9 g5 \% C$ P) B6 |
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>( Q/ K5 F1 P# \) i/ Z( L: @9 D
    </video>9 V3 R: o2 P3 A
    <memballoon model='virtio'>
" l/ Q. a6 F  B      <alias name='balloon0'/>
2 ?$ |! n" ~0 Z+ A2 C1 f& V. S      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>* i; U. q% ^7 D
    </memballoon>" C: j( A; }9 o3 C$ L/ \
  </devices>2 q; [! y2 _4 h, U. U
</domain>

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2019-9-5 14:15:51 | 显示全部楼层
kvm使用xml文件创建全过程,注意几点,在楼上的xml文件,4 R, ^! i- r2 D& [: X, A
<domain type='kvm' id='1'  <name>centos</name>      //虚拟机名称唯一  
, E  P) H* U/ ]
9 {  y- z' k1 M2 r1 I! @0 {9 @3 i- c  j9 L8 @" }* L* Q" f
   <memory unit='KiB'>102400</memory>" s7 J3 O0 y( t& u) A' h% N
   <currentMemory unit='KiB'>102400</currentMemory>
2 w3 L4 `4 B& B1 l- x5 i$ {# q/ ?<vcpu placement='static'>1</vcpu>
5 y% G- F# m$ n6 }6 o1 J   <os>
# j  Z* R& C; F0 m0 Z5 ]. ^+ ?/ x     <type arch='x86_64' machine='rhel6.6.0'>hvm</type>  //arch指出系统架构类型,machine 则是机器类型,查看机器类型:qemu-system-x86_64
$ I/ _0 \# E2 P$ a; X( ]* t     <boot dev='hd'/>         //启动介质,第一次需要装系统可以选择cdrom光盘启动' ]. ~" s) E/ t0 R& h
  </os>
1 G/ }2 V' X* u$ A! V& ]  F( c   <features>* k$ |# R6 ?" z: c! j6 g
     <acpi/>                 //Advanced Configuration and Power Interface,高级配置与电源接口6 o- I9 g' K3 ]$ n8 r
    <apic/>                 //Advanced Programmable Interrupt Controller,高级可编程中断控制器5 o6 M8 l3 d/ j9 |2 n4 ]- O
    <pae/>                 //Physical Address Extension,物理地址扩展
, I0 H: ~5 @" g7 g) f/ M6 s  </features>
3 w$ h/ `& x% I   <clock offset='utc'/>      //虚拟机时钟设置,这里表示本地本机时间1 q9 m$ b2 o# H/ y# ~. \' W
  <on_poweroff>destroy</on_poweroff>       //突发事件动作
( S+ p7 b3 X' E, n) L( M1 I$ v/ ]" s  \+ Q4 ~5 S: b& g6 e
  <on_reboot>restart</on_reboot>
( n) p2 V  c! q( c2 ~. C+ W
% [; s" }# p: e) P   <on_crash>restart</on_crash>  L) `' v- ?* x  \1 V! I
   <devices>
7 J# L: o! ]" U, i$ ~" u     <emulator>/usr/libexec/qemu-kvm</emulator>       //kvm 默认
* F+ w' v3 y6 ]5 O" k  A, A    <disk type='file' device='disk'>$ z: I7 _% v5 ]1 s( D; M* H( s4 m. R
       <driver name='qemu' type='qcow2' cache='none'/>    //镜像类型" o$ o1 g, U0 q* \
      <source file='/var/lib/libvirt/images/cirros-0.3.3-x86_64-disk.img'/>    //镜像位置
* E1 ~1 [  _: t, U2 A) w3 `6 ~; P& G      <target dev='hda' bus='ide'/>        ! Y5 ?* y3 W0 w3 l
     </disk>7 r: q6 W: Q. q/ H2 X
     <interface type='bridge'>    //虚拟机网卡类型
  {, Z9 A% {& z& ?' |* B      <source bridge='br0'/>    # T$ O& B! t4 N' `9 H: l
       <target dev='vnet0'/>      //宿主机设备名称& J9 H4 [2 H9 E9 J
    </interface>% [. v+ ~7 \4 j' s: K
     <console type='pty' tty='/dev/pts/2'>   //控制台登录设置
; K6 b9 g6 P3 G6 P: h9 t2 i5 U      <source path='/dev/pts/2'/>& q, ^" ?, W9 p. W9 P( R6 B
       <target type='serial' port='0'/>
) c1 Q8 }. X; f     </console>
9 ]: L! o; O8 G1 d     <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>   //配置VNC 设置
* ~. D- j! u- n% v6 f      <listen type='address' address='0.0.0.0'/>
  K' p, u/ B% y4 J) p4 R     </graphics>' n# b; L2 d0 G; c: e% n
   </devices>6 T; n' G* r0 s8 A& X( x0 d
</domain>
5 X$ @5 Y' Y) A4 m* e7 j, E
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 02:51 , Processed in 0.026519 second(s), 25 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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