发新话题
打印

OpenBSD LiveCD制作过程

OpenBSD LiveCD制作过程

OpenBSD LiveCD制作过程

    刚开始接触OpenBSD时,我就很想使用OpenBSD LiveCD,但没找到。今年1月那时起就想自己做一个LiveCD,一个新年一过, 就将它放下了,现在又重新开始制作,今天写这篇文章只是我思路的一个开始,制作的LiveCD,还是完善,我会后断为其改进。

    制作过程:
一、        准备工作:
1、        一个能运行OpenBSD系统的所需要的必备文件,这里我就没像一些mini LiveCD那样对系统进行剔牛肉进行精减了,只是将一个能运行的系统的所有文件进行备份。而且如果备份的文件不大, 那制作出的LiveCD就很小, 我们就可以将这个备份的系统文件也一起放进CD中, 到时就可以用这个LiveCD安装系统,方法就是我今年1月3日写的《OpenBSD  另类安装法》。
2、        OpenBSD系统的源程序,我们在制作过程中需要编译光盘镜像。

二、        将备份的系统文件解开到一个目录下,我将以这个目录作为LiveCD的根目录制作CD,如/usr/live/。
三、        将OpenBSD源程序解开到/usr/src下,然后:
1、        安装必须的程序:
# cd /usr/src/distrib/crunch/crunchgen
#make; make install
#cd /usr/src/distrib/crunch/crunchide
#make; make install

2、        定制内核
内核文件是/usr/src/sys/arch/i386/conf/RAMDISK_CD,我们需要对这个文件进行修改,其中有三行最重要,一定不能少:
option  MFS
option  UNION
config  bsd root on cd0a
LiveCD运行于MFS上,而且它的根目录在CD上。

还有其它一些选项如:
option SMALL_KERNEL
option NO_PROPOLICE
option TIMEZONE=0
option DST=0
option RAMDISK_HOOKS
option MINIROOTSIZE=3560

需要将一些多余的东西删除,因此这个内核大小控制在2.88M以内, 太大时会编译失败。我的RAMDISK_CD是将/usr/src/sys/arch/i386/conf/GENERIC 和/usr/src/sys/conf/GENERIC这两个文章合并然后去掉一些内容整理出来的。在本文最后, 我将自己的RAMDISK_CD贴给大家参考一下。

3、        编译内核
# cd /usr/src/distrib/i386/ramdisk_cd
#make
成功后会在目录下生成cdrom36.fs这个文件,我们将这个文件复制到制作LiveCD的目录下/usr/live/。

四、        修改/usr/live/etc中的各类文件
1、fstab
   /dev/cd0a / cd9660 rw 0 0

2、rc
   OpenBSD启动时首先读取这个文件, 如果找不到它就会读取根目录下的/.profile文件进行初始配置。
   我的这个文件还没修改成功, ?时可以用用, 各位前辈帮我完善完善。
   
#        $OpenBSD: rc,v 1.251 2004/08/21 08:17:28 hshoexer Exp $

# System startup script run by init on autoboot
# or after single-user.
# Output and error are redirected to console by init,
# and the console is the controlling terminal.

# Subroutines (have to come first).

# Strip comments (and leading/trailing whitespace if IFS is set)
# from a file and spew to stdout

stripcom() {
        local _file="$1"
        local _line

        {
                while read _line ; do
                        _line=${_line%%#*}                # strip comments
                        test -z "$_line" && continue
                        echo $_line
                done
        } < $_file
}

# End subroutines

stty status '^T'

# Set shell to ignore SIGINT (2), but not children;
# shell catches SIGQUIT (3) and returns to single user after fsck.
trap : 2
trap : 3        # shouldn't be needed

HOME=/; export HOME
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

if [ $1x = shutdownx ]; then
        dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >/dev/null 2>&1
        chmod 600 /var/db/host.random >/dev/null 2>&1
        if [ $? -eq 0 -a -f /etc/rc.shutdown ]; then
                echo /etc/rc.shutdown in progress...
                . /etc/rc.shutdown
                echo /etc/rc.shutdown complete.

                # bring carp interfaces down gracefully
                for hn in /etc/hostname.carp[0-9]*; do
                        # Strip off /etc/hostname. prefix
                        if=${hn#/etc/hostname.}
                        test "$if" = "carp[0-9]*" && continue

                        ifconfig $if > /dev/null 2>&1
                        if [ "$?" != "0" ]; then
                                ifconfig $if down
                        fi
                done

                if [ "X${powerdown}" = X"YES" ]; then
                        exit 2
                fi

        else
                echo single user: not running /etc/rc.shutdown
        fi
        exit 0
fi

# Configure ccd devices.
if [ -f /etc/ccd.conf ]; then
        ccdconfig -C
fi

# Configure raid devices.
for dev in 0 1 2 3; do
        if [ -f /etc/raid$dev.conf ]; then
                raidctl -c /etc/raid$dev.conf raid$dev
        fi
done

# Check parity on raid devices.
raidctl -P all

swapctl -A -t blk

if [ -e /fastboot ]; then
        echo "Fast boot: skipping disk checks."
elif [ $1x = autobootx ]; then
        echo "Automatic boot in progress: starting file system checks."
#        fsck ?p      这一行要注释掉
        case $? in
        0)
                ;;
        2)
                exit 1
                ;;
        4)
                echo "Rebooting..."
                reboot
                echo "Reboot failed; help!"
                exit 1
                ;;
        8)
                echo "Automatic file system check failed; help!"
                exit 1
                ;;
        12)
                echo "Boot interrupted."
                exit 1
                ;;
        130)
                # interrupt before catcher installed
                exit 1
                ;;
        *)
                echo "Unknown error; help!"
                exit 1
                ;;
        esac
fi

trap "echo 'Boot interrupted.'; exit 1" 3

umount -a >/dev/null 2>&1

在内存中分挂载点,但这里我还需要上网找资料重写, 有一些错误。
echo 'mounting mfs union'
mount_mfs -s 16384 swap /tmp 2>&1
echo "Generating /tmp under MFS"

mount_mfs -s 16384 swap /var 2>&1
tar -xzpf /mfs/var.tgz -C / >/dev/null 2>&1
echo "Generating /var under MFS"

mount_mfs -s 16384 swap /etc 2>&1
tar -xzpf /mfs/etc.tgz -C / >/dev/null 2>&1
echo "Generating /etc under MFS"

mount_mfs -s 16384 swap /root 2>&1
tar -xzfp /mfs/root.tgz -C / >/dev/null 2>&1
echo "Generating /root under MFS"

# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
echo 'setting tty flags'
ttyflags -a

