Introduction to NanoBSD - NanoBSD のイントロダクション

  • NanoBSD is a tool currently developed by Poul-Henning Kamp <phk@FreeBSD.org>. It creates a FreeBSD system image for embedded applications, suitable for use on a Compact Flash card (or other mass storage medium).
    • NanoBSD は Poul-Henning Kamp <phk@FreeBSD.org> によって開発されたツールです.これは,コンパクトフラッシュカード (または他の大容量な記憶装置媒体) に適した,組み込みアプリケーションの為の FreeBSD システムイメージを作成します.
  • It can be used to build specialized install images, designed for easy installation and maintenance of systems commonly called “computer appliances”. Computer appliances have their hardware and software bundled in the product, which means all applications are pre-installed. The appliance is plugged into an existing network and can begin working (almost) immediately.
    • 一般的に "コンピュータアプライアンス" と呼ばれるシステムの簡単な導入,保守の為にデザインされ,用途に特化したインストールイメージを構築する事が出来ます.コンピュータアプライアンスは,製品内にバンドルされたハードウェア,ソフトウェアを持っており,それは全てのアプリケーションがプリインストール済みである事を意味しています.アプライアンスは,既存のネットワークに接続して (ほぼ) 即座に作動させる事が出来ます.
  • The features of NanoBSD include:
    • NanoBSD は以下の機能を含んでいます:
  • Ports and packages work as in FreeBSD -- Every single application can be installed and used in a NanoBSD image, the same way as in FreeBSD.
    • FreeBSD の ports と packages が動作します -- FreeBSD と同様の作法で全てのアプリケーションを NanoBSD イメージにインストールし利用する事が可能です.
  • No missing functionality -- If it is possible to do something with FreeBSD, it is possible to do the same thing with NanoBSD, unless the specific feature or features were explicitly removed from the NanoBSD image when it was created.
    • 失われる機能はありません -- FreeBSD 上で何かを行う事が可能ならば,特定の機能又は機能らが NanoBSD イメージから明示的に削除されない限り,NanoBSD も同じ事を行う事が可能です.
  • Everything is read-only at run-time -- It is safe to pull the power-plug. There is no necessity to run fsck(8) after a non-graceful shutdown of the system.
    • 実行中は全て読み取り専用です -- 電源プラグを抜いても安全です.綺麗で無いシャットダウン後でも fsck(8) を実行する必要は全くありません.
  • Easy to build and customize -- Making use of just one shell script and one configuration file it is possible to build reduced and customized images satisfying any arbitrary set of requirements.
    • 構築,カスタマイズが簡単です -- たった 1つのシェルスクリプトと,1つの設定ファイルを利用し,要求しているどんな任意のセットも満たす,削減やカスタマイズされたイメージを構築する事が可能です.

NanoBSD Howto - NanoBSD の手引き

The design of NanoBSD - NanoBSD の設計

  • Once the image is present on the medium, it is possible to boot NanoBSD. The mass storage medium is divided into three parts by default:
    • メディア上にイメージが存在するならば,NanoBSD をブートする事が可能です.デフォルトではマスストレージメディアは3つのパートに分けられます.
  • Two image partitions: code#1 and code#2.
    • 2つのイメージパーティション: code#1 と code#2
  • The configuration file partition, which can be mounted under the /cfg directory at run time.
    • 動作時に /cfg ディレクトリにマウントする事が可能な,設定ファイル用のパーティション
  • These partitions are normally mounted read-only.
    • これらのパーティションは通常は読み取り専用でマウントされます.
  • The /etc and /var directories are md(4) (malloc) disks.
    • /etc と /var ディレクトリは md(4) (malloc) ディスクです
  • The configuration file partition persists under the /cfg directory. It contains files for /etc directory and is briefly mounted read-only right after the system boot, therefore it is required to copy modified files from /etc back to the /cfg directory if changes are expected to persist after the system restarts.
    • 設定ファイルパーティションは /cfg ディレクトリに存続します.これは /etc ディレクトリの為のファイルを含んでおり,システム起動時に一時的に読み取り専用でマウントされます.従って,変更をシステムの再起動後も継続する事を期待している場合 /etc 以下から /cfg ディレクトリに修正したファイルをコピーする事が必要となります.

Example 1. Making persistent changes to /etc/resolv.conf - 例1. /etc/resolv.conf の変更を持続させる

