What is the operating system?-familiar with the experimental environment and Operating System Environment

Source: Internet
Author: User

What is the operating system?-familiar with the experimental environment and Operating System Environment

Prepare lab materials

1. Download the experiment materials hit-oslab-linux-20110823.tar.gz (including linux-0.11 source code, bochs simulator, etc)

URL: http://www.ritchiehuang.cn/

2, download and install the gcc-3.4 (compile the linux-0.11 to use lower gcc)

URL: old-releases.ubuntu.com/ubuntu/pool/universe/g/gcc-3.4/

Download content: (Unified download stored in the new gcc-3.4 folder, because my ubuntu is 64-bit So download amd64)

1 cpp-3.4_3.4.6-6ubuntu3_amd64.deb2 g++-3.4_3.4.6-6ubuntu3_amd64.deb3 gcc-3.4_3.4.6-6ubuntu3_amd64.deb4 gcc-3.4-base_3.4.6-6ubuntu3_amd64.deb5 libstdc++6-dev_3.4.6-6ubuntu3_amd64.deb

Experiment description

1. x86 simulator Bochs

Bochs is a free and open source IA-32 (x86) architecture PC simulator. Linux, DOS, Windows, and other operating systems can be run in the simulated environment. Bochs is highly portable and can run on multiple software and hardware platforms. If you want to embrace free Linux, Bochs is your best choice. If you want to continue binding yourself to Windows, you can choose VMware or Microsoft Virtual PC in addition to Bochs. They are the most famous Virtual Machine Software and are available for free. Because Bochs is a simulator, its principle determines that its operation efficiency is lower than that of virtual machines. However, Bochs has unparalleled ability to debug operating systems on virtual machines.

2. Working Mode of the experiment environment

Hit-oslablab environment is a compressed file (hit-oslab-linux-20110823.tar.gz). You can copy this file to your experiment working directory and useTar zxvf hit-oslab-linux-20110823.tar.gzCommand to decompress and expand. Oslab works on a host operating system, we use Linux, on the host operating system to complete the development, modification and compilation of Linux 0.11, In the linux-0.11 directory will produceImageIs the target file after compilation. This file contains the binary code of the boot and all kernels. If you use a floppy disk and write the Image file content byte from its zero sector, you can use this floppy disk to start a real computer and enter the Linux 0.11 kernel.Oslab uses the bochs simulator to load the Image file and simulate the execution of Linux 0.11, saving the trouble of restarting the computer.

The bochs directory contains the bochs-related execution files, data files, and configuration files. Run is the script command for running bochs. After running bochs will automatically mount an Image file on its virtual drive A and virtual hard disk, the linux-0.11/Image is mounted on the soft drive, the hdc-0.11.img is mounted on the hard disk. Because the settings in the bochs configuration file are started from soft drive A, Linux 0.11 is automatically loaded. Linux 0.11 will drive the hard disk and mount the file system on the hard disk, that is, mount the file system of the image in the hdc-0.11.img to the root directory of the 0.11 system-"/". Access the file system under 0.11, access is the Virtual File System in the hdc-0.11.img file.

The format of the hdc-0.11.img file is an image of the Minix file system. All Linux versions support this format of file system, so you can directly access the files in this file through the mount command on the host Linux, this allows you to exchange files between the host system and Linux 0.11 running in bochs. Currently, there is no (or no) direct access to the Minix file system in Windows. Therefore, we need to use fdb. img, which is an image file of a M floppy disk and a FAT12 file system. Mount it to the soft drive B of bochs to access it in 0.11. By using filedisk or WinImage, you can access files in Windows.

Hdc-0.11.img package contains:

  • Bash shell
  • Some basic Linux commands and tools, such as cp, rm, mv, and tar.
  • Vi Editor
  • The gcc 1.4 compiler can be used to compile standard C Programs.
  • As86 and ld86
  • The source code of Linux 0.11 can be compiled under 0.11 and then overwrite the existing binary kernel.

