| | 7 | |
| | 8 | == virshを利用したKVM仮想マシンの作り方 == |
| | 9 | === イメージ作成 === |
| | 10 | {{{ |
| | 11 | # qemu-img create -f raw ubuntu.img 10G |
| | 12 | }}} |
| | 13 | === libvirt XMLファイルの作成方法 === |
| | 14 | {{{ |
| | 15 | # uuidgen |
| | 16 | }}} |
| | 17 | でuuidを取得しておく。下記のXMLを適当に編集。特に、 |
| | 18 | * name |
| | 19 | * uuid |
| | 20 | * memory(メモリ容量) |
| | 21 | * vcpu(CPUの数) |
| | 22 | * diskとcdromのsource file |
| | 23 | 辺りに注意しておく。 |
| | 24 | {{{ |
| | 25 | <domain type='kvm' id='3'> |
| | 26 | <name>UbuntuVM</name> |
| | 27 | <uuid>0738f2c4-f03e-4901-9954-0f59480ba1f3</uuid> |
| | 28 | <memory>524288</memory> |
| | 29 | <currentMemory>524288</currentMemory> |
| | 30 | <vcpu>1</vcpu> |
| | 31 | <os> |
| | 32 | <type arch='x86_64' machine='fedora-13'>hvm</type> |
| | 33 | <boot dev='hd'/> |
| | 34 | <boot dev='cdrom'/> |
| | 35 | </os> |
| | 36 | <features> |
| | 37 | <acpi/> |
| | 38 | <apic/> |
| | 39 | <pae/> |
| | 40 | </features> |
| | 41 | <clock offset='utc'/> |
| | 42 | <on_poweroff>destroy</on_poweroff> |
| | 43 | <on_reboot>destroy</on_reboot> |
| | 44 | <on_crash>destroy</on_crash> |
| | 45 | <devices> |
| | 46 | <emulator>/usr/libexec/qemu-kvm</emulator> |
| | 47 | <disk type='file' device='disk'> |
| | 48 | <driver name='qemu' type='raw'/> |
| | 49 | <source file='/mnt/sda5/ubuntu.img'/> |
| | 50 | <target dev='hda' bus='ide'/> |
| | 51 | <alias name='ide0-0-0'/> |
| | 52 | <address type='drive' controller='0' bus='0' unit='0'/> |
| | 53 | </disk> |
| | 54 | <disk type='file' device='cdrom'> |
| | 55 | <driver name='qemu'/> |
| | 56 | <source file='/mnt/sda5/iso/ubuntu-ja-10.04-desktop-i386-20100512.iso'/> |
| | 57 | <target dev='hdc' bus='ide'/> |
| | 58 | <readonly/> |
| | 59 | <alias name='ide0-1-0'/> |
| | 60 | <address type='drive' controller='0' bus='1' unit='0'/> |
| | 61 | </disk> |
| | 62 | <controller type='ide' index='0'> |
| | 63 | <alias name='ide0'/> |
| | 64 | <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> |
| | 65 | </controller> |
| | 66 | <interface type='network'> |
| | 67 | <mac address='52:54:00:1d:18:5e'/> |
| | 68 | <source network='default'/> |
| | 69 | <target dev='vnet2'/> |
| | 70 | <alias name='net0'/> |
| | 71 | <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> |
| | 72 | </interface> |
| | 73 | <serial type='pty'> |
| | 74 | <source path='/dev/pts/4'/> |
| | 75 | <target port='0'/> |
| | 76 | <alias name='serial0'/> |
| | 77 | </serial> |
| | 78 | <console type='pty' tty='/dev/pts/4'> |
| | 79 | <source path='/dev/pts/4'/> |
| | 80 | <target port='0'/> |
| | 81 | <alias name='serial0'/> |
| | 82 | </console> |
| | 83 | <input type='mouse' bus='ps2'/> |
| | 84 | <graphics type='vnc' port='5902' autoport='yes' keymap='ja'/> |
| | 85 | <sound model='es1370'> |
| | 86 | <alias name='sound0'/> |
| | 87 | <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> |
| | 88 | </sound> |
| | 89 | <video> |
| | 90 | <model type='cirrus' vram='9216' heads='1'/> |
| | 91 | <alias name='video0'/> |
| | 92 | <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> |
| | 93 | </video> |
| | 94 | </devices> |
| | 95 | </domain> |
| | 96 | }}} |
| | 97 | === virshに登録して機動 === |
| | 98 | {{{ |
| | 99 | # define virt-kvm.xml |
| | 100 | # start UbuntuVM |
| | 101 | # list |
| | 102 | Id 名前 状態 |
| | 103 | ---------------------------------- |
| | 104 | 8 UbuntuVM 実行中 |
| | 105 | }}} |
| | 106 | 停止 |
| | 107 | {{{ |
| | 108 | # shutdown UbuntuVM |
| | 109 | }}} |
| | 110 | ハイバネートとレジューム |
| | 111 | {{{ |
| | 112 | # save UbuntuVM UbuntuVM.mem |
| | 113 | # restore UbuntuVM UbuntuVM.mem |
| | 114 | }}} |