if [ -f /etc/sysctl.conf ]; then
(
        # delete comments and blank lines
        set -- `stripcom /etc/sysctl.conf`
        while [ $# -ge 1 ] ; do
                sysctl $1
                shift
        done
)
fi

# if there's no /var/db/host.random, make one through /dev/urandom
if [ ! -f /var/db/host.random ]; then
        dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 \
                >/dev/null 2>&1
        chmod 600 /var/db/host.random >/dev/null 2>&1
else
        dd if=/var/db/host.random of=/dev/urandom bs=1024 count=64 \
            > /dev/null 2>&1
        dd if=/var/db/host.random of=/dev/arandom bs=1024 count=64 \
            > /dev/null 2>&1
fi

# reset seed file, so that if a shutdown-less reboot occurs,
# the next seed is not a repeat
dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 \
    > /dev/null 2>&1

# clean up left-over files
rm -f /etc/nologin
rm -f /var/spool/lock/LCK.*
rm -f /var/spool/uucp/STST/*
(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
(cd /var/authpf && rm -rf -- *)

# save a copy of the boot messages
dmesg >/var/run/dmesg.boot

#echo 'starting system logger'
#m -f /dev/log
#if [ "X${named_flags}" != X"NO" ]; then
#        rm -f /var/named/dev/log
#        syslogd_flags="${syslogd_flags} -a /var/named/dev/log"
#fi
#if [ -d /var/empty ]; then
#        rm -f /var/empty/dev/log
#        mkdir -p -m 0555 /var/empty/dev
#        syslogd_flags="${syslogd_flags} -a /var/empty/dev/log"
#fi
#syslogd ${syslogd_flags}
#
#swapctl -A -t noblk

# /var/crash should be a directory or a symbolic link
# to the crash directory if core dumps are to be saved.
#if [ -d /var/crash ]; then
#        savecore ${savecore_flags} /var/crash
#fi

# build ps databases
#echo -n 'building ps databases:'
#echo -n " kvm"
#kvm_mkdb
#echo -n " dev"
#dev_mkdb
#echo "."

# check the password temp/lock file
if [ -f /etc/ptmp ]; then
        logger -s -p auth.err \
        'password file may be incorrect -- /etc/ptmp exists'
fi

echo clearing /tmp

# prune quickly with one rm, then use find to clean up /tmp/[lq]*
# (not needed with mfs /tmp, but doesn't hurt there...)
(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
    find . ! -name . ! -name lost+found ! -name quota.user \
        ! -name quota.group -execdir rm -rf -- {} \; -type d -prune)

[ -f /etc/rc.securelevel ] && . /etc/rc.securelevel
if [ X${securelevel} != X"" ]; then
        echo -n 'setting kernel security level: '
        sysctl kern.securelevel=${securelevel}
fi

if [ -f /var/account/acct ]; then
        echo 'turning on accounting';        accton /var/account/acct
fi

if [ -f /sbin/ldconfig ]; then
        echo 'creating runtime link editor directory cache.'
        if [ -d /usr/local/lib ]; then
                shlib_dirs="/usr/local/lib $shlib_dirs"
        fi
        if [ -d /usr/X11R6/lib ]; then
                shlib_dirs="/usr/X11R6/lib $shlib_dirs"
        fi
        ldconfig $shlib_dirs
fi

if [ -x /sbin/wsconsctl -a -f /etc/wsconsctl.conf ]; then
(
        # delete comments and blank lines
        save_IFS="$IFS"
        IFS="
"
        set -- `stripcom /etc/wsconsctl.conf`
        IFS="$save_IFS"
        while [ $# -ge 1 ] ; do
                eval /sbin/wsconsctl -w $1
                shift
        done
)
fi

if [ -f /sbin/kbd -a -f /etc/kbdtype ]; then
        kbd `cat /etc/kbdtype`
fi

echo "Setting Network......"
. /etc/setnetwork

date

原准备将/dev也作为mfs挂载,但好像有点问题, 需要找资料研究学习, 找到解决方法,我在后续写出。

3、上一步最后有一个setnetwork脚本,这一步写出。我的脚本编写不会, 只好从其它地方抄过来,有一些错误,需要请高手改写。这个文件有点大, 贴在最后吧!

4、将一些网络配置的文件删除如:hosts, mygate等。上一步的network在启动时会生成这些配置文件。

五、        备份几个目录,在4.3 rc脚本中的MFS部分那个文件。
在/usr/live/ LiveCD根目录下建立文件夹:mfs 然后:
# tar cvzfp mfs/root.tgz root
# tar cvzfp mfs/etc.tgz etc
# tar cvzfp mfs/var.tgz var
  
六、        制作ISO镜像:
# cd /usr/live
# mkhybrid ?b cdrom36.fs ?c boot.catalog ?R ?v ?o /usr/OpenBSD-LiveCD.iso /usr/live

现在制作完成, 你可以用虚拟机测试这个生成的ISO镜像。

我现在还有几个问题需要解决,主要是MFS这方面的,另外shell脚本的错误也需要大家来解决。

以下是RAMDISK_CD和setnetwork这两个文件:      
★ *""*☆*""* ★ FreeBSD & OpenBSD 爱好者 ★ *""*☆*""* ★ FreeBSD版 OpenBSD 系列.....

TOP

RAMDISK_CD:
#        $OpenBSD: GENERIC,v 1.376 2004/07/20 20:30:09 dhartmei Exp $
#
#        GENERIC -- everything that's currently supported
#

machine                i386                # architecture, used by config; REQUIRED

option                I386_CPU        # CPU classes; at least one is REQUIRED
option                I486_CPU
option                I586_CPU
option                I686_CPU
option                GPL_MATH_EMULATE        # floating point emulation.

option                USER_PCICONF        # user-space PCI configuration

#option                VM86                # Virtual 8086 emulation
option                USER_LDT        # user-settable LDT; see i386_set_ldt(2)
option                APERTURE        # in-kernel aperture driver for XFree86

#option                KGDB                # Remote debugger support; exclusive of DDB
#option                "KGDB_DEVNAME=\"pccom\"",KGDBADDR=0x2f8,KGDBRATE=9600

#option                DUMMY_NOPS        # speed hack; recommended

#option                COMPAT_SVR4        # binary compatibility with SVR4
#option                COMPAT_IBCS2        # binary compatibility with SCO and ISC
#option                COMPAT_LINUX        # binary compatibility with Linux
#option                COMPAT_FREEBSD        # binary compatibility with FreeBSD
#option                COMPAT_BSDOS        # binary compatibility with BSD/OS
#option                COMPAT_AOUT        # a.out binaries are emulated

option                NTFS                # Experimental NTFS support

maxusers        8                # estimated number of users

option                NO_PROPLICE
option                RAMDISK_HOOKS
option                MINIROOTSIZE=3560

option                TIMEZONE=0
option                DST=0

config                bsd        root on cd0a

mainbus0 at root

cpu0        at mainbus? apid ?
bios0        at mainbus0 apid ?
apm0        at bios0 flags 0x0000        # flags 0x0101 to force protocol version 1.1
pcibios0 at bios0 flags 0x0000        # use 0x30 for a total verbose

isa0        at mainbus0
isa0        at pcib?
isa0        at ichpcib?
isa0        at gscpcib?
eisa0        at mainbus0
pci*        at mainbus0 bus ?

option                PCIVERBOSE
#option                EISAVERBOSE
option                USBVERBOSE

pchb*        at pci? dev ? function ?        # PCI-Host bridges
ppb*        at pci? dev ? function ?        # PCI-PCI bridges
pci*        at ppb? bus ?
pci*        at pchb? bus ?
pcib*        at pci? dev ? function ?        # PCI-ISA bridge
ichpcib* at pci? dev ? function ?        # Intel ICHx/ICHx-M LPC bridges
gscpcib* at pci? dev ? function ?        # NS Geode SC1100 PCI-ISA bridge
gpio*        at gscpcib?

# power management and other environmental stuff
#amdpm*        at pci? dev ? function ?        # AMD768MPX
elansc*        at pci? dev ? function ?        # AMD Elan SC520 System Controller
gpio*        at elansc?
geodesc* at pci? dev ? function ?        # Geode SC1100/SCx200 IAOC

# National Semiconductor LM7[89] and compatible hardware monitors
lm0        at isa? port 0x290
#lm1        at isa? port 0x280
#lm2        at isa? port 0x310
nsclpcsio* at isa?                        # NS PC87366 LPC Super I/O
gpio*        at nsclpcsio?
gscsio*        at isa?                                # NS Geode SC1100 Super I/O
iic0        at gscsio?                        # ACCESS.bus 1
iic1        at gscsio?                        # ACCESS.bus 2
lmtemp0        at iic1 addr 0x48                # NS LM75/LM77 temperature sensor

it0        at isa? port 0x290                # IT8705F, IT8712F and SiS970 hardware
                                        # monitors
viaenv*        at pci? dev ? function ?        # VIA VT82C686A hardware monitor

# ISA PCMCIA controllers
#option PCMCIAVERBOSE
pcic0        at isa? port 0x3e0 iomem 0xd0000 iosiz 0x10000
pcic1        at isa? port 0x3e2 iomem 0xe0000 iosiz 0x4000
pcic2        at isa? port 0x3e4 iomem 0xe0000 iosiz 0x4000
tcic0        at isa? disable port 0x240 iomem 0xd0000 iosiz 0x10000

# ISA Plug-and-Play PCMCIA controllers
#option DEBUG_ISAPNP
pcic*        at isapnp?

# PCI PCMCIA controllers
pcic*        at pci? dev? function ?

# PCMCIA bus support
pcmcia*        at pcic? controller ? socket ?
pcmcia* at tcic? controller ? socket ?

# CardBus bus support
cardbus*        at cardslot?
pcmcia*                at cardslot?
cbb*                at pci? dev ? function ?
cardslot*        at cbb?

# PCI USB Controllers
ehci*        at pci?                                # Enhanced Host Controller
uhci*        at pci?                                # Universal Host Controller (Intel)
ohci*        at pci?                                # Open Host Controller

# USB bus support
usb*        at ehci?
usb*        at uhci?
usb*        at ohci?

# USB devices
uhub*        at usb?                                # USB Hubs
uhub*        at uhub? port ? configuration ?        # USB Hubs
umodem*        at uhub? port ? configuration ?        # USB Modems/Serial
ucom*        at umodem?
uvisor*        at uhub? port ? configuration ?        # Handspring Visor
ucom*        at uvisor?
uvscom*        at uhub? port ?                        # SUNTAC Slipper U VS-10U serial
ucom*        at uvscom? portno ?
ubsa*        at uhub? port ?                        # Belkin serial adapter
ucom*        at ubsa? portno ?
uftdi*        at uhub? port ?                        # FTDI FT8U100AX serial adapter
ucom*        at uftdi? portno ?
uplcom* at uhub? port ?                        # I/O DATA USB-RSAQ2 serial adapter
ucom*        at uplcom? portno ?
umct*        at uhub? port ?                        # MCT USB-RS232 serial adapter
ucom*        at umct? portno ?
uaudio* at uhub? port ? configuration ?        # USB Audio
audio*        at uaudio?
umidi*        at uhub? port ? configuration ?        # USB MIDI
midi*        at umidi?
ulpt*        at uhub? port ? configuration ? # USB Printers
umass*        at uhub? port ? configuration ? # USB Mass Storage devices
scsibus* at umass?
uhidev*        at uhub? port ? configuration ? interface ?        # Human Interface Devices
ums*        at uhidev? reportid ?                # USB mouse
wsmouse* at ums? mux 0
ukbd*        at uhidev? reportid ?                # USB keyboard
wskbd*        at ukbd? console ? mux 1
uhid*        at uhidev? reportid ?                # USB generic HID support
aue*        at uhub? port ?                        # ADMtek AN986 Pegasus Ethernet
axe*        at uhub? port ?                        # ASIX Electronics AX88172 USB Ethernet
cue*        at uhub? port ?                        # CATC USB-EL1201A based Ethernet
kue*        at uhub? port ?                        # Kawasaki KL5KUSB101B based Ethernet
cdce*        at uhub? port ?                        # CDC Ethernet
upl*        at uhub? port ?                        # Prolific PL2301/PL2302 host-to-host `network'
url*        at uhub? port ?                        # Realtek RTL8150L based adapters
wi*        at uhub? port ?                        # WaveLAN IEEE 802.11DS
urio*        at uhub? port ?                        # Diamond Multimedia Rio 500
uscanner* at uhub? port ?                # USB Scanners
usscanner* at uhub? port ?                # USB SCSI scanners, e.g., HP5300
scsibus* at usscanner?
uyap*        at uhub? port ?                        # Y@P firmware loader
udsbr*        at uhub? port ?                        # D-Link DSB-R100 radio
radio*        at udsbr?                        # USB radio
ugen*        at uhub? port ? configuration ? # USB Generic driver

# FireWire Controllers
#fwohci*        at pci? dev ? function ?        # PCI FireWire adapter
#fwohci*        at cardbus? dev ? function ?        # CardBus FireWire adapter

#fwnode*        at fwbus? idhi ? idlo ?

#fwscsi*        at fwnode?                        # SCSI over FireWire
#scsibus* at fwscsi?

#option        FWOHCI_DEBUG
#option        FWNODE_DEBUG
#option        P1212_DEBUG
#option        SBP2_DEBUG
#option        FWSCSI_DEBUG

puc*        at pci?                                # PCI "universal" communication device

npx0        at isa? port 0xf0 irq 13        # math coprocessor
isadma0        at isa?
isapnp0        at isa?

option        WSDISPLAY_COMPAT_USL                # VT handling
option        WSDISPLAY_COMPAT_RAWKBD                # can get raw scancodes
option        WSDISPLAY_DEFAULTSCREENS=6
option        WSDISPLAY_COMPAT_PCVT                # emulate some ioctls

pckbc0                at isa?                        # PC keyboard controller
pckbd*                at pckbc?                # PC keyboard
pms*                at pckbc?                # PS/2 mouse for wsmouse
pmsi*                at pckbc?                # PS/2 "Intelli"mouse for wsmouse
vga0                at isa?
option                PCIAGP
vga*                at pci? dev ? function ?
pcdisplay0        at isa?                        # CGA, MDA, EGA, HGA
wsdisplay*        at vga? console ?
wsdisplay*        at pcdisplay? console ?
wskbd*                at pckbd? console ?
wsmouse*        at pms? mux 0
wsmouse*        at pmsi? mux 0

pcppi0                at isa?
sysbeep0        at pcppi?

pccom0        at isa? port 0x3f8 irq 4        # standard PC serial ports
pccom1        at isa? port 0x2f8 irq 3
pccom2        at isa? port 0x3e8 irq 5
#pccom3        at isa? port 0x2e8 irq 9        # (conflicts with some video cards)
ast0        at isa? port 0x1a0 irq 5        # AST 4-port serial card
#ast1        at isa? port 0x2a0 irq 6        # 2nd AST 4-port serial card
pccom*        at ast? slave ?
#boca0        at isa? port 0x100 irq 5        # BOCA 8-port serial cards
#pccom*        at boca? slave ?
#addcom0        at isa? port 0x108 irq 5        # Addonics FlexPort
#pccom*        at addcom? slave ?
#rtfps0        at isa? port 0x1230 irq 10        # RT 4-port serial cards
#pccom*        at rtfps? slave ?
#hsq0        at isa? port 0x140 irq 10        # Hostess 4-port serial card
#pccom*        at hsq? slave ?
pccom*        at pcmcia? function ?                # PCMCIA modems/serial ports
pccom*        at isapnp?
pccom*        at puc? port ?

# option for using CD1400 handshaking for incoming data
# requires a special cable that exchanges the RTS and DTR lines
# options CY_HW_RTS
cy0        at isa? iomem 0xd4000 irq 12        # ISA cyclom serial card
cy*        at pci?                                # PCI cyclom serial card
#cz*        at pci? dev ? function ?        # Cyclades-Z multi-port serial boards

lpt0        at isa? port 0x378 irq 7        # standard PC parallel ports
lpt1        at isa? port 0x278
lpt2        at isa? port 0x3bc
lpt*        at puc? port ?

lms0        at isa? port 0x23c irq 5        # Logitech bus mouse
lms1        at isa? port 0x238 irq 5
mms0        at isa? port 0x23c irq 5        # Microsoft InPort mouse
mms1        at isa? port 0x238 irq 5

wsmouse*        at lms? mux 0
wsmouse*        at mms? mux 0

bha0        at isa? port 0x330 irq ? drq ?        # BusLogic [57]4X SCSI controllers
bha1        at isa? disable port 0x334 irq ? drq ? # BusLogic [57]4X SCSI controllers
bha2        at isa? disable port ? irq ?
bha*        at pci? dev ? function ?
#bha*        at eisa? slot ?                        # XXX eisa still runs in isa-compat
scsibus* at bha?
aha0        at isa? port 0x330 irq ? drq ?        # Adaptec 154[02] SCSI controllers
aha1        at isa? port 0x334 irq ? drq ?        # Adaptec 154[02] SCSI controllers
aha*        at isapnp?
scsibus* at aha?
ahb*        at eisa? slot ?                        # Adaptec 174[024] SCSI controllers
scsibus* at ahb?
ahc0        at isa? port ? irq ?                # Adaptec 284x SCSI controllers
ahc*        at eisa? slot ?                        # Adaptec 274x, aic7770 SCSI controllers
ahc*        at pci? dev ? function ?        # Adaptec 2940/3940/78?? SCSI controllers
scsibus* at ahc?
ahd*        at pci? dev ? function ?        # Adaptec 79?? SCSI controllers
scsibus* at ahd?
mpt*        at pci? dev ? function ?        # LSI Fusion-MPT SCSI/Fibre
scsibus* at mpt?
dpt*        at pci? dev ? function ?        # DPT SmartCache/SmartRAID PCI
dpt*        at eisa? slot ?                        # DPT SmartCache/SmartRAID EISA
scsibus* at dpt?
gdt*        at pci? dev ? function ?        # ICP Vortex GDT RAID controllers
scsibus* at gdt?
twe*        at pci? dev ? function ?        # 3ware Escalade RAID controllers
scsibus* at twe?
aac*        at pci? dev ? function ?        # Adaptec FSA RAID controllers
scsibus* at aac?
ami*        at pci? dev ? function ?        # AMI MegaRAID controllers
scsibus* at ami?
cac*        at pci? dev ? function ?        # Compaq Smart ARRAY RAID controllers
cac*        at eisa? slot ?
scsibus* at cac?
iha*        at pci? dev ? function ?        # Initio Ultra/UltraWide SCSI controllers
scsibus* at iha?
isp*        at pci? dev ? function ?        # Qlogic ISP [12]0x0 SCSI/FibreChannel
scsibus* at isp?
aic0        at isa? port 0x340 irq 11        # Adaptec 152[02] SCSI controllers
aic*        at pcmcia? function ?                # PCMCIA based aic SCSI controllers
aic*        at isapnp?                         # isapnp configured aic SCSI controllers
scsibus* at aic?
#esp*        at pcmcia? function ?                # PCMCIA based NCR 53C9X SCSI
#scsibus* at esp?
#ncr*        at pci? dev ? function ?        # NCR 538XX SCSI controllers(old)
#scsibus* at ncr?
siop*        at pci? dev ? function ?        # NCR 538XX SCSI controllers(new)
scsibus* at siop?
adv*        at pci? dev ? function ?        # AdvanSys 1200A/B and ULTRA SCSI
scsibus* at adv?
adw*        at pci? dev ? function ?        # AdvanSys ULTRA WIDE SCSI
scsibus* at adw?
pcscp*        at pci? dev ? function ?        # AMD 53c974 PCscsi-PCI SCSI
scsibus* at pcscp?
sea0        at isa? disable iomem 0xc8000 irq 5        # Seagate ST0[12] SCSI controllers
scsibus* at sea?
trm*        at pci? dev ? function ?        # Tekram DC-3x5U SCSI Controllers
scsibus* at trm?
uha0        at isa? port 0x330 irq ? drq ?        # UltraStor [13]4f SCSI controllers
uha1        at isa? disable port 0x334 irq ? drq ? # UltraStor [13]4f SCSI controllers
uha*        at eisa? slot ?                        # UltraStor 24f SCSI controllers
scsibus* at uha?
wds0        at isa? disable port 0x350 irq 15 drq 6        # WD7000 and TMC-7000 controllers
#wds1        at isa? port 0x358 irq 11 drq 5
scsibus* at wds?

sd*        at scsibus? target ? lun ?        # SCSI disk drives
st*        at scsibus? target ? lun ?        # SCSI tape drives
cd*        at scsibus? target ? lun ?        # SCSI CD-ROM drives
ch*        at scsibus? target ? lun ?        # SCSI autochangers
ss*        at scsibus? target ? lun ?        # SCSI scanners
uk*        at scsibus? target ? lun ?        # unknown SCSI

fdc0        at isa? port 0x3f0 irq 6 drq 2        # standard PC floppy controllers
#fdc1        at isa? port 0x370 irq ? drq ?
fd*        at fdc? drive ? flags 0x00

#mcd0        at isa? port 0x300 irq 10        # Mitsumi CD-ROM drives

# IDE controllers
pciide* at pci ? dev ? function ? flags 0x0000

wdc0        at isa? port 0x1f0 irq 14 flags 0x00
wdc1        at isa? port 0x170 irq 15 flags 0x00
wdc*        at pcmcia? function ?
wdc*        at isapnp?

# IDE hard drives
wd*        at wdc? channel ? drive ? flags 0x0000
wd*        at pciide? channel ? drive ? flags 0x0000

# ATAPI<->SCSI
atapiscsi* at wdc? channel ?
atapiscsi* at pciide? channel ?
scsibus* at atapiscsi?

#wt0        at isa? port 0x308 irq 5 drq 1        # Archive and Wangtek QIC tape drives

# Networking devices
we0        at isa? port 0x280 iomem 0xd0000 irq 9        # WD/SMC 80x3 ethernet
we1        at isa? port 0x300 iomem 0xcc000 irq 10        #
#we2        at isa? port 0x280 iomem 0xd0000 irq 3        # WD/SMC 80x3 ethernet
we*        at isapnp?
ec0        at isa? port 0x250 iomem 0xd8000 irq 9        # 3C503 ethernet
ne0        at isa? port 0x240 irq 9                # NE[12]000 ethernet
ne1        at isa? port 0x300 irq 10                # NE[12]000 ethernet
ne2        at isa? port 0x280 irq 9                # NE[12]000 ethernet
ne*        at isapnp?                                # NE[12]000 PnP ethernet
eg0        at isa? disable port 0x310 irq 5        # 3C505/Etherlink+ ethernet
el0        at isa? disable port 0x300 irq 9         # 3C501 ethernet
ep0        at isa? port ? irq ?                        # 3C509 ethernet
ep*        at isapnp?                                # 3C509 PnP ethernet
ep*        at isa? port ? irq ?                        # 3C509 ethernet
ef*        at isapnp?                                # 3C515 PnP ethernet
ie0        at isa? port 0x360 iomem 0xd0000 irq 7        # StarLAN and 3C507
#ie1        at isa? port 0x300 irq 10                # EtherExpress
lc0        at isa? port 0x200 irq ?                # DEC EtherWorks
lc1        at isa? port 0x280 irq ?                # DEC EtherWorks
le0        at isa? port 0x360 irq 15 drq 6                # IsoLan, NE2100, and DEPCA
ex0        at isa? port 0x320 irq 5                # Intel EtherExpress PRO/10
#tr0        at isa? port 0xa20 iomem 0xd8000 irq ?        # IBM TROPIC based Token-Ring
#tr1        at isa? port 0xa24 iomem 0xd0000 irq ?        # IBM TROPIC based Token-Ring
#tr*        at isa? port ? irq ?                        # 3COM TROPIC based Token-Ring
ep0        at eisa? slot ?
ep*        at eisa? slot ?                                # 3C579 ethernet
fea*        at eisa? slot ?                                # DEC DEFEA FDDI
lmc*        at pci? dev ? function ?                # Lan Media Corp SSI/T3/HSSI
san*         at pci? dev ? function ?                # Sangoma PCI AFT card
le*        at pci? dev ? function ?                # PCnet-PCI based ethernet
le*        at isapnp?
de*        at pci? dev ? function ?                # DC21X4X-based ethernet
fxp*        at pci? dev ? function ?                # EtherExpress 10/100B ethernet
fxp*        at cardbus? dev ? function ?                # Intel PRO/100 ethernet
ne*        at pci? dev ? function ?                # NE2000-compat ethernet
ep0        at pci? dev ? function ?                # 3C59x ethernet
ep*        at pci? dev ? function ?                # 3C59x ethernet
ne*        at pcmcia? function ?                        # PCMCIA based NE2000 ethernet
ep*        at pcmcia? function ?                        # PCMCIA based 3C5xx ethernet
sm*        at pcmcia? function ?                        # PCMCIA based sm ethernet
xe*        at pcmcia? function ?                        # Xircom ethernet
fpa*        at pci? dev ? function ?                # DEC DEFPA FDDI
xl*        at pci? dev ? function ?                # 3C9xx ethernet
xl*        at cardbus? dev ? function ?                # 3C575/3C656 ethernet
rl*        at pci? dev ? function ?                # RealTek 81[23]9 ethernet
rl*        at cardbus? dev ? function ?                # RealTek 81[23]9 ethernet
mtd*        at pci? dev ? function ?                # Myson MTD800/803/891
tx*        at pci? dev ? function ?                # SMC 83C170 EPIC ethernet
tl*        at pci? dev ? function ?                # Compaq Thunderlan ethernet
vr*        at pci? dev ? function ?                # VIA Rhine ethernet
wb*        at pci? dev ? function ?                # Winbond W89C840F ethernet
sf*        at pci? dev ? function ?                # Adaptec AIC-6915 ethernet
sis*        at pci? dev ? function ?                # SiS 900/7016 ethernet
ste*        at pci? dev ? function ?                # Sundance ST201 ethernet
dc*        at pci? dev ? function ?                # 21143, "tulip" clone ethernet
dc*        at cardbus? dev ? function ?                # 21143, "tulip" clone ethernet
ti*        at pci? dev ? function ?                # Alteon Tigon 1Gb ethernet
skc*        at pci? dev ? function ?                # SysKonnect GEnesis 984x
sk*        at skc?                                        #  each port of above
em*        at pci? dev ? function ?                # Intel Pro/1000 ethernet
txp*        at pci? dev ? function ?                # 3com 3CR990
nge*        at pci? dev ? function ?                # NS DP83820/DP83821 GigE
bge*        at pci? dev ? function ?                # Broadcom BCM570x (aka Tigon3)
re*        at pci? dev ? function ?                # Realtek 8169/8169S/8110S
stge*        at pci? dev ? function ?                # Sundance TC9021 GigE
#lge*        at pci? dev ? function ?                # Level1 LXT1001 GigE
hme*        at pci? dev ? function ?                # Sun Happy Meal
bce*        at pci? dev ? function ?                # Broadcom BCM4401      
★ *""*☆*""* ★ FreeBSD & OpenBSD 爱好者 ★ *""*☆*""* ★ FreeBSD版 OpenBSD 系列.....

TOP

# Wireless network cards
atw*        at pci? dev ? function ?                # ADMtek ADM8211 (802.11)
atw*        at cardbus? dev ? function ?                # ADMtek ADM8211 (802.11)
wi*        at pci? dev ? function ?                # WaveLAN IEEE 802.11DS
wi*        at pcmcia? function ?                        # WaveLAN IEEE 802.11DS
#awi*        at pcmcia? function ?                        # Bay Networks IEEE 802.11FH
an*        at pci? dev ? function ?                # Aironet IEEE 802.11DS
an*        at isapnp?                                # Aironet IEEE 802.11DS
an*        at pcmcia? function ?                        # Aironet IEEE 802.11DS
#cnw*        at pcmcia? function ?                        # Xircom Netwave
ray*        at pcmcia? function ?                        # Raylink Aviator2.4/Pro 802.11FH

# Media Independent Interface (mii) drivers
exphy*        at mii? phy ?                                # 3Com internal PHYs
inphy*        at mii? phy ?                                # Intel 82555 PHYs
iophy*        at mii? phy ?                                # Intel 82553 PHYs
icsphy*        at mii? phy ?                                # ICS 1890 PHYs
lxtphy*        at mii? phy ?                                # Level1 LXT970 PHYs
nsphy*        at mii? phy ?                                # NS and compatible PHYs
nsphyter*        at mii? phy ?                        # NS and compatible PHYs
qsphy*        at mii? phy ?                                # Quality Semi QS6612 PHYs
sqphy*        at mii? phy ?                                # Seeq 8x220 PHYs
rlphy* at mii? phy ?                                # RealTek 8139 internal PHYs
mtdphy* at mii? phy ?                                # Myson MTD972 PHYs
dcphy*        at mii? phy ?                                # Digital Clone PHYs
acphy*        at mii? phy ?                                # Altima AC101 PHYs
amphy*        at mii? phy ?                                # AMD 79C873 PHYs
tqphy*        at mii? phy ?                                # TDK 78Q212x PHYs
bmtphy*        at mii? phy ?                                # Broadcom 10/100 PHYs
brgphy*        at mii? phy ?                                # Broadcom Gigabit PHYs
eephy* at mii? phy ?                                # Marvell 88E1000 series PHY
xmphy*        at mii? phy ?                                # XaQti XMAC-II PHYs
nsgphy*        at mii? phy ?                                # NS gigabit PHYs
urlphy*        at mii? phy ?                                # Realtek RTL8150L internal PHY
rgephy*        at mii? phy ?                                # Realtek 8169S/8110S PHY
ukphy*        at mii? phy ?                                # "unknown" PHYs

pss0        at isa? port 0x220 irq 7 drq 6                # Personal Sound System
sp0        at pss0 port 0x530 irq 10 drq 0                # sound port driver

eap*        at pci? dev ? function ?                # Ensoniq AudioPCI S5016
eso*        at pci? dev ? function ?                # ESS Solo-1 PCI AudioDrive
sv*        at pci? dev ? function ?                # S3 SonicVibes (S3 617)
neo*        at pci? dev ? function ?                # NeoMagic 256AV/ZX
cmpci*        at pci? dev ? function ?                # C-Media CMI8338/8738
auich*        at pci? dev ? function ? flags 0x0000        # i82801 ICH AC'97 audio
autri*        at pci? dev ? function ? flags 0x0000        # Trident 4D WAVE
auvia*        at pci? dev ? function ?                # VIA VT82C686A
clcs*        at pci? dev ? function ?                # CS4280 CrystalClear audio
clct*        at pci? dev ? function ?                # CS4281 CrystalClear audio
fms*        at pci? dev ? function ?                # Forte Media FM801
maestro* at pci? dev ? function ?                # ESS Maestro PCI
esa*        at pci? dev ? function ?                # ESS Maestro3 PCI
yds*        at pci? dev ? function ? flags 0x0000        # Yamaha YMF Audio
emu*        at pci? dev ? function ?                # SB Live!
sb0        at isa? port 0x220 irq 5 drq 1                # SoundBlaster
sb*        at isapnp?
ess*        at isapnp?                                # ESS Tech ES188[78], ES888
wss0        at isa? port 0x530 irq 10 drq 0                # Windows Sound System
wss*        at isapnp?
pas0        at isa? port 0x220 irq 7 drq 1                # ProAudio Spectrum
gus0        at isa? port 0x220 irq 7 drq 1 drq2 6        # Gravis (drq2 is record drq)
ym*        at isapnp?
mpu*        at isapnp?
mpu*        at isa? port 0x300                         # generic MPU, Yamaha SW60XG
#aria0        at isa? port 0x280 irq 10 drq 0 flags 0x1 # Prometheus Aria 16

# OPL[23] FM synthesizers
#opl0        at isa? port 0x388        # use only if not attached to sound card
opl*        at eso?
opl*        at sb?
opl*        at ess?
opl*        at yds?

# MIDI support
midi*        at pcppi?                # MIDI interface to the PC speaker
midi*        at sb?                        # SB MPU401 port
midi*        at opl?                        # OPL FM synth
midi*        at ym?
midi*        at mpu?
midi*        at autri?

# The spkr driver provides a simple tone interface to the built in speaker.
#spkr0        at pcppi?                # PC speaker

# Audio Support
audio*        at sb?
audio*        at gus?
audio*        at pas?
audio*        at sp?
audio*        at ess?
audio*        at wss?
audio*        at ym?
audio*        at eap?
audio*        at eso?
audio*        at sv?
audio*        at neo?
audio*        at cmpci?
audio*        at clcs?
audio*        at clct?
audio*        at auich?
audio*        at autri?
audio*        at auvia?
audio*        at fms?
audio*        at maestro?
audio*        at esa?
audio*        at yds?
audio*        at emu?

bktr0        at pci? dev ? function ?

# FM-Radio devices
#gtp*        at pci? dev ? function ? # Gemtek/Guillemot Radio PCI Radio Card
#sfr0        at isa? port 0x384        # SoundForte RadioLink SF16-FMR FM Radio Card
#sf2r0        at isa? port 0x384        # SoundForte RadioLink SF16-FMR2 FM Radio Card
#az0        at isa? port 0x350        # Aztech/PackardBell FM Radio Card
#rt0        at isa? port 0x30c        # AIMS Lab Radiotrack FM Radio Card
#rt*        at isapnp?
#rtii0        at isa? port 0x30c        # AIMS Lab Radiotrack II FM Radio Card

# FM-Radio support
radio*        at bktr?
radio*        at fms?
#radio*        at gtp?
#radio*        at sfr?
#radio*        at sf2r?
#radio*        at az?
#radio*        at rt?
#radio*        at rtii?

# Joystick driver. Probe is a little strange; add only if you have one.
#joy0        at isa? port 0x201
joy*        at isapnp?

#wdt0        at pci? dev ? function ?        # Ind Computer Source PCI-WDT50x driver

# crypto support
hifn*        at pci? dev ? function ?        # Hi/fn 7751 crypto card
lofn*        at pci? dev ? function ?        # Hi/fn 6500 crypto card
nofn*        at pci? dev ? function ?        # Hi/fn 7814/7851/7854 crypto card
ubsec*        at pci? dev ? function ?        # Bluesteel Networks 5xxx crypto card
safe*        at pci? dev ? function ?        # SafeNet SafeXcel 1141/1741
#ises*        at pci? dev ? function ?        # Pijnenburg PCC-ISES

# I2O
iop*        at pci? dev ? function ?        # I2O
ioprbs*        at iop? tid ?                        # Random block storage
scsibus* at ioprbs?

pseudo-device        pctr                1
pseudo-device        mtrr                1        # Memory range attributes control
pseudo-device        sequencer        1
#pseudo-device        raid                4        # RAIDframe disk driver
pseudo-device        bio                1        # ioctl multiplexing device
pseudo-device        hotplug                1        # devices hot plugging

# mouse & keyboard multiplexor pseudo-devices
pseudo-device        wsmux                2
pseudo-device        crypto                1      
★ *""*☆*""* ★ FreeBSD & OpenBSD 爱好者 ★ *""*☆*""* ★ FreeBSD版 OpenBSD 系列.....

TOP

#        $OpenBSD: GENERIC,v 1.109 2004/07/31 21:27:31 brad Exp $
#
#        Machine-independent option; used by all architectures for their
#        GENERIC kernel

#option                INSECURE        # default to secure

#option                DDB                # in-kernel debugger
#option                DDB_SAFE_CONSOLE # allow break into ddb during boot
#makeoptions        DEBUG="-g"        # compile full symbol table
#makeoptions        PROF="-pg"        # build profiled kernel
#option                GPROF                # kernel profiling, kgmon(8)
#option                DIAGNOSTIC        # internal consistency checks
#option                KTRACE                # system call tracing, a la ktrace(1)
#option                ACCOUNTING        # acct(2) process accounting
#option                KMEMSTATS        # collect malloc(9) statistics
#option                PTRACE                # ptrace(2) system call

#option                CRYPTO                # Cryptographic framework

#option                SYSVMSG                # System V-like message queues
#option                SYSVSEM                # System V-like semaphores
#option                SYSVSHM                # System V-like memory sharing

#option                UVM_SWAP_ENCRYPT# support encryption of pages going to swap

#option                COMPAT_23        # Kernel compatibility with OpenBSD 2.3,
#option                COMPAT_25        # 2.5,
#option                COMPAT_35        # 3.5,
#option                COMPAT_43        # and 4.3BSD
#option                TCP_COMPAT_42        # TCP bug compatibility with 4.2BSD

#option                LKM                # loadable kernel modules

option                FFS                # UFS
option                FFS_SOFTUPDATES        # Soft updates
#option                UFS_DIRHASH        # hash large directories
#option                QUOTA                # UFS quotas
option                EXT2FS                # Second Extended Filesystem
option                MFS                # memory file system
#option                XFS                # xfs filesystem

option                TCP_SACK        # Selective Acknowledgements for TCP
option                TCP_ECN                # Explicit Congestion Notification for TCP
option                TCP_SIGNATURE        # TCP MD5 Signatures, for BGP routing sessions
#option                TCP_FACK        # Forward Acknowledgements for TCP

#option                NFSCLIENT        # Network File System client
#option                NFSSERVER        # Network File System server

option                CD9660                # ISO 9660 + Rock Ridge file system
option                MSDOSFS                # MS-DOS file system
#option                FDESC                # /dev/fd
#option                FIFO                # FIFOs; RECOMMENDED
#option                KERNFS                # /kern
#option                PORTAL                # dynamically created filesystem objects
#option                PROCFS                # /proc
# layer filesystems
option                NULLFS                # loopback file system
option                UMAPFS                # NULLFS + uid and gid remapping
option                UNION                # union file system

option                INET                # IP + ICMP + TCP + UDP
option                ALTQ                # ALTQ base
option                INET6                # IPv6 (needs INET)
option                IPSEC                # IPsec
#option                KEY                # PF_KEY (implied by IPSEC)
#option                NS                # XNS
#option                NSIP                # XNS tunneling over IP
#option                IPX                # IPX+SPX
#option                IPXIP                # IPX tunneling over IP
#option                NETATALK        # AppleTalk
#option                CCITT,LLC,HDLC        # X.25
option                PPP_BSDCOMP        # PPP BSD compression
option                PPP_DEFLATE
#option                MROUTING        # Multicast router

pseudo-device        pf                # packet filter
pseudo-device        pflog                # pf log if
pseudo-device        pfsync                # pf sync if
pseudo-device        sppp        1        # Sync PPP/HDLC
pseudo-device        enc        1        # option IPSEC needs the encapsulation interface
#pseudo-device        strip        1        # Starmode Radio IP interface

pseudo-device        pty        16        # initial number of pseudo-terminals
pseudo-device        tb        1        # tablet line discipline
pseudo-device        vnd        16        # paging to files
pseudo-device        ccd        4        # concatenated disk devices
pseudo-device        ksyms        1        # kernel symbols device
pseudo-device        systrace 1        # system call tracing device

# clonable devices
pseudo-device        bpfilter         # packet filter
pseudo-device        bridge                # network bridging support
pseudo-device        carp                # CARP protocol support
pseudo-device        gif                # IPv[46] over IPv[46] tunnel (RFC1933)
pseudo-device        gre                # GRE encapsulation interface
pseudo-device        loop                # network loopback
pseudo-device        ppp                # PPP
pseudo-device        sl                # CSLIP
pseudo-device        tun                # network tunneling over tty
pseudo-device        vlan                 # IEEE 802.1Q VLAN

# for IPv6
#pseudo-device        faith        1        # IPv[46] tcp relay translation i/f

option                BOOT_CONFIG        # add support for boot ?c









setnetwork:
#!/bin/sh

get_dkdevs() {
        bsort `sed -ne "${MDDISKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}" /var/run/dmesg.boot`
}

get_cddevs() {
        bsort `sed -ne "${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p}" /var/run/dmesg.boot`
}

get_ifdevs() {
        ifconfig -a \
            | egrep -v '^[[:space:]]|(bridge|enc|gif|gre|lo|pflog|pfsync|ppp|sl|tun|vlan)[[:digit:]]+:' \
            | sed -ne 's/^\(.*\):.*/\1/p'
}

