摘要: 在Linux系统中在Bochs模拟器上安装Minix系统。
Contents [Hide ]
|
首先建立安装Minix虚拟机的目录:
mkdir ~/minix
将Minix 2.0.0的光盘文件放在:
mkdir ~/minix/cdrom
最新的Minix2的版本是2.0.4,可以在: http://www.minix3.org/previous-versions/index.html 下载。
为什么没有使用最新版本,而是2.0.0?
这里用到的安装目录有:
~/minix/cdrom/MINIX:
i386\ROOT - Minix boot & root floppy image (386 and better)
i386\USR - Floppy image with programs needed for installation
i386\USR.TAZ - All Minix programs, libraries, etc.
SYS.TAZ - System sources and manual pages
CMD.TAZ - Commands sources
在MINIX目录下还有和安装相关帮助文件。 另外,在2.0.4的发布版本中,包含有许多html格式的 文档和手册页,这些是很有帮助的。
Bochs是一个IA86(x86)硬件的模拟器(emulator), 它所有的虚拟硬件都是通过软件模拟 完成的,和其他虚拟机(vmware, virtual box, virtual pc, qemu)相比,速度较慢, 但是支持硬件级别的调试,适合于学习系统内核。
sudo apt-get install bochs bochs-doc bochs-wx bochs-term bochsbois bximage
cd ~/minix
使用 bximage
命令创建磁盘映像,
bximage
运行命令 bximage
,会出现如下提示,按提示创建一个100M的硬盘,
使用flat类型,一次性分配所有硬盘空间:
========================================================================
bximage
Disk Image Creation Tool for Bochs
$Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts Exp $
========================================================================
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] hd
What kind of image should I create?
Please type flat, sparse or growing. [flat]
Enter the hard disk size in megabytes, between 1 and 129023[10]
100
I will create a 'flat' hard disk image with
cyl=203
heads=16
sectors per track=63
total sectors=204624
total size=99.91 megabytes
What should I name the image?
[c.img] minix-hd.img
Writing: [] Done.
I wrote 104767488 bytes to minix-hd.img.
The following line should appear in your bochsrc:
ata0-master: type=disk, path="minix-hd.img", mode=flat, cylinders=203, heads=16, spt=63
将生成的配置命令行:
ata0-master: type=disk, path="minix-hd.img", mode=flat, cylinders=203, heads=16, spt=63
保存在 ~/minix/.bochsrc
文本文件中。
再次运行命令 bximage
, 按照提示生成1.44M软盘的映像:
========================================================================
bximage
Disk Image Creation Tool for Bochs
$Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts Exp $
========================================================================
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd
Choose the size of floppy disk image to create, in megabytes.
Please type 0.16, 0.18, 0.32, 0.36, 0.72, 1.2, 1.44, 1.68, 1.72, or 2.88.
[1.44] 1.44
I will create a floppy image with
cyl=80
heads=2
sectors per track=18
total sectors=2880
total bytes=1474560
What should I name the image?
[a.img] minix-fd.img
Writing: [] Done.
I wrote 1474560 bytes to minix-fd-boot.img.
The following line should appear in your bochsrc:
floppya: image="minix-fd.img", status=inserted
将生成的配置命令行:
floppya: image="minix-fd.img", status=inserted
保存在 ~/minix/.bochsrc
文本文件中。
磁盘映像和磁盘的没有经过文件系统格式化的绝对存储是对应的, 因此还有一些比较便捷的方法生成磁盘映像:
dd if=/dev/zero of=minix-fd.img bs=1440k count=1
dd if=/dev/zero of=minix-hd.img bs=1M count=100
关于磁盘的绝对读写,可以参考dd
命令的手册页。
现在来修改bochs的启动配置 ~/minix/.bochsrc
。
可以参考bochs-doc
中的样本-
/usr/share/doc/bochs/examples/bochsrc.gz
将.bochrc
修改为:
config_interface: textconfig display_library: wx floppya: image="/home/justin/minix/minix-fd.img", status=inserted ata0-master: type=disk, path="/home/justin/minix-hd.img", mode=flat, cylinders=203, heads=16, spt=63 boot: floppy, disk, cdrom keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map
注意: 实际上,还有许多的默认启动参数,Bochs可以通过 /etc/bochs-init/bochsrc
中来获得,
在上述文件中可以覆盖默认的启动选项,这里给出一个虚拟机器的最简单配置。
现在可以通过命令行:
cd ~/minix bochs -q -f .bochsrc
启动我们的虚拟机,在屏幕上出现:
Plex86/Bochs VGABios current-cvs 02 Dec 2009
This VGA/VBE Bios is released under the GNU LGPL
Please visit :
. http://bochs.sourceforge.net
. http://www.nongnu.org/vgabios
Bochs VBE Display Adapter enabled
Bochs BIOS - build: 06/08/10
$Revision: 1.247 $ $Date: 2010/04/04 19:33:50 $
Options: apmbios pcibios pnpbios eltorito rombios32
ata0 master: Generic 1234 ATA-6 Hard-Disk ( 99 MBytes)
Press F12 for boot menu. # <F12> Pressed
Select boot device:
1. Floppy
2. Hard Disk
3. CD-Rom
现在机器还是一台裸机,只能通过开机时的 F12
键进入Bios的启动菜单。
至此完成了一个可开机的虚拟机器。
参考资料:http://fanqiang.chinaunix.net/program/project/2005-11-03/3795.shtml
在Linux和Bochs下制作启动软盘是相当容易的:
cd ~/minix cat cdrom/MINIX/i386/ROOT cdrom/MINIX/i386/USR > minix-fd.img
这是因为ROOT和USR已经是sector-by-sector的磁盘数据,因此可以直
接用cat写入到磁盘映像中。从名字上可以猜测到,ROOT和USR是软盘
上的系统映像 /
和 /usr
。
上述方法对minix-fd.img
是破坏性质的,因为
ROOT
与USR
的大小之和比
1.44M小,minx-fd.img
会被truncate掉。因此需要在安
装后重新用 bximage
生成该映像。
比较稳妥的办法是:
cat cdrom/MINIX/i386/ROOT cdrom/MINIX/i386/USR > tmp.img dd if=tmp.img of=minix-fd.img conv=notrunc
除了启动软盘,在安装过程中,需要制作一系列的数据软盘,其中:
~/minix/cdrom/MINIX/I386/USR.TAR
,包含应用程序
需要3张1.44M软盘~/minix/cdrom/MINIX/SRC.TAR
, 包含系统内核,库
函数的源代码,需要2张1.44M的软盘~/minix/cdrom/MINIX/CMD.TAR
, 包含命令和应用程
序的源代码,需要3张1.44M的软盘以USR.TAR为例子,介绍两种数据软盘映像的制作:
cd ~/minix split -b 1440k cdrom/MINIX/I386/USR.TAR
这样会将USR.TAR分割为3个文件,xaa、xab、xac,在需要的时候依次导入磁盘:
cat xaa > minix-fd.img # some ops ... cat xab > minix-fd.img # some ops ... cat xab > minix-fd.img
这样做也会出现minix-fd.img被truncate的情况,有时候会在安装的时候出现问题
cd ~/minix dd if=cdrom/MINIX/I386/USR.TAR of=minix-fd.img bs=1440k count=1 skip=0 conv=notrunc # some ops ... dd if=cdrom/MINIX/I386/USR.TAR of=minix-fd.img bs=1440k count=1 skip=1 conv=notrunc # some ops ... dd if=cdrom/MINIX/I386/USR.TAR of=minix-fd.img bs=1440k count=1 skip=2 conv=notrunc
下面介绍的时候不再说明如何制作这些,在指出需要插入USR.TAR的第 1/2/3张软盘,分别执行上述第1/2/3条cat或者dd命令即刻。
现在就可以用这个映像来启动Bochs虚拟机器了。
运行 bochs
:
cd ~/minix bochs -q -f .bochsrc
可以在启动屏幕上看到:
Minix 2.0.0 Copyright 1997 Prentice-Hall, Inc.
Executing in 32-bit protected mode
Memory size = 8010K MINIX = 295K RAM disk = 480K Available = 7236K
RAM disk loaded.
Tue Oct 1 16:21:37 MET 1996
Finish the name of device to mount as /usr: /dev/fd0c
对于1.44M的软盘来说,/usr
已经是这张软盘了,可以输入 /dev/fd0c
。
现在进入登录界面:
/dev/fd0c is read-write mounted on /usr
Starting standard daemons: update.
Login as root and run 'setup' to install Minix.
Minix Release 2.0 Version 0
noname login: root
以root用户身份登录(密码默认为空),然后执行
setup
,进入安装程序:
# setup
This is the Minix installation script.
Note 1: If the screen blanks suddenly then hit F3 to select "software
scrolling".
Note 2: If things go wrong then hit DEL and start over.
Note 3: The installation procedure is described in the manual page
usage(8). It will be hard without it.
Note 4: Some questions have default answers, like this: [y]
Simply hit RETURN (or ENTER) if you want to choose that answer.
Note 5: If you see a colon (:) then you should hit RETURN to continue.
: [enter]
What type of keyboard do you have? You can choose one of:
french italian latin-am scandinavn uk us-swap
german japanese olivetti spanish us-std
Keyboard type? [us-std] [enter]
将键盘设置为 use-std
因为采用的硬盘映像,整个磁盘都可以分给Minix,编译Minix内核需要30M的空间,所以系统分区
必需大于30M,这里将100M硬盘分成两个50M的分区。其中一个被Minix安装程序分成4个子分区,
前三个分别用于: /
, swap
, /usr
硬盘分区为:
Select device —-first—- —geom/last— ——sectors——
Device Cyl Head Sec Cyl Head Sec Base Size Kb
/dev/hd0 203 16 63
0 0 0 202 15 62 0 204624 102312
Num Sort Type
1* hd1 81 MINIX 0 1 0 103 13 43 63 104624 52312
2 hd2 81 MINIX 103 13 44 202 15 45 104687 99920 49960
3 hd3 00 None 0 0 0 0 0 -1 0 0 0
4 hd4 00 None 0 0 0 0 0 -1 0 0 0
hd1的子分区为:
Active flag —-first—- —geom/last— ——sectors——
Device Cyl Head Sec Cyl Head Sec Base Size Kb
/dev/hd0 203 16 63
/dev/hd0:1 0 1 0 103 13 43 63 104624 52312
Num Sort Type
1* hd1a 81 MINIX 0 1 1 2 14 45 64 2880 1440
2 hd1b 00 None 0 0 0 0 0 -1 0 0 0
3 hd1c 81 MINIX 2 14 46 103 13 43 2944 101743 50871
4 hd1d 00 None 0 0 0 0 0 -1 0 0 0
具体操作参考part的手册页和联机帮助。
联机帮助中有一些有用的提示为:
*Choose a disk with '+' and '-', then hit 'r'.
*To change any value: Move to it and use '+', '-' or type the desired value.
*To make a new partition: Move over to the Size or Kb field of an unused
partition and type the size. Hit the 'm' key to pad the partition out to
a cylinder boundary. Hit 'm' again to pad it out to the end of the disk.
You can hit 'm' more than once on a base or size field to see several
interesting values go by. Note: Other Operating Systems can be picky about
partitions that are not padded to cylinder boundaries. Look for highlighted
head or sector numbers.
*To reuse a partition: Change the type to MINIX.
*To delete a partition: Type a zero in the hex Type field.
*To make a partition active: Type '+' in the Num field.
*To study the list of keys: Type '?'.
还有一些键盘操作:
? ! - This help / more advice!
+ - (= _ Pg Up Pg Dn) - Select/increment/decrement/make active
0-9 (a-f) - Enter value
hjkl (arrow keys) - Move around
CTRL-K CTRL-J - Move entry up/down
CTRL-L - Redraw screen
> - Start a subpartition table
< - Back to the primary partition table
m - Cycle through magic values
spacebar - Show "Size" or "Last"
r w - Read/write partition table
p s q x - Raw dump / Shell escape / Quit / Exit
y n DEL - Answer "yes", "no", "cancel"
Things like this must be checked, but this is not really a problem
当修改完成后,按 q
退出,按 y
确认保存分区表。
Save partition table? (y/n) y
随后确认将minix安装至分区 /dev/hd1
:
Please finish the name of the primary partition you have created:
(Just type RETURN if you want to rerun "part") /dev/hd1
You have created a partition named: /dev/hd3
The following subpartitions are about to be created on /dev/hd1:
Root subpartition: /dev/hd1a 1440 kb
/usr subpartition: /dev/hd1c rest of hd3
Hit return if everything looks fine, or hit DEL to bail out if you want to
think it over. The next step will destroy /dev/hd1.
: [enter]
Migrating from floppy to disk...
Scanning /dev/hd3c for bad blocks. (Hit DEL to stop the scan if are absolutely
sure that there can not be any bad blocks. Otherwise just wait.)
cp /fd0/etc/hostname.file /mnt/etc/hostname.file
cp /fd0/etc/motd /mnt/etc/motd
...
mkdir /mnt/root
mkdir /mnt/tmp
cp /fd0/.ellepro.b1 /mnt/.ellepro.b1
/dev/fd0 unmounted from /fd0
/dev/hd1a unmounted from /mnt
系统安装完成后,会确认系统的内存大小, 默认系统物理内存为15M,大于4096, 直接回车:
What is the memory size of this system in kilobytes? [4096 or more] [enter]
Second level file system block cache set to 1024 kb.
完成后从硬盘上启动系统,验证安装:
Please insert the installation ROOT floppy and type 'halt' to exit Minix.
You can type 'boot hd1' to try the newly installed Minix system. See
"TESTING" in the usage manual.
# halt
System Halted
fd0> boot hd1
Minix 2.0.0 Copyright 1997 Prentice-Hall, Inc.
Executing in 32-bit protected mode
at-hd0: Conner Peripherals 240MB - CP2251
Memory size = 15946K MINIX = 516K RAM disk = 1024K Available = 14406K
Tue Oct 1 16:39:24 MET 1996
/dev/hd1c is read-write mounted on /usr
Starting standard daemons: update.
Login as root and run 'setup /usr' to install floppy sets.
Minix Release 2.0 Version 0
noname login: root
至此,一个最简单的Minix系统安装成功。
最小安装外,还需要安装一些实用程序,系统源代码,以便学习Minix
使用USR.TAR的三张软盘,以root登录,运行:
noname login: root
# setup /usr
What is the size of the images on the diskettes? [all] 1440
What floppy drive to use? [0] [enter]
Please insert input volume 1 and hit return
created directory: local/lib
created directory: local/man
created directory: local/src
created directory: man
Can't make directory mdec: File exists ignore this
...
Please insert input volume 2 and hit return [enter]
...
Please insert input volume 3 and hit return [enter]
...
按照提示依次插入3张软盘,方法已在前面详细说明。
使用SYS.TAR的两张软盘,方法同上。
使用CMD.TAR的三张软盘,方法同上。
2.0.4附带了一个补丁文件,FIX.TAR, 安装方法同上。 实际上,可以通过这种方法安装任意的TAR文件到系统某个目录:
setup /usr/mydir
Minix安装后的源代码在/usr/src
:
-rw-r--r-- 1 bin operator 341 Oct 1 1996 .ashrc -rw-r--r-- 1 bin operator 300 Oct 1 1996 .ellepro.b1 -rw-r--r-- 1 bin operator 6001 Aug 3 11:31 .ellepro.e -rw-r--r-- 1 bin operator 44 Oct 1 1996 .exrc -rw-r--r-- 1 bin operator 393 Oct 1 1996 .profile -r--r--r-- 1 bin operator 3996 Oct 1 1996 LICENSE -rw-r--r-- 1 bin operator 619 Oct 1 1996 Makefile drwxr-xr-x 2 bin operator 448 Aug 3 12:41 boot drwxr-xr-x 37 bin operator 608 Jul 29 01:38 commands -rw-r--r-- 1 bin operator 68900 Oct 1 1996 crclist drwxr-xr-x 2 bin operator 192 Jul 29 01:44 etc drwxr-xr-x 2 bin operator 960 Aug 2 17:47 fs drwxr-xr-x 3 bin operator 432 Aug 6 23:18 inet drwxr-xr-x 3 bin operator 1552 Aug 6 23:08 kernel drwxr-xr-x 18 bin operator 448 Aug 2 14:55 lib drwxr-xr-x 2 bin operator 528 Aug 2 17:44 mm drwxr-xr-x 2 bin operator 800 Jul 29 01:48 test drwxrwxrwx 2 bin operator 32 Oct 1 1996 tmp drwxr-xr-x 2 bin operator 176 Aug 2 17:48 tools
Minix还有一部分可供修改的头文件在 /usr/include
下。
这里说明编译各个模块的步骤:
# update /usr/src/lib/Makefile first if necessary cd /usr/src/lib make install reboot cd /usr/src/tools make hdboot reboot
cd /usr/src/kernel make install cd /usr/src/tools make hdboot reboot
编译mm、boot、inet、fs等模块, 先进入相应目录,采用和内核相同的方式进行。
/usr/src/commands
包含了许多命令行的实用工具:
如果想编译其中的一个,例如 ping
:
cd /usr/src/commands/simple make ping make /usr/bin/ping #install
如果想编译所有命令行工具,步骤类似上述,但是不需要reboot
。
make hdboot
和 make fdboot
分别制作硬盘和软盘的启动映像。
在重新编译和使用新的内核前,需要对原有的稳定的内核备份, 防止新的内核无法正常使用,甚至Crash。
Minix的内核在 /minix
目录下。
原始的内核文件名称为 /minix/2.0.0
, 一旦编译并执行了
make hdboot
,就会将该文件删除,生成文件名为
/minix/2.0.0rX
的新的内核(X是内核修改版本,初试值为1,递增)。
实际上,被删除的是/minix
目录下最新的那个文件。
在编译安装新内核前,备份原有内核文件:
cd /minix mkdir bak cp 2.0.0rX bak
一旦新的内核无法使用,需要在Boot Monitor中指定使用备份的系统 内核:
hd1a> image=/minix/bak/2.0.0rX hd1a> boot
然后删除有问题的内核,重新恢复已经备份的内核即可。
为了方便Minix和宿主机交换信息,利用宿主机的编译开发环境, 我们需要在二者之间建立网络连接。
在上述Bochs的配置中,使用的是宿主机Linux系统中的真实的网卡作 为Bochs的网络设备,这样配置虽然在Bochs上的Minxi可以访问网络, 但是宿主机上Linux和Bochs上Minix通过网络连接是有障碍的,这里利 用Linux中的虚拟网卡来建立Linux和Bochs之间的一个内部网络,然后 通过Linux的iptable的设置,使bochs可以通过宿主机来连接 internet,或者和宿主机上的Linux交互。
目标网络地址:
配置Linux下的虚拟网卡, 参考资料:http://bochs.sourceforge.net/doc/docbook/user/config-tuntap.html
在Debian文件 /etc/modules
添加:
alias char-major-10-200 tun
运行命令,自动装载内核模块所添加的内核模块:
depmod -a
~/local/bin/tunconfig
脚本,利用iptable实现network masquerade:#!/bin/bash /sbin/ifconfig ${1##/*/} 192.168.1.1 /sbin/iptables -D POSTROUTING -t nat -s 192.168.1.0/24 -d ! 192.168.1.0/24 -j MASQUERADE >& /dev/null /sbin/iptables -t nat -s 192.168.1.0/24 -d ! 192.168.1.0/24 -A POSTROUTING -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward
~/minix/.bochsrc
中的网卡配置,使用如下配置:ne2k: ioaddr=0x300, irq=5, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=/dev/net/tun, script=/home/justin/local/bin/tunconfig
sudo bochs -q -f .bochsrc
Esc
,进入Boot
Monitor环境,修改Boot Monitor的启动参数配置:hd1a> DPETH0=300:5 hd1a> save hd1a> boot
/src/include/minix/config.h
中的下述参数值:#define ENABLE_NETWORKING 1 //enable networking #define NR_PTYS 8 //used by telnet #define NR_PROCS 32 //used by telnet
为了避免Bochs出现网络错误对话框:
+-------------------------------------------+ |PANIC |X|| +-------------------------------------------+ | Device [NE2K] | | Message CR write - tx start, dev in reset| | | | +--------+ | | Continue | OK | | | Continue and don't ask again +--------+ | | Kill simulation +--------+ | | Abort (dump core) | Cancel | | | +--------+ | +-------------------------------------------+
需要在使用补丁:http://minix1.woodhull.com/pub/minix.2.0/2.0.4/fixes/dp8390fx.tar.Z
修改/usr/src/kernel/dp8390.c
具体参考:http://minix1.woodhull.com/faq/bxmxhowto.html#netmob
cd /usr/src/kernel make install cd /usr/src/tools make hdboot reboot
/etc/rc.net
:ifconfig -h 192.168.1.2 -n 255.255.255.0 add_route -g 192.168.1.1
/etc/resolv.conf
:nameserver xxx.xxx.xxx.xxx # used by Linux
其中xxx.xxx.xxx.xxx是Linux系统所使用的DNS server。
/etc/hosts
:192.168.1.1 hostme 192.168.1.2 minix
passwd
最后两步是为了使用ftp做的设置,ftp要求登录用户ip的主机名可知, 登录用户密码不为空。
Minix下的开发环境包括编辑器,编译器,构建环境,版本控制。
Minix默认支持2个的控制台登录, 用F1
和 F2
来切换。
Minix环境自带了vi, elle, mined编辑器, 其中elle(Elle Looks Like Emacs)和Emacs相似,但是需要一个小小的配置:
cd / #相对于root的HOME目录,cd ~ mv .ellepro.b1 .ellepro.b1.bak
这样elle的行为就更像emacs, 但是还是有很多差别的,具体可以参考elle的manpage。
可以通过修改编译 /usr/src/.ellepro.e
来生成新的 .ellepro.b1
。
cc
是默认的编译工具链,包含下面一些东西:
Program Input Output Operation performed lib/ncpp prog.c prog.i C preprocessor: #include, #define, #ifdef lib/irrel prog.i prog.i Removal of unnecessary prototypes lib/ncem prog.i prog.k Parsing and semantic analysis lib/nopt prog.k prog.m Optimization of the intermediate code lib/ncg prog.m prog.s Code generation bin/as prog.s prog.o Assembly lib/ld prog.o prog.out Linking lib/cv prog.out a.out Conversion to MINIX a.out format
编译自己的程序,可以尝试以下步骤:
cd /usr/tmp cc hello.c -o hello chmod +x hello ./hello
Minix安装中带有一个微型版的make工具。
Minix甚至有一个简单的版本控制工具SVC,使用方法:
ci -u file
ci -lu file
co -l file
co -l -r 2 file
co -r 2 file
svnlog file
~/minix/cdrom/DEBUGGER/MDB.TAZ
是一个Minix下的Debugger.
安装方法:
1) Place MDB.TAZ on a floppy with FDVOL
2) Boot Minix, login as bin and type: setup /usr/local/src
3) Move to /usr/local/src/mdb and review additional information in the
README file.
4) Edit Makefile for Compiler and extra options as required.
5) make
6) make install
7) make install_man
上述安装*.TAZ文件的过成就是使用的Raw Disk实现宿主机与Minix的交换。
需要安装如下软件包:
sudo apt-get install ncompress
如何得到一个.TAZ文件:
tar cvf files.tar files ... compress files.tar mv files.tar.Z files.TAZ
把资料写入软盘:
cat files.TAZ > minix-fd.img
进入minix执行:
setup /usr/local/src # any dir you want put files
参考资料:http://bochs.sourceforge.net/doc/docbook/user/loop-device-usage.html
首先在minix下格式化一张软盘:
format /dev/fd0 1440 1440
将软盘的image通过loop虚拟设备装载:
sudo losetup /dev/loop0 ~/minix/minix-fd.img mount -t minix /dev/loop0 -o loop /mnt/floppy
如果想转入minix下使用:
umount /mnt/floppy sudo losetup -d /dev/loop0
ftp 192.168.1.2
或者通过emacs tramptelnet 192.168.1.2
Minix3 Latest - http://www.minix3.org
Minix2 and Minix1 - http://minix1.woodhull.com/
Minix Network and Boot - http://www.os-forum.com/minix/
The two authors' homepages of Operating System - Design and Implementation:
news group - comp.os.minix
Wiki comments powered by Disqus