hnakamur’s blog

ものすごい勢いで忘れる私のために未整理でもいいからとりあえずメモ

ラベル Linux-VServer の投稿を表示しています。 すべての投稿を表示
ラベル Linux-VServer の投稿を表示しています。 すべての投稿を表示

2008-12-05

bcapabilitiesにSYS_CHROOTを追加したらホストからゲストにsshできた



ホストからゲストにsshできないの続きです。


util-vserver:Capabilities and Flags - Linux-VServerを見て



SYS_CHROOT


という内容で/etc/vservers/vserver1/bcapabilitiesファイルを作成してからvserver1起動して、ホストからゲストにsshしてみるといけましたよ!


util-vserver:Capabilities and Flags - Linux-VServerのページはここ数日何回か見てたんだけどdefault bcaps are:というところにSYS_CHROOTが含まれているし、/etc/vservers/vserver1/bcapabilitiesファイルは無いからデフォルトになってるんだろうな、と思って試してなかったのですが、明示的に指定すれば行けたってことですね。


となるとreducecap --showで表示された情報ってのもなんだったのか。あれはホストで実行するとホストのcapabilitiesを表示しているのかな?これも要調査。というかまだまだ基本的なところがわかってないな。


まあ何はともあれ一歩前進。





2008-12-04

ホストからゲストにhttpではアクセスできた







guest# yum install httpd
guest# /etc/init.d/httpd start
guest# echo 'It works' > /var/www/html/index.html
guest# wget http://192.168.0.3/


でまず自分自身では取得できた(192.168.0.3はguestのIPアドレス。lo(loopback)が無い状態なのでlocalhostとは指定できない状況)


次にホストから



host$ wget http://192.168.0.3/


でも取得できた。





ホストからゲストにsshできない




  • ホスト: Debian etch

  • ゲスト: CentOS 5.2


ホストからゲストにsshで入ろうとすると



$ ssh 192.168.0.3
Read from socket failed: Connection reset by peer
$


となってしまいます。


ゲストの/var/log/secureには



Dec 3 16:58:51 vserver1 sshd[4587]: fatal: chroot("/var/empty/sshd"): Operation not permitted


という行ができてた。


Capabilities and Flags - Linux-VServerのSystem capabilities (bcaps) のSYS_CHROOTが無いのかなと思ったけどutil-vserver:Capabilities and Flags - Linux-VServerを見てもデフォルトで入ってるらしい。/etc/vservers/vserver1/にbcapabilitiesというファイルは無い状態なのでデフォルト値になってるはず。


vserver development mailing list: [Vserver] "Defaults Caps of chcontext" and whish listというページでreducecapというコマンドの存在を知り(dpkg -S /usr/sbin/reducecapによるとutil-vserverパッケージに含まれる)、ホストで実行してみると



# reducecap --show
Capability Effective Permitted Inheritable
...
CAP_SYS_RAWIO X X


となるので、やはり許可されているようだ。


今後さらに調査が必要ということで一旦棚上げ。





2008-11-25

Linux-VServerのゲストOSとしてCentOSをインストール



Building Guest Systems - Linux-VServerを読みながらトライ中。


まずは、yumを入れておく。



# aptitude install yum


Howtos Linux-Vserver With LVM And Quotas - 5dollarwhitebox.org Media Wikiというページを見つけたのでこれに従ってやってみる。



# aptitude update && aptitude upgrade
# aptitude install lvm2 util-vserver coreutils


NTFSのsparse fileの手順に沿ってcentos5guest.ext3という名前で8Gのsparse fileを作り、coLinuxを以下のような設定で再起動。



kernel=C:\coLinux\coLinux_VServer\vmlinux-2.6.22.18-vs2.2.0.6-co-0.7.3
hda1=c:\coLinux\etch.ext3
hdb1=c:\coLinux\swap.img
hdc1=c:\coLinux\centos5guest.ext3
root=/dev/hda1
initrd=C:\coLinux\coLinux_VServer\initrd.img-2.6.22.18-vs2.2.0.6-co-0.7.3
mem=512
eth0=slirp
eth1=tuntap


物理ボリューム、ボリュームグループ、論理ボリューム作成



# pvcreate /dev/hdc1
Physical volume "/dev/hdc1" successfully created
# vgcreate vg0 /dev/hdc1
Volume group "vg0" successfully created
# lvcreate -L1024 -n vserver1 vg0
Logical volume "vserver1" created


ファイルシステム作成とマウント



# mke2fs -j /dev/vg0/vserver1
...
# mkdir /var/lib/vservers/vserver1
# mount -t ext3 /dev/vg0/vserver1 /var/lib/vservers/vserver1


