Virtualization in Grid'5000: Difference between revisions

From Grid5000
Jump to navigation Jump to search
No edit summary
Line 49: Line 49:
eg : <code class="file">domain.xml</code>
eg : <code class="file">domain.xml</code>
  <domain type='kvm'>
  <domain type='kvm'>
  <name>squeeze-vm1</name>
  <name>squeeze</name>
  <memory>524288</memory>
  <memory>524288</memory>
  <vcpu>1</vcpu>
  <vcpu>1</vcpu>
  <os>
  <os>
    <type arch="x86_64">hvm</type>
    <type arch="x86_64">hvm</type>
  </os>
  </os>
  <clock sync="localtime"/>
  <clock sync="localtime"/>
  <devices>
  <devices>
    <disk type='file' device='disk'>
    <emulator>/usr/bin/kvm</emulator>
      <source file='/tmp/squeeze-x64-base.qcow2'/>
    <disk type='file' device='disk'>
      <target dev='hda'/>
      <source file='/tmp/squeeze-x64-base.qcow2'/>
    </disk>
      <target dev='hda'/>
    <interface type='ethernet'>
    </disk>
      <target dev='tap0'/>
    <interface type='ethernet'>
      <script path='no'/>
      <target dev='tap0'/>
      <mac address='00:16:3e:82:a6:ea'/>
      <script path='no'/>
    </interface>
      <mac address='00:16:3e:fc:66:09'/>
    <graphics type='vnc' port='5900'/>
    </interface>
  </devices>
    <serial type='pty'>
      <source path='/dev/pts/2'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/2'>
      <source path='/dev/pts/2'/>
    <target port='0'/>
    </console>
  </devices>
  </domain>
  </domain>
* Now, the guest OS can be started.
* Now, the guest OS can be started.
  jdoe@griffon-37:~$ virsh create domain.xml
  jdoe@griffon-37:~$ virsh create domain.xml

Revision as of 03:35, 15 December 2011

Purpose

This page presents ways to use KVM on production image.

Usage

First, submit the job using habitual oarsub command

jdoe@fnancy:~$ oarsub -I

Copy the kvm disk image to /tmp on the node

jdoe@griffon-37:~$ cp /grid5000/images/KVM/squeeze-x64-base.qcow2 /tmp/

Create Tun/Tap interface for your guest OS

jdoe@griffon-37:~$ sudo create_tap
  • Tun/Tap interfaces are listed by issuing the command /sbin/ifconfig.
jdoe@griffon-37:~$ /sbin/ifconfig
[...]
tap0      Link encap:Ethernet  HWaddr 00:16:3e:db:c6:41  
          inet6 addr: fe80::58ff:a4ff:fe97:c6a8/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:29435 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
Note.png Note

Create one Tun/Tap interface per guest OS.
The first three octets are important (identification for the virtualized network). Don't change it.

Generate a random mac address for the Tun/Tap interface

  • Use the following script
jdoe@griffon-37:~$ random_mac
Note.png Note

The first three octets are important (identification for the virtualized network). Don't change it.

Now, you can run the guest OS using kvm

jdoe@griffon-37:~$ screen kvm -m 512 -hda /tmp/squeeze-x64-base.qcow2 -net nic,macaddr=$MACADDR -net tap,ifname=tap0,script=no -nographic
Note.png Note

Replace $MACADDR by the mac address generated.
In this example, tap0 is the name of our Tun/Tap interface. Adapt it with the Tun/Tap name on witch you want to attach your guest OS.

Or, you can start the guest OS using libvirt

  • Edit the domain file

eg : domain.xml

<domain type='kvm'>
 <name>squeeze</name>
 <memory>524288</memory>
 <vcpu>1</vcpu>
 <os>
   <type arch="x86_64">hvm</type>
 </os>
 <clock sync="localtime"/>
 <devices>
   <emulator>/usr/bin/kvm</emulator>
   <disk type='file' device='disk'>
     <target dev='hda'/>
   </disk>
   <interface type='ethernet'>
     <target dev='tap0'/>
     <script path='no'/>
     <mac address='00:16:3e:fc:66:09'/>
   </interface>
   <serial type='pty'>
     <target port='0'/>
   </serial>
   <console type='pty' tty='/dev/pts/2'>
   <target port='0'/>
   </console>
 </devices>
</domain>
  • Now, the guest OS can be started.
jdoe@griffon-37:~$ virsh create domain.xml
  • You can use virsh to manage your guest OS.
jdoe@griffon-37:~$ virsh list 
Note.png Note

You can use the script /usr/local/bin/random_mac to generate a mac address.

Misc notes

jdoe@griffon-37:~$ /usr/sbin/tunctl -d tap0