R.A. Epigonos et al.

[virtualbox] LXC on VirtualBox

debian on viatualbox on windows7 で LXC を使った仮想マシンを作成した時のまとめ。

ホスト側の作業

新しくインストールの hdd イメージ (10GiB) を作成。

> "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" createhd --filename "LXC-10GiB.vdi" --sizebyte 10737418240

VirtualBox ゲストに ssh で接続する場合は、VirtualBox 仮想マシン設定でNATからホストオンリーアダプタまたはブリッジアダプタにしておく。VirtualBox ゲスト内の LXC コンテナでネットワークを使うには、VirtualBox 仮想マシン設定でプロミスキャスモードをすべて許可にしておく。

debian インストール DVD で作成した hdd イメージにシステムをインストール。

ゲスト側の作業

cdrom: を コメントアウト

# sed -i \
	-e 's/^\(deb\(-src\|\) cdrom:\)/# \1/' \
	/etc/apt/sources.list \
	;

openssh-server のインストール。

# apt-get install --no-install-recommends openssh-server

ssh でログインした後の VirtualBox ゲスト側の作業

RecommendsとSuggestsパッケージは手作業で入れる方針

# cat << 'EOT' > "/etc/apt/apt.conf.d/01norecommend";
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOT
# apt-config dump \
	| grep -e 'APT::Install-';

LXC のインストール

# apt-get install lxc

ネットワーク設定。ブリッジの作成

# apt-get install bridge-utils
# vi /etc/network/interfaces
# grep -v -e '^$' -e '^#' /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto br0
iface br0 inet dhcp
        bridge_ports eth0

ブリッジが使えないなら、スイッチの作成

# apt-get install vde2
# vi /etc/network/interfaces
# grep -v -e '^$' -e '^#' /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
auto tap0
iface tap0 inet manual
  vde2-switch -t tap0
auto br0
iface br0 inet static
  bridge_ports tap0
  address 10.0.0.1
  netmask 255.255.255.0

コンテナの作成

# apt-get install debootstrap rsync
# lxc-create -n testlxc -t debian
(snip)
Root password is '********', please change !
# lxc-destroy -n testlxc
# LANG=C MIRROR=http://ftp.jp.debian.org/debian \
	lxc-create \
	-n testlxc \
	-t debian \
	-- --release sid --arch amd64 \
	;
(snip)
Root password is '********', please change !

VitualBox ゲスト (つまり LXC ホスト) からみた各インターフェイスの状態 (Flg、最後のフィールド) は以下。ここでもプロミスキャスモードをONにしておく必要がある。M がプロミスキャスモードを意味するフラグらしい。

# netstat --interface
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
br0        1500 0       712      0      0 0           493      0      0      0 BMRU
eth0       1500 0      5006      0      0 0           630      0      0      0 BMRU
lo        65536 0         0      0      0 0             0      0      0      0 LRU
veth******  1500 0       127      0      0 0           155      0      0      0 BMRU

リファレンス

  1. [Lxc-users] Bridged network interface inside Virtualbox VM
  2. The netstat Command
  3. networking - Understand netstat -i flgs - Unix & Linux Stack Exchange
  4. Linux netstat command explained with 10 examples (Real world Linux)

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-05-26T20:04:38+09:00
  2. Modified: 2008-05-26T20:04:38+09:00
  3. Generated: 2023-08-27T23:09:17+09:00