How to Make a Computer Operating System (2)

第一步是建立一个良好和可行的开发环境。使用Vagrant和Virtualbox,您将能够从很多平台(Linux、Windows或Mac)编译和测试您的操作系统。

Install Vagrant 安装Vagrant

Vagrant is free and open-source software for creating and configuring virtual development environments. It can be considered a wrapper around VirtualBox.

Vagrant是一款用于创建和配置虚拟开发环境的免费开源软件。它可以看作是VirtualBox的包装器。

Vagrant will help us create a clean virtual development environment on whatever system you are using.
The first step is to download and install Vagrant for your system at

Vagrant将帮助我们在您使用的任何系统上创建一个干净的虚拟开发环境。第一步是在 为您的系统下载并安装Vagrant。

Install Virtualbox 安装Virtualbox

Oracle VM VirtualBox is a virtualization software package for x86 and AMD64/Intel64-based computers.

Oracle VM VirtualBox是一个针对x86和AMD64/intel64计算机的虚拟化软件包。

Vagrant needs Virtualbox to work, Download and install for your system at https://www.virtualbox.org/wiki/Downloads.

Vagrant先需要安装Virtualbox,将它下载和安装到您的系统,下载地址:https://www.virtualbox.org/wiki/Downloads。

Start and test your development environment 启动并测试您的开发环境

Once Vagrant and Virtualbox are installed, you need to download the ubuntu lucid32 image for Vagrant:

安装好Vagrant和Virtualbox后,需要下载ubuntu lucid32的Vagrant:

vagrant box add lucid32

Once the lucid32 image is ready, we need to define our development environment using a Vagrantfile, create a file named Vagrantfile. This file defines what prerequisites our environment needs: nasm, make, build-essential, grub and qemu.

一但lucid32映像准备好了,我们就可以使用 Vagrantfile 定义开发环境,创建一个名为 Vagrantfile 的文件。使用这个文件需要先准备以下环境:nasm、make、build-essential、grub和qemu。

Start your box using:

启动你的虚拟机

vagrant up

You can now access your box by using ssh to connect to the virtual box using:

您现在可以使用ssh访问您的虚拟机,使用:

vagrant ssh

The directory containing the Vagrantfile will be mounted by default in the /vagrant directory of the guest VM (in this case, Ubuntu Lucid32):

包含Vagrantfile的目录将默认挂载在客户VM的 /vagrant 目录中(本例中为Ubuntu Lucid32):

cd /vagrant Build and test our operating system 构建和测试我们的操作系统

The file Makefile defines some basics rules for building the kernel, the user libc and some userland programs.

文件Makefile定义了一些构建内核、用户libc和一些用户空间程序的基本命令规则。

Build:

构建:

make all

Test our operating system with qemu:

使用qemu测试我们的操作系统:

make run

The documentation for qemu is available at QEMU Emulator Documentation.

You can exit the emulator using: Ctrl-a.

qemu的文档可以在QEMU Emulator Documentation(qemu模拟器文档)中找到。

您可以使用:Ctrl-a退出模拟器。

Chapter 3: First boot with GRUB 第3章:GRUB主引导 How the boot works?

引导是如何工作的?

When an x86-based computer is turned on, it begins a complex path to get to the stage where control is transferred to our kernel's "main" routine (kmain()). For this course, we are only going to consider the BIOS boot method and not it's successor (UEFI).

当一台基于x86的计算机被启动时,它会经历一段很复杂的路程,以到达将控制权转移到内核“主”例程(“kmain()”)的阶段。对于本课程,我们只考虑BIOS引导方法,而不考虑它的后续方法(UEFI)。

The BIOS boot sequence is: RAM detection -> Hardware detection/Initialization -> Boot sequence.

BIOS引导序列为:RAM检测->硬件检测/初始化->引导序列。

The most important step for us is the "Boot sequence", where the BIOS is done with its initialization and tries to transfer control to the next stage of the bootloader process.

对我们来说最重要的步骤是“引导序列”,此时BIOS完成了初始化,并试图将控制转移到引导加载程序的下一个阶段。

During the "Boot sequence", the BIOS will try to determine a "boot device" (e.g. floppy disk, hard-disk, CD, USB flash memory device or network). Our Operating System will initially boot from the hard-disk (but it will be possible to boot it from a CD or a USB flash memory device in future). A device is considered bootable if the bootsector contains the valid signature bytes 0x55 and 0xAA at offsets 511 and 512 respectively (called the magic bytes of the Master Boot Record, also known as the MBR). This signature is represented (in binary) as 0b1010101001010101. The alternating bit pattern was thought to be a protection against certain failures (drive or controller). If this pattern is garbled or 0x00, the device is not considered bootable.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfsxx.html