2011/02/19

debianでソースからqemu-kvmをインストールしてみる

USB接続のHDDにdebianをインストール。
netinstのCDでインストール。
let's note R7だとビデオの関係で画面が出ないので、最初の画面でinstallでTABを押してオプションを表示、 vga=normal に書き換えて起動。
baseとsshだけインストール。
grubは /dev/sdb にインストール。

再起動後はsshでrootでのログインは拒否する。

とりあえずカーネルを最新にしておく。
apt-get install kernel-package fakeroot ncurses
カーネルは http://kernel.org/ からstableなソースをダウンロード。
cd /usr/src
tar xjvf ダウンロードしたカーネル
ln -s /usr/src/解凍したディレクトリ linux
cd /usr/src/linux
cp -p /boot/config-○○ .config
make oldconfig
新しい項目を聞かれるけどデフォルトでとりあえず終了。
make menuconfig
変更はせずそのまま終了。
make-kpkg clean
fakeroot make-kpkg --initrd --revision=bananagunso-1 kernel_image kernel_headers
rebisionは数字が必須らしい。
再構築
再構築



cd ../
dpkg -i 今回作った.debのファイル。
grubも更新してくれた。
再起動で終了。

kvmをソースからインストール
http://sourceforge.net/projects/kvm/files/ からダウンロード。
cd /usr/local/src
tar xzvf qemu-kvm-0.14.0-rc1.tar.gz
cd qemu-kvm-0.14.0-rc1
./configure
  Error: zlib check failed 怒られた 
apt-get install zlib1g-dev
./configure
make
make install


libvirtdをインストール(これもソースから)
apt-get install bridge-utils
ftp://libvirt.org/libvirt/ からダウンロード
cd /usr/local/src
tar xzvf /mnt/debian/libvirt-0.8.8.tar.gz
cd libvirt-0.8.8/
./configure 
 Could not find libxml2 anywher 怒られる
apt-get install libxml2-dev
./configure
 You must install the GnuTLS library 怒られる
apt-get install libgnutls-dev
./configure
 You must install device-mapper-devel/libdevmapper まだ怒られる
apt-get install libdevmapper-dev
 libnl-devel >= 1.1 is required for macvtap support まだかいな
apt-get install libnl-dev
./configure 
 libnl-devel >= 1.1 is required for macvtap support なんで?
apt-get install libvirt-dev
./configure やっと通った
make
make install


起動してみる
libvirtd
エラーいっぱい
libvirtd: /usr/lib/libvirt.so.0: version `LIBVIRT_0.8.6' not found (required by libvirtd)
libvirtd: /usr/lib/libvirt.so.0: version `LIBVIRT_0.8.5' not found (required by libvirtd)
libvirtd: /usr/lib/libvirt.so.0: version `LIBVIRT_0.8.8' not found (required by libvirtd)
libvirtd: /usr/lib/libvirt.so.0: version `LIBVIRT_PRIVATE_0.8.8' not found (required by libvirtd)



ldconfig
libvirtd
エラーではなくワーニングになった
23:38:47.676: 8445: info : libvirt version: 0.8.8
23:38:47.676: 8445: error : virCommandWait:1229 : internal error Child process (/sbin/iptables --table mangle --insert POSTROUTING --out-interface virbr0 --protocol udp --destination-port 68 --jump CHECKSUM --checksum-fill) exited with status 2.
23:38:47.676: 8445: warning : networkAddGeneralIptablesRules:1128 : Could not add rule to fixup DHCP response checksums on network 'default'.
23:38:47.676: 8445: warning : networkAddGeneralIptablesRules:1129 : May need to update iptables package & kernel to support CHECKSUM rule.
23:38:47.818: 8445: error : virCommandWait:1229 : internal error Child process (dnsmasq --strict-order --bind-interfaces --pid-file=/usr/local/var/run/libvirt/network/default.pid --conf-file=  --except-interface lo --listen-address 192.168.122.1 --dhcp-range 192.168.122.2,192.168.122.254 --dhcp-lease-max=253 --dhcp-no-override) exited with status 1.
23:38:47.874: 8445: error : virCommandWait:1229 : internal error Child process (/sbin/iptables --table mangle --delete POSTROUTING --out-interface virbr0 --protocol udp --destination-port 68 --jump CHECKSUM --checksum-fill) exited with status 2.
23:38:47.986: 8445: error : ebiptablesDriverInit:3749 : internal error essential tools to support ip(6)tables firewalls could not be located
23:38:47.986: 8445: error : ebiptablesDriverInit:3758 : internal error firewall tools were not found or cannot be used
23:38:48.125: 8445: warning : lxcStartup:2128 : Unable to create cgroup for driver: No such device or address


別の端末から
virsh net-undefine default


libvirtd を再起動
virbr0に関するものは消えた
23:41:55.309: 8669: info : libvirt version: 0.8.8
23:41:55.309: 8669: error : ebiptablesDriverInit:3749 : internal error essential tools to support ip(6)tables firewalls could not be located
23:41:55.309: 8669: error : ebiptablesDriverInit:3758 : internal error firewall tools were not found or cannot be used
23:41:55.429: 8669: warning : lxcStartup:2128 : Unable to create cgroup for driver: No such device or address




mkdir /dev/cgroup
mount none -t cgroup /dev/cgroup



libvirtd を再起動
23:43:16.201: 8695: info : libvirt version: 0.8.8
23:43:16.201: 8695: error : ebiptablesDriverInit:3749 : internal error essential tools to support ip(6)tables firewalls could not be located
23:43:16.201: 8695: error : ebiptablesDriverInit:3758 : internal error firewall tools were not found or cannot be used



多分大丈夫


/usr/local/etc/libvirt/libvirtd.confを書き換える
listen_tcp = 1
unix_sock_group = "libvirt"
unix_sock_rw_perms = "0770"
auth_unix_ro = "none"
auth_unix_rw = "none"


libvirtグループを追加
groupadd -g 10000 libvirt

kvmを起動してみる(一般ユーザーで)
 open /dev/kvm: No such file or directory
 Could not initialize KVM, will disable KVM support

modprobe kvm_intel

もう一度kvm
 open /dev/kvm: Permission denied
グループkvmを追加

groupadd -g 10001 kvm
kvmを実行するユーザーはkvmグループにも追加
usermod -a --group kvm ユーザーID
chgrp kvm /dev/kvm
chmod g+rw /dev/kvm
エラーが出なくなった
 
kvmを使うために必要なコマンドを/etc/rc.localに追加
/bin/mkdir /dev/cgroup
/bin/mount none -t cgroup /dev/cgroup
/sbin/modprobe kvm_intel
/bin/chgrp kvm /dev/kvm
/bin/chmod g+rw /dev/kvm