wiki:linux/kvm

Version 2 (modified by yuna, 54 years ago) (diff)

--

KVMメモ

Windowsゲストドライバ

Windowsゲストドライバを利用すると、ネットワークI/OやディスクI/Oが速くなります。 ゲストドライバの取得とインストール方法は下記のURLを参照。

virshを利用したKVM仮想マシンの作り方

イメージ作成

# qemu-img create -f raw ubuntu.img 10G

libvirt XMLファイルの作成方法

# uuidgen

でuuidを取得しておく。下記のXMLを適当に編集。特に、

  • name
  • uuid
  • memory(メモリ容量)
  • vcpu(CPUの数)
  • diskとcdromのsource file

辺りに注意しておく。

<domain type='kvm' id='3'>
  <name>UbuntuVM</name>
  <uuid>0738f2c4-f03e-4901-9954-0f59480ba1f3</uuid>
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='fedora-13'>hvm</type>
    <boot dev='hd'/>
    <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/sda5/ubuntu.img'/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu'/>
      <source file='/mnt/sda5/iso/ubuntu-ja-10.04-desktop-i386-20100512.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <controller type='ide' index='0'>
      <alias name='ide0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:1d:18:5e'/>
      <source network='default'/>
      <target dev='vnet2'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/4'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5902' autoport='yes' keymap='ja'/>
    <sound model='es1370'>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </sound>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
  </devices>
</domain>

virshに登録して機動

# define virt-kvm.xml
# start UbuntuVM
# list 
 Id 名前               状態
----------------------------------
  8 UbuntuVM           実行中

停止

# shutdown UbuntuVM

ハイバネートとレジューム

# save UbuntuVM UbuntuVM.mem
# restore UbuntuVM UbuntuVM.mem