TenForward

技術ブログ。はてなダイアリーから移転しました

LXC (3)

さて,最低限の sshd 実行がコンテナ内で出来たので,次は Debian を動かしてみました.

lxc を make すると,lxc-debian というコマンドがインストールされますが,これは chroot 環境を作るのに,内部で debootstrap を使っていますので,Plamo では動きません (Debian 系だったら,カーネルの準備が出来れば,これを実行するだけでコンテナ環境を一つ出来あがるということです).

lxc-debian は単なるシェルスクリプトですから,内部でやっていることをなぞれば,Plamo Linux 上でも Debian コンテナを作るのは可能です.以下のような手順で作りました.

  1. OpenVZ用の precreated なテンプレートキャッシュを取得.これは OpenVZ で使うコンテナ用のテンプレートで,単にコンテナ用の chroot 環境を tar.gz したものです.これを展開すれば,そのまま Debian 環境です.ダウンロードしたのは http://ftp.iij.ad.jp/pub/openvz/template/precreated/debian-5.0-x86.tar.gz です.
  2. これを適当な所で展開します."rootfs.debian" というディレクトリを作っているのは,lxc-debian スクリプトがこういうディレクトリを作製し,その中に debootstrap で環境を構築するからです.
    # mkdir rootfs.debian
    # cd rootfs.debian
    # tar zxvf /path/to/debian-5.0-x86.tar.gz
  3. /usr/bin/lxc-debian スクリプトを手元にコピーします.スクリプトのうち,debootstrap を実行している部分をコメントアウトします.後で patch を示します.
  4. 先ほど "rootfs.debian" ディレクトリを作製したディレクトリ (= rootfs.debianの親ディレクトリ) で lxc-debian を実行します (実行するトコはどこでも良いんですけど.lxc-debian 実行中に指定可能なので.).
    # ./lxc-debian create
    What is the name for the container ? [debian]
    What hostname do you wish for this container ? [debian]
    What IP address do you wish for this container ? [172.20.0.21] 192.168.0.100
    What is the gateway IP address ? [172.20.0.1] 192.168.0.1
    What is the MTU size ? [1500]
    Specify the location of the rootfs [./rootfs.debian]
    Specify the location for an extra fstab file [(none)]
    以上のように質問に答えると,"dpkg-reconfigure locales" の実行画面が開きますので,適当に設定してください.以上でスクリプトの実行は終わりです.
  5. 後は 2009-12-11 - TenForwardの日記 にあるようにブリッジを定義します.
  6. 以下を実行.
    # lxc-start -n debian
bash-3.2# export LANG=C
bash-3.2# lxc-start -n debian
INIT: version 2.86 booting
Activating swap...done.
Cleaning up ifupdown....
Loading kernel modules...FATAL: Could not load /lib/modules/2.6.31.6-plamoSMP-PAE-2/modules.dep: No such file or directory
Checking file systems...fsck 1.41.3 (12-Oct-2008)
done.
Setting kernel variables (/etc/sysctl.conf)...done.
Mounting local filesystems...done.
Activating swapfile swap...done.
Setting up networking....
Configuring network interfaces...if-up.d/mountnfs[eth0]: waiting for interface lo before doing NFS mounts (warning).
done.
Setting console screen modes and fonts.
INIT: Entering runlevel: 3
Starting system log daemon....
Starting OpenBSD Secure Shell server: sshd.
To enable saslauthd, edit /etc/default/saslauthd and set START=yes (warning).
Starting internet superserver: xinetd.
Starting Mail Transport Agent (MTA): sendmailhostname: Host name lookup failure
hostname: Host name lookup failure
.
Starting periodic command scheduler: crond.
Starting web server: apache2apache2: apr_sockaddr_info_get() failed for debian
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
.

Debian GNU/Linux 5.0 debian console

debian login: 

lxc-debian スクリプトを実行するとき,"configuration path" がないとか怒られたら,/var/lib/lxc ディレクトリがないんだと思いますので,作製してください.

lxcの変更点はこんな感じ.

3a4,5
> export LANG=C
> 
290c292
<     install_debian
    • -
> # install_debian