縮小版NetBSDの作成

Install image等のために、一部の機能を省いたNetBSDの作成。

kernel設定

とりあえず不要なdeviceや機能は外す。さらに、SYMTAB_SPACEを削減するため、 kernelを作ったあとにdbsymを走らせてkernel symbol tableの大きさを確認。

$ cd ~/netbsd-5.0/usr/src/sys/arch/landisk/compile/obj/GENERIC 
$ ~/netbsd-5.0/usr/bin/shle--netbsdelf-dbsym -v netbsd
got SYMTAB_SPACE symbols from netbsd
loaded symbol table from netbsd
mapped netbsd
symtab size 266596, space available 266596
done copying image to file offset 0x160258
exiting
$ vi ~/netbsd-5.0/usr/src/sys/arch/landisk/conf/GENERIC.in
...

Symbol tableが266696byteであることがわかるので、GENERIC.inの SYMTAB_SPACEをそれにあわせて書き換える。

...
options    SYMTAB_SPACE=270000
...

mk.conf

いらない物を極力省くために、mk.confは次のようにする。

LOPPY_FLIST      = yes

MKCATPAGES        = no
MKCOMPAT          = no
MKDEBUGLIB        = no
MKDOC             = no
MKHESIOD          = no
MKHTML            = no
MKINET6           = no
MKINFO            = no
MKIPFILTER        = no
MKISCSI           = no
MKKERBEROS        = no
MKLDAP            = no
MKLINT            = no
MKMAINTAINERTOOLS = no
MKMAN             = no
MKMANZ            = yes
MKNLS             = no
MKPAM             = no
MKPCC             = no
MKPF              = no
MKPIE             = no
MKPOSTFIX         = no
MKPROFILE         = no
MKPUFFS           = no
MKSKEY            = no
MKSTRIPIDENT      = yes
MKX11             = no
MKYP              = no
USE_HESIOD        = no
USE_INET6         = no
USE_KERBEROS      = no
USE_LDAP          = no
USE_PAM           = no
USE_SKEY          = no
USE_SSP           = no
USE_YP            = no

STRIPFLAG         = -s
CPUFLAGS          = -m4-nofpu
COPTS             = -Os

Compact Flashの用意

# dd if=/dev/zero of=/dev/rsd0d bs=512

# fdisk -i /dev/rsd0d

We haven't written the MBR back to disk yet.  This is your last chance.
Should we write new partition table? [n] y

# disklabel -I -i /dev/rsd0d
...
partition> P
4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:    250000         0     4.2BSD      0     0     0  # (Cyl.      0 -    122*)
 c:    250000         0     unused      0     0        # (Cyl.      0 -    122*)
 d:    250368         0     unused      0     0        # (Cyl.      0 -    122*)

# newfs -m 3 /dev/rsd0a
...

# installboot -v /dev/rsd0a /usr/mdec/bootxx_ffsv1
File system:         /dev/rsd0a
Primary bootstrap:   mdec/bootxx_ffsv1

# mount /dev/sd0a /mnt

# cp /usr/mdec/boot /mnt

Install

# cd /mnt

# tar xfvzp /sets/kern-GENERIC.tgz
./netbsd
tar: ustar vol 1, 1 files, 2682880 bytes read, 0 bytes written in 6 secs (447146 bytes/sec)

# tar xfvzp /sets/etc.tgz 
...
tar: ustar vol 1, 289 files, 727040 bytes read, 0 bytes written in 28 secs (25965 bytes/sec)

# tar xfvzp /sets/base.tgz 
...
tar: ustar vol 1, 2819 files, 41338880 bytes read, 0 bytes written in 382 secs (108216 bytes/sec)

# cd /mnt/dev

# ./MAKEDEV all

# mknod -m 640 power c 55 2

必要に応じて不要な部分を削除。

# rm -r -f /mnt/rescue /mnt/usr/lkm/* /mnt/usr/X11R6 /mnt/usr/X11R7

設定

/mnt/etc/rc.conf
余計なdaemon類を走らせる必要は無いので、次のようにrc.confを書く。
# Load the defaults in from /etc/defaults/rc.conf (if it's readable).
# These can be overridden below.
#
if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf
fi

# If this is not set to YES, the system will drop into single-user mode.
#
rc_configured=YES

hostname=usl5p.example.com
defaultroute=192.168.1.254
# dhclient=YES
# dhclient_flags="re0"

inetd=YES
nfs_client=NO
postfix=NO
sshd=NO
powerd=YES
cron=NO
ntpd=NO
named=NO
no_swap=YES

update_motd=NO
ccd=NO
raidframe=NO
cgd=NO
quota=NO
/mnt/etc/fstab
Swapは不要なので、root のみ
/dev/wd0a  /         ffs    rw  1 1
ptyfs      /dev/pts  ptyfs  rw  0 0
/mnt/etc/ifconfig.re0
inet 192.168.1.100 netmask 255.255.255.0
/mnt/etc/inetd.conf
...
telnet          stream  tcp     nowait  root    /usr/libexec/telnetd    telnetd
...
/mnt/etc/ttys
telnetからroot loginを許可する。
console "/usr/libexec/getty std.9600"   unknown on secure
pts/0 none network off secure
pts/1 none network off secure
/mnt/etc/motd
NetBSD 5.0

Welcome to NetBSD!
/mnt/etc/sysctl.conf
...
kern.no_sa_support?=0
...
ShellをBashに
# chroot /mnt
# chsh -s /bin/sh
# exit
/mnt/root/.profile
お好みに応じて変更
#       $NetBSD: dot.profile,v 1.18 2005/02/22 09:12:17 sketch Exp $

set -o tabcomplete
set -o emacs

export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin
export PATH=${PATH}:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin

export HOST="$(hostname)"

if [ -z "$TERM" ] || [ "unknown"=="$TERM" ]; then
  export TERM=vt100
fi

umask 022
#ulimit -c 0
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias la='ls -aF'

export ENV=/root/.shrc

/mnt/sets の用意

binary/sets以下をCompact Flashに入れる。

Disk imageの吸い出し

これで縮小版NetBSDは完成。起動すると/var/log/messageなどが書かれて汚れ るので、起動する前にdisk imageを吸い出しておく。

# umount /mnt
# dd if=/dev/rsd0d of=netbsd-mini.img bs=512 count=250000

ご意見、ご感想は、花房 真広 <webmaster@hanabusa.net>まで。メールする前にtop pageの注意書を読んでください。