askpass() {
        set -o noglob
        stty -echo
        read resp?"$1 "
        stty echo
        set +o noglob
        echo
}

ask() {
        local _question=$1 _default=$2

        set -o noglob
        while : ; do
                echo -n "$_question "
                [[ -z $_default ]] || echo -n "[$_default] "
                read resp
                case $resp in
                !)        echo "Type 'exit' to return to install."
                        sh
                        ;;
                !*)        eval ${resp#?}
                        ;;
                *)        : ${resp:=$_default}
                        break
                        ;;
                esac
        done
        set +o noglob
}

ask_until() {
        resp=
        while [[ -z $resp ]] ; do
                ask "$1" "$2"
        done
}

ask_yn() {
        local _q=$1 _a=${2:-no} _resp
        typeset -l _resp

        while : ; do
                ask "$_q" "$_a"
                _resp=$resp
                case $_resp in
                y|yes)        resp=y ; return ;;
                n|no)        resp=n ; return ;;
                esac
        done
}

ask_which() {
        local _name=$1 _query=$2 _devs=$3 _defdev=$4 _err=$5

        set -- $_devs
        if [[ $# -lt 1 ]]; then
                echo "${_err:=No ${_name}s found}."
                resp=done
                return
        fi
        : ${_defdev:=$1}

        _devs="$*"

        while : ; do
                ask "Available ${_name}s are: ${_devs}.\nWhich one ${_query}? (or 'done')" "$_defdev"
                [[ $resp == done ]] && break

                if isin "$resp" $_devs; then
                        makedev $resp && break
                else
                        echo "'$resp' is not a valid choice."
                fi
        done
}

isin() {
        local        _a=$1 _b

        shift
        for _b; do
                [ "$_a" = "$_b" ] && return 0
        done
        return 1
}

addel() {
        local        _a=$1

        shift

        echo -n "$*"
        isin "$_a" $* || echo -n " $_a"
}

rmel() {
        local        _a=$1 _b

        shift
        for _b; do
                [ "$_a" != "$_b" ] && echo -n "$_b "
        done
}

edit_tmp_file() {
        local _file=$1

        ask_yn "Edit $_file with $EDITOR?"
        [[ $resp == y ]] && $EDITOR /tmp/$_file
}

manual_net_cfg() {
        ask_yn "Do you want to do any manual network configuration?"

        [[ $resp == y ]] && { echo "Type 'exit' to return to $MODE." ; sh ; }
}

makedev() {
        local _dev=$1 _node=/dev/r${1}c

        if isin $_dev $IFDEVS || [[ -c $_node || -z ${_dev##+([0-9])} ]] ; then
                return 0
        fi

        if [[ ! -r /dev/MAKEDEV ]] ; then
                echo "No /dev/MAKEDEV. Can't create device nodes for ${_dev}."
                return 1
        fi

        (cd /dev; sh MAKEDEV $_dev)

        [[ -c $_node ]] || return 1

        DEVSMADE=`addel $_dev $DEVSMADE`
}

addhostent() {
        sed "/ $2\$/d" /etc/hosts > /etc/hosts.new
        mv /etc/hosts.new /etc/hosts

        echo "$1 $2" >> /etc/hosts
}

configure_ifs() {
        local _IFDEVS=$IFDEVS _ifs _name _media _hn

        while : ; do
                ask_which "interface" "do you wish to initialize" "$_IFDEVS" \
                        "" "No more interfaces to initialize"
                [[ $resp == done ]] && break

                _ifs=$resp
                _hn=/etc/hostname.$_ifs

                ask "Symbolic (host) name for $_ifs?" "$(hostname -s)"
                _name=$resp

                _media=$(ifconfig -m $_ifs | grep "media ")
                if [[ -n $_media ]]; then
                        cat << __EOT
The media options for $_ifs are currently
$(ifconfig -m $_ifs | sed -n '/supported/D;/media:/p')
__EOT
                        ask_yn "Do you want to change the media options?"
                        case $resp in
                        y)        cat << __EOT
Supported media options for $_ifs are:
$_media
__EOT
                                ask "Media options for $_ifs?"
                                _media=$resp
                                ifconfig $_ifs $_media || return 1
                                ;;
                        n)        _media=
                                ;;
                        esac
                fi

                rm -f $_hn
                v4_config "$_ifs" "$_media" "$_name" "$_hn"

                [[ -f $_hn ]] && _IFDEVS=$(rmel "$_ifs" $_IFDEVS)
        done
}

v4_info() {
        ifconfig $1 inet | sed -n '
                1s/.*<UP,.*/UP/p
                1s/.*<.*/DOWN/p
                /inet/s/netmask//
                /inet/s///p'
}

dhcp_request() {
        local _ifs=$1 _hostname=$2

        echo "initial-interval 1;" > /etc/dhclient.conf

        if [[ -n $_hostname ]]; then
                echo "send host-name \"$_hostname\";" >> /etc/dhclient.conf
                echo "Issuing hostname-associated DHCP request for $_ifs."
        else
                echo "Issuing free-roaming DHCP request for $_ifs."
        fi

        cat >> /etc/dhclient.conf << __EOT
request subnet-mask,
        broadcast-address,
        routers,
        domain-name,
        domain-name-servers,
        host-name;
__EOT

        cat >> /etc/resolv.conf.tail << __EOT
lookup file bind
__EOT

        dhclient $_ifs

        set -- $(v4_info $_ifs)

        if [[ $1 == UP && $2 == "0.0.0.0" ]]; then
                ifconfig $_ifs delete down
                rm /etc/dhclient.conf /etc/resolv.conf.tail
                return 1
        fi

#        cp /etc/dhclient.conf /tmp/dhclient.conf
#        cp /etc/resolv.conf.tail /tmp/resolv.conf.tail

        return 0
}

v4_config() {
        local _ifs=$1 _media=$2 _name=$3 _hn=$4 _prompt

        set -- $(v4_info $_ifs)
        if [[ -n $2 ]]; then
                ifconfig $_ifs inet $2 delete
                [[ $2 != "0.0.0.0" ]] && { _addr=$2; _mask=$3; }
        fi

        [[ -x /sbin/dhclient ]] && _prompt=" or 'dhcp'"
        _prompt="IPv4 address for $_ifs? (or 'none'$_prompt)"

        ask_until "$_prompt" "$_addr"
        case $resp in
        none)        ;;
        dhcp)        if [[ ! -x /sbin/dhclient ]]; then
                        echo "DHCP not possible - no /sbin/dhclient."
                elif dhcp_request $_ifs "$_name" || dhcp_request $_ifs ; then
                        addhostent "127.0.0.1" "$_name"
                        echo "dhcp NONE NONE NONE $_media" > $_hn
                fi
                ;;
        *)        _addr=$resp
                ask_until "Netmask?" "${_mask:=255.255.255.0}"
                if ifconfig $_ifs inet $_addr netmask $resp up ; then
                        addhostent "$_addr" "$_name"
                        echo "inet $_addr $resp NONE $_media" > $_hn
                fi
                ;;
        esac
}

