前言
在前面我们已经讲过如何制作软盘上运行的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. maxusers 48 # estimated number of users # CPU support. At least one is REQUIRED. # CPU-related options. # This option allows you to force a serial console at the specified # Avoid irq 5 and 7, the most likely cause of problems on modern laptops. # Standard system options options INSECURE # disable kernel security levels options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT options USERCONF # userconf(4) support # File systems options VNODE_OP_NOINLINE # Not inlining vnode op calls saves mem # Networking options # builtin terminal emulations # Kernel root file system and dump configuration. # mainbus0 at root cpu* at mainbus? apm0 at mainbus0 # Advanced power management
# PCI bus support # PCI bridges # ISA bus support # ISA Plug-and-Play bus support # Coprocessor Support # Math Coprocessor support
# ISA console # wscons pcppi0 at isa? # Serial Devices # PCI serial interfaces # ISA Plug-and-Play serial interfaces # ISA serial interfaces # Miscellaneous mass storage devices # Network Interfaces # PCI network interfaces amhphy* at mii? phy ? # AMD 79c901 Ethernet PHYs # Pseudo-Devices # disk/mass storage pseudo-devices # network pseudo-devices # miscellaneous pseudo-devices |
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系统就已经做好了。