MNET-KBB
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Linux Boot Process tags: Unlocking-Linux, SystemD disqus: hackmd --- # Linux Boot Process The process of booting up a Linux kernel can be view as 6 separate stages - BIOS selects the boot device. - GRUB loader - Kernel decompression - Low-level initialization by init ### Lets look at each of the stages, and see what they do 1. **Bios Selects Boot Device** On startup, power is sent to the CPU and it starts executing instructions. The first instruction it runs passes control to the BIOS (Basic Input/Output System). The BIOS then does two things: * Run POST (Power On Self Test) operation. * Selecting first Boot device. <br> POST operation - The POST operation checks for hardware availability by sending electrical pulses to the devices. If no electrical pulses are sent back, it means the device is faulty or does not exists. These activities are outside the scope of Linux, as the Kernel is not even loaded in yet until later <br> Selecting the First Boot Device - After running POST is completed, the BIOS will have a list of available devices. It will select the first boot device and returns control to the CPU. If the first boot device cannot be found, it will continue to look for the next available boot device. If BIOS do not find any available boot devices it will alert user stating "No boot device found" <br> 2. **Bios Loads Boot Sector from the Boot Device** One the boot device has been identified, the BIOS passes control back to the CPU. The CPU will then read the first 512 bytes of the boot device to obtain the Master Boot Recorder (MBR). The MBR consists of the following information - Primary boot loader code / Stage 1 Boot loader (446 Bytes) - Partition table information (64 Bytes) - Magic Number (2 Bytes) <br> Primary Boot Loader Code - This code provides information regarding the actual boot loader on the hard disk. It is used to load the actual boot loader <br> Partition Table Information - This information here stores the details of all the partitions in the hard disk. It includes information such as the start and end of the partition, and what type of partition it is. Each partition needs 16 Bytes to be represented. Since the Partition Table Information section is only 64 Bytes long, we can store at most 64/16=4 partitions on a hard disk <br> Magic Number - This number is use for validating the MBR. It is used to recover the MBR when it gets corrupted. <br> 3. **GRUB Loader / Stage 2 boot Loader** If the CPU has a valid boot device, which has a valid MBR that contains the Primary boot loader code / Stage 1 Boot loader, we proceed to load the Stage 2 Boot loader, or the GRUB (Grand Unified Bootloader) into memory. The GRUB is located 30 KB away from the MBR and before the first partition. The GRUB displays the available Kernels to the user. Once the user selects a kernel, the kernel image is then loaded into memory and control is passed to the kernel. Nowadays GRUB2 is being used in place of GRUB. GRUB2 is the default boot loader for RHEL 7, Fedora, and Ubuntu. To read more about GRUB2 <br> 4. **Kernel Decompression** The kernel is a compressed image, and it is store in /boot along with an initial RAM disk image, and device maps of the hard drives. Once the kernel is loaded into the main memory, it begins decompression. After decompression, the expanded image overwrite the initial uncompressed image. Once the kernel has extracted itself, it loads systemd, which is the replacement for the old SysV init program, and turns control over to it. At this point, the Linux kernel and systemd (or in some systems, init) are running <br> 5. **Low-level initialization (init, Upstart and Systemd)** Once the kernel has been decompressed, it begins the init function, which is the low level initialization of the kernel. The kernel looks at the /etc/inittab file and decides the run level. It also looks into the folder /etc/rc* and runs the startup scripts there. The files for init are stored in /etc/init init is a daemon process which starts as soon as the computer starts and continues running till it is shutdown. init has a pid of 1. If somehow the init daemon could not start, no process will be started and the system will enter Kernel Panic. init is going to be replaced by systemd in the future, as systemd offers a cleaner way of booting. Ubuntu used to adopt upstart as their initialization, but switched to systemd as of 9 March 2015. ### More on Grub2 The main changes of GRUB2 from GRUB are as follows: 1. GRUB2 directly shows a login prompt and no menu is displayed. 2. If you want to see the menu during boot, hold down SHIFT key or press ESC 3. The configuration file is /boot/grub/grub.cfg. This main configuration file contains different types of scripts we cannot edit this file directly. grub.cfg is generated from the contents of the /etc/default/grub and /etc/grub.d . You should modify or add to those files to configure GRUB 2 4. There is no file called /boot/grub/menu.lst 5. Users can create custom files to place their own menu entries via 40_custom in /etc/grub.d folder. 6. Users can change the menu display settings through a file called grub in /etc/default folder. 7. The numbering of partitioning has changed. The first partition is now 1 instead of 0. The first device is still identified with hd0 There are 3 stages to the GRUB2 process: * boot.img is stored in the master boot record (MBR) or in the Volume Boot Records (VBR). At installation time it is configured to load the first sector of core.img: * Also known as stage 1.5.core.img is by default written to the sectors between the MBR and the first partition, when these sectors are free and available. Once executed, core.img will load its configuration file and any other modules and file systems needed, at installation time, it is generated from diskboot.img and configured to load stage 2 by its file path * Also known as stage 2. Files belonging to the stage 2 are all being held in the /boot/grub Once GRUB2 stage 2 has loaded, it presents a kernel selection menu for the user to select which operating system to boot. GRUB2 can be configured to automatically load a specified kernel after a user-defined timeout Once boot options have been selected, GRUB2 loads the selected kernel into memory and passes control to the kernel. Alternatively, GRUB2 can pass control of the boot process to another boot loader, using chain loading.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully