下載實驗包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。