KVM on ubuntu
自宅サーバのubuntuをhardyからintrepidにupgradeした後で、xenのホストになれないことが判明してから早数ヶ月...
xenの仮想マシンも起動できないまま放置でしたが、KVMを利用して仮想サーバを立ち上げることにしました。
Community Ubuntu Documentation - KVM
https://help.ubuntu.com/community/KVM
を参考に、
KVMのインストール
$ sudo aptitude install kvm libvirt-bin ubuntu-vm-builder qemu
インストールが終わったら、libvirtdグループに自分のアカウントを登録しておく。
$ sudo adduser `id -un` libvirtd
Network設定
下記を参考に。
https://help.ubuntu.com/community/KVM/Networking
bridgeの設定
cd /etc/network/ sudo cp -p interfaces interfaces.orig sudo vim interfaces
下記の様に変更する。
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto br0 iface br0 inet static address 192.168.2.2 network 192.168.2.0 netmask 255.255.255.0 broadcast 192.168.2.255 gateway 192.168.2.1 bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off
変更したら、ひとまずrebootする。
VMの作成
VMのHDDイメージ作成
- ホスト名「lime」
- ubuntu hardy
- i386
で作成することに。
# ubuntu-vm-builder kvm hardy \ -o -v \ --domain lime \ --dest lime \ --arch amd64 \ --hostname lime \ --mem 512 \ --ip 192.168.2.20 \ --mask 255.255.255.0 \ --net 192.168.2.0 \ --bcast 192.168.2.255 \ --gw 192.168.2.1 \ --dns 192.168.2.1 \ --libvirt qemu:///system \ --addpkg openssh-server
/root/lime/disk0.qcow2
が作成される。なぜに /root 直下...
VMの起動
$ virsh Connecting to uri: qemu:///system Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # start lime Domain lime started virsh # list Id Name State
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sshでVMにログイン可能か確認したところ、無事に起動できたみたい。
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=8.04 DISTRIB_CODENAME=hardy DISTRIB_DESCRIPTION="Ubuntu 8.04.1" $ uname -a Linux lime 2.6.24-22-virtual #1 SMP Mon Nov 24 19:55:07 UTC 2008 i686 GNU/Linux
$ virsh reboot lime Connecting to uri: qemu:///system libvir: error : this function is not supported by the hypervisor: virDomainReboot error: Failed to reboot domain lime
KVMはrebootできないらしい...
ホストに戻って、このVMを終了してみる。
$ virsh shutdown lime Connecting to uri: qemu:///system Domain lime is being shutdown
でも全くshutdownされる気配がない...
sshでlimeにアクセスして、shutdownするしかないみたい。
2009-01-04追記
debian、ubuntuではvirsh shutdownできないのは、ACPIのsignalが送れないからだという記述を
http://wiki.libvirt.org/page/Tips
に発見。
解決策としては、acpidパッケージをインストールすればOKでした。
$ sudo aptitude install acpid
これで、virsh shutdown VM名 でshutdownができるようになりました。