「Bonsai Linuxの楽しみ方 / Bonsai Kitの使い方」
目次
====
- Bonsai(盆栽) Linux Projectとは?
- 概要
- 特徴
- 開発フロー
- 開発環境準備
- カーネル作成
- ユーザランド作成 ptxdistを使って自動生成
- 起動方法(1) User-mode Linuxを使って、Linux上で仮想的に起動
- 起動方法(2) coLinuxを使って、Windows上で仮想的に起動
- 起動方法(3) GRUBを使ってHDから起動
- 起動方法(4) GRUBを使ってCFから起動
- 起動方法(5) isolinuxを使ってCD-ROMから起動
- システム構成
Bonsai(盆栽) Linux Projectとは?
===============================
主に技術的興味を満たすために作る*小型計算機研究所流*組み込みLinux作り。
どんなLinuxをどう育てるか、そのプロセスを楽しみ、みんなと共有するプロジェクト。
「そんなの作って何に使うの?」
「育てるだけでイイじゃん、盆栽だもの」
組み込み開発未経験者が気軽に挑戦できるよう、ハード寄りな知識なしで楽しめるように心掛けています。
また、Open Sourceを利用しますので費用もかかりません。Embedded Linux に興味をもったらすぐ試して
頂ける、組み込み開発の第一歩として十分に敷居の低い環境を目指します。
皆で自分のBonsaiを育てましょう。できあがったLinuxは皆さんのオリジナル。当研究所は何の権利も主張
しません、趣味でもお仕事にも自由にお使い下さい(^_^)
概要
====
- RAM DISKだけで動く小型Linux
→ 16MB以下のinitrdだけの小さなLinux。
- 自動化・仮想化された開発環境/手順の開発
→ 開発/試験環境としてptxdist, User-mode Linux, coLinuxの採用。
- 起動方法は自由自在
→ 出来上がったLinuxは、CF,CD-R,USB Memory,Networkからの直接起動、Linux/Windows上の
仮想環境からでも起動可能。
- ロイヤリティフリーで利用できる開発環境の提供
→ オープンソースを利用し、Bonsai Linuxもオープンソースとします。
- 利用する主なオープンソース
- Linux kernel (http://www.kernel.org/)
- Busy Box (http://busybox.net/)
- ptxdist (http://www.pengutronix.de/software/ptxdist_en.html)
- User-mode Linux (http://user-mode-linux.sourceforge.net/)
- coLinux (http://www.colinux.org/)
- GRUB (http://www.gnu.org/software/grub/)
- syslinux (http://syslinux.zytor.com/)
特徴
====
- RAM DISK運用
メモリ上だけで動くLinuxですから、突然の断電にも、CFメディアの書き換え回数制限などへの
心配もありません。
- どこからでも起動
一度作られたLinuxイメージファイルは、HD,CF,USB Memory,CD-ROMから起動できます。
また、Linux/Windows上の仮想環境上でも利用可能。ネットワークからのPXEブート、DOSからの
起動も可能です。
- 開発の敷居が低い
組込み開発環境として一般的なPCとオープンソースを活用します。専用ボード/商用Linux/クロス
開発などが不要、同時に開発コストを低減します。
- 組込み知識不要
ハードウェア/BIOS/マシン語など、組み込みに必須と言われている知識なしに、まず挑戦して
みることが可能です。自分で新規に開発する部分はあまりなく、すでにあるオープンソースを
組み合わせて利用するだけ。Linuxにある程度詳しい方ならすぐに使いこなせます。
- スクラッチから半自動build
Linuxカーネルにはソースから簡単にbuildできる仕組みが準備されています。"ptxdist"の利用
により、同様にユーザランドも簡単に作成できるようになりました。ptxdistは必要なソース/
パッチを自らネットワーク上よりGETし、コンパイルを行います。数時間でほぼ半自動的にソー
スからのbuildができます。
- エミュレーション環境で動作実験
完成したユーザランドを、User-mode Linux, coLinux上で仮想的に起動させることが可能です。
リブート不要で動作確認が出来、システムの作り込みに便利です。
- どこでもシステム開発
エミュレーション環境があるということは実機がなくても動作確認ができるということです。
どこにでもあるLinux機に、入手が簡単なオープンソースの組み合わせは、まさに「どこでも
システム開発」環境を実現します。
- 多くのアーキテクチャに発展可能
解説するにあたり簡単化のためにハイテックシステム社製MicroPCを開発環境/実行環境として
利用しますが、Intel系PCでCFがついた機種なら同様に作業可能ですし、実行環境がARM,PPCで
あっても一部手順をのぞき同様に開発可能です。
- フリーソフトウエア
フリーソフトウエアを組み合わせて利用し、当然 Bonsai Linuxのオリジナル部分もフリーソフト
ウェアとします。趣味に仕事に自由に使ってください。
開発フロー
==========
| 開発環境準備:
| PC(Intel互換) + Linux (RedHat, Debian GNU/Linux他) + 高速回線
| Linux Kernel source + ptxdist + User Mode Linux + coLinux + GRUB + syslinux
|
| <--------------------------+
| |
| カーネル作成: | Linux kernelの 仕様決定&build
| どんなカーネルが必要なのか | % make menuconfig
| 機能/ドライバの検討 | % make dep
| | % make bzImage
+----------------------------+
|
| <--------------------------+
| |
| ユーザランド作成: | ptxdistを利用しユーザランドの仕様決定&build
| どんなコマンドやデーモンが | % make menuconig
| 必要なのか検討 | % make world
| |
+----------------------------+
|
| <--------------------------+
| |
| ユーザランド動作実験: | User Mode Linuxを利用し仮想的な起動実験
| 準備したコマンドが使えるか | % linux ubd0=uml.diff,userland.img eth0=tuntap,,,127.0.0.10
| boot時にデーモンが起動する |
| のか実験 |
| |
+----------------------------+
|
| <--------------------------+
| |
| Linuxイメージのリリース: | 各種メディアからの起動可能なようにブートローダを選択、実装。
| HD,CF,CD-ROMなど各種メディ | HD,CF : GRUB
| アから起動可能なように加工 | CD-ROM: isolinux
| する |
| |
+----------------------------+
|
v
Bonsai Linux 完成
開発環境準備
============
- ディレクトリ構成
~/bonsai -+- linux (Kernel作業用)
|
+- ptxdist (ptxdist作業用)
|
+- uml (User Mode Linux作業用)
|
+- syslinux (syslinux作業用)
|
+- cdr (CD-R作成用)
|
+- bin (各種ツール)
|
+- src (各種ソース)
|
+- image -+ (ファイルシステムイメージファイル)
| +- bzImage.eden
| +- userland.img
| +- isolinux.iso
|
+- conf --+ (設定ファイル保存用)
+- dot.config_kernel Kernel用の.configファイル
+- dot.config_ptxdist ptxdist用の.configファイル
+- dot.config_uml UML用の.configファイル
+- rootfs_etc ptxdistで生成したユーザランド用のetcディレクトリ
/mnt -+- cf (CF mount用)
|
+- img (image file mount用)
- 各種sourceの入手
% cd ~/bonsai/src
% wget http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.27.tar.bz2
% wget http://ovh.dl.sourceforge.net/sourceforge/user-mode-linux/uml-patch-2.4.27-1.bz2
% wget http://www.pengutronix.de/software/ptxdist/download/v0.7/ptxdist-0.7.3.tgz
% wget http://freshmeat.net/redir/syslinux/10177/url_bz2/syslinux-2.11.tar.bz2
% wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.07.tar.gz
- UMLの準備
% tar jxf src/linux-2.4.27.tar.bz2
% cd linux-2.4.27
% bzcat ../src/uml-patch-2.4.27-1.bz2 | patch -p1
% cd ..
% mv linux-2.4.27 uml
% cd uml
% make menuconfig ARCH=um
Module不使用、proc,tmpfsを利用(devpts,devfsは不使用)。
UMLのためにTUN/TAPとhostfsを使用。
Code maturity level options -> OFF
General Setup -> Host filesystem -> ON
Loadable Module support -> Enable loadable module support -> OFF
Character Devices -> Unix98 PTY support -> OFF
Block devises -> virtual block device -> ON
Block devises -> Always do synchronous disk IO for UBD -> ON
Block devises -> COW device -> ON
Block devises -> RAM disk support -> Default RAM disk size -> (16384)
Block devises -> RAM disk support -> Initial RAM disk (initrd) support -> ON
Network Devices -> Virtual network device -> Ethertap transport -> ON
Network Devices -> Virtual network device -> TUN/TAP transport -> ON
File System -> Virtual memory file system support -> ON
File System -> /proc file system support -> ON
% setenv LANG C
% make dep ARCH=um
% make linux ARCH=um
% strip linux
% mv linux ~/bonsai/bin
カーネル作成
============
Linuxのカーネルを作成します
% cd ~/bonsai
% tar jxf src/linux-2.4.27.tar.bz2
% ln -s linux-2.4.27 linux
% cd linux
% setenv LANG C
% make mrproper (既存の.configを消します)
(make oldconfig 以前のバージョンの.configがあればコンバート)
% make menuconfig (自分好みにカスタマイズ)
Loadable Module support -> Enable loadable module support -> OFF
Processor type and features -> Prosessor family -> "CyrixIII/VIA-C3" (←Eden用ですが、お好みで)
Block devises -> Loopback device support" -> ON
Block devises -> RAM disk support" -> ON -> "Default RAM disk size" -> 16384
Block devises -> RAM disk support" -> "Initial RAM disk (initrd) support -> ON
ATA/IDE/MFM/RLL support -> IDA,ATA Block devises -> PCI IDE chipset support -> Cyrix CS5530 MediaGX -> ON
ATA/IDE/MFM/RLL support -> IDA,ATA Block devises -> PCI IDE chipset support -> VIA82CXXX -> ON
SCSI support -> SCSI support -> ON
Network device support -> Ethernet(10or100Mbit) -> EISA,VLB,PCI and on board controllers -> RealTek RTL-8139 -> ON
Network device support -> PPP support -> ON
Input core support -> Input core support -> Keyboard -> ON
Input core support -> Input core support -> Mouse support -> ON
Charatter devices -> Unix89 PTY support -> OFF
File systems -> Ext3 journalling file system support
File systems -> DOS FAT fs support
File systems -> Virtual memory file system support
File systems -> ISO 9660 CDROM file system support
File systems -> /proc file system support
Sound -> Sound card support -> VIA 82C686 Audio Codec
USB support -> Support for USB -> UHCI Alternate Driver (JE) support
USB support -> Mass Storage support
USB support -> Support for USB -> USB Human Interface Device (full HID) support
% make dep
% make clean
% make bzImage
% ls ~/bonsai/linux/arch/i386/boot/bzImage (コンパイルに約20分)
ユーザランド作成
================
ptxdistを使ってLinuxのユーザランドを作成します
% cd ~/bonsai
% tar zxf src/ptxdist-0.7.3.tgz
% ln -s ptxdist-0.7.3 ptxdist
% cd ptxdist
% setenv LANG C
% make i586-generic-glibc_config
% make menuconfig (自分好みにカスタマイズ)
- General Options -> Target Options -> Code Optimization (586)
- General Options -> Toolchain/Ceosstool -> Build Cross Toolchain with Crosstool -> GCC Version (3.4.1)
- General Options -> Root Filesystem -> Populate root filesystem -> on
- Core System -> Kernel -> Don't compile kernel -> on
- Shell & Console tools -> Compile BusyBox -> on
-> General Configration -> Support for devfs -> off
-> General Configration -> Use the devpts filesystem for Unix98 PTYs -> off
-> Login/Password Management Utilities -> addgroup/delgroup/adduser/deluser/password/su
-> Networking Utilities -> hostname/ifconfig/ping/route/telnet/telnetd
- Network Tools -> Networking Apps -> NTP/ppp/proftpd
- Disk and file utils -> grub -> on
% set path = (~/bonsai/ptxdist/local/i586-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin $path)
% make world
必要なソース、パッチ類は全て自動的にインターネットへ取りに行きます。
通信手段を確保しておいてください。Eden/667MHz+256MBRAMで5時間程度。
% ls ~/bonsai/ptxdist/root (出来上がりを確認)
- /devの整備
% su root
# cd ~/bonsai/ptxdist/root/dev
# cp -dpR /dev/hda[1-6] .
# cp -dpR /dev/hdc[1-6] .
# cp -dpR /dev/tty[0-3] .
# cp -dpR /dev/ttyp[0-3] .
# cp -dpR /dev/ptyp[0-3] .
# cp -dpR /dev/shm .
# cp -dpR /dev/pts .
# cp -dpR /dev/console .
# cp -dpR /dev/null .
# cp -dpR /dev/log .
# cp -dpR /dev/urandom .
# mknod ubd0 b 98 0
# mknod ubd1 b 98 16
# mknod ubd2 b 98 32
# mknod ubd3 b 98 48
# mknod cobd0 b 117 0
- /etcの整備
% cd ~/bonsai/ptxdist/root/etc
% vi inittab
-----
#
# /etc/inittab
#
console::sysinit:/etc/init.d/rcS
# Start an "askfirst" shell on the console
console::askfirst:/bin/sh
# login prompt on the console
#console::respawn:/sbin/getty 38400 console
# put a getty on a serial line (for a terminal)
#console::respawn:/sbin/getty -L ttyS0 9600 vt100
#console::respawn:/sbin/getty -L 115200 /dev/tts/0 vt100
# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
-----
# vi passwd
----
root:x:0:0:Linux User,,,:/:/bin/sh
sshd:x:100::SSH Server:/var/run/sshd:/bin/false
ftp:x:11:101:ftp user:/home:/bin/false
user:x:500:500:Linux User,,,:/:/bin/sh
----
# vi shadow (password:"root")
----
root:$1$$oCLuEVgI1iAqOA8pwkzAg1:12515:0:99999:7:::
sshd:!:0:0:99999:7:::
ftp::0:0:99999:7:::
user::12515:0:99999:7:::
----
# vi group
----
root:x:0:
users:x:100:
ftp:x:101:
user:x:500:
----
# vi hosts
----
127.0.0.1 localhost
----
# vi proftpd.conf
----
ServerName "ProFTPD server"
ServerType standalone
Port 21
Umask 022
MaxInstances 3
ScoreboardFile /var/log/proftpd.scoreboard
PidFile /var/log/proftpd.pid
User ftp
Group ftp
AllowAll
----
# vi init.d/rcS
-----
#!/bin/sh
#
echo
echo "Bonsai Linux project (build:20050505)"
echo
# mount file system
/bin/mount -t proc proc /proc
dev=`mount | grep " / " | awk '{print $1}'`
case $dev in
"/dev/ubd0" ) # for User-mode Linux
echo "mount /dev/ubd0 as /"
/bin/mount -t ext2 -o remount,rw /dev/ubd0 /
/bin/mount -t hostfs -o /home hostfs /home
;;
"/dev/cobd0" ) # for coLinux
echo "mount /dev/cobd0 as /"
/bin/mount -t ext2 -o remount,rw /dev/cobd0 /
;;
"/dev/root" ) # for userland on RAM disk
echo "mount /dev/root as /"
/bin/mount -t ext2 -o remount,rw /dev/root /
;;
"/dev/hdc1" ) # for userland on HD
echo "mount /dev/hdc1 as /"
/bin/mount -t ext2 -o remount,rw /dev/hdc1 /
;;
* )
;;
esac
# network configure
hostname="bonsai"
# for static IP
# address="192.168.2.100"
# gwaddress="192.168.2.254"
# /bin/hostname $hostname
# /sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0
# /sbin/ifconfig eth0 $address netmask 255.255.255.0
# /sbin/route add default gw $gwaddress
# echo "$address $hostname" >> /etc/hosts
# for dynamic IP (DHCP)
/bin/hostname $hostname
/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0
/sbin/udhcpc --hostname=$hostname --interface=eth0 --script=/etc/udhcpc.script
address=`/sbin/ifconfig -a | sed 's/:/ /' | grep 'Bcast' | awk '{print $3}'`
echo "$address $hostname" >> /etc/hosts
# service start
# echo "running rc.d services..."
# run-parts -a start /etc/rc.d
/sbin/syslogd
/usr/sbin/telnetd
/usr/sbin/proftpd &
-----
# chmod +x init.d/rcS
起動方法(1) User-mode Linuxを使って、Linux上で仮想的に起動
===========================================================
ユーザランドが入ったルートファイルイメージを作成し、UMLを使って仮想的にブートします。
起動実験毎にPCのリブートは必要ないのでシステムの作り込みに利用できます。
- 空のroot file image(16MB)の作成
% cd ~/bonsai
% mkdir image
% /bin/dd if=/dev/zero of=image/userland.img bs=16777216 count=1
% /sbin/mke2fs image/userland.img
% su root
# /bin/mount -o loop image/userland.img /mnt/img
- ユーザランドを書き込む
# cd ~/bonsai/ptxdist/root
# tar cf - . | ( cd /mnt/img ; tar xf - )
- カーネルの書き込み
カーネルの書き込みは不要です。UMLが起動用のカーネルとなります。
- 起動実験
# umount /mnt/img
# exit
% cd ~
% bonsai/bin/linux ubd0=uml.diff,bonsai/image/userland.img eth0=tuntap,,,192.168.2.254
起動方法(2) coLinuxを使って、Windows上で仮想的に起動
=====================================================
ユーザランドが入ったルートファイルイメージを作成し、coLinuxを使って仮想的にブートします。
Windows上で動作の確認が出来、何かと便利です。
- 空のroot file image(16MB)の作成
% cd ~/bonsai
% mkdir image
% /bin/dd if=/dev/zero of=image/userland.img bs=16777216 count=1
% /sbin/mke2fs image/userland.img
% su root
# /bin/mount -o loop image/userland.img /mnt/img
- ユーザランドを書き込む
# cd ~/bonsai/ptxdist/root
# tar cf - . | ( cd /mnt/img ; tar xf - )
- カーネルの書き込み
カーネルの書き込みは不要です。coLinuxが起動用のカーネルとなります。
- 起動実験
# umount /mnt/img
# exit
Windowsを起動し、Linux上で準備したuserland.imgを準備しておきます。
以下、Windowsでの作業です。
http://www.colinux.org/ より、coLinuxをダウンロード。
(http://jaist.dl.sourceforge.net/sourceforge/colinux/coLinux-0.6.1.exe)
インストーラを起動し、C:\Program Files\coLinux\ (デフォルト)へインストールします。
userland.imgもC:\Program Files\coLinux\userland.imgへコピーします。
C:\Program Files\coLinux\default.colinux.xml を編集
-----
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
root=/dev/cobd0
-----
以下のコマンドで起動します。
DOS Prompt> % cd C:\Program Files\coLinux
DOS Prompt> % colinux-daemon.exe -c default.colinux.xml
起動方法(3) GRUBを使ってHD上から起動
=====================================
既存のHD上の別な領域にカーネルとユーザランドのイメージをコピーし、GRUBで起動します。
RedHatや最近のDebianなどすでにGRUBが入ったシステム上で、手軽な起動の実験として利用できます。
- 空のroot file image(16MB)の作成
% /bin/dd if=/dev/zero of=image/userland.img bs=16777216 count=1
% /sbin/mke2fs image/userland.img
% su root
# /bin/mount -o loop image/userland.img /mnt/img
- ユーザランドを書き込む
# cd ~/bonsai/ptxdist/root
# tar cf - . | ( cd /mnt/img ; tar xf - )
# umount /mnt/img
# mkdir /ramlinux
# cp ~/bonsai/image/userland.img /ramlinux
- カーネルの書き込み
# cp ~/bonsai/linux/arch/i386/boot/bzImage /ramlinux
- GRUB
cd /boot/grub
vi menu.lst
-----
...
title Bonsai Linux
root (hd0,0)
kernel /ramlinux/bzImage root=/dev/ram0 ro noswap
initrd /ramlinux/userland.img
savedefault
boot
-----
起動方法(4) GRUBを使ってCF上から起動
=====================================
CFをマウントしカーネルとユーザランドをコピーしリブート、実際にCFからブートします。
- CFの初期化
# /sbin/fdisk /dev/hdc (CF上にhdc1としてLinuxパーティションを作成)
# /sbin/mke2fs /dev/hdc1 (hdc1にext2のファイルシステムを作成)
# /bin/mount /dev/hdc1 /mnt/cf (/mnt/cfとしてmount)
- ユーザランドの書き込み
# cd ~/bonsai/ptxdist/root
# tar cf - . | ( cd /mnt/cf ; tar xf - )
- カーネルの書き込み
# cp ~/bonsai/linux/arch/i386/boot/bzImage /mnt/cf/boot/bzImage
- Boot loaderの書き込み
HDからLinuxをbootしCFのMBRにGRUBを書き込む。
sgate1,stage2 などはすでにCF上にあることが前提(ptxdistで作成)。
# ls /mnt/cf/boot/grub
# /sbin/grub
grub> root (hd1,0) hd0かhd1かはBIOSが見つけている順。bootしたデバイスがhd0になる
grub> setup (hd1) hd1つまりCFのMBRにGRUBをインストール
grub> quit
# vi /mnt/cf/boot/grub/grub.conf
-----
default=0
timeout=10
title Bonsai Linux
root (hd0,0)
kernel /boot/bzImage ro root=/dev/hdc1
-----
# cd /mnt/cf/boot/grub
# ln -s grub.conf menu.lst
起動方法(5) isolinuxを使ってCD-ROMから起動
===========================================
- isolinuxを準備
% cd ~/binsai
% tar zxf src/syslinux-3.07.tar.gz
% ln -s syslinux-3.07 syslinux
% mkdir cdr; mkdir cdr/isolinux
% cp syslinux/isolinux.bin cdr/isolinux
% vi cdr/isolinux/isolinux.cfg
-----
default BonsaiLinux
prompt 1
timeout 50
display boot.msg
LABEL BonsaiLinux
kernel bzImage
append root=/dev/ram initrd=userland.img ramdisk_size=16384
-----
% vi cdr/isolinux/boot.msg
-----
^L
Bonsai Linux Project
====================
Bonsai is the art of growing dwarfed, ornamentally shaped trees
by special methods of culture in small pots.
Bonsai Linux helps you to plant your small garden with linux-tree
and please enjoy the beauties of your linux world.
Koichiro Takemaru (http://www.takemaru,com/) 2005/05/05
-----
% cp linux/arch/i386/boot/bzImage cdr/isolinux
% cp image/userland.img cdr/isolinux
% chmod 755 cdr/isolinux
% chmod 644 cdr/isolinux/*
% ls cdr/isolinux
boot.msg bzImage isolinux.bin isolinux.cfg userland.img
% mkisofs -o ~/bonsai/image/isolinux.iso
-b isolinux/isolinux.bin -c isolinux/boot.cat
-no-emul-boot -boot-load-size 4 -boot-info-table -r -V "BONSAI LINUX" ~/bonsai/cdr
% ls -la ~/bonsai/image/isolinux.iso
何かのライティングソフトを用いてイメージをCD-Rに焼いてください。
システム構成
============
$ df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/ubd0 15863 6304 8740 42% /
hostfs 18516460 5078876 12496980 29% /home
$ ps -ef
PID Uid VmSize Stat Command
1 root 536 S init
2 root SW [keventd]
3 root SWN [ksoftirqd_CPU0]
4 root SW [kswapd]
5 root SW [bdflush]
6 root SW [kupdated]
7 root SW [scsi_eh_0]
8 root SW [mtdblockd]
29 root 524 S /sbin/syslogd
31 root 360 S /usr/sbin/telnetd
33 root 568 S /bin/sh
34 ftp 1060 S proftpd: (accepting connections)
$ free
total used free shared buffers
Mem: 28812 12672 16140 0 100
Swap: 0 0 0
Total: 28812 12672 16140