ChinaUnix.net 首页 | 博客 | Linux | 论坛 | 人才 | 培训 | 知识库 | 资料 | 读书 | 手册 | 精华 | 下载 | 沙龙 | 搜索
Linux首页 | Linux论坛 | 论坛精华 | 开源新闻 | 技术文章 | 专题专栏 | 新手指南 | 迁移方案 | 产品方案 | 开源项目 | 开源图书 | 软件下载 | 人才招聘 | Linux博客
  搜索

  产品与方案
·中科红旗全面打造现代化邮政体系
·红旗助力“网上审批服务” 推动电子政务
·红旗正版化开创呼和浩特网吧建设新起点
·红旗Linux助信息产业部邮件服务器“快跑”
·中标普华Linux 为电子政务信息化保驾护航
·中标普华Linux助力基金产业
·中标普华Office率先支持UOF标准
·中标普华邮件系统助力西藏政府信息化建设
·红旗Linux助力国库集中支付系统改革
·红旗助中信卫星 掀起GIS通信应用风暴
·红旗软件助力烟草总局 全面建设“数字烟草”
·红旗助力“信访阳光工程”打造畅通信访渠道
·红帽联合FIS发布下一代实时核心银行平台
·红旗助力金盾 打造全无忧出入境信息系统
·红旗Linux全力打造中国邮政总局名址信息库
·爱尔兰证交所从Unix迁移到红帽企业Linux
·一流的意大利银行选择使用红帽企业Linux
·PLUS Finanzservice选择使用红帽企业Linux
·红帽助力TransACT Communications 公司
·法国零售业巨头Lapeyre采用Redhat Linux
·旅游预订网站选择使用红帽企业Linux
·马哈拉施特拉邦政府的红帽解决之道
·美国联邦政府案例
·红帽为慕尼黑展览会提供现代化集群系统
·Yuba郡用开源软件和红帽产品提高了效率
·红帽企业Linux助印度理工建立高性能计算中心
·采用红帽Linux 将系统维护时间缩短了65%
·从UNIX迁移到Linux使Peñoles公司获益非浅
·Hikal公司用红帽企业Linux开展任务关键的ERP项目
·KDE3.5.4新版本发布
·芝加哥商业交易所从Unix向Linux迁移
·南方基金管理有限公司成功案例 Red Hat Linux
·广东北电通讯设备有限公司成功案例
·挪威国家石油公司从UNIX迁移到红帽Linux,成本减半
·中央电视台CCTV动画部案例 Red Hat Linux

  图书

鸟哥的Linux私房菜基础学..


Linux程序设计.第3版


Linux设备驱动开发详解


  下载
·Endian Firewall
·linux kernel(Linux 内核)
·CentOS
·Fedora Core 6
·Scientific Linux
·Slackware 11.0
·Gentoo Linux
·ubuntu-6.10-i386服务器版本
·ubuntu-6.10-amd64服务器版
·ubuntu-6.10-i386桌面版
·ubuntu-6.10-amd64桌面版
·Engarde Linux
您的位置: Linux时代 > 技术文档 > 内核研究 >

制作RAMDISK in KERNEL的NetBSD

日期:2006-11-28 作者:Mathrew 来自:cnfug


前言

在前面我们已经讲过如何制作软盘上运行的FreeBSD和OpenBSD系统,现在我们来看看如何制作一个运行在软盘上的NetBSD系统。同软盘中的OpenBSD系统一样,我们还是将系统中的所有配制文件及程序全部存放到NetBSD的内核中,这样整个系统看起来就是一个文件。下面让我们具体来看看如何完成这样一个微系统的制作。

0、NetBSD的启动过程

当硬盘MBR中的引导程序接过启动之后,MBR中的程序将读入硬盘NetBSD分区中的引导程序,引导程序默认情况下会加载/boot,然后由 boot载入内核/netbsd,此时内核开始检测一些硬件和做一些初始化。初始化完成后kernel将mount root device,然后启动系统初始化进程/sbin/init,init将根据/etc/rc中的设置来进行初始化等。

1、定制RAMDISK内核

要使用RAMDISK in KERNEL就必须在内核配制文件中加入以下选项:

options MEMORY_DISK_HOOKS
options MEMORY_DISK_IS_ROOT # force root on memory disk
options MEMORY_DISK_SERVER=0
options MEMORY_DISK_ROOT_SIZE=10000 # size of memory disk, in blocks
options MEMORY_RBFLAGS=0x00 # boot in to multi-user mode
pseudo-device md 1 # memory disk device (ramdisk)

以上的内核参数意义如下:

MEMORY_DISK_ROOT_SIZE : 内存磁盘大小,以块为单位
MEMORY_RBFLAGS=0x00 : 启动到多用户模式

