NetBSD on solid state
D a t e : 09 Decemb e r 200 3
A u t h o r : Roberto Trovò
RCSID = " $ H e a d e r $ "
1
Copyright 200 3 by Roberto
Discl a i m e r
I m p o r t a n t : THIS DOCUMENTATION IS PROVIDED "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
2
Table of Contents
1 Document aim .............................................................................................................................4
2 Introduction to CF......................................................................................................................4
3 HW & SW requirements .............................................................................................................4
4 Installation ...................................................................................................................................5
4.1 Create the "/tmp" symlink to "/var/tmp / " .........................................................................5
4.2 Create the "/var" image..........................................................................................................6
4.3 Create startup script ................................................................................................................6
4.4 Configure the rc.conf...............................................................................................................6
4.5 Delete unused files...................................................................................................................7
4.6 Make the root file system read- o n l y.....................................................................................7
4.7 Finishing the installation ........................................................................................................8
Appendix A.......................................................................................................................................9
Appendix B "dmesg" output ......................................................................................................11
Appendix C acknowledgments ..................................................................................................12
3
1 Document aim
T h e purpose of this document is to build a system running NetBSD on a Compact- Fla s h
c a r d (denoted as CF in the following), treated like to an ATA disk by means of CF-to- IDE
a d a p t e r . Using other solid state device like DiskOnChip , SmartMedia etc should be
p o s s i b l e as long as you take the necessary action.
T hi s document is the dump of my distributed documentation (notes write by hand,
d o w n l o a d e d Internet docs, mailing list search, etc. ). I hope this writing will help me and
a n y other reader to refine the ideas here contained.
2 Introduction to CF
TO DO!!!
I n s t a l l i n g an O.S. on CF should be useful for embedded application/box that run on
s m a l l motherboard that do not need standard hard disk that are a common failure point
for a PC, due to its moving mechanical components. Instead CF is a solid state hard disk
d evic e .
T h e O.S. installed on CF, due to its limits, must have the root file system mounted as
r e a d - o n l y . Instead /var and /tmp are mounted as read- wri t e to permit the normal O.S.
a c t ivi t y and therefore as memory file systems.
T h e r e are other installation method to achieve the same purpose, for example using
c o m p r e s s e d file system image, bootable cdrom, but according to me, these are quite
h a r d to update: if you modify any configuration files you should rebuild the image. With
o u r CF & read- o n l y file system you can switch temporary on writable file system:
(r e - m o u n t rootfs rw);
# mount -uw /
( m a k e the desired configuration changes);
(r e - m o u n t rootfs ro);
# mount -ur /
T hi s method could be useful to save data periodically, for example log files, collected
d a t a etc. But remember CF cards are built with a limited number of write cycle: after that
li m i t they were not operational. Even remember that all data on memory file system, that
i nf o r m a t i o n will be lost after a reboot. From a certain point of view this could be an
a d v a n t a g e : every time the system restart, it will start from the same initial configuration
st o r e d on CF. The shutdown operations are actually optional.
3 HW & SW requiremen t s
T h e requirements are:
4
· a i386 PC (for embedded box best if fan less) with 64MB RAM (32MB
RAM minimum I've tested) with a bootable CDROM (or floppy);
· CF card of 128MB of capacity (minimum 64MB I've tested);
· CF- t o - IDE adapter: this passive connector permits O.S. to treat the CF as
a n ATA disk;
· Ne tBSD 1.6.1 install CDROM media (the release I used);
4 Installation
I n s t a l l the CF card with the CF-IDE connector on the IDE controller (follow the
i n s t r u c t i o n accompanying your adapter ).
T h e n you should perform a typical NetBSD install on CF disk recognized as "wd0", with
t h e following suggestion:
· fdi sk: create only one NetBSD slice as big as the whole drive and mark it
as active (if you install NetBSD MBM it is optional);
· d i s kl a b e l : create only a partition, the root one; you could optimize the
file system to save space with newfs by reducing the number of inode ( -i
o p t i o n ) and to set zero the space reserved for super user (-m option), for
ex a m p l e :
# newfs -i -m 0
· d o not create the swap partition (it must not be used on CF);
· p e r f o r m a minimal install:
for a 64 MB CF:
base.tgz
etc. tg z
ker n e l . t g z
t o t a l install: 52MB
for a 128 MB CF:
base.tgz
etc. tg z
ker n e l . t g z
ma n.tgz
t o t a l install: 80MB
c o n fi g u r e the system as required (host name, IP, default gateway ...) and finishing the
ins t a ll a ti o n .
4.1 Create the "/tmp " symlink to "/var/t m p / "
Re b o o t in single user: this will ensure no program is retain open files under /var and /
5
tmp. Move any files under /tmp (not /tmp itself) in /var/tmp, even the dot ones like .
Xfree86 if exists, then create the symlink:
# cd /
# mv /tmp/* /tmp/.* /var/tmp/
# rmdir tmp
# ln -s var/tmp /tmp
4.2 Create the "/var" image
Cre a t e the tar- gzi p p e d image of /var file system:
# cd /
# tar -cvzf var-image.tar.gz var
a n d leave the image under "/".
4.3 Create startup script
You must create a startup script under /etc/rc.d to create the memory file system
( mf s) on "/var" and to load the tar- gzi p p e d image just created on it:
# cd /etc/rc.d
# vi mount_mfs_fs
(insert the mount_msf_fs script in the appendix A)
I n short the script mount a mfs on /var then load the files contained into the image
cr e a t e d .
T h e n you should set the correct startup script sequence:
ro o t -> mount_mfs_fs -> mountcritlocal
t o ensure this edit mountcritlocal and use the utility rcorder to check the real
seq u e n c e :
# vi /etc/mountcritlocal
and set the required script: # REQUIRE: mount_mfs_fs
# cd /etc/rc.d; rcorder * | less
t h i s should show the desired boot script sequence.
It is not necessary to create the /dev image as it will be created automatically by init, but
c o u l d be useful make a copy for /dev/MAKEDEV and /dev/MAKEDEV.local under /
sbin (even they do not seem used by init).
6
4.4 Configure the rc.conf
T hi s is the main startup configuration file: you should edit it to disable the swap device
a n d optionally set the hostname and other stuff you need:
# vi /etc/rc.conf
t h e n insert the lines:
no_swap="YES"
hostname="your_desired_name"
4.5 Delete unused files
Re m o v e unused files under /var and /dev because you will create them as mfs.
Re m e m b e r that we do not create the image dev- t a r . g z as we did for /var because the
i ni t program will do it automatically upon reboot.
The n :
# cd /
# rm -rf /var/*
D o not delete the /var directory as it will be the mount point;
# mv /dev /dev-old; mkdir /dev
D o not delete the special files because they (maybe) are open or used under the next
sh u t d o w n ;
Bef o r e reboot the system in single user again, please check that the mount point /dev
h a s the right permission as /dev-old: if not use chmod to fix it.
O n the next reboot you should see the following message:
...
warning: no /dev/console
init: Creating mfs /dev
...
Mounting memory file system: /var:
...
Mounting memory file systems: Done.
...
Re m o v e /dev-old to free space:
# rm -rf /dev-old
4.6 Make the root file system read- o n l y
Afte r the reboot in single user, edit the startup script /etc/rc.d/root and /
etc/fstab to mount read- o n l y the whole system:
# vi /etc/fstab
7
then change the "rw" into "ro": /dev/wd0a / ffs ro 1 1
# vi /etc/rc.d/root
t h e n change "mount -w /" into "mount -r /";
4.7 Finishing the installation
T h e n perform the final reboot: check the boot message to ensure all is correct.
T h e n login as root and check the mounted file system : you should see root as read- o n l y,
/dev and /var as memory file system.
Exa m p l e for mount and df:
# mount
/dev/wd0a on / type ffs (read-only, local)
mfs:7 on /dev type mfs (synchronous, local)
mfs:2601 on /var type mfs (synchronous, local)
# df
Filesystem 1K-blocks Used Avail Capacity iused ifree %iused
Mounted on
/dev/wd0a 121023 81240 33731 70% 5503 24959 18% /
mfs:7 103 51 47 52% 1642 372 81% /dev
mfs:2601 7903 1399 6108 18% 104 1942 5% /var
8
Appendix A
T hi s is the mount_mfs_fs script:
#!/bin/sh
#
# mount_mfs_fs: mount memory file system /var and /dev
# by roby, 23 jun 2003
# PROVIDE: mount_mfs_fs
# REQUIRE: root
. /etc/rc.subr
name="mount_mfs_fs"
start_cmd="mount_mfs_fs_start"
stop_cmd=":"
mount_mfs_fs_start()
{
echo "Mounting memory file system: /var:"
# Mount /dev fs
#
#mount_mfs none /dev
#
# build device files
#cd /dev
#/sbin/MAKEDEV all
# Mount /var fs
#
mount_mfs none /var
#
# build dir/files in var
tar -xvzpf /var-image.tar.gz -C /
echo "Mounting memory file systems: Done."
sleep 5
}
load_rc_config $name
run_rc_command "$1"
# END mount_mfs_fs script
T hi s is the mountcritlocal modified script:
#!/bin/sh
#
9
# $NetBSD: mountcritlocal,v 1.7 2002/04/29 12:29:53 lukem Exp $
#
# PROVIDE: mountcritlocal
# REQUIRE: mount_mfs_fs
. /etc/rc.subr
name="mountcritlocal"
start_cmd="mountcritlocal_start"
stop_cmd=":"
mountcritlocal_start()
{
# Mount critical filesystems that are `local'
# (as specified in $critical_filesystems_local)
# This usually includes /var.
#
mount_critical_filesystems local
# clean up left-over files.
# this could include the cleanup of lock files and /
var/run, etc.
#
rm -f /etc/nologin /var/spool/lock/LCK.* /
var/spool/uucp/STST/*
(cd /var/run && rm -rf -- *)
}
load_rc_config $name
run_rc_command "$1"
# END mount_mfs_fs script
T hi s is the root modified script:
#!/bin/sh
#
# $NetBSD: root,v 1.2 2000/05/13 08:45:09 lukem Exp $
#
# PROVIDE: root
# REQUIRE: fsck
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
10
{
#umount -a >/dev/null 2>&1
#mount /
umount -a
mount -r /
rm -f /fastboot
}
load_rc_config $name
run_rc_command "$1"
# END root script
Appendix B "dmesg" output
Ne t BS D 1.6.1 (GENERIC) #0: Tue Apr 8 12:05:52 UTC 2003
autobuild@tgm.daemon.org:/autobuild/ n e t b s d - 1- 6 / i 3 8 6 / O BJ / a u t o b u i l d / n e t b s d - 1 -
6 / s r c / s y s / a r c h / i 3 8 6 / c o m p i l e / G E N E R IC
c p u 0: IDT Pentium Pro compatible (686-class), 532.66 MHz
c p u 0: features 803035
c p u 0: features 803035
t o t a l memory = 247 MB
av a il memory = 223 MB
u s i n g 3195 buffers containing 12780 KB of memory
BIOS32 rev. 0 found at 0xfb500
m a i n b u s 0 (root)
p c i0 at mainbus0 bus 0: configuration mode 1
p c i0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
p c h b 0 at pci0 dev 0 function 0
p c h b 0 : VIA Technologies product 0x0601 (rev. 0x05)
ag p 0 at pchb0: aperture at 0xe0000000, size 0x10000000
p p b 0 at pci0 dev 1 function 0: VIA Technologies product 0x8601 (rev. 0x00)
p c i1 at ppb0 bus 1
p c i1: i/o space, memory space enabled
vga1 at pci1 dev 0 function 0: Trident Microsystems product 0x8500 (rev. 0x6a)
ws d i s p l a y 0 at vga1 kbdmux 1: console (80x25, vt100 emulation)
ws m u x 1: connecting to wsdisplay0
p c i b 0 at pci0 dev 7 function 0
p c i b 0: VIA Technologies VT82C686A (Apollo KX133) PCI-ISA Bridge (rev. 0x40)
p c ii d e 0 at pci0 dev 7 function 1: VIA Technologies VT82C686A (Apollo KX133) ATA100 controller
p c ii d e 0: bus- m a s t e r DMA support present
p c ii d e 0: primary channel configured to compatibility mode
p c ii d e 0: primary channel ignored (disabled)
p c ii d e 0: secondary channel configured to compatibility mode
w d0 at pciide0 channel 1 drive 0:
w d0: drive supports 1-sector PIO transfers, LBA addressing
w d0: 122 MB, 980 cyl, 8 head, 32 sec, 512 bytes/sect x 250880 sectors
w d0: 32-bit data port
p c ii d e 0: secondary channel interrupting at irq 15
w d0 ( p c ii d e 0: 1:0): using PIO mode 0
VIA Technologies VT82C686A SMBus Controller (miscellaneous bridge, revision 0x40) at pci0 dev 7
fu n c t i o n 4 not configured
rt k0 at pci0 dev 8 function 0: RealTek 8139 10/100BaseTX
rt k0: interrupting at irq 12
rt k0: Ethernet address 00:40:f4:8a:03:71
uk p h y 0 at rtk0 phy 7: Generic IEEE 802.3u media interface
uk p h y 0: OUI 0x000000, model 0x0000, rev. 0
11
ukphy0: 10baseT, 10baseT- FDX, 100baseTX, 100baseTX-FDX, auto
rt k1 at pci0 dev 9 function 0: RealTek 8139 10/100BaseTX
rt k1: interrupting at irq 10
rt k1: Ethernet address 00:40:f4:8a:03:70
uk p h y 1 at rtk1 phy 7: Generic IEEE 802.3u media interface
uk p h y 1: OUI 0x000000, model 0x0000, rev. 0
uk p h y 1: 10baseT, 10baseT- FDX, 100baseTX, 100baseTX-FDX, auto
rt k2 at pci0 dev 11 function 0: RealTek 8139 10/100BaseTX
rt k2: interrupting at irq 11
rt k2: Ethernet address 00:40:f4:8a:03:6f
uk p h y 2 at rtk2 phy 7: Generic IEEE 802.3u media interface
uk p h y 2: OUI 0x000000, model 0x0000, rev. 0
uk p h y 2: 10baseT, 10baseT- FDX, 100baseTX, 100baseTX-FDX, auto
is a0 at pcib0
p c k b c 0 at isa0 port 0x60-0x64
p c k b d 0 at pckbc0 (kbd slot)
p c k b c 0: using irq 1 for kbd slot
wsk b d 0 at pckbd0: console keyboard, using wsdisplay0
p c p p i 0 at isa0 port 0x61
m i d i 0 at pcppi0: PC speaker
sys b e e p 0 at pcppi0
is a p n p 0 at isa0 port 0x279: ISA Plug 'n Play device support
n px0 at isa0 port 0xf0-0xff: using exception 16
is a p n p 0 : no ISA Plug 'n Play devices found
bi o m a s k e3fd netmask fffd ttymask ffff
Ker n e l i z e d RAIDframe activated
b o o t device: wd0
ro o t on wd0a dumps on wd0b
ro o t file system type: ffs
wa r n i n g: no /dev/console
ws d i s p l a y 0: screen 1 added (80x25, vt100 emulation)
ws d i s p l a y 0: screen 2 added (80x25, vt100 emulation)
ws d i s p l a y 0: screen 3 added (80x25, vt100 emulation)
ws d i s p l a y 0: screen 4 added (80x25, vt100 emulation)
Appendix C acknowledgmen t s
I will thanks all the NetBSD mailing list user that helped me.
12