From pressing power switch to bash prompt

Source: Internet
Author: User
Article Title: from pressing the power switch to the bash prompt. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems and open source, and other basic categories. This section describes the process of linux from pressing power to displaying bash prompts. Understanding these details is very helpful when you encounter problems or want to configure the system.

1. Preface

I find many things happen on my linux machine that I don't know, which makes me very frustrated. This article is a good start if you want to know your system and how to use it like me, it is useful if you want to become a linux expert.

I suppose you have a computer with a linux system installed and have basic Unix and PC Knowledge. If not, Eric S. raymond's Unix and Internet Fundamentals HOWTO is a good article. It is very short, readable, and comprehensive.

Although the main thread of this article is how to start linux, I also tried to fully introduce the linux system. I have added exercises in each chapter. If you have performed practical exercises, you will learn more than reading.

I hope that readers can learn the best way I know, that is, to write a system from the source code. The Italian philosopher Giambattista Vico 1668-1744 said that "verum ipsum factum" is "understanding from practice". Thank you, Alex (Thank you) for providing this proverb.

If you want to be "self-reliant", you should take a look at Gerard Beekmans Linux From Scratch HOWTO (LFS). LFS provides detailed instructions on how to compile a complete and available system. On the LFS official website, you will find the list of related emails. The content that was previously part of this article is now separated and becomes "Building a Minimal Linux System from Source Code". You can find it on the homepage from startup to bash prompt. It reveals how to build a system and is a pure learning experience.

Describe these programs in the order of startup, which means that if you install files in this order, you will find that every system startup will be close to the bash prompt. This proves from the other hand that the system is started in the order we call it.

I recommend that you read the main content of each part every time, skip the exercises and bibliography, and then determine the depth and effort you want to understand. Finally, go back to the beginning to practice and read references.

2. Hardware

When you turn on the computer, it automatically checks whether everything is normal. This process is called "start self-check" and the BIOS Boot Loader located in the ROM will find the Boot Sector. A boot sector is the first segment in the disk. It carries a program that can load the operating system. The magic of the boot sector is marked as 0xAA55 = 43603, in bytes 0x1FE = 510. This is the last two bytes of a segment. The hardware relies on them to determine whether the segment is a boot sector.

The Bootstrap program has a table that can be used to find the position of the startup sector. My old machine will first look for a soft drive and then the primary hard disk. Many modern computers can find the Boot Sector on the disc. If a boot sector is found, the boot program will read it into the memory and give control to the program in the boot sector. In a standard linux system, this program is the first-stage startup program of LILO. There are many methods to set the startup time. For more details, see the LILO user manual. Obviously, we have a lot to talk about PC hardware functions, but it is not suitable for discussion here. You can refer to various books on PC hardware.

2.1 Configuration

The machine stores a lot of its own information in CMOS. Including hard disk and memory information, the BIOS program allows you to change these settings. Check the screen information when your machine starts to know how to enter the BIOS program. On my machine, press delete before starting the operating system.

2.2 exercise

A good way to understand PC hardware is to collect machines in the second-hand market. You can run linux in the 386 configuration, and it does not cost much.

Download and create a Unios boot disk, which is just a "Hello World !" Program, a total of more than one hundred lines of assembly code. If you use software that can understand GNU Assembly, it will be easier to read.

Here is a guiding article "Do It Yourself" in Roll Your Own if you want to seek real challenges.

Open the unios image disk in the hexadecimal editor. The image is 512 bytes long, which is exactly a segment. Find the magic number 0xAA55, find a bootable disk, and do the same job. You can use the dd command to copy the boot area to a file: dd if =/dev/fd0 of = boot. sector Note! The command format is correct. Look at the source code of the LILO boot program


2.3 More Information

The Unix and Internet Fundamentals HOWTO by Eric S. Raymond, especially The third part, What happens when you switch on a computer? The first chapter of The LILO User's Guide describes The hard disk partition and startup of a PC. Please refer to LILO's website. the NEW Peter Norton Programmer's Guide to the ibm pc & PS/2, by Peter Norton and Richard Wilton, Microsoft Press 1988 is a good book, but I can't afford it now.

Many books about upgrading your computer.

3. Lilo

When the system reads a boot sector from a Linux system, it actually reads part of lilo, called the "first-stage startup program", which is a very small program, all of its work is to read the "Phase 2 Startup Program ". In the second phase, the startup program will give you a prompt (if you set this when installing) and then start the operating system you selected.

When your computer is running, you execute lilo to install the startup layout. It will read/etc/lilo. conf then writes the boot program and the list of available systems to the hard disk.

There are many different ways to set the startup process. What I just explained is that for the most significant and common methods in Linux, Lilo's user manual explains many examples of the "startup concept. It is worth a read and worth a try.

3.1 Configuration

The configuration file of LILO is/etc/lilo. conf. Input man lilo. conf will help. Lilo. conf mainly stores the tasks that LILO will complete at startup. As the Linux portal, it tells us where the kernel is and where the partition serves as the root file system. For other operating systems, the main thing is where they start.

   3.2 exercise

Danger: exercise carefully. If an error occurs, your main boot zone will be screwed up and your system will not be able to run. Make sure you have a usable backup disk and instruct you how to fix it. Read the following tomsrtbt connection and have the rescue disk I recommend. The best precaution is to use an unimportant machine.

Create a lilo on your floppy disk. It doesn't matter if there is any kernel. When the kernel is ready to load init, you will get a "kernel panic" message. But at least you know lilo is working. If you want to continue to see how much content is running on the floppy disk. This may be the second good learning method. Let's take a look at Bootdisk HOWTO and tomsrtbt (the URL is below)

Start unios with lilo (refer to hardware exercises). As A big challenge, see if you can complete this exercise on A floppy disk. Start lilo in the Main Boot area, start lilo in the partition, and then start lilo in the Main Boot area ...... Or use lilo of the primary boot partition and lilo of the four primary partitions to create a fun big loop!

3.3 More Information

Lilo help manual (man pages) The Lilo package (lilo), including The ''lilo User's guide'' lilo-u-21.ps.gz (or a later version ). You may already have one. Look at/usr/doc/lilo. The postscript version is better than the plain text version. Because there are images and tables. Tomsrtbt's coolest floppy linux disk is a very good emergency disk. The Bootdisk HOWTO

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.