以下是在我机器上使用的一个内核配制文件

include "arch/i386/conf/std.i386"

#options INCLUDE_CONFIG_FILE # embed config file in kernel binary

makeoptions COPTS="-Os" # Optimise for space. Implies -O2

# Enable the hooks used for initializing the root memory-disk.
options MEMORY_DISK_HOOKS
options MEMORY_DISK_IS_ROOT # force root on memory disk
options MEMORY_DISK_SERVER=1 # 0 readonly 1 writable
options MEMORY_DISK_ROOT_SIZE=10000 # size of memory disk, in blocks
options MEMORY_RBFLAGS=0x00 # boot in to multi-user mode

maxusers 48 # estimated number of users

# CPU support. At least one is REQUIRED.
options I386_CPU
options I686_CPU

# CPU-related options.
options MATH_EMULATE # floating point emulation

# This option allows you to force a serial console at the specified
# I/O address.
#options CONSDEVNAME="\"com\"",CONADDR=0x3f8,CONSPEED=9600

# Avoid irq 5 and 7, the most likely cause of problems on modern laptops.
options PCIC_ISA_INTR_ALLOC_MASK=0xff5f

# Standard system options

options INSECURE # disable kernel security levels

options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT
#options NTP # NTP phase/frequency locked loop

options USERCONF # userconf(4) support
options PIPE_SOCKETPAIR # smaller, but slower pipe(2)
options MALLOC_NOINLINE # Not inlining MALLOC saves memory

# File systems
file-system FFS # UFS
file-system MFS # memory file system
file-system MSDOSFS # MS-DOS file system
file-system KERNFS # /kern

options VNODE_OP_NOINLINE # Not inlining vnode op calls saves mem

# Networking options
options GATEWAY # packet forwarding
options INET # IP + ICMP + TCP + UDP
#options PFIL_HOOKS # pfil(9) packet filter hooks

# builtin terminal emulations
options WSEMUL_VT100 # VT100 / VT220 emulation
# different kernel output - see dev/wscons/wsdisplayvar.h
options WS_KERNEL_FG=WSCOL_BLACK
options WS_KERNEL_BG=WSCOL_WHITE
# compatibility to other console drivers
#options WSDISPLAY_COMPAT_PCVT # emulate some ioctls
#options WSDISPLAY_COMPAT_SYSCONS # emulate some ioctls
#options WSDISPLAY_COMPAT_USL # VT handling
#options WSDISPLAY_COMPAT_RAWKBD # can get raw scancodes
# see dev/pckbc/wskbdmap_mfii.c for implemented layouts
#options PCKBD_LAYOUT="(KB_DE | KB_NODEAD)"
# allocate a number of virtual screens at autoconfiguration time
#options WSDISPLAY_DEFAULTSCREENS=4
# use a large software cursor that doesn't blink
options PCDISPLAY_SOFTCURSOR
# modify the screen type of the console; defaults to "80x25"
#options VGA_CONSOLE_SCREENTYPE="\"80x24\""

# Kernel root file system and dump configuration.
config netbsd root on ? type ?
#config netbsd root on sd0a type ffs
#config netbsd root on ? type nfs

#
# Device configuration
#

mainbus0 at root

cpu* at mainbus?

apm0 at mainbus0 # Advanced power management


# Basic Bus Support

# PCI bus support
pci* at mainbus? bus ?
pci* at pchb? bus ?
pci* at ppb? bus ?

# PCI bridges
pchb* at pci? dev ? function ? # PCI-Host bridges
pceb* at pci? dev ? function ? # PCI-EISA bridges
pcib* at pci? dev ? function ? # PCI-ISA bridges
ppb* at pci? dev ? function ? # PCI-PCI bridges
# XXX 'puc's aren't really bridges, but there's no better place for them here
puc* at pci? dev ? function ? # PCI "universal" comm. cards

# ISA bus support
isa0 at mainbus?
isa0 at pceb?
isa0 at pcib?

# ISA Plug-and-Play bus support
isapnp0 at isa?

# Coprocessor Support

# Math Coprocessor support
npx0 at isa? port 0xf0 irq 13 # x86 math coprocessor


# Console Devices

# ISA console
#pc0 at isa? port 0x60 irq 1 # pccons generic PC console driver

# wscons
pckbc0 at isa? # pc keyboard controller
pckbd* at pckbc? # PC keyboard
#pms* at pckbc? # PS/2 mouse for wsmouse
vga0 at isa?
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

pcppi0 at isa?
sysbeep0 at pcppi?

# Serial Devices

# PCI serial interfaces
com* at puc? port ? # 16x50s on "universal" comm boards
#cy* at pci? dev ? function ? # Cyclades Cyclom-Y serial boards

# ISA Plug-and-Play serial interfaces
com* at isapnp? # Modems and serial boards

# ISA serial interfaces
#options COM_HAYESP # adds Hayes ESP serial board support
com0 at isa? port 0x3f8 irq 4 # Standard PC serial ports
com1 at isa? port 0x2f8 irq 3
com2 at isa? port 0x3e8 irq 5
#com3 at isa? port 0x2e8 irq 9
#ast0 at isa? port 0x1a0 irq 5 # AST 4-port serial cards
#com* at ast? slave ?
#boca0 at isa? port 0x100 irq 5 # BOCA 8-port serial cards
#com* at boca? slave ?
#tcom0 at isa? port 0x100 irq 7 # TC-800 8-port serial cards
#com* at tcom? slave ?
#rtfps0 at isa? port 0x1230 irq 10 # RT 4-port serial cards
#com* at rtfps? slave ?
#cy0 at isa? iomem 0xd4000 irq 12 # Cyclades serial cards

# Miscellaneous mass storage devices

# Network Interfaces

# PCI network interfaces
fxp* at pci? dev ? function ? # Intel EtherExpress PRO 10+/100B
le* at pci? dev ? function ? # PCnet-PCI Ethernet
pcn* at pci? dev ? function ? # AMD PCnet-PCI Ethernet
rtk* at pci? dev ? function ? # Realtek 8129/8139

amhphy* at mii? phy ? # AMD 79c901 Ethernet PHYs
urlphy* at mii? phy ? # Realtek RTL8150L internal PHYs
ukphy* at mii? phy ? # generic unknown PHYs

# Pseudo-Devices

# disk/mass storage pseudo-devices
pseudo-device md 1 # memory disk device (ramdisk)
#pseudo-device vnd 4 # disk-like interface to files

# network pseudo-devices
pseudo-device bpfilter 8 # Berkeley packet filter
pseudo-device ipfilter # IP filter (firewall) and NAT
pseudo-device loop # network loopback
pseudo-device ppp 2 # Point-to-Point Protocol
pseudo-device pppoe 3

# miscellaneous pseudo-devices
pseudo-device pty 2 # pseudo-terminals (Sysinst needs two)
# wscons pseudo-devices
pseudo-device wsmux # mouse & keyboard multiplexor
#pseudo-device wsfont

2、制作ramdisk镜像

# dd if=/dev/zero of=/ramdisk bs=512 count=9000
# vnconfig -c /dev/vnd0d /ramdisk
# disklabel -r -w /dev/vnd0d rdroot
# newfs -m 0 -S 512 -i 4096 /dev/vnd0a
# mount /dev/vnd0a /mnt
# mkdir /mnt/{dev,bin,sbin,etc}
# cp /dev/MAKEDEV /mnt/dev
# cp /bin/{sh,ls} /mnt/bin
# cp /sbin/init /mnt/sbin
# cd /mnt/dev/ && ./MAKEDEV ramdisk
# echo 'echo "This is my minibsd all in kernel" && /bin/sh' > /mnt/etc/rc
# sync && umount /mnt
# sync && vnconfig -u vnd0d && sync

3、将ramdisk写入kernel

# mdsetroot /minibsd ramdisk

4、压缩kernel大小

# gzip -9 -c /minibsd > /minibsd.gz

5、制作目标软盘

因为系统需要使用/boot(/usr/mdec/boot)来加载kernel,所以我们需要在软盘上放置boot文件。

# disklabel -B -w -r /dev/fd0a fd1440
# newfs -m 0 -S 512 /dev/fd0a
# mount /dev/fd0a /mnt
# cp /usr/mdec/boot /mnt
# cp /minibsd.gz /mnt/netbsd

现在你的ramdisk in kernel的mininetbsd系统就已经做好了。

原文链接:http://cnfug.org/journal/systems/2004/000070.html

本文被浏览



 相关新闻

使用NetBSD构建基于iSCSI的小型SAN2006-11-27 14:06:26
BSD发行版:NetBSD Live! 20072006-11-10 09:53:27
BSD发行版发布:NetBSD 3.12006-11-06 09:48:34
NetBSD 入门2006-10-20 14:24:53
开发者发行版:NetBSD 3.1 RC42006-10-13 15:49:48
NetBSD的创建人之一为NetBSD的未来担忧2006-09-04 09:32:05
了解NetBSD2006-08-31 18:07:49
开发者发行版发布:NetBSD 3.1 RC12006-08-23 08:37:34
新版本NetBSD-Office发布2005-06-29 09:52:07


 相关评论
关于我们 | 联系方式 | 广告合作 | 诚聘英才 | 网站地图 | 免费注册

Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们

京ICP证041476号