# vi /etc/resolv.conf
[...]
# mount /cfg
# cp /etc/resolv.conf /cfg
# umount /cfg
  • Note: The partition containing /cfg should be mounted only at boot time and while overriding the configuration files.
    • 注意: /cfg パーティションは起動時及び設定ファイルを上書きする間のみマウントして下さい.
  • Keeping /cfg mounted at all times is not a good idea, especially if the NanoBSD system runs off a mass storage medium that may be adversely affected by a large number of writes to the partition (i.e. when the filesystem syncer flushes data to the system disks).

Building a NanoBSD image - NanoBSD イメージの構築

  • A NanoBSD image is built using a simple nanobsd.sh shell script, which can be found in the /usr/src/tools/tools/nanobsd directory. This script creates an image, which can be copied on the storage medium using the dd(1) utility.
    • NanoBSD イメージは単純な nanobsd.sh シェルスクリプトを使用して構築可能で,/usr/src/tools/tools/nanobsd ディレクトリに存在します.このスクリプトでイメージを作成し,dd(1) ユーティリティを使用して記憶媒体にコピーする事が出来ます.
  • The necessary commands to build a NanoBSD image are:
    • NanoBSD イメージを構築するのに必要なコマンドは以下の通りです:
# cd /usr/src/tools/tools/nanobsd (1)
# sh nanobsd.sh (2)
# cd /usr/obj/nanobsd.full (3)
# dd if=_.disk.full of=/dev/da0 bs=64k (4)
  1. Change the current directory to the base directory of the NanoBSD build script.
    1. カレントディレクトリを NanoBSD ビルドスクリプトがあるディレクトリに移動します.
  2. Start the build process.
    1. ビルドプロセスを開始します.
  3. Change the current directory to the place where the built images are located.
    1. カレントディレクトリをビルドイメージが置かれている場所に移動します.
  4. Install NanoBSD onto the storage medium.
    1. 記憶媒体に NanoBSD をインストールします.

Customizing a NanoBSD image - NanoBSD イメージのカスタマイズ

  • This is probably the most important and most interesting feature of NanoBSD. This is also where you will be spending most of the time when developing with NanoBSD.
    • これは多分,NanoBSD の最も重要且つ,最も興味深い機能になります.これはあなたが NanoBSD を開発する時間の殆どを費やすだろう箇所になります.
  • Invocation of the following command will force the nanobsd.sh to read its configuration from the myconf.nano file located in the current directory:
    • 以下のコマンドの実行は,カレントディレクトリに置かれた myconf.nano ファイルから設定を読み出す事を nanobsd.sh に強制します:
# sh nanobsd.sh -c myconf.nano
  • Customization is done in two ways:
    • カスタマイズには2つの方法があります:
  1. Configuration options
    1. 設定オプション
  2. Custom functions
    1. カスタムな機能

Configuration options - 設定オプション

  • With configuration settings, it is possible to configure options passed to both the buildworld and installworld stages of the NanoBSD build process, as well as internal options passed to the main build process of NanoBSD. Through these options it is possible to cut the system down, so it will fit on as little as 64MB. You can use the configuration options to trim down FreeBSD even more, until it will consists of just the kernel and two or three files in the userland.
    • 設定により,NanoBSD のメインのビルドプロセスに渡される内部オプションと同様に,NanoBSD ビルドプロセスの buildworld と installworld の両方の段階に渡すオプションを設定する事が可能です.これらのオプションを通じて,システムを切り詰める事が可能で,その場合はたった 64MB に収める事も可能でしょう.さらに切り詰める為に FreeBSD の設定を使用する事が可能で,それによって kernel とユーザランドの 2,3 個のファイルまで落とす事も可能です.
  • The configuration file consists of configuration options, which override the default values. The most important directives are:
    • 設定ファイルは,設定オプションから成り立ち,それらはデフォルト値を無効にします.最も重要なディレクティブは以下の通りです:
  • NANO_NAME -- Name of build (used to construct the workdir names).
    • NANO_NAME -- 構築時の名前 (workdir 名を作成する為に使用されます).
  • NANO_SRC -- Path to the source tree used to build the image.
    • NANO_SRC -- イメージの構築の為に使用するソースツリーのパス
  • NANO_KERNEL -- Name of kernel configuration file used to build kernel.
    • NANO_KERNEL -- カーネル構築時に使用するカーネル設定ファイル名
  • CONF_BUILD -- Options passed to the buildworld stage of the build.
    • CONF_BUILD -- 構築時の buildworld ステージに渡されるオプション.
  • CONF_INSTALL -- Options passed to the installworld stage of the build.
    • CONF_INSTALL -- 構築時の installworld ステージに渡されるオプション.
  • CONF_WORLD -- Options passed to both the buildworld and the installworld stage of the build.
    • CONF_WORLD -- 構築時の buildworld と installworld の両方に渡されるオプション.
  • FlashDevice -- Defines what type of media to use. Check the FlashDevice.sub file for more details.
    • FlashDevice -- 使用するメディアのタイプを定義します.詳細については FlashDevice.sub ファイルをチェックして下さい.