v4_defroute() {
        local _dr _prompt=" or 'none'"

        [[ -x /sbin/dhclient ]] && _prompt=", 'dhcp'$_prompt"
        _prompt="Default IPv4 route? (IPv4 address$_prompt)"

        _dr=$(route -n show -inet | sed -ne '/^default */{s///; s/ .*//; p;}')
        [[ -f /tmp/dhclient.conf ]] && _dr=dhcp

        while : ; do
                ask_until "$_prompt" "$_dr"
                case $resp in
                none|dhcp) break ;;
                esac
                route delete -inet default > /dev/null 2>&1
                route -n add -inet -host default "$resp" && { echo "$resp" >/etc/mygate ; break ; }
                route -n add -inet -host default $_dr >/dev/null 2>&1
        done
}

isalphanumeric() {
        local _n=$1
        while [[ ${#_n} -ne 0 ]]; do
                case $_n in
                [A-Za-z0-9]*)        ;;
                *)                return 1;;
                esac
                _n=${_n#?}
        done
        return 0
}

enable_network() {
        local _netfile

#        for _netfile in hosts dhclient.conf resolv.conf resolv.conf.tail protocols services; do
#                if [ -f /mnt/etc/${_netfile} ]; then
#                        cp /mnt/etc/${_netfile} /etc/${_netfile}
#                fi
#        done

        ifconfig lo0 inet 127.0.0.1

        for hn in /etc/hostname.*; do
                if=${hn#/etc/hostname.}

                if ! isalphanumeric "$if"; then
                        continue
                fi
                ifconfig $if > /dev/null 2>&1
                if [ $? -ne 0 ]; then
                        continue
                fi

                while :; do
                        if [ "$cmd2" ]; then
                                set -- $cmd2
                                af=$1 name=$2 mask=$3 bcaddr=$4 ext1=$5 cmd2=
                                i=1; while [ i -lt 6 -a -n "$1" ]; do shift; let i=i+1; done
                                ext2="$@"
                        else
                                read af name mask bcaddr ext1 ext2 || break
                        fi
                        case $af in
                        "#"*|"!"*|"bridge"|""|"rtsol")
                                continue
                                ;;
                        "dhcp")        [ "$name" = "NONE" ] && name=
                                [ "$mask" = "NONE" ] && mask=
                                [ "$bcaddr" = "NONE" ] && bcaddr=
                                ifconfig $if $name $mask $bcaddr $ext1 $ext2 down
                                cmd="dhclient $if"
                                ;;
                        "up")
                                cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 up"
                                ;;
                        *)        read dt dtaddr
                                if [ "$name" = "alias" ]; then
                                        alias=$name
                                        name=$mask
                                        mask=$bcaddr
                                        bcaddr=$ext1
                                        ext1=$ext2
                                        ext2=
                                else
                                        alias=
                                fi
                                cmd="ifconfig $if $af $alias $name "
                                case $dt in
                                dest)        cmd="$cmd $dtaddr"
                                        ;;
                                [a-z!]*)
                                        cmd2="$dt $dtaddr"
                                        ;;
                                esac
                                if [ ! -n "$name" ]; then
                                        echo "/etc/hostname.$if: invalid network configuration file"
                                        return
                                fi
                                case $af in
                                inet)        [ "$mask" ] && cmd="$cmd netmask $mask"
                                        if [ "$bcaddr" -a "$bcaddr" != "NONE" ]; then
                                                cmd="$cmd broadcast $bcaddr"
                                        fi
                                        [ "$alias" ] && rtcmd="; route -qn add -host $name 127.0.0.1"
                                        ;;
                                inet6)
                                        continue
                                        ;;
                                *)        cmd="$cmd $mask $bcaddr"
                                esac
                                cmd="$cmd $ext1 $ext2$rtcmd" rtcmd=
                                ;;
                        esac
                        eval "$cmd"
                done </etc/hostname.$if