站內搜尋

Sunday, August 28, 2011

[Linux][KVM] 在ubuntu上 建立免費的虛擬主機系統

步驟1.檢查 CPU 是否有支援 KVM ?
#apt-get install cpu-checker
#kvm-ok

步驟2.開始安裝 KVM
#apt-get install kvm kvm-pxe

步驟3.檢視 KVM 系統是否啟動 ?
#lsmod | grep kvm

以上為基本安裝步驟


以下為優化KVM操作的步驟


步驟4.安裝高階命令
apt-get install libvirt-bin

步驟5.建立一支.sh檔
內容為
#!/bin/bash
[ "$USER" != "root" ] && echo "需要 root 權限" && exit 1
which virsh &>/dev/null
[ "$?" != "0" ] && echo "沒有安裝 libvirt" && exit 1
cp floppyfw-3.0.14.img /var/lib/libvirt/images/
virsh define FloppyFW.xml

步驟6.建立一支.xml檔
內容為
<domain type='kvm'>
  <name>FloppyFW</name>
  <memory>131072</memory>
  <currentMemory>131072</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='i686' machine='pc-0.12'>hvm</type>
    <boot dev='fd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='floppy'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/floppyfw-3.0.14.img'/>
      <target dev='fda' bus='fdc'/>
    </disk>
    <interface type='network'>
      <mac address='52:54:00:db:92:77'/>
      <source network='default'/>
      <target dev='vnet0'/>
    </interface>
    <console type='pty'>
      <target port='0'/>
    </console>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'/>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
    </video>
  </devices>
</domain>
*注意! name不能重複、mac address不能重複

No comments:

Post a Comment