Custom functions - カスタム関数

  • It is possible to fine-tune NanoBSD using shell functions in the configuration file. The following example illustrates the basic model of custom functions:
    • 設定ファイル内でシェル関数を使用して NanoBSD の微調整が可能です.以下の例はカスタム関数の基本モデルを説明します:
cust_foo () (
    echo "bar=topless" > \
        ${NANO_WORLDDIR}/etc/foo
)
customize_cmd cust_foo
  • A more useful example of a customization function is the following, which changes the default size of the /etc directory from 5MB to 30MB:
    • カスタマイズ機能のもっと有益な例は以下の通りで,/etc ディレクトリのデフォルトサイズを 5MB から 30MB に変更しています:
cust_etc_size () (
    cd ${NANO_WORLDDIR}/conf
    echo 30000 > default/etc/md_size
)
customize_cmd cust_etc_size
  • There are a few default pre-defined customization functions ready for use:
    • すぐに使用する事が出来る,デフォルトで事前準備が完了したカスタマイズ機能もあります:
  1. cust_comconsole -- Disables getty(8) on the VGA devices (the /dev/ttyv* device nodes) and enables the use of the COM1 serial port as the system console.
    1. cust_comconsole -- getty(8) VGA デバイス (/dev/ttyv* デバイスノード) を無効にし,システムコンソールとして COM1 シリアルポートの使用を可能にします.
  2. cust_allow_ssh_root -- Allow root to login via sshd(8).
    1. cust_allow_ssh_root -- sshd(8) への root ログインを許可します.
  3. cust_install_files -- Installs files from the nanobsd/Files directory, which contains some useful scripts for system administration.
    1. cust_install_files -- nanobsd/Files ディレクトリから,ファイルをインストールします.これはシステム管理の為に有益なスクリプトを含んでいます.

Adding packages - パッケージの追加

  • Packages can be added to a NanoBSD image using a custom function. The following fuction will install all the packages located in /usr/src/tools/tools/nanobsd/packages:
    • パッケージをカスタム関数を使用して NanoBSD イメージに追加する事が可能です.以下の関数は /usr/src/tools/tools/nanobsd/packages に置かれている全てのパッケージをインストールします:
mkdir -p ${NANO_WORLDDIR}/packages
cp /usr/src/tools/tools/nanobsd/packages/* ${NANO_WORLDDIR}/packages
chroot ${NANO_WORLDDIR} sh -c 'cd packages; pkg_add -v *;cd ..;'
rm -rf ${NANO_WORLDDIR}/packages
)
customize_cmd install_packages

Configuration file example - 設定ファイルの例

  • A complete example of a configuration file for building a custom NanoBSD image can be:
    • カスタム NanoBSD イメージを構築する為の設定ファイルの例は以下の様になるでしょう:
NANO_NAME=custom
NANO_SRC=/usr/src
NANO_KERNEL=MYKERNEL
NANO_IMAGES=2
CONF_BUILD='
NO_KLDLOAD=YES
NO_NETGRAPH=YES
NO_PAM=YES
'
CONF_INSTALL='
NO_ACPI=YES
NO_BLUETOOTH=YES
NO_CVS=YES
NO_FORTRAN=YES
NO_HTML=YES
NO_LPR=YES
NO_MAN=YES
NO_SENDMAIL=YES
NO_SHAREDOCS=YES
NO_EXAMPLES=YES
NO_INSTALLLIB=YES
NO_CALENDAR=YES
NO_MISC=YES
NO_SHARE=YES
'

CONF_WORLD='
NO_BIND=YES
NO_MODULES=YES
NO_KERBEROS=YES
NO_GAMES=YES
NO_RESCUE=YES
NO_LOCALES=YES
NO_SYSCONS=YES
NO_INFO=YES
'

FlashDevice SanDisk 1G

cust_nobeastie() (
    touch ${NANO_WORLDDIR}/boot/loader.conf
    echo "beastie_disable=\"YES\"" >> ${NANO_WORLDDIR}/boot/loader.conf
)

customize_cmd cust_comconsole
customize_cmd cust_install_files
customize_cmd cust_allow_ssh_root
customize_cmd cust_nobeastie

Updating NanoBSD - NanoBSD のアップデート

  • The update process of NanoBSD is relatively simple:
    • NanoBSD のアップデートプロセスは割とシンプルです:
  1. Build a new NanoBSD image, as usual.
    1. いつも通りに新しい NanoBSD イメージを構築して下さい.
  2. Upload the new image into an unused partition of a running NanoBSD appliance.
    The most important difference of this step from the initial NanoBSD installation is that now instead of using the _.disk.full file (which contains an image of the entire disk), the _.disk.image image is installed (which contains an image of a single system partition).'''
    1. 動作中の NanoBSD アプライアンスの未使用パーティションに新しいイメージをアップロードして下さい.
      最初の NanoBSD の導入との重要な違いは _.disk.full ファイル (ディスク全体のイメージが含まれています) を使用する代わりに,_.disk.image ファイル (単一のシステムパーティションイメージが含まれています) をインストールします.
  3. Reboot, and start the system from the newly installed partition.
    1. リブートを行い,新しくインストールされたパーティションからシステムを起動して下さい.
  4. If all goes well, the upgrade is finished.
    1. 全てが正常に完了したら,アップグレードは終了です.
  5. If anything goes wrong, reboot back into the previous partition (which contains the old, working image), to restore system functionality as fast as possible. Fix any problems of the new build, and repeat the process.
    1. 何か不具合が生じた場合,可能な限り送球にシステムの機能を復元する為に,前のパーティション (以前使用していたイメージが含まれています) を使用して起動して下さい.新しく構築した際の問題を解決する為に,このプロセスを繰り返してください.
  • To install new image onto the running NanoBSD system, it is possible to use either the updatep1 or updatep2 script located in the /root directory, depending from which partition is running the current system.
    • 動作中の NanoBSD システムに新しいイメージをインストールする際,どのパーティションが現在のシステムを実行しているかによって /root ディレクトリ内の updatep1 又は updatep2 スクリプトの何れかを使用する事が出来ます.
  • According to which services are available on host serving new NanoBSD image and what type of transfer is preferred, it is possible to examine one of these three ways:
    • どんなサービスがホスト上で使用可能か,どんなタイプの転送方法が望ましいかによって,新しい NanoBSD イメージの転送をこれら 3つの方法の内の 1つを試して下さい.

Using ftp(1) - ftp(1) を使う

  • If the transfer speed is in first place, use this example:
    • 転送スピードを第一とする場合はこの例を使って下さい:
      # ftp myhost
      get _.disk.image "| sh updatep1"

Using ssh(1) - ssh(1) を使う

  • If a secure transfer is preferred, consider using this example:
    • セキュアな転送を好む場合は,この例を使う事を検討して下さい:

Using nc(1) - nc(1) を使う

  • Try this example if the remote host is not running neither ftp(1) or sshd(8) service:
    • リモートホストが ftp(1)sshd(8) のサービスの何れも実行していない場合はこの例を試して下さい:
# ssh myhost cat _.disk.image.gz | zcat | sh updatep1
  1. At first, open a TCP listener on host serving the image and make it send the image to client:
    1. 最初に,イメージを抱えているホストへの TCP リスナをオープンし,イメージをクライアントに送信させて下さい:
      myhost# nc -l 2222 < _.disk.image
    2. Note: Make sure that the used port is not blocked to receive incoming connections from NanoBSD host by firewall.
      1. 注意: 使用するポートが,ファイアウォールによって NanoBSD ホストからの受信コネクションをブロックしていない事を確認して下さい.
  2. Connect to the host serving new image and execute updatep1 script:
    1. ホストの抱えているイメージに接続詞,updatep1 スクリプトを実行して下さい:
      # nc myhost 2222 | sh updatep1



Hiroyuki Seino http://www.seichan.org/ http://www.seichan.org/blog/
Today:4 Yesterday:0 All:14760