Lab environment setup (ubuntu-14.04.1-desktop-amd64)

1, in ~ (Create an oslabfolder under the user's homefolder and decompress hit-oslab-linux-20110823.tar.gz to oslab .)

mkdir oslabcd oslabtar -zxvf hit-oslab-linux-20110823.tar.gz

2, gcc-3.4 Installation

cd gcc-3.4sudo apt-get --purge remove gcc
sudo chmod 777 *sudo dpkg -i *.deb

3. Install as86 and ld86 (for compiling and linking bootsect under linux/boot. s and setup. s, they use as86 Assembly syntax; other assembly language files under the linux-0.11 use the gas syntax AT&T)

Search for packages containing as86 and ld86:

apt-cache search as86 ld86

The execution result is as follows:

bin86 - 16-bit x86 assembler and loader

Install bin86:

sudo apt-get install bin86

4. General Environment Settings

32-bit compatible libraries must be installed for 64-bit Systems

sudo apt-get install libc6-dev-i386 

C language compiling environment

sudo apt-get install build-essential

Install IDE

sudo apt-get install vim cscope exuberant-ctags

Compile the kernel

cd ~/oslab/oslab/linux-0.11make

Compilation interrupted, output error message:

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 directoryIn 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 directoryIn 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 directoryIn 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 search found that the 64-bit linux asm directory is:

/usr/include/x86_64-linux-gnu/asm

Make cannot find the file, causing compilation interruption.

Solution (create link ):

sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm

Run

Run the compiled kernel in the oslab directory:

./run

Error:

./bochs/bochs-gdb: error while loading shared libraries: libXpm.so.4: cannot open shared object file: No such file or directory

Print Dynamic Link Configuration:

ldconfig -p | grep libXpm.so.4

LibXpm. so.4 link information:

libXpm.so.4 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libXpm.so.4

What we need is a 32-bit library. The package name corresponding to the Search Library:

apt-file search libXpm.so.4

Print result:

libxpm4: /usr/lib/x86_64-linux-gnu/libXpm.so.4libxpm4: /usr/lib/x86_64-linux-gnu/libXpm.so.4.11.0

Obtain the corresponding package name libxpm4 and install the corresponding 32-bit Library:

sudo apt-get install libxpm4:i386

 Basic operations and precautions

Compile-level debugging: execute commands in the oslab directory

./dpg-asm

C language-level debugging in the oslab directory, open the first terminal window to execute commands

./dbg-c

Open the second terminal window and execute the command

./rungdb

File exchange between Ubuntu and Linux0.11

The hdc-0.11-new.img under oslab is the root file system image file after the 0.11 kernel is started, equivalent to the hard disk mounted in the bochs virtual machine. The method to access its content on Ubuntu is

sudo ./mount-hdc

Then, the hdc directory is the same as the 0.11 Kernel File System and can read and write any files (some files may be accessible using sudo ). After reading and writing, do not forget to uninstall the file system:

sudo umount hdc

After sudo. /mount-hdc. c file, and then use the editing tool on Ubuntu (such as gedit) to implement the xxx. c file editing after editing and saving. Run sudo umount hdc, and then go to Linux 0.11 (that is, after running starts bochs), you will see this xxx. c. This avoids editing xxx on Linux 0.11. c is troublesome, because Linux 0.11 is a very small operating system and the editing tool on it only has vi, which is inconvenient to use.

In addition, the files generated on Linux 0.11 can be obtained in this way. "The python program is used for processing in Ubuntu. Of course, this python program is obviously difficult in Linux 0.11, because the python interpretation environment cannot be set up on Linux 0.11.

Note 1: Do not mount the image file when the 0.11 kernel is running; otherwise, the file system may be damaged. Similarly, do not run the 0.11 kernel when it has been mounted.

NOTE 2: Before disabling Bochs, Run "sync" on the 0.11 command line to ensure that all cached data is stored on the disk, and then disable Bochs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.