仮想サーバー作ろうとしたらエラー。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
ERROR: Can not find configuration for the distribution 'centos5';
please read http://linux-vserver.org/HowToRegisterNewDistributions
for information how to add support for your own distribution.



# dpkg -L util-vserver | lv


で確認してみると、確かにcentos5の設定は無かった(centos4ならあったけど)。検索してみるとvserver development mailing list: Re: [Vserver] CentOS 5 building guest machineで、util-vserverのバージョンを0.30.213にあげれば入っているとのこと。dpkg -l util-vserverしてみると手元のは0.30.212-1。Debian -- パッケージ検索結果 -- util-vserverを見るとtestingレポジトリにはもっと新しいのが登録されているそうだ。


tesingからutil-vserverをインストールしたときの手順は一部のパッケージだけ手動でtestingレポジトリから取得するに書きました。


というわけでもう一度やってみると今度は別のエラー発生。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
mount: mount point /etc/rpm does not exist
rm: cannot remove directory `/etc/vservers/.defaults/vdirbase/vserver1': Device or resource busy


#444224 - util-vserver: please include /etc/rpm and suggest:yum - Debian Bug report logsという記事を見て



# mkdir -p /etc/vservers/vserver1/rpmetc
# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
vserver-topdirectory '/etc/vservers/.defaults/vdirbase/vserver1' and/or configuration at '/etc/vservers/vserver1'
exist already; please try to use '--force', or remove them manually.


とやってみたらまたエラーに。


ここは素直に/etc/rpmを作るほうがよさそうと思いやってみると



# rm -r /etc/vservers/vserver1/
# mkdir /etc/rpm
# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
You are using a version of yum which is insecure and broken in chroot
related operations; either apply the patches shipped in the 'contrib/'
directory of util-vserver, or ask the author of yum to apply them
(preferred).

In the meantime, 'vyum' will continue with dirty hacks which might not
work when the vserver is running and local DOS attacks are possible.

Execution will continue in 5 seconds...


と出て固まった。と思ったのは間違いで別の端末でps見たら起動してるようです。しばらく待っているとyumでインストールするときのリストが出てきたのでゲストOS用にパッケージをインストールしているようです。


待ってる間に別の端末でyumをtestingからインストール。かなりいろいろつられてバージョンアップするそうだが気にせずGO!



# aptitude show yum | grep Version:
Version: 2.4.0-3.1
# aptitude show yum -t testing | grep Version:
Version: 3.2.12-1.2
# aptitude install yum -t testing


長くなってきたので続きは別エントリにします。





coLinux入りカーネルソースにLinux-VServerのカーネルパッチ当ててカーネルビルド成功



OpenVZがうまくいかなかったので、Welcome to Linux-VServer.org - Linux-VServerにトライしてみることにした。


Downloads - Linux-VServerArchivesリンクをたどり、ftp://ftp.linux-vserver.org/pub/kernel/vs2.2/patch-2.6.22.18-vs2.2.0.6.diff を見つけてダウンロード(こちらはカーネルの各バージョンごとにそれぞれパッチがあった)。patchを当てるとはじかれたのは2箇所でcoLinuxと#includeがかち合ってるだけだった。これなら手で修正可能だ。


coLinuxのソース取得とカーネル一旦作成。



# cd /usr/src
# wget http://www.colinux.org/snapshots/stable-colinux-20080524.tar.gz
# tar zxf stable-colinux-20080524.tar.gz
# cd stable-colinux-20080524
# ./configure
# make kernel


(そういえば、make kernelのときだかにwww.kernel.orgからカーネルソースをダウンロードしようとしてタイムアウトになり困ったので、iij.ad.jpとかからwgetして/usr/src/downloadに置いた。)


Linux-VServerのカーネルパッチ取得とパッチ当て。



# cd /usr/src/download/
# wget ftp://ftp.linux-vserver.org/pub/kernel/vs2.2/patch-2.6.22.18-vs2.2.0.6.diff
# cd /usr/src/build/linux-2.6.22.18-source
# patch -p1 < /usr/src/download/patch-2.6.22.18-vs2.2.0.6.diff
# find . -name '*.rej'
./arch/i386/kernel/traps.c.rej
./mm/page_alloc.c.rej



# cat ./arch/i386/kernel/traps.c.rej
***************
*** 56,61 ****
#include <asm/stacktrace.h>

#include <linux/module.h>

#include "mach_traps.h"

--- 56,63 ----
#include <asm/stacktrace.h>

#include <linux/module.h>
+ #include <linux/vs_context.h>
+ #include <linux/vserver/history.h>

#include "mach_traps.h"



# cat ./mm/page_alloc.c.rej
***************
*** 41,46 ****
#include <linux/pfn.h>
#include <linux/backing-dev.h>
#include <linux/fault-inject.h>

#include <asm/tlbflush.h>
#include <asm/div64.h>
--- 41,48 ----
#include <linux/pfn.h>
#include <linux/backing-dev.h>
#include <linux/fault-inject.h>
+ #include <linux/vs_base.h>
+ #include <linux/vs_limit.h>

#include <asm/tlbflush.h>
#include <asm/div64.h>


*.rejの内容を見ながら手動パッチ当て。


次にcoLinuxのメモ - カーネルのコンパイルのカーネルのコンフィグレーションの部分を実行。CUIからロードするのは面倒なので直接.configにコピーした。



# cd /usr/src/build/linux-2.6.22.18-source
# cp /usr/src/devel-colinux-20080226/conf/linux-2.6.22.18-config .config
# make menuconfig



  • 「File systems → DOS/FAT/NT Filesystems → Default codepage」を「932」

  • 「File systems → DOS/FAT/NT Filesystems → Default iocharset for FAT」 を「utf-8」


としてみた(参照先はcharsetはeuc-jpだったのだがutf-8にしてみた)。NFSは使わないつもりなので設定省略。


とりあえずmakeでやってみた。



# make


しかし途中でコンパイルエラー。



CC [M] fs/squashfs/inode.o
fs/squashfs/inode.c: In function 'squashfs_get_cached_block':
fs/squashfs/inode.c:367: error: 'TASK_UNINTERRUPTIBLE' undeclared (first use in this funct
ion)


grepで探すとTASK_UNINTERRUPTIBLEはinclude/linux/sched.hで定義されていることが判明。ググってみるとRe: [ANN] Squashfs 3.3 released | KernelTrapRe: [ANN] Squashfs 3.3 released | KernelTrapという記事を発見。間違って必要な#includeを削ってリリースしてしまったということらしい。というわけで手で修正。



--- linux-2.6.22.orig/fs/squashfs/inode.c 2007-07-12 14:57:22.000000000 +0400
+++ linux-2.6.22/fs/squashfs/inode.c 2007-07-12 14:57:53.000000000 +0400
@@ -31,6 +31,7 @@
#include <linux/vfs.h>
#include <linux/vmalloc.h>
+#include <linux/sched.h>
#include <linux/smp_lock.h>

#include "squashfs.h"



再度makeしてみると今度は通りました!ついでに設定をバックアップ。



# make
# cp .config colinux-2.6.22.18-1


ビルドが通ることを確認したので、debianの流儀でパッケージを作成。



# make-kpkg --initrd --revision=colinux.1 kernel_image kernel_headers
# cp -p vmlinux vmlinux-2.6.22.18-vs2.2.0.6-co-0.7.3


パッケージインストール。



# mv /lib/modules/2.6.22.18-co-0.7.3/ /lib/modules/2.6.22.18-co-0.7.3.old
# cd /usr/src/build/
# dpkg -i linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3_colinux.1_i386.deb


こんなエラーが出た。



Selecting previously deselected package linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3.
(Reading database ... 16479 files and directories currently installed.)
Unpacking linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 (from linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3_colinux.1_i386.deb) ...
Done.
Setting up linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 (colinux.1) ...
Running depmod.
Finding valid ramdisk creators.
Using mkinitramfs-kpkg to build the ramdisk.
Could not find postinst hook script [update-grub].
Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'
dpkg: error processing linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 (--install):
subprocess post-installation script returned error exit status 2
Errors were encountered while processing:
linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3


coLinuxのメモ - カーネルのコンパイルに書いてあったこれを忘れてた。



# vi /etc/kernel-img.conf
--- /etc/kernel-img.conf.orig 2007-04-17 17:22:27.000000000 -0400
+++ /etc/kernel-img.conf 2008-11-24 01:33:35.000000000 -0500
@@ -6,5 +6,5 @@
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
-postinst_hook = update-grub
-postrm_hook = update-grub
+#postinst_hook = update-grub
+#postrm_hook = update-grub


もう一度dpkgを実行したら/lib/modules/に既に同じ名前のがあると言われたので抜けて消して再実行。



# rm -rf /lib/modules/2.6.22.18-vs2.2.0.6-co-0.7.3/
# dpkg -i /usr/src/build/linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3_colinux.1_i386.deb
(Reading database ... 16823 files and directories currently installed.)
Preparing to replace linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 colinux.1 (using linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3_colinux.1_i386.deb) ...
Done.
Unpacking replacement linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 ...
Setting up linux-image-2.6.22.18-vs2.2.0.6-co-0.7.3 (colinux.1) ...
Running depmod.
Finding valid ramdisk creators.
Using mkinitramfs-kpkg to build the ramdisk.
Not updating initrd symbolic links since we are being updated/reinstalled
(colinux.1 was configured last, according to dpkg)
Not updating image symbolic links since we are being updated/reinstalled
(colinux.1 was configured last, according to dpkg)


WinSCPを使って以下の2つのファイルをWindowsにコピー。



  • /usr/src/build/linux-2.6.22.18-source/vmlinux-2.6.22.18-vs2.2.0.6-co-0.7.3

  • /boot/initrd.img-2.6.22.18-vs2.2.0.6-co-0.7.3


coLinuxの設定ファイルでkernelとinitrdに上記をそれぞれ設定してcoLinuxを起動してみたら無事ブートしてログインできました。


あとはutil-vserverパッケージをインストールしておく。



# aptitude install util-vserver





2008-11-24

Linux-VServerのゲストOSとしてCentOSをインストール(続き)



Linux-VServerのゲストOSとしてCentOSをインストールの続き


ゲストOSのインストールが遅いのはyumのダウンロードのミラーが遅いことに気づき、/usr/lib/util-vserver/distributions/centos5/yum.repo.d/CentOS-Base.repoを書き換えたら、よくなった。


しかし、次の問題が発生。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
You are using a version of yum which is insecure and broken in chroot
related operations; either apply the patches shipped in the 'contrib/'
directory of util-vserver, or ask the author of yum to apply them
(preferred).

In the meantime, 'vyum' will continue with dirty hacks which might not
work when the vserver is running and local DOS attacks are possible.

Execution will continue in 5 seconds...
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 236, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 152, in main
(result, resultmsgs) = base.buildTransaction()
File "/var/lib/python-support/python2.4/yum/__init__.py", line 626, in buildTransaction
(rescode, restring) = self.resolveDeps()
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 663, in resolveDeps
CheckDeps, checkinstalls, checkremoves, missing = self._resolveRequires(errors)
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 746, in _resolveRequires
thisneeds = self._checkInstall(txmbr)
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 788, in _checkInstall
provs = self.tsInfo.getProvides(*req)
File "/var/lib/python-support/python2.4/yum/transactioninfo.py", line 428, in getProvides
result = self.getOldProvides(name, flag, version)
File "/var/lib/python-support/python2.4/yum/transactioninfo.py", line 421, in getOldProvides
for pkg, hits in self.rpmdb.getProvides(name, flag, version).iteritems():
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 397, in getProvides
pkgs = self.searchProvides(name)
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 156, in searchProvides
return self.searchPrco(name, 'provides')
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 139, in searchPrco
mi = ts.dbMatch(tag, name)
TypeError: unknown key type


testingのyumを入れたのは失敗でしたよ。というわけでstableのに戻します(もっといいやり方があるかもしれないけどとりあえずこれで)。



# aptitude uninstall yum
# aptitude install yum


vyumがyumについてエラーを言うのはYum-patch - Linux-VServerで対応するようだ。これは後日やってみよう。


とりあえず今度こそvserverのbuildはエラーなく終わりました。


Building Guest Systems - Linux-VServerに従って動作確認。



root@debian:~# vserver vserver1 start
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
root@debian:~# vserver vserver1 enter
bash-3.2# pwd
/
bash-3.2# ifconfig
eth0 Link encap:Ethernet HWaddr 00:FF:2A:6F:C4:80
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
Interrupt:2

bash-3.2# logout
root@debian:~#


おー、動きましたよ。


停止と状態確認はこれで。



root@debian:~# vserver vserver1 stop
Shutting down kernel logger: [FAILED]
Shutting down system logger: [ OK ]
Starting killall: [ OK ]
root@debian:~# vserver vserver1 status
Vserver 'vserver1' is stopped


上のFAILEDのときにコンソールでは以下のようなメッセージが表示されてた。



vxW: [xid #0] !!! limit: de75704c[VM,9] = 75 on exit.
vxW: [xid #0] !!! limit: dd34b04c[VM,9] = 76 on exit.
vxW: [xid #0] !!! limit: dd3a904c[VM,9] = 153 on exit.
vxW: [xid #0] !!! limit: dd11704c[VM,9] = 29 on exit.


これもおいおい調べよう。





ブログ アーカイブ