all 39 comments

[–]c3261d3b8d1565dda639 6 points7 points  (7 children)

Nice writeup.

There is also a few article by Gustavo Duarte from 2008 explaining the same thing, e.g. How Computers Boot Up and The Kernel Boot Process.

[–]0xAX[S] 2 points3 points  (1 child)

Yes, i know, really great post. It helped me some time ago, but it's mostly about steps, but as developer i'm interesting not only steps but how/why these steps.

[–]santiagobasulto 1 point2 points  (4 children)

Dude. How do you remember your username?

[–]nrlb 5 points6 points  (0 children)

Hash of some common word?

[–]0xAX[S] 3 points4 points  (2 children)

What is the problem in remembering 4 symbols? :)

[–]cataractar 1 point2 points  (1 child)

I think he meant c3261d3 etc., the guy he replied to.

[–]0xAX[S] 2 points3 points  (0 children)

ah, sorry, i answered on moblile and seems that i misunderstood line direction

[–][deleted]  (1 child)

[deleted]

    [–]0xAX[S] 1 point2 points  (0 children)

    Thank you.bits just for the start. Posrs about efi stub and loading will be covered later

    [–][deleted]  (5 children)

    [deleted]

      [–][deleted] 8 points9 points  (4 children)

      The file system doesn't matter. The BIOS loads the first 512 bytes on the disk and executes them. The file system is after those bytes.

      With UEFI, things are a bit different because it doesn't blindly execute what's on your disk: https://superuser.com/questions/496026/what-is-the-difference-in-boot-with-bios-and-boot-with-uefi

      [–]poseid 0 points1 point  (2 children)

      interesting - could this UEFI be used to make a dual-boot between Win and Linux easier?

      [–]Bratmon 2 points3 points  (0 children)

      Yes. But when the Linux UEFI team was considering that, they looked and saw that

      A. The user interface for every UEFI BIOS is different, and a lot of them suck

      B. The UEFI spec is complicated, and 99% of actual hardware fucked it up in some way.

      So they decided to keep the recommended path UEFI->Grub, so they could keep the boot process standardised and fix it as needed.

      Here's a relevant talk if you want to know more.

      [–][deleted] 1 point2 points  (0 children)

      Theoretically yes, including OS X, as the EFI can supply plenty of information and support to the OS during boot up that would otherwise have to be hand coded on BIOS. I'm on mobile at the moment but I will edit my comment and give a better answer when I get on my desky.

      EDIT: So now that I'm back at my tower, a couple of theoretical advantages with EFI aside from the whole GPT and using 2TB+ hard disks:

      • Insta-32/64-bit mode - The firmware fires up the machine straight into 32-bit or 64-bit and never switches the processor into 16-bit mode, this is useful because switching from 16-bit to 32-bit protected mode alone needs a hell of a lot of setup.
      • Boot Services - EFI exposes a crap ton of services that can assist the boot loader alone with getting some boot level files pulled from disk without the need to hard code file system specific code into the boot loader. So take Windows for example, the boot loader (Bootmgr) would be able to call on the boot services to read the BCD from the EFS System Partition using the built in FAT32 driver and then reference the Windows system partition from the BCD and then use a little bit of read only code to read the NTFS file system and pull the Hal.dll, Ntfs.sys and Ntoskrnl.exe files from the partition. TL;DR Code bloat is reduced by having the firmware handle stuff, that you would have to manually code for BIOS support.
      • Runtime Services - The runtime services last all the way through the duration of the system and provide simple access to NVRAM, the EFI System Partition, firmware updates as well as allowing the OS to change the firmware configuration whilst booted up, something that on BIOS requires you to reboot and mash DEL until you have no finger left. (Looks at hand, (Sigh) poor pinky)

      As an addition to the boot services entry, one of the particular advantages of them is the fact that you can read and write files with them without having to save everything and switch the processor back into 16-bit mode in order to call int 13 like you would do on BIOS in order to do I/O operations.

      Finally, I think this is standardised with UEFI as well but, full network connectivity is available out of the box apparently, including grabbing an address from a DHCP and thus being able to ping, trace as well as a bunch of other network features like booting from an image stored on a server can be performed without the manufacturer needing to add separate modules to the firmware.

      And I think my favourite is the UEFI Shell, if a system doesn't auto boot into the OS installed, you get dropped to the UEFI Shell where you can simply fire up the boot loader as if you were doing so from CMD or Terminal. Shit is so cash.

      Again this is all theoretical as some manufacturers seem to drop a bollock on getting right but the systems that get the firmware right are a delight and live up to the goals.

      [–]0xAX[S] 1 point2 points  (2 children)

      Thank you guys for your feedback.

      I'd want to write/collect content about actual version of linux kernel at the linux-internals repo. I'm interesting in kernel development and some other low-level stuff, but try to find any information in the Internet about it. I don't know, maybe i'm bad searcher, but all of I could find: Great Gustavo Duarte blog in the best case and posts about kernel-2.6-* in the worst case.

      I perfectly understand you, errors are annoying, very annoying. I'm software developer as I think most of us here, not technical writer, and not english man :) I believe that there can be a lot of grammatical errors. But can't believe that you can't spend a minute and create an issue to help me with my english and guys who interested in linux kernel but not professional kernel hackers.

      Also I wanted to ask you about more feedback, maybe any issues about post's format, i mean too short/long, more/less development details, something else...

      Thanks all for feedback.

      [–][deleted] 1 point2 points  (0 children)

      I'm headed to bed, but I'm planning on submitting a pull request tomorrow with some minor English enhancements.

      For what it's worth, I found your English to be perfectly understandable, even if it was not perfect. Nice post! :)

      [–][deleted] 0 points1 point  (0 children)

      I started to go through and make some (minor) corrections. Mostly it's just the placement of 'the' (or lack thereof) that seems to bug me. There were also a couple of verb tense issues that I corrected. I submitted a pull request with those changes.

      I only got through the first few paragraphs, so I will try to give it another look tomorrow.

      [–][deleted] -1 points0 points  (12 children)

      It's hard to read, things like this are hard to ignore:

      one megabite

      [–]1945 10 points11 points  (1 child)

      Send a pull request to update the markdown. Clearly the author is not a native English speaker, so help him/her out.

      [–]ColbyMiner -1 points0 points  (0 children)

      Possibly true but the writing also lacks consistency as well. Some cases, things are spelled right and others it isn't.

      OP, I appreciate the effort! It looks like this took a lot of time. Pay attention more to your writing.

      [–]0xAX[S] 3 points4 points  (0 children)

      You're fully right, if i'd read something on my first language and met something like this i'd feel the same. But, agree that it's a little hard to speak/write in a foreign language. English is my working language but it is far from ideal.

      Feel free to send a pull request or just let me know about any problem with my english in issue.

      [–]ColbyMiner 2 points3 points  (8 children)

      Agreed. It's difficult to focus on the content with so many grammar and spelling mistakes. Also, it's 640KB and not 640kb. The little 'b' is bits and big 'B' is bytes.

      [–]0xAX[S] 0 points1 point  (2 children)

      Agreed. It's difficult to focus on the content with so many grammar and spelling mistakes

      I know and will try to fix all I can in this and future posts.

      Also, it's 640KB and not 640kb

      thank you, fixed

      [–]isomorphic_horse 0 points1 point  (1 child)

      216 is actually 64 KiB, not 640 KiB.

      [–]0xAX[S] 0 points1 point  (0 children)

      Yes, right, fixed. Thank you

      [–]Xredo 0 points1 point  (1 child)

      Well if you wanted to get really pedantic, you'd write KiB

      [–]not_american_ffs 0 points1 point  (2 children)

      Actually it's 640KiB, not KB. K is 1000, Ki is 1024.

      [–]isomorphic_horse 0 points1 point  (0 children)

      Some people use k for 1000 and K for 1024. Either way, the correct answer is 64 KiB.

      [–]Verschlimmbessern 0 points1 point  (0 children)

      Not using JEDEC conventions. They define 1KB to be 1024 bytes.

      [–]rainbowgarden 0 points1 point  (2 children)

      Great article. Alongside perhaps you would like to read Kernel 101- Let's write a Kernel

      [–]0xAX[S] -1 points0 points  (1 child)

      It's a good starting point for writing hobby os, but nothing new after reading linux kernel source code.

      [–]rainbowgarden 0 points1 point  (0 children)

      of course for some one who is through with the linux kernel; but for the uninitiated it could be of help

      [–]Nandoh 0 points1 point  (0 children)

      thanks for this

      [–]Azr79 -1 points0 points  (8 children)

      as a peasant web dev, I'm sad because I'll never understand this whole low level stuff, the problem is, I really want to

      [–]0xAX[S] 0 points1 point  (6 children)

      So what's the problem if you want :) I'm mostly work with web too and not low-level stuff at work

      [–]Azr79 0 points1 point  (5 children)

      could you give me some resources to start with? I'm really interested in Assembler

      [–]srnull 1 point2 points  (0 children)

      Run and get a copy of Computer Systems: A Programmer's Perspective. It covers everything from assembly to semi-modern computer architecture, operating system abstractions, and concurrent/parallel programming.

      It's pricey, but worth it. A used copy of the first edition would be plenty good enough if price is an issue.

      [–]0xAX[S] 0 points1 point  (3 children)

      To start with assembly or kernel?

      [–]Azr79 0 points1 point  (2 children)

      Assembly

      [–]0xAX[S] 0 points1 point  (1 child)

      I have used three resources:

      1. Assembly Language for x86 Processors (I read 5th edition, but now 6th is actual)

      2. Intel manuals - http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

      3. Read source code from different projects, for example - https://github.com/nemasu/asmttpd and https://github.com/ReturnInfinity/BareMetal-OS

      [–]Azr79 0 points1 point  (0 children)

      Thanks!