BuildrootでQEMUで動作するLinux i386イメージを作る

Buildrootを使用してQEMUで動作するLinux i386イメージを作成します。

Buildroot
http://buildroot.uclibc.org/

<使用環境>
CentOS 5.6
buildroot-2009.11.tar.gz

Buildroot実行環境の整備

Buildrootを実行するために必要なパッケージをインストールします。

# yum install binutils bzip2 gawk gcc gcc-c++ gettext make ncurses-devel patch unzip wget zlib-devel

Buildrootのダウンロード

Buildrootをダウンロードします。
buildroot-2009.11.tar.gz を使用します。

Buildrootダウンロードサイト
http://buildroot.uclibc.org/download.html

$ cd ~/
$ wget http://git.buildroot.net/buildroot/snapshot/buildroot-2009.11.tar.gz

Buildrootの展開

ダウンロードしたファイルbuildroot-2009.11.tar.gzを展開して、そのディレクトリに入ります。

$ tar zxvf buildroot-2009.11.tar.gz
$ cd buildroot-2009.11

ダウンロードファイル格納用ディレクトリの作成とリンク

ダウンロードファイル格納用ディレクトリを作成し、そのシンボリックリンクをbuildroot-2009.11ディレクトリに作成します。

$ mkdir ../dl
$ ln -s ../dl

[bld@localhost ~]$ pwd
/home/bld
[bld@localhost ~]$ ls -l
合計 6084
drwxr-xr-x 2 bld bld    4096 10月  6 20:02 Desktop
drwxrwxr-x 9 bld bld    4096 10月  6 20:19 buildroot-2009.11
-rw-rw-r-- 1 bld bld 6198256 10月  5 22:00 buildroot-2009.11.tar.gz
drwxrwxr-x 2 bld bld    4096 10月  6 00:12 dl
-rwxr-xr-x 1 bld bld     368 10月 12 10:26 qemu_start.sh
[bld@localhost ~]$ 

[bld@localhost buildroot-2009.11]$ ls -l
合計 104
-rw-rw-r--   1 bld bld 11458 12月  1  2009 CHANGES
-rw-rw-r--   1 bld bld 17987 12月  1  2009 COPYING
-rw-rw-r--   1 bld bld 10130 12月  1  2009 Config.in
-rw-rw-r--   1 bld bld 19497 12月  1  2009 Makefile
-rw-rw-r--   1 bld bld   806 12月  1  2009 TODO
drwxrwxr-x   2 bld bld  4096 12月  1  2009 configs
lrwxrwxrwx   1 bld bld     5 10月  5 22:02 dl -> ../dl
drwxrwxr-x   3 bld bld  4096 12月  1  2009 docs
drwxrwxr-x 306 bld bld 12288 12月  1  2009 package
drwxrwxr-x   3 bld bld  4096 12月  1  2009 scripts
drwxrwxr-x  21 bld bld  4096 12月  1  2009 target
drwxrwxr-x  13 bld bld  4096 12月  1  2009 toolchain
[bld@localhost buildroot-2009.11]$ 

Buildrootのコンフィギュレーション

Buildroot ConfigurationでBuildrootのコンフィギュレーションを行います。

$ make menuconfig

.config - buildroot v2009.11 Configuration

Target Architecture (i386) --->
Target Architecture Variant (i686) --->
Target options --->
Build options --->
Toolchain --->
Package Selection for the target --->
Target filesystem options --->
Kernel --->
---
Load an Alternate Configuration File
Save an Alternate Configuration File

Buildrootのコンパイル

Buildrootをコンパイルします。

$ make

コンパイル中に、Linux Kernelのコンフィギュレーションが必要になります。

コンパイル後、 buildroot-2009.11/output/images ディレクトリに、
 Linux image: bzImage
 root file system: rootfs.i686.ext2
が作成されます。

[bld@localhost images]$ pwd
/home/bld/buildroot-2009.11/output/images
[bld@localhost images]$ ls -l
合計 11744
-rw-rw-r-- 1 bld bld 8368528 10月  6 21:45 bzImage
-rw-rw-r-- 1 bld bld 3637248 10月 12 10:28 rootfs.i686.ext2
[bld@localhost images]$ 

Linuxイメージの起動

QEMUでlinuxイメージを起動します。

次のような起動スクリプト qemu_start を作成します。
$ nano qemu_start.sh

#!/bin/sh
LOCATION="/home/bld/buildroot-2009.11/output/images"
KERNEL="bzImage"
DISK="rootfs.i686.ext2"
qemu -kernel $LOCATION/$KERNEL \
-hda $LOCATION/$DISK \
-boot c \
-m 128 \
-append "root=/dev/hda rw" \
-localtime \
-no-reboot \
-name Linux \
-k ja \

qemu_start には実行権限を付けておきます。
$ chmod +x qemu_start.sh

QEMUを起動します。
$ ./qemu_start.sh

root でログインします。
パスワードは必要ありません。

ネットワークインターフェースの設定

/etc/network/interfaces を編集します。
# vi /etc/network/interfaces

eth0の設定を追加します。

auto eth0
iface eth0 inet dhcp

2011.10.12