下载实验包hit-oslab-linux-20110823.tar.gz(包含linux-0.11源码、bochs虚拟机等):php
https://cms.hit.edu.cn/pluginfile.php/3329/mod_folder/content/6/hit-oslab/hit-oslab-linux-20110823.tar.gz?forcedownload=1
下载gcc-3.4-ubuntu.tar.gz(编译linux-0.11须要用到的低版本gcc):linux
https://cms.hit.edu.cn/pluginfile.php/3329/mod_folder/content/6/hit-oslab/gcc-3.4-ubuntu.tar.gz?forcedownload=1
在~(用户Home文件夹)下建立workspace文件夹,将hit-oslab-linux-20110823.tar.gz解压到workspace下:shell
mkdir workspace cd workspace tar xzf hit-oslab-linux-20110823.tar.gz
解压gcc-3.4-ubuntu.tar.gz到/opt下:ubuntu
cd /opt tar xzf ~/Downloads/gcc-3.4-ubuntu.tar.gz
安装gcc-3.4(由于个人是64位系统,因此安装参数为amd64;若为32位系统,参数应为i386):vim
cd gcc-3.4 sudo ./inst.sh amd64
搜索包含as8六、ld86的包:缓存
apt-cache search as86 ld86
执行结果:工具
bin86 - 16-bit x86 assembler and loader
安装bin86:oop
sudo apt-get install bin86
sudo apt-get install libc6-dev-i386
sudo apt-get install build-essential
sudo apt-get install vim cscope exuberant-ctags
1 cd ~/workspace/oslab/linux-0.11 2 make
编译中断,输出错误信息:ui
In file included from /usr/include/linux/fs.h:10, from tools/build.c:28: /usr/include/linux/ioctl.h:4:23: asm/ioctl.h: No such file or directory In file included from /usr/include/linux/fs.h:11, from tools/build.c:28: /usr/include/linux/types.h:4:23: asm/types.h: No such file or directory In file included from /usr/include/linux/types.h:8, from /usr/include/linux/fs.h:11, from tools/build.c:28: /usr/include/linux/posix_types.h:35:29: asm/posix_types.h: No such file or directory In file included from /usr/include/linux/fs.h:11, from tools/build.c:28: /usr/include/linux/types.h:27: error: syntax error before "__le16" /usr/include/linux/types.h:28: error: syntax error before "__be16" /usr/include/linux/types.h:29: error: syntax error before "__le32" /usr/include/linux/types.h:30: error: syntax error before "__be32" /usr/include/linux/types.h:31: error: syntax error before "__le64" /usr/include/linux/types.h:32: error: syntax error before "__be64" /usr/include/linux/types.h:34: error: syntax error before "__sum16" /usr/include/linux/types.h:35: error: syntax error before "__wsum" In file included from tools/build.c:28: /usr/include/linux/fs.h:43: error: syntax error before "__u64" /usr/include/linux/fs.h:45: error: syntax error before "minlen" make: *** [tools/build] Error 1
google搜索得知是由于64位linux的asm目录为:google
/usr/include/x86_64-linux-gnu/asm
make找不到文件从而致使编译中断
解决方法(创建连接):
sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
运行编译好的内核,在oslab目录下:
./run
出现错误:
./bochs/bochs-gdb: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory
打印动态连接配置:
ldconfig -p | grep libSM.so.6
libSM.so.6的连接信息:
libSM.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libSM.so.6
咱们须要的是32位的。搜索库对应的包名称:
apt-file search libSM.so.6
打印结果:
libsm6: /usr/lib/x86_64-linux-gnu/libSM.so.6 libsm6: /usr/lib/x86_64-linux-gnu/libSM.so.6.0.1
获得其对应的包名为libsm6,安装对应的32位库:
sudo apt-get install libsm6:i386
再次尝试,出现错误:
./bochs/bochs-gdb: error while loading shared libraries: libXpm.so.4: cannot open shared object file: No such file or directory
也可按以上方法解决,不过这里用了另外一个工具:
dpkg-query -S libXpm.so.4
同理解决之,再次尝试:
./run
成功运行!
./dbg-asm
操做参考Bochs使用手册
./dbg-c
Ctrl+Alt+T打开另外一个终端窗口,进到~/workspace/oslab下执行:
./rungdb
出现两次库不存在错误,按照上面的方法安装对应32位库解决后运行成功:
操做参考GDB的Manuel:
man gdb
./mount-hdc
mount-hdc是一个shell脚本:
1 #!/bin/sh 2 export OSLAB_PATH=$(dirname `which $0`) 3 mount -t minix -o loop,offset=1024 $OSLAB_PATH/hdc-0.11.img $OSLAB_PATH/hdc
第1行 指明脚本使用的shell
第2行 将调用本脚本的目录设置为oslab的目录
第3行 根据mount的manual手册,
-t minix 表示要挂载的文件系统类型为minix
-o[ption] 能够有3个参数(参考losetup的manual):
loop 能够指定文件所映射的回环设备;若不指定,则由mount自动搜寻
offset 指定文件或设备中数据起始位置在该文件或设备中的偏移
sizelimit 从offset开始算起文件或设备的最大大小
故此行将$OSLAB_PATH/hdc-0.11.img映射到mount搜寻到的设备中,文件系统为minix,数据起始偏移为1024byte,再挂载到$OSLAB_PATH/hdc目录下。
这样Ubuntu就能够在$OSLAB_PATH/hdc下访问Linux-0.11的文件了。
在oslab目录下:
umount hdc
1:不要在0.11内核运行的时候mount镜像文件,不然可能会损坏文件系统。同理,也不要在已经mount的时候运行0.11内核;
2:在关闭Bochs以前,须要先在Linux-0.11的命令行运行“sync”,确保全部缓存数据都存盘后,再关闭Bochs。