如何在 Linux 上安裝/更新 Intel 微碼固件

如果你是一個 Linux 系統管理方面的新手,如何在 Linux 上使用命令行方式去安裝或者更新 Intel/AMD CPU 的微碼固件呢?
微碼 就是由 Intel/AMD 提供的 CPU 固件。Linux 的內核可以在引導時更新 CPU 固件,而無需 BIOS 更新。處理器的微碼保存在內存中,在每次啟動系統時,內核可以更新這個微碼。這些來自 Intel/AMD 的微碼的更新可以去修復 bug 或者使用補丁來防範 bug。這篇文章演示了如何使用包管理器或由 lntel 提供的 Linux 處理器微碼更新來安裝 AMD 或 Intel 的微碼更新。
如何查看當前的微碼狀態
以 root 用戶運行下列命令:
# dmesg | grep microcode
輸出如下:
請注意,你的 CPU 在這裡完全有可能出現沒有可用的微碼更新的情況。如果是這種情況,它的輸出可能是如下這樣的:
[ 0.952699] microcode: sig=0x306a9, pf=0x10, revision=0x1c
[ 0.952773] microcode: Microcode Update Driver: v2.2.
如何在 Linux 上使用包管理器去安裝微碼固件更新
對於運行在 x86/amd64 架構的 CPU 上的 Linux 系統,Linux 自帶了工具去更改或者部署微碼固件。在 Linux 上安裝 AMD 或者 Intel 的微碼固件的過程如下:
- 打開終端應用程序
- Debian/Ubuntu Linux 用戶推輸入:
sudo apt install intel-microcode
- CentOS/RHEL Linux 用戶輸入:
sudo yum install microcode_ctl
對於流行的 Linux 發行版,這個包的名字一般如下 :
microcode_ctl
和linux-firmware
—— CentOS/RHEL 微碼更新包intel-microcode
—— Debian/Ubuntu 和衍生髮行版的適用於 Intel CPU 的微碼更新包amd64-microcode
—— Debian/Ubuntu 和衍生髮行版的適用於 AMD CPU 的微碼固件linux-firmware
—— 適用於 AMD CPU 的 Arch Linux 發行版的微碼固件(你不用做任何操作,它是默認安裝的)intel-ucode
—— 適用於 Intel CPU 的 Arch Linux 發行版微碼固件microcode_ctl
、linux-firmware
和ucode-intel
—— Suse/OpenSUSE Linux 微碼更新包
警告 :在某些情況下,微碼更新可能會導致引導問題,比如,伺服器在引導時被掛起或者自動重置。以下的步驟是在我的機器上運行過的,並且我是一個經驗豐富的系統管理員。對於由此引發的任何硬體故障,我不承擔任何責任。在做固件更新之前,請充分評估操作風險!
示例
在使用 Intel CPU 的 Debian/Ubuntu Linux 系統上,輸入如下的 [apt 命令](https://www.cyberciti.biz/faq/ubuntu-lts-debian-linux-apt-command-examples/ "See Linux/Unix apt command examples for more info")/[apt-get 命令](https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html "See Linux/Unix apt-get command examples for more info"):
$ sudo apt-get install intel-microcode
示例輸出如下:
你 必須重啟伺服器以激活微碼 更新:
$ sudo reboot
重啟後檢查微碼狀態:
# dmesg | grep 'microcode'
示例輸出如下:
[ 0.000000] microcode: microcode updated early to revision 0x1c, date = 2015-02-26
[ 1.604672] microcode: sig=0x306a9, pf=0x10, revision=0x1c
[ 1.604976] microcode: Microcode Update Driver: v2.01 <tigran@aivazian.fsnet.co.uk>, Peter Oruba
如果你使用的是 RHEL/CentOS 系統,使用 [yum 命令](https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ "See Linux/Unix yum command examples for more info") 嘗試去安裝或者更新以下兩個包:
$ sudo yum install linux-firmware microcode_ctl
$ sudo reboot
$ sudo dmesg | grep 'microcode'
如何更新/安裝從 Intel 網站上下載的微碼
只有在你的 CPU 製造商建議這麼做的時候,才可以使用下列的方法去更新/安裝微碼,除此之外,都應該使用上面的方法去更新。大多數 Linux 發行版都可以通過包管理器來維護、更新微碼。使用包管理器的方法是經過測試的,對大多數用戶來說是最安全的方式。
如何為 Linux 安裝 Intel 處理器微碼塊(20180108 發布)
首先通過 AMD 或 Intel 網站 去獲取最新的微碼固件。在本示例中,我有一個名稱為 ~/Downloads/microcode-20180108.tgz
的文件(不要忘了去驗證它的檢驗和),它的用途是去防範 meltdown/Spectre
bug。先使用 tar
命令去提取它:
$ mkdir firmware
$ cd firmware
$ tar xvf ~/Downloads/microcode-20180108.tgz
$ ls -l
示例輸出如下:
drwxr-xr-x 2 vivek vivek 4096 Jan 8 12:41 intel-ucode
-rw-r--r-- 1 vivek vivek 4847056 Jan 8 12:39 microcode.dat
-rw-r--r-- 1 vivek vivek 1907 Jan 9 07:03 releasenote
我只在 CentOS 7.x/RHEL、 7.x/Debian 9.x 和 Ubuntu 17.10 上測試了如下操作。如果你沒有找到
/sys/devices/system/cpu/microcode/reload
文件的話,更老的發行版所帶的更老的內核也許不能使用此方法。參見下面的討論。請注意,在應用了固件更新之後,有一些客戶遇到了系統重啟現象。特別是對於那些運行 Intel Broadwell 和 Haswell CPU 的用於客戶機和數據中心伺服器上的系統。不要在 Intel Broadwell 和 Haswell CPU 上應用 20180108 版本。儘可能使用軟體包管理器方式。
檢查一下,確保存在 /sys/devices/system/cpu/microcode/reload
:
$ ls -l /sys/devices/system/cpu/microcode/reload
你必須使用 [cp 命令](https://www.cyberciti.biz/faq/cp-copy-command-in-unix-examples/ "See Linux/Unix cp command examples for more info") 拷貝 intel-ucode
目錄下的所有文件到 /lib/firmware/intel-ucode/
下面:
$ sudo cp -v intel-ucode/* /lib/firmware/intel-ucode/
你只需要將 intel-ucode
這個目錄整個拷貝到 /lib/firmware/
目錄下即可。然後在重新載入介面中寫入 1
去重新載入微碼文件:
# echo 1 > /sys/devices/system/cpu/microcode/reload
更新現有的 initramfs,以便於下次啟動時它能通過內核來載入:
$ sudo update-initramfs -u
$ sudo reboot
重啟後通過以下的命令驗證微碼是否已經更新:
# dmesg | grep microcode
到此為止,就是更新處理器微碼的全部步驟。如果一切順利的話,你的 Intel CPU 的固件將已經是最新的版本了。
關於作者
作者是 nixCraft 的創始人、一位經驗豐富的系統管理員、Linux/Unix 操作系統 shell 腳本培訓師。他與全球的包括 IT、教育、國防和空間研究、以及非盈利組織等各行業的客戶一起工作。可以在 Twitter、Facebook、Google+ 上關注他。
via: https://www.cyberciti.biz/faq/install-update-intel-microcode-firmware-linux/
作者:Vivek Gite 譯者:qhwdw 校對:wxy
本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive
nordvpn cashback 350fairfax
I have been exploring for a little for any high quality articles or
blog posts in this sort of area . Exploring in Yahoo I finally stumbled upon this
website. Reading this information So i’m happy to exhibit that I have an incredibly just right uncanny feeling I came upon exactly what I needed.
I most indubitably will make certain to do not overlook this web site and give it a glance on a constant basis.
Thanks very nice blog!
my blog post :: nordvpn coupons inspiresensation (http://in.mt/nordvpn-coupons-inspiresensation–25665)
I enjoy what you guys tend to be up too. This type of clever work and coverage!
Keep up the good works guys I’ve added you guys to
blogroll.
Feel free to surf to my web blog :: nordvpn coupons inspiresensation (t.co)
I’m extremely impressed along with your writing talents as well as with the format in your weblog.
Is this a paid theme or did you customize it your self? Either way stay up the nice high quality writing, it’s uncommon to see a great weblog like
this one today..
My web-site – nordvpn coupons inspiresensation (easyurl.cc)