小緯
    • 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 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
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
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
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 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
    ## Yocto Project (6):Testing and Debugging Openbmc service 前篇:[Yocto Project (5):在樹梅派 4 上跑 Openbmc](https://hackmd.io/@zhonwei/BJqZEhSTbe) 目標:測試與確認 Openbmc service 是否可以正常運作 --- 確認 OpenBMC 版本 ```bash $ cat /etc/os-release ``` 確認基本服務是否正常運作 ```bash $ systemctl list-units --state=failed ``` 出現三個 fail ``` bmcweb.service failed obmc-phosphor-sysd.service failed start-ipkvm.service failed ```` 查看那三個服務的狀態 ```bash $ systemctl status bmcweb.service $ systemctl status obmc-phosphor-sysd.service $ systemctl status start-ipkvm.service ``` --- ## bmcweb.service ::: info bmcweb 是 OpenBMC 的前端網頁伺服器與 API 通道。它負責處理所有進入 BMC 的 HTTP/HTTPS 請求 ::: 研讀:[[OpenBMC] 快速上手OpenBMC的Redfish](https://iris123321.blogspot.com/2022/02/openbmc-openbmcredfish.html) 查看日記,裡面會記載錯誤原因 ```b $ journalctl -u bmcweb.service -n 50 Process: 215 ExecStart=/usr/bin/bmcweb (code=exited, status=255/EXCEPTION) ``` 參考 https://github.com/openbmc/bmcweb/issues/126 ::: danger 錯誤的原因是缺少了 `/var/log/redfish`,因為 bmcweb 啟動時會嘗試初始化 Redfish 的事件日誌系統,它的程式碼裡有一段邏輯會去開啟或寫入 `/var/log/redfish` 這個資料夾。所以我們就手動去建立資料夾,就可以解決這個問題了。 ::: 手動建立資料夾,重新啟動服務 ```bash $ mkdir -p /var/log/redfish $ systemctl daemon-reload $ systemctl restart bmcweb.service $ systemctl status bmcweb.service ``` 在重新查看一下 bmcweb.service 就會是 active(running)了 但之後重開機的話又會顯示 bmcweb.service failed,這是因為 ```b $ df -h /var/log tmpfs 3.9G 8.0K 3.9G 0% /var/volatile ``` ```b $ ls -la /var/log /var/log -> volatile/log ``` `/var/log` 是指向 `/var/volatile/log` 的符號連結 ::: danger 又發生錯誤的原因是 OpenBMC 把 /var/volatile 掛載為 tmpfs(記憶體檔案系統),/var/log 只是指向 /var/volatile/log 的符號連結。 tmpfs 的特性是: * 資料存在記憶體裡,不寫入儲存裝置 * 每次重開機記憶體清空,所有資料消失 * 速度快,適合暫存資料 所以手動建立的 `/var/log/redfish` 實際上是建立在記憶體裡,重開機後會自然消失。 ::: 解決方法是寫一個開機自動建立 /var/log/redfish 目錄的 service ```b cat > /etc/systemd/system/create-redfish-log-dir.service << EOF [Unit] Description=Create /var/log/redfish directory Before=bmcweb.service [Service] Type=oneshot ExecStart=/bin/mkdir -p /var/volatile/log/redfish RemainAfterExit=yes [Install] WantedBy=multi-user.target EOF ``` 啟用服務 ``` $ systemctl enable create-redfish-log-dir.service $ systemctl start create-redfish-log-dir.service ``` 重新開機確認 ``` $ reboot $ systemctl status bmcweb.service ``` --- ## obmc-phosphor-sysd.service ::: info obmc-phosphor-sysd 是 OpenBMC 架構中負責「系統狀態監控與管理」的背景服務,監控 BMC(基板管理控制器)內部的各種系統事件,並確保系統依照預定的狀態執行。 ::: > 參考:https://github.com/openbmc/phosphor-state-manager 查看 obmc-phosphor-sysd 的狀態 ```b $ systemctl status obmc-phosphor-sysd.service Active: failed (Result: exit-code) since Thu 1970-01-01 00:00:06 UTC Process: 328 ExecStart=/usr/bin/env obmc-phosphor-sysd (code=exited, status=1/FAILURE) Main PID: 328 (code=exited, status=1/FAILURE) Scheduled restart job, restart counter is at 2. Failed to start Phosphor System Manager. ``` 查看日記 ```bash $ journalctl -u obmc-phosphor-sysd.service -n 50 Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized LookupError: no codec search functions registered: can't find encoding ``` 確認 Python encodings 資料夾內容 ```b $ ls /usr/lib/python3.8/encodings/ __pycache__ ``` 確認只有 __pycache__,沒有任何 .py 檔案。 測試 Python 是否能正常執行 ```b $ python3 -c "print('hello')" Could not find platform independent libraries <prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] Python configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = 'python3' sys.path = [ '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', ] Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding LookupError: no codec search functions registered: can't find encoding ``` ::: danger 錯誤原因是 OpenBMC 為了縮小 image 大小,在編譯時透過 python3_%.bbappend 這個檔案,把所有 Python .py 檔案刪除,只保留 __pycache__。導致 obmc-phosphor-sysd 啟動時呼叫 Python,Python 找不到 encodings 模組,直接崩潰。 ::: > 參考:https://github.com/openbmc/openbmc/issues/3661 查看 python3_%.bbappend 內容(在 Ubuntu 虛擬機上) ```b $ cat ~/openbmc/meta-phosphor/recipes-devtools/python/python3_%.bbappend inherit update-alternatives ALTERNATIVE_${PN}-core += "python" ALTERNATIVE_LINK_NAME[python] = "${bindir}/python" ALTERNATIVE_TARGET[python] = "${bindir}/python3" # python3 takes up a lot of space that most embedded systems # do not have, so remove some un-needed files from the rootfs do_install_append_class-target() { # Even though python3 is built with --without-ensurepip, it still installs # a large, compressed version of pip. Remove it to free up the space. rm -rf ${D}${libdir}/python${PYTHON_MAJMIN}/ensurepip # Remove all python .py files from python recipe. Only the .pyc # files are required. # The _sysconfigdata*.py files are system configuration files generated # during build time. It's used in the yocto packaging process so # it is required to remain in the image. find ${D}${libdir}/python${PYTHON_MAJMIN} -name \*.py ! -name _sysconfigdata*.py -exec rm {} \; } ``` 把這行整段刪除 ```bash $ find ${D}${libdir}/python${PYTHON_MAJMIN} -name \*.py ! -name _sysconfigdata*.py -exec rm {} \; ``` 之後再重新編譯 ```b $ cd ~/openbmc $ source openbmc-env $ bitbake obmc-phosphor-image ``` 編譯好之後,image 檔會在 `/home/zhonwei/openbmc/build/tmp/deploy/images/` 複製 image 檔到共享資料夾 ```b $ sudo cp /home/zhonwei/openbmc/build/tmp/deploy/images/raspberrypi4/obmc-phosphor-image-raspberrypi4-20260427072528.rootfs.rpi-sdimg /media/sf_shared/ ``` 重新燒錄到 SD 卡中開機,會出現前面有出現的錯誤,再按照前面的方式解決一次就可以了 確認 Python 正常 ```b $ python3 -c "print('hello')" hello ``` 確認 obmc-phosphor-sysd 服務正不正常 ```b $ systemctl status obmc-phosphor-sysd. Active: failed ``` 還是失敗,再次查看詳細錯誤原因 ```b $ journalctl -u obmc-phosphor-sysd.service -n 30 SyntaxError: Missing parentheses in call to 'print'. Did you mean print("obmc-phosphor-watchdog starting...")? File "/usr/sbin/obmc-phosphor-sysd", line 26 ``` ::: danger 錯誤原因:obmc-phosphor-sysd 是用 Python 2 語法寫的,但系統上的 python 已經指向 Python 3.8.2,Python 3 不支援舊的 print 語法。 ::: 確認 python 版本 ```b $ python --version $ python3 --version $ ls -la /usr/bin/python Python 3.8.2 Python 3.8.2 /usr/bin/python -> /usr/bin/python3 ``` 修正 /usr/sbin/obmc-phosphor-sysd 裡的 print 語法 ```bash $ sed -i 's/print "obmc-phosphor-watchdogd starting..."/print("obmc-phosphor-watchdogd starting...")/' /usr/sbin/obmc-phosphor-sysd ``` 重新啟動服務 ```bash $ systemctl restart obmc-phosphor-sysd.service $ systemctl status obmc-phosphor-sysd.service ``` obmc-phosphor-sysd.service 成功啟動! ::: info 補充:可以查看 service 的 Unit file 來了解這個 service 的內容 ::: ```b $ cat /lib/systemd/system/obmc-phosphor-sysd.service [Unit] Description=Phosphor System Manager [Service] Restart=always ExecStart=/usr/bin/env obmc-phosphor-sysd SyslogIdentifier=obmc-phosphor-sysd [Install] WantedBy=multi-user.target ``` --- ## start-ipkvm.service ``` $ journalctl -u start-ipkvm.service -n 50 Process: 343 ExecStart=/usr/bin/obmc-ikvm -v /dev/video0 -k /dev/hidg0 -p /dev/hidg1 (code=dumped, signal=ABRT) ``` KVM 服務直接崩潰,這個在樹莓派上是正常的,因為樹莓派沒有 KVM 硬體,可以忽略。

    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 Google 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