Windows下用Bochs编译运行Linux-0.11

Linux内核学习 专栏收录该内容
5 篇文章 1 订阅

简要介绍:Bochs主要是一个免费且开源的基于x86架构PC机模拟器。学习linux0.11内核,推荐在该模拟器上进行。

  • 环境搭建步骤:

1、下载Linux0.11系统包,本链接的下载包已包含Bochs软件。

点击打开链接http://oldlinux.org/Linux.old/bochs/linux-0.11-devel-040329.zip
2、解压linux-0.11-devel-040329.zip,目录结构如下图所示:


这里真正使用到的文件为:Bochs-2.1.1.exe 、bochsrc-hd.bxrc、bootimage-0.11、bootimage-0.11-hd、hdc-0.11.img

3、点击Bochs-2.1.1.exe进行安装。

4、安装完毕后,将所有linux-0.11-devel-040329下的文件,拷贝到刚才安装bochs下的根目录。原目录如下:


拷贝过后目录为:


5、拷贝完成后,运行bochsrc-hd.bxrc,若安装成功,打开即能见到如下界面:


这已经是x86PC模拟器上,搭建完成的Linux操作系统。建立linux操作平台命令,就能操作Linux。由于学习操作系统需要,我们需要在Linux下,编译操作系统以及完成简单的源码修改,从而达到理解Linux内核的能力。接下来,主要演示Linux内核源码的修改,以及内核的编译过程。由于该Linux版本的原因,我们还需要对代码做出调整,方能成功编译。

  • 内核编译过程:

1、进入/usr/src/linux 目录下,键入命令 cd ../src/linux ,如下图所示:


2、进行编译,键入命令 make clean 和 make后。


若出现如下所示错误:gcc-cc1: Invalid option "string-insns"。这是需将Linux目录下的Makefile文件中的-mstring-insns参数去掉。除此之外,每个子目录fs,lib,kernel以及kernel目录下的三个驱动程序子目录(math, blk_drv, chr_drv)的Makefike当中的-mstring-insns参数去除掉。此处只演示根目录下的Makefile文件修改。

3、依次修改:/linux/Makefile、/linux/fs/Makefile、/linux/lib/Makefile、

/linux/kernel/Makefile、/linux/kernel/math/Makefile、/linux/kernel/blk_drv/Makefile、/linux/kernel/chr_drv/Makefile文件。linux目录下,键入:vi Makefile。如下图所示:


找到文件中的-mstring-insns 参数,并删去保存。

4、到/usr/local/bin中找到文件ar,并把ar 改名为gar,键入命令:mv ar gar。如下图所示:


5、回到linux 目录下,重新键入make clean以及 make,完成内核的编译链接。


出现上图提示,即表面程序编译成功。完成编译后,便可以开始修改内核源码,从而达到扩展操作系统功能以及学习操作系统的目的。这里,我们简单修改下,linux操作系统开机启动项bootsect.s源码,让开机后输出个性化的字符串。

6、进入/usr/src/linux/boot目录,修改bootsect.s源码,保存并退出。

! Print some inane message
mov    ah,#0x03        ! read cursor pos
xor    bh,bh
int    0x10
mov    cx,#47
mov    bx,#0x0007        ! page 0, attribute 7 (normal)
mov    bp,#msg1
mov    ax,#0x1301        ! write string, move cursor
int    0x10
msg1:
.byte 13,10
.ascii "Loading system ...this is create by demon"
.byte 13,10,13,10
.org 508

7、修改完成后,在linux目录下,重新键入make命令,完成编译。

8、make成功后生成引导启动映象文件Image。若需要输出这个Image文件, 可以首先备份bootimage-0.11-hd文件, 然后使用下面命令就会把bootimage-0.11-hd替换成新的引导启动文件,键入命令:dd bs=8192 if=Image of=/dev/fd0。如下图所示:


9点击reset重启Linux操作系统。如下图所示:



# # Install the bochs emulate system first! # Included is bochs version 2.1.1 packet.(Bochs-2.1.1.exe) #---------------------------------------------------------- # This is a root file system for linux 0.11 kernel. # Rebuild from materials gathered from Internet. # # Zhao Jiong ( gohigh@sh163.net ) # http://oldlinux.org/ 2004.1.4 # Third release 2004.3.29 Now, this is a very basic root file system for linux 0.1x. I will add more things to this release soon. see the changelog bellow. This release is a basic system. you can test vi, ls, mkdir etc. Just for testing with kernel source code. Now I have added gcc 1.40 tools into the harddisk rootimage file. you can compile some c source file now. enjoy it :-) NOTE: By using the resources in this directory, you must first install the Bochs emulation software in your system. The included Bochs-2.1.1.exe is for win32. You can always download the newest version of it from http://sourceforge.net When testing floppy root (as running bochsrc-fd), when showing the message of " Insert root floppy and press ENTER", JUST press the Enter key. I have already attached the root floppy to the 'B:' diskette driver. The system will panic unpredicatablly. Use at your own risk! Changelog: ===================== 2004.3.29 Add gcc 1.40 & libs into the harddisk image. Now you can compile the orignal kernel sources without need any modification to it! But when running the system, please read another README file in /usr/root directory first. ------------------------------------------------ cd /usr/root gcc -s -o hello hello.c ./hello ------------------------------------------------ files included: README -- This file. Bochs-2.1.1.exe -- Bochs system for use in win32 environment. Must be installed on your windows system first. bootimage-0.11 -- kernel 0.11 bootimage request rootimage from floppy. bootimage-0.11-fd -- request rootimage in disk b: bootimage-0.11-hd -- boot harddisk root file system. bootimage-0.12-fd -- kernel 0.12 bootimage use with floppy root iamge. bootimage-0.12-hd -- kernel 0.12 bootimage use with harddisk root image. rootimage-0.11 -- kernel 0.11 rootimage. hdc-0.11 -- harddisk root filesystem image. diskb.img -- a dos format disk image. can be w/r with mtools. example: mdir b:, mcopy b:, mdel b:filename bochsrc-fd.bxrc -- bochs rc file configured for using disk root iamge. bochsrc-hd.bxrc -- bochs rc file configured for using hd root image. gcclib-1.40.taz -- tar files of the gcc bins & libs. You can change the line 'floppya' in bochsrc-xx.bxrc file to use the diferent bootimage file provided. In order to insert any programs into the hd image file, you can use winimage program or something like that to add/delete files in diskb.img and then read these files by using mtoos in the system. Play & enjoy the pleasure of it! 2004.3.4 This is truelly kernel 0.11 driving system!! In order to run bash 1.12.1, I inserted several system call stubs. To show the file date correctly, I added one line to the kernel/mktime.c at the top of file. For details, see the linux-0.11.dif file. Add Input/Output tools, such as mtools dealing with DOS diskettes, mount/umount command, compress, df, awk... ~ ~ ~ :wq #
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值