林博仁 Buo-ren Lin
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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

      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.
      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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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

    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.
    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Ubuntu 簽署了 Secureboot 的 GRUB 開機程式開機原理分析 ## 可移除式儲存裝置版本 ### 內嵌的設定檔 取得方式:$ `strings /boot/efi/EFI/BOOT/grubx64.efi` 找後半段內容 ```bash if [ -z "$prefix" -o ! -e "$prefix" ]; then if ! search --file --set=root /.disk/info; then search --file --set=root /.disk/mini-info set prefix=($root)/boot/grub if [ -e $prefix/x86_64-efi/grub.cfg ]; then source $prefix/x86_64-efi/grub.cfg elif [ -e $prefix/grub.cfg ]; then source $prefix/grub.cfg else source $cmdpath/grub.cfg normal (memdisk)/grub.cfg ``` 因為 `fi` 關鍵字似乎因為過短被 `strings` 無視故根據縮排等級將其補完: ```bash if [ -z "$prefix" -o ! -e "$prefix" ]; then if ! search --file --set=root /.disk/info; then search --file --set=root /.disk/mini-info fi set prefix=($root)/boot/grub fi if [ -e $prefix/x86_64-efi/grub.cfg ]; then source $prefix/x86_64-efi/grub.cfg elif [ -e $prefix/grub.cfg ]; then source $prefix/grub.cfg else source $cmdpath/grub.cfg fi normal (memdisk)/grub.cfg ``` 再直接到 GRUB 終端機中執行 `cat (memdisk)/grub.cfg` 來比對內容是否正確: ![](https://i.imgur.com/8UTO3Mn.jpg) 確定實際上嵌入腳本為: ```bash if [ -z "$prefix" -o ! -e "$prefix" ]; then if ! search --file --set=root /.disk/info; then search --file --set=root /.disk/mini-info fi set prefix=($root)/boot/grub fi if [ -e $prefix/x86_64-efi/grub.cfg ]; then source $prefix/x86_64-efi/grub.cfg elif [ -e $prefix/grub.cfg ]; then source $prefix/grub.cfg else source $cmdpath/grub.cfg fi ``` ### 腳本程式碼分析 #### 嵌入到 GRUB 可執行檔的腳本 ```bash # 如果 prefix 變數(GRUB最終階段安裝路徑前綴)沒有設定的話將存在下列任一路徑的檔案系統分區 # 設定為 root 變數(GRUB最終階段安裝分區),然後再根據 root 變數指定GRUB最終階段安裝路徑 # 前綴 # https://www.gnu.org/software/grub/manual/grub/grub.html#root # https://www.gnu.org/software/grub/manual/grub/grub.html#prefix if [ -z "$prefix" -o ! -e "$prefix" ]; then if ! search --file --set=root /.disk/info; then search --file --set=root /.disk/mini-info fi set prefix=($root)/boot/grub fi # 依序偵測到指定路徑的GRUB設定檔的話就讀取該設定檔 if [ -e $prefix/x86_64-efi/grub.cfg ]; then source $prefix/x86_64-efi/grub.cfg # 這個設定檔自己會讀取 $prefix/grub.cfg elif [ -e $prefix/grub.cfg ]; then source $prefix/grub.cfg else # 在 UEFI 版本的 GRUB 中 cmdpath 為 UEFI 可執行檔所在之目錄 # 於可移除式磁碟中為 <UEFI系統分區>\EFI\BOOT # https://www.gnu.org/software/grub/manual/grub/grub.html#cmdpath source $cmdpath/grub.cfg fi ``` #### $prefix/x86_64-efi/grub.cfg ```bash # 載入所有分區表支援的模組 insmod part_acorn insmod part_amiga insmod part_apple insmod part_bsd insmod part_dfly insmod part_dvh insmod part_gpt insmod part_msdos insmod part_plan insmod part_sun insmod part_sunpc # 實際上會讀 $prefix/grub.cfg 的是這行 configfile /boot/grub/grub.cfg ``` #### $prefix/grub.cfg ```bash if loadfont /boot/grub/font.pf2 ; then set gfxmode=auto insmod efi_gop insmod efi_uga insmod gfxterm terminal_output gfxterm fi set menu_color_normal=white/black set menu_color_highlight=black/light-gray # 實際上看到的選單(Ubuntu 系統安裝媒體的開機選單) menuentry "Try Ubuntu without installing" { set gfxpayload=keep linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --- initrd /casper/initrd.lz } menuentry "Install Ubuntu" { set gfxpayload=keep linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity quiet splash --- initrd /casper/initrd.lz } menuentry "OEM install (for manufacturers)" { set gfxpayload=keep linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity quiet splash oem-config/enable=true --- initrd /casper/initrd.lz } menuentry "Check disc for defects" { set gfxpayload=keep linux /casper/vmlinuz.efi boot=casper integrity-check quiet splash --- initrd /casper/initrd.lz } ``` ### $prefix/loopback.cfg (?) 似乎是給安裝媒體光碟映像檔直接放在磁碟中的使用者用的,並無自動載入 ```bash menuentry "Try Ubuntu without installing" { set gfxpayload=keep linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper iso-scan/filename=${iso_path} quiet splash --- initrd /casper/initrd.lz } menuentry "Install Ubuntu" { linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity iso-scan/filename=${iso_path} quiet splash --- initrd /casper/initrd.lz } menuentry "Check disc for defects" { linux /casper/vmlinuz.efi boot=casper integrity-check iso-scan/filename=${iso_path} quiet splash --- initrd /casper/initrd.lz } menuentry "Test memory" { linux16 /install/mt86plus } ``` ## 內接式儲存裝置版本 待補 ## 問題 ### 有沒有辦法可以直接解出嵌入 grubx64.efi 的 GRUB 設定檔? 嵌入似乎是用 `grub-mkimage` 命令,但是卻不知道怎麼解開來 ## 其他<br>Misc. ### 可移除式儲存裝置 UEFI 開機模式的 BOOTx64.EFI 載入後變數清單 ![](https://i.imgur.com/yq68tCS.jpg) ## 參考資料 * [GNU GRUB Manual](https://www.gnu.org/software/grub/manual) * [GNU GRUB Manual - Writing your own configuration file - Writing full configuration files directly](https://www.gnu.org/software/grub/manual/grub/grub.html#Shell_002dlike-scripting) * [Bug #1097570 “grub2-signed can not find the right device when th...” : Bugs : grub2 package : Ubuntu](https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1097570) * [~ubuntu-branches/ubuntu/raring/grub2/raring : revision 154](http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/raring/grub2/raring/revision/154) * [Bug #1188364 “grub-install will install a misconfigured EFI imag...” : Bugs : grub2 package : Ubuntu](https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1188364)

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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