Sei sulla pagina 1di 33

Virtualization With KVM On A Debian Squeeze Server

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 0!10!"011
This #uide e$%lains how &ou can install and use 'V( for creatin# and runnin# )irtual
machines on a *e+ian ,-uee.e ser)er. / will show how to create ima#e0+ased )irtual
machines and also )irtual machines that use a lo#ical )olume 1LV(2. 'V( is short for
Kernel-based Virtual Machine and makes use of hardware )irtuali.ation3 i.e.3 &ou need a
456 that su%%orts hardware )irtuali.ation3 e.#. /ntel VT or A(*0V.
/ do not issue an& #uarantee that this will work for &ou7
1 Preliminary Note
/8m usin# a machine with the hostname server1.example.com and the /5 address
192.168.0.100 here as m& 'V( host.
9e also need a deskto% s&stem where we install )irt0mana#er so that we can connect to the
#ra%hical console of the )irtual machines that we install. /8m usin# an 6+untu 10.10 deskto%
here.
2 Installing KVM
Debian Squeeze KVM Host:
First check if &our 456 su%%orts hardware )irtuali.ation 0 if this is the case3 the command
egrep '(vmx|svm)' --color=always /proc/cpui!o
should dis%la& somethin#3 e.#. like this:
roo"#server1$%& egrep '(vmx|svm)' --color=always /proc/cpui!o
!lags $ !pu vme 'e pse "sc msr pae mce cx8 apic sep m"rr pge mca cmov pa"
pse(6 cl!lus) mmx !xsr sse sse2 )" syscall
x mmxex" !xsr*op" r'"scp lm ('owex" ('ow rep*goo' pi cx16 la)!*lm
cmp*legacy svm ex"apic cr8*legacy ('owpre!e"c)
!lags $ !pu vme 'e pse "sc msr pae mce cx8 apic sep m"rr pge mca cmov pa"
pse(6 cl!lus) mmx !xsr sse sse2 )" syscall
x mmxex" !xsr*op" r'"scp lm ('owex" ('ow rep*goo' pi cx16 la)!*lm
cmp*legacy svm ex"apic cr8*legacy ('owpre!e"c)
roo"#server1$%&
/f nothin# is dis%la&ed3 then &our %rocessor doesn8t su%%ort hardware )irtuali.ation3 and &ou
must sto% here.
To install 'V( and vir"is" 1a tool to create )irtual machines23 we run
ap"-ge" is"all +vm ,emu-+vm li-vir"--i vir"is"
Afterwards we must add the user as which we8re currentl& lo##ed in 1roo"2 to the #rou%s
li-vir" and +vm:
a''user .i' -u. li-vir"
a''user .i' -u. +vm
:ou need to lo# out and lo# +ack in for the new #rou% mem+ershi% to take effect.
To check if 'V( has successfull& +een installed3 run
virs) -c ,emu$///sys"em lis"
/t should dis%la& somethin# like this:
roo"#server1$%& virs) -c ,emu$///sys"em lis"
/' 0ame 1"a"e
----------------------------------
roo"#server1$%&
/f it dis%la&s an error instead3 then somethin# went wron#.
;e$t we need to set u% a network +rid#e on our ser)er so that our )irtual machines can +e
accessed from other hosts as if the& were %h&sical s&stems in the network.
To do this3 we install the %acka#e -ri'ge-u"ils...
ap"-ge" is"all -ri'ge-u"ils
... and confi#ure a +rid#e. <%en /e"c/e"wor+/i"er!aces:
vi /e"c/e"wor+/i"er!aces
=efore the modification3 m& file looks as follows:
# This file describes the network interfaces
available on your system
# and how to activate them. For more information, see
interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#allow-hotplu eth!
#iface eth! inet dhcp
auto eth!
iface eth! inet static
address "#$."%&.!."!!
netmask $55.$55.$55.!
network "#$."%&.!.!
broadcast "#$."%&.!.$55
ateway "#$."%&.!."
/ chan#e it so that it looks like this:
# This file describes the network interfaces
available on your system
# and how to activate them. For more information, see
interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#allow-hotplu eth!
#iface eth! inet dhcp
auto eth!
iface eth! inet manual
auto br!
iface br! inet static
address "#$."%&.!."!!
network "#$."%&.!.!
netmask $55.$55.$55.!
broadcast "#$."%&.!.$55
ateway "#$."%&.!."
bride'ports eth!
bride'fd #
bride'hello $
bride'ma(ae "$
bride'stp off
1(ake sure &ou use the correct settin#s for &our network72
>estart the network...
/e"c/ii".'/e"wor+ig res"ar"
... and run
i!co!ig
/t should now show the network +rid#e 1-r02:
roo"#server1$%& i!co!ig
-r0 2i+ ecap$3")ere" 45a''r 00$1e$90$!($!0$02
ie" a''r$192.168.0.100 6cas"$192.168.0.277 8as+$277.277.277.0
ie"6 a''r$ !e80$$21e$90!!$!e!($!002/69 1cope$2i+
:; 6<=>?@>1A <:00/0B 8:2A/@>1A 8A:$1700 8e"ric$1
<C pac+e"s$7 errors$0 'roppe'$0 overrus$0 !rame$0
AC pac+e"s$9 errors$0 'roppe'$0 overrus$0 carrier$0
collisios$0 "x,ueuele$0
<C -y"es$(10 ((10.0 6) AC -y"es$8(8 (8(8.0 6)
e")0 2i+ ecap$3")ere" 45a''r 00$1e$90$!($!0$02
ie"6 a''r$ !e80$$21e$90!!$!e!($!002/69 1cope$2i+
:; 6<=>?@>1A <:00/0B 8:2A/@>1A 8A:$1700 8e"ric$1
<C pac+e"s$97(69 errors$0 'roppe'$0 overrus$0 !rame$0
AC pac+e"s$296(9 errors$0 'roppe'$0 overrus$0 carrier$0
collisios$0 "x,ueuele$1000
<C -y"es$6690999( (6(.8 8i6) AC -y"es$1988D2D (1.8 8i6)
/"errup"$28
lo 2i+ ecap$2ocal 2oop-ac+
ie" a''r$12D.0.0.1 8as+$277.0.0.0
ie"6 a''r$ $$1/128 1cope$4os"
:; 2==;6>@E <:00/0B 8A:$169(6 8e"ric$1
<C pac+e"s$8 errors$0 'roppe'$0 overrus$0 !rame$0
AC pac+e"s$8 errors$0 'roppe'$0 overrus$0 carrier$0
collisios$0 "x,ueuele$0
<C -y"es$760 (760.0 6) AC -y"es$760 (760.0 6)
roo"#server1$%&
3 Installing virt-viewer Or virt-manager On Your Ubuntu 1010
!es"to#
Ubuntu 10.10 Desktop:
9e need a means of connectin# to the #ra%hical console of our #uests 0 we can use )irt0
mana#er 1see 'V( ?uest (ana#ement 9ith Virt0(ana#er <n 6+untu @.102 for this. /8m
assumin# that &ou8re usin# an 6+untu 10.10 deskto%.
>un
su'o ap"-ge" is"all vir"-maager
to install )irt0mana#er.
$ %reating & !ebian '(uee)e *uest +Image-,ase-. /rom 01e
%omman- 2ine
Debian Squeeze KVM Host:
;ow let8s #o +ack to our *e+ian ,-uee.e 'V( host.
Take a look at
ma vir"-is"all
to learn how to use it.
9e will create our ima#e0+ased )irtual machines in the director&
/var/li-/li-vir"/images/ which was created automaticall& when we installed 'V( in
cha%ter two.
To create a *e+ian ,-uee.e #uest 1in +rid#in# mode2 with the name vm103 A1"(= of >A(3
two )irtual 456s3 and the disk ima#e /var/li-/li-vir"/images/vm10.img 1with a si.e of
1"?=23 insert the *e+ian ,-uee.e ;etinstall 4* into the 4* dri)e and run
vir"-is"all --coec" ,emu$///sys"em - vm10 -r 712 --vcpus=2 --'is+
pa")=/var/li-/li-vir"/images/vm10.imgFsiGe=12 -c /'ev/c'rom --vc
--oau"ocosole --os-"ype liux --os-varia" 'e-ias,ueeGe --accelera"e
--e"wor+=-ri'ge$-r0 --)vm
<f course3 &ou can also create an /,< ima#e of the *e+ian ,-uee.e ;etinstall 4* 1%lease
create it in the /var/li-/li-vir"/images/ director& +ecause later on / will show how to
create )irtual machines throu#h )irt0mana#er from &our 6+untu deskto%3 and )irt0mana#er
will look for /,< ima#es in the /var/li-/li-vir"/images/ director&2...
'' i!=/'ev/c'rom o!=/var/li-/li-vir"/images/'e-ia-6.0.0-am'69-e"is".iso
... and use the /,< ima#e in the )irt0install command:
vir"-is"all --coec" ,emu$///sys"em - vm10 -r 712 --vcpus=2 --'is+
pa")=/var/li-/li-vir"/images/vm10.imgFsiGe=12 -c
/var/li-/li-vir"/images/'e-ia-6.0.0-am'69-e"is".iso --vc --oau"ocosole
--os-"ype liux --os-varia" 'e-ias,ueeGe --accelera"e --e"wor+=-ri'ge$-r0
--)vm
The out%ut is as follows:
roo"#server1$%& vir"-is"all --coec" ,emu$///sys"em - vm10 -r 712 --vcpus=2
--'is+ pa")=/var/li-/li-vir"/images/vm10.imgFsiGe=12 -c
/var/li-/li-vir"/images/'e-ia-6.0.0-am'69-e"is".iso --vc --oau"ocosole
--os-"ype liux --os-varia" 'e-ias,ueeGe --accelera"e --e"wor+=-ri'ge$-r0
--)vm
1"ar"ig is"all...
>lloca"ig 'vm10.img' | 12 B6 00$00
@rea"ig 'omai... | 0 6 00$00
?omai is"alla"io s"ill i progress. Hou ca recoec" "o
")e cosole "o comple"e ")e is"alla"io process.
roo"#server1$%&
Virtuali.ation 9ith 'V( <n A *e+ian ,-uee.e ,er)er 0 5a#e "
Virtuali.ation 9ith 'V( <n A *e+ian ,-uee.e ,er)er 0 5a#e
Virtuali.ation 9ith 'V( <n A *e+ian ,-uee.e ,er)er 0 5a#e B
Virtuali.ation 9ith 'V( <n A *e+ian ,-uee.e ,er)er 0 5a#e A
3 %onne4ting 0o 01e *uest
Ubuntu 10.10 Desktop:
The 'V( #uest will now +oot from the *e+ian ,-uee.e ;etinstall 4* and start the *e+ian
installer 0 that8s wh& we need to connect to the #ra%hical console of the #uest. :ou can do
this with )irt0mana#er on the 6+untu 10.10 deskto% 1see 'V( ?uest (ana#ement 9ith Virt0
(ana#er <n 6+untu @.102.
?o to >pplica"ios I 1ys"em Aools I Jir"ual 8ac)ie 8aager to start )irt0mana#er:
/n )irt0mana#er3 #o to Kile I >'' @oec"io... to connect to &our *e+ian ,-uee.e 'V(
host:
,elect L38:/EJ8 as 4ypervisor3 then choose <emo"e "uel over 114 in the @oec"io
dro%0down menu3 t&%e in the hostname 1server1.example.com2 or /5 address
1192.168.0.1002 of the *e+ian ,-uee.e 'V( host in the 4os"ame field3 and click on
@oec":
/f this is the first connection to the remote 'V( ser)er3 &ou must t&%e in yes and click on =E:
Afterwards t&%e in the root %assword of the 'V( host:
:ou should see vm10 as runnin#. (ark that #uest and click on the =pe +utton to o%en the
#ra%hical console of the #uest:
T&%e in the root %assword of the 'V( host a#ain:
:ou should now +e connected to the #ra%hical console of the #uest and see the *e+ian
installer:
;ow install *e+ian as &ou would normall& do on a %h&sical s&stem. 5lease note that at the
end of the installation3 the *e+ian #uest needs a re+oot. The #uest will then sto%3 so &ou
need to start it a#ain3 either with )irt0mana#er or like this on our *e+ian ,-uee.e 'V( host
command line:
Debian Squeeze KVM Host:
virs) --coec" ,emu$///sys"em
s"ar" vm10
,ui"
Afterwards3 &ou can connect to the #uest a#ain with )irt0mana#er and confi#ure the #uest. /f
&ou install <%en,,C 1%acka#e opess)-server2 in the #uest3 &ou can connect to it with an
,,C client 1such as 5uTT:2.
5 %reating & !ebian '(uee)e *uest +Image-,ase-. /rom 01e
!es"to# 6it1 virt-manager
/nstead of creatin# a )irtual machine from the command line 1as shown in cha%ter B23 &ou
can as well create it from the 6+untu deskto% usin# )irt0mana#er 1of course3 the )irtual
machine will +e created on the *e+ian ,-uee.e 'V( host 0 in case &ou ask &ourself if )irt0
mana#er is a+le to create )irtual machines on remote s&stems2.
To do this3 click on the followin# +utton:
The 0ew J8 dialo#ue comes u%. Fill in a name for the V( 1e.#. vm1123 select 2ocal is"all
me'ia (/1= image or @?<=8)3 and click on Korwar':
;e$t select 2iux in the =1 "ype dro%0down menu and ?e-ia 1,ueeGe in the Jersio
dro%0down menu3 then check :se /1= image and click on the 6rowse... +utton:
,elect the 'e-ia-6.0.0-am'69-e"is".iso ima#e that &ou created in cha%ter B and click
on @)oose Jolume:
;ow click on Korwar':
Assi#n memor& and the num+er of 456s to the )irtual machine and click on Korwar':
;ow we come to the stora#e. 4heck 3a-le s"orage !or ")is vir"ual mac)ie3 select
@rea"e a 'is+ image o ")e compu"er's )ar' 'rive3 s%ecif& the si.e of the hard dri)e
1e.#. 1"?=23 and check >lloca"e e"ire 'is+ ow. Then click on Korwar':
;ow we come to the last ste% of the 0ew J8 dialo#ue. ?o to the >'vace' op"ios section.
,elect 1peci!y s)are' 'evice ameD the 6ri'ge ame field will then a%%ear where &ou fill
in -r0 1the name of the +rid#e which we created in cha%ter "2. 4lick on Kiis) afterwards:
The disk ima#e for the V( is now +ein# created:
Afterwards3 the V( will start. T&%e in the root %assword of the *e+ian ,-uee.e 'V( host:
:ou should now +e connected to the #ra%hical console of the #uest and see the *e+ian
installer:
;ow install *e+ian as &ou would normall& do on a %h&sical s&stem.
7 Managing & KVM *uest /rom 01e %omman- 2ine
Debian Squeeze KVM Host:
'V( #uests can +e mana#ed throu#h virs)3 the E)irtual shellE. To connect to the )irtual
shell3 run
virs) --coec" ,emu$///sys"em
This is how the )irtual shell looks:
roo"#server1$%& virs) --coec" ,emu$///sys"em
5elcome "o virs)F ")e vir"ualiGa"io i"erac"ive "ermial.
Aype$ ')elp' !or )elp wi") comma's
',ui"' "o ,ui"
virs) &
:ou can now t&%e in commands on the )irtual shell to mana#e &our #uests. >un
)elp
to #et a list of a)aila+le commands:
virs) & )elp
@omma's$
)elp pri" )elp
a""ac)-'evice a""ac) 'evice !rom a C82 !ile
a""ac)-'is+ a""ac) 'is+ 'evice
a""ac)-i"er!ace a""ac) e"wor+ i"er!ace
au"os"ar" au"os"ar" a 'omai
capa-ili"ies capa-ili"ies
c' c)age ")e curre" 'irec"ory
coec" (re)coec" "o )ypervisor
cosole coec" "o ")e gues" cosole
cpu--aselie compu"e -aselie @;:
cpu-compare compare )os" @;: wi") a @;: 'escri-e' -y a C82 !ile
crea"e crea"e a 'omai !rom a C82 !ile
s"ar" s"ar" a (previously 'e!ie') iac"ive 'omai
'es"roy 'es"roy a 'omai
'e"ac)-'evice 'e"ac) 'evice !rom a C82 !ile
'e"ac)-'is+ 'e"ac) 'is+ 'evice
'e"ac)-i"er!ace 'e"ac) e"wor+ i"er!ace
'e!ie 'e!ie (-u" 'o'" s"ar") a 'omai !rom a C82 !ile
'omi' cover" a 'omai ame or ::/? "o 'omai i'
'omuui' cover" a 'omai ame or i' "o 'omai ::/?
'omi!o 'omai i!orma"io
'omMo-i!o 'omai Mo- i!orma"io
'omMo-a-or" a-or" ac"ive 'omai Mo-
'omame cover" a 'omai i' or ::/? "o 'omai ame
'oms"a"e 'omai s"a"e
'om-l+s"a" ge" 'evice -loc+ s"a"s !or a 'omai
'omi!s"a" ge" e"wor+ i"er!ace s"a"s !or a 'omai
'ommems"a" ge" memory s"a"is"ics !or a 'omai
'om-l+i!o 'omai -loc+ 'evice siGe i!orma"io
'omxml-!rom-a"ive @over" a"ive co!ig "o 'omai C82
'omxml-"o-a"ive @over" 'omai C82 "o a"ive co!ig
'umpxml 'omai i!orma"io i C82
e'i" e'i" C82 co!igura"io !or a 'omai
!i'-s"orage-pool-sources 'iscover po"e"ial s"orage pool sources
!i'-s"orage-pool-sources-as !i' po"e"ial s"orage pool sources
!reecell 0:8> !ree memory
)os"ame pri" ")e )ypervisor )os"ame
lis" lis" 'omais
migra"e migra"e 'omai "o ao")er )os"
migra"e-se"max'ow"ime se" maximum "olera-le 'ow"ime
e"-au"os"ar" au"os"ar" a e"wor+
e"-crea"e crea"e a e"wor+ !rom a C82 !ile
e"-'e!ie 'e!ie (-u" 'o'" s"ar") a e"wor+ !rom a C82 !ile
e"-'es"roy 'es"roy a e"wor+
e"-'umpxml e"wor+ i!orma"io i C82
e"-e'i" e'i" C82 co!igura"io !or a e"wor+
e"-lis" lis" e"wor+s
e"-ame cover" a e"wor+ ::/? "o e"wor+ ame
e"-s"ar" s"ar" a (previously 'e!ie') iac"ive e"wor+
e"-u'e!ie u'e!ie a iac"ive e"wor+
e"-uui' cover" a e"wor+ ame "o e"wor+ ::/?
i!ace-lis" lis" p)ysical )os" i"er!aces
i!ace-ame cover" a i"er!ace 8>@ a''ress "o i"er!ace ame
i!ace-mac cover" a i"er!ace ame "o i"er!ace 8>@ a''ress
i!ace-'umpxml i"er!ace i!orma"io i C82
i!ace-'e!ie 'e!ie (-u" 'o'" s"ar") a p)ysical )os" i"er!ace !rom a C82
!ile
i!ace-u'e!ie u'e!ie a p)ysical )os" i"er!ace (remove i" !rom
co!igura"io)
i!ace-e'i" e'i" C82 co!igura"io !or a p)ysical )os" i"er!ace
i!ace-s"ar" s"ar" a p)ysical )os" i"er!ace (ea-le i" / Ni!-upN)
i!ace-'es"roy 'es"roy a p)ysical )os" i"er!ace ('isa-le i" / Ni!-'owN)
maage'save maage' save o! a 'omai s"a"e
maage'save-remove <emove maage' save o! a 'omai
o'ei!o o'e i!orma"io
o'e'ev-lis" eumera"e 'evices o ")is )os"
o'e'ev-'umpxml o'e 'evice 'e"ails i C82
o'e'ev-'e""ac) 'e""ac) o'e 'evice !rom i"s 'evice 'river
o'e'ev-rea""ac) rea""ac) o'e 'evice "o i"s 'evice 'river
o'e'ev-rese" rese" o'e 'evice
o'e'ev-crea"e crea"e a 'evice 'e!ie' -y a C82 !ile o ")e o'e
o'e'ev-'es"roy 'es"roy a 'evice o ")e o'e
w!il"er-'e!ie 'e!ie or up'a"e a e"wor+ !il"er !rom a C82 !ile
w!il"er-u'e!ie u'e!ie a e"wor+ !il"er
w!il"er-'umpxml e"wor+ !il"er i!orma"io i C82
w!il"er-lis" lis" e"wor+ !il"ers
w!il"er-e'i" e'i" C82 co!igura"io !or a e"wor+ !il"er
pool-au"os"ar" au"os"ar" a pool
pool--uil' -uil' a pool
pool-crea"e crea"e a pool !rom a C82 !ile
pool-crea"e-as crea"e a pool !rom a se" o! args
pool-'e!ie 'e!ie (-u" 'o'" s"ar") a pool !rom a C82 !ile
pool-'e!ie-as 'e!ie a pool !rom a se" o! args
pool-'es"roy 'es"roy a pool
pool-'ele"e 'ele"e a pool
pool-'umpxml pool i!orma"io i C82
pool-e'i" e'i" C82 co!igura"io !or a s"orage pool
pool-i!o s"orage pool i!orma"io
pool-lis" lis" pools
pool-ame cover" a pool ::/? "o pool ame
pool-re!res) re!res) a pool
pool-s"ar" s"ar" a (previously 'e!ie') iac"ive pool
pool-u'e!ie u'e!ie a iac"ive pool
pool-uui' cover" a pool ame "o pool ::/?
secre"-'e!ie 'e!ie or mo'i!y a secre" !rom a C82 !ile
secre"-'umpxml secre" a""ri-u"es i C82
secre"-se"-value se" a secre" value
secre"-ge"-value =u"pu" a secre" value
secre"-u'e!ie u'e!ie a secre"
secre"-lis" lis" secre"s
pw' pri" ")e curre" 'irec"ory
,ui" ,ui" ")is i"erac"ive "ermial
exi" ,ui" ")is i"erac"ive "ermial
re-oo" re-oo" a 'omai
res"ore res"ore a 'omai !rom a save' s"a"e i a !ile
resume resume a 'omai
save save a 'omai s"a"e "o a !ile
sc)e'i!o s)ow/se" sc)e'uler parame"ers
'ump 'ump ")e core o! a 'omai "o a !ile !or aalysis
s)u"'ow grace!ully s)u"'ow a 'omai
se"mem c)age memory alloca"io
se"maxmem c)age maximum memory limi"
se"vcpus c)age um-er o! vir"ual @;:s
suspe' suspe' a 'omai
""ycosole ""y cosole
u'e!ie u'e!ie a iac"ive 'omai
up'a"e-'evice up'a"e 'evice !rom a C82 !ile
uri pri" ")e )ypervisor caoical :</
vol-crea"e crea"e a vol !rom a C82 !ile
vol-crea"e-!rom crea"e a volF usig ao")er volume as ipu"
vol-crea"e-as crea"e a volume !rom a se" o! args
vol-cloe cloe a volume.
vol-'ele"e 'ele"e a vol
vol-wipe wipe a vol
vol-'umpxml vol i!orma"io i C82
vol-i!o s"orage vol i!orma"io
vol-lis" lis" vols
vol-pool re"urs ")e s"orage pool !or a give volume +ey or pa")
vol-pa") re"urs ")e volume pa") !or a give volume ame or +ey
vol-ame re"urs ")e volume ame !or a give volume +ey or pa")
vol-+ey re"urs ")e volume +ey !or a give volume ame or pa")
vcpui!o 'omai vcpu i!orma"io
vcpupi co"rol 'omai vcpu a!!ii"y
versio s)ow versio
vc'isplay vc 'isplay
saps)o"-crea"e @rea"e a saps)o"
saps)o"-curre" Be" ")e curre" saps)o"
saps)o"-'ele"e ?ele"e a 'omai saps)o"
saps)o"-'umpxml ?ump C82 !or a 'omai saps)o"
saps)o"-lis" 2is" saps)o"s !or a 'omai
saps)o"-rever" <ever" a 'omai "o a saps)o"
virs) &
lis"
shows all runnin# #uestsD
lis" --all
shows all #uests3 runnin# and inacti)e:
virs) & lis" --all
/' 0ame 1"a"e
----------------------------------
17 vm11 ruig
- vm10 s)u" o!!
virs) &
/f &ou modif& a #uest8s $ml file 1located in the /e"c/li-vir"/,emu/ director&23 &ou must
redefine the #uest:
'e!ie /e"c/li-vir"/,emu/vm10.xml
5lease note that whene)er &ou modif& the #uest8s $ml file in /e"c/li-vir"/,emu/3 &ou must
run the 'e!ie command a#ain7
To start a sto%%ed #uest3 run:
s"ar" vm10
To sto% a #uest3 run
s)u"'ow vm10
To immediatel& sto% it 1i.e.3 %ull the %ower %lu#23 run
'es"roy vm10
,us%end a #uest:
suspe' vm10
>esume a #uest:
resume vm10
These are the most im%ortant commands.
T&%e
,ui"
to lea)e the )irtual shell.
8 %reating &n 2VM-,ase- *uest /rom 01e %omman- 2ine
Debian Squeeze KVM Host:
LV(0+ased #uests ha)e some ad)anta#es o)er ima#e0+ased #uests. The& are not as hea)&
on hard disk /<3 and the& are easier to +ack u% 1usin# LV( sna%shots2.
To use LV(0+ased #uests3 &ou need a )olume #rou% that has some free s%ace that is not
allocated to an& lo#ical )olume. /n this e$am%le3 / use the )olume #rou% /'ev/vg0 with a
si.e of a%%ro$. BFA?=...
vg'isplay
roo"#server1$%& vg'isplay
--- Jolume group ---
JB 0ame vg0
1ys"em /?
Korma" lvm2
8e"a'a"a >reas 1
8e"a'a"a 1e,uece 0o (
JB >ccess rea'/wri"e
JB 1"a"us resiGa-le
8>C 2J 0
@ur 2J 2
=pe 2J 2
8ax ;J 0
@ur ;J 1
>c" ;J 1
JB 1iGe 967.28 Bi6
;3 1iGe 9.00 8i6
Ao"al ;3 119112
>lloc ;3 / 1iGe 290D9 / 99.06 Bi6
Kree ;3 / 1iGe 970(( / (D1.22 Bi6
JB ::/? :!8Or--eu18-0lHw-;Bx1-w87!-9'D1-x10)pw
roo"#server1$%&
... that contains the lo#ical )olume /'ev/vg0/roo" with a si.e of a%%ro$. G?= and the
lo#ical )olume /'ev/vg0/swap*1 1a+out 1?=2 0 the rest is not allocated and can +e used for
'V( #uests:
lv'isplay
roo"#server1$%& lv'isplay
--- 2ogical volume ---
2J 0ame /'ev/vg0/roo"
JB 0ame vg0
2J ::/? y'J6(-e7D!-A(vu-xc6?-=PDu-gC;!-LoBxJ+
2J 5ri"e >ccess rea'/wri"e
2J 1"a"us availa-le
& ope 1
2J 1iGe 9(.1( Bi6
@urre" 23 2(891
1egme"s 1
>lloca"io i)eri"
<ea' a)ea' sec"ors au"o
- curre"ly se" "o 276
6loc+ 'evice 279$0
--- 2ogical volume ---
2J 0ame /'ev/vg0/swap*1
JB 0ame vg0
2J ::/? 0406>x-Je6:-p49A-@p?-DoK/-6ul;-+rl66i
2J 5ri"e >ccess rea'/wri"e
2J 1"a"us availa-le
& ope 1
2J 1iGe 972.00 8i6
@urre" 23 2(8
1egme"s 1
>lloca"io i)eri"
<ea' a)ea' sec"ors au"o
- curre"ly se" "o 276
6loc+ 'evice 279$1
roo"#server1$%&
/ will now create the )irtual machine vm12 as an LV(0+ased #uest. / want vm12 to ha)e "0?=
of disk s%ace3 so / create the lo#ical )olume /'ev/vg0/vm12 with a si.e of "0?=:
lvcrea"e -220B - vm12 vg0
Afterwards3 we use the )irt0install command a#ain to create the #uest:
vir"-is"all --coec" ,emu$///sys"em - vm12 -r 712 --vcpus=2 --'is+
pa")=/'ev/vg0/vm12 -c /var/li-/li-vir"/images/'e-ia-6.0.0-am'69-e"is".iso
--vc --oau"ocosole --os-"ype liux --os-varia" 'e-ias,ueeGe --accelera"e
--e"wor+=-ri'ge$-r0 --)vm
5lease note that instead of --'is+ pa")=/var/li-/li-vir"/images/vm12.imgFsiGe=20 /
use --'is+ pa")=/'ev/vg0/vm123 and / don8t need to define the disk s%ace an&more
+ecause the disk s%ace is defined +& the si.e of the lo#ical )olume vm12 1"0?=2.
;ow follow cha%ter A to install that #uest.
9 %onverting Image-,ase- *uests 0o 2VM-,ase- *uests
Debian Squeeze KVM Host:
;o let8s assume we want to con)ert our ima#e0+ased #uest vm10 into an LV(0+ased #uest.
This is how we do it:
First make sure the #uest is sto%%ed:
virs) --coec" ,emu$///sys"em
s)u"'ow vm10
,ui"
Then create a lo#ical )olume 1e.#. /'ev/vg0/vm102 that has the same si.e as the ima#e file 0
the ima#e has 1"?=3 so the lo#ical )olume must ha)e 1"?= of si.e as well:
lvcrea"e -212B - vm10 vg0
;ow there are two wa&s of con)ertin# the ima#e:
1. The first one is as follows:
,emu-img cover" /var/li-/li-vir"/images/vm10.img -= )os"*'evice
/'ev/vg0/vm10
2. OR &ou do it like this:
,emu-img cover" /var/li-/li-vir"/images/vm10.img -= raw
/var/li-/li-vir"/images/vm10.raw
'' i!=/var/li-/li-vir"/images/vm10.raw o!=/'ev/vg0/vm10
rm -! /var/li-/li-vir"/images/vm10.raw
1The command
,emu-img cover" /var/li-/li-vir"/images/vm10.img -= raw /'ev/vg0/vm10
does not workD &ou will #et the followin# error messa#e:
,emu-img$ 3rror w)ile !orma""ig '/'ev/vg0/vm10'
2
Afterwards &ou can delete the disk ima#e:
rm -! /var/li-/li-vir"/images/vm10.img
;ow we must o%en the #uest8s $ml confi#uration file /e"c/li-vir"/,emu/vm10.xml...
vi /e"c/li-vir"/,emu/vm10.xml
... and chan#e the followin# section...
)...*
+disk type,-file- device,-disk-.
+driver name,-/emu- type,-raw-0.
+source
file,-0var0lib0libvirt0imaes0vm"!.im-0.
+taret dev,-vda- bus,-virtio-0.
+address type,-pci- domain,-!(!!!!- bus,-!(!!-
slot,-!(!1- function,-!(!-0.
+0disk.
)...*
... so that it looks as follows:
)...*
+disk type,-block- device,-disk-.
+driver name,-/emu- type,-raw-0.
+source dev,-0dev0v!0vm"!-0.
+taret dev,-vda- bus,-virtio-0.
+address type,-pci- domain,-!(!!!!- bus,-!(!!-
slot,-!(!1- function,-!(!-0.
+0disk.
)...*
Afterwards we must redefine the #uest:
virs) --coec" ,emu$///sys"em
'e!ie /e"c/li-vir"/,emu/vm10.xml
,till on the virs) shell3 we can start the #uest...
s"ar" vm10
... and lea)e the virs) shell:
,ui"
10 2in"s
'V(: htt%:!!www.linu$0k)m.or#!
*e+ian: htt%:!!www.de+ian.or#!
6+untu: htt%:!!www.u+untu.com!

Potrebbero piacerti anche