Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LinuxからThinkPad BIOSを設定(Think-LMI)

LinuxからThinkPad BIOSを設定(Think-LMI)

Kenichiro MATOHARA

September 11, 2021
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. LinuxからThinkPad
    LinuxからThinkPad
    BIOSを設定(Think-
    BIOSを設定(Think-
    LMI)
    LMI)
    Kenichiro Matohara(matoken)
    1 / 33

    View Slide

  2. 南隅から参加(鹿児島の右下)
    好きなLinuxディストリビューションはDebian
    お仕事募集 mailto:work@matohara.org
    Kenichiro Matohara(matoken)
    Kenichiro Matohara(matoken)
    https://matoken.org
    https://matoken.org
    2 / 33

    View Slide

  3. 鹿児島らぐ 2021.09
    鹿児島らぐ 2021.09
    202-09-25(Sat)
    Online
    https://kagolug.org/
    https://kagolug.connpass.com/event/223477/
    3 / 33

    View Slide

  4. で Think-LMI を知る
    で Think-LMI を知る
    August 24 to August 28, 2021.
    ,

    DebConf21
    DebConf21
    Lenovo + Debian - 2021 - DebConf21
    Video
    📽️ Video lq
    📽️
    36-lenovo-debian-2021 | DebConf Video Etherpad
    📓
    Lenovo Linux - Trilug April 2021
    📄
    4 / 33

    View Slide

  5. Think-LMI
    Think-LMI
    LinuxからThinkPadのBIOS構成を取得設定がsysfs経由で可能になる
    Linux 5.14からkernelに取り込まれた
     Linux 5.11 Has Many x86 Platform Driver Changes For From Dell
    BIOS Controls To Telemetry - Phoronix
    5 / 33

    View Slide

  6. 今回の環境
    今回の環境
    LENOVO ThinkPad Yoga 260(Intel Core i5-6200U)
    USではLinux(Ubuntu 14.04)モデルあり
    Debian Bullseyeではサスペンドに失敗 → Linux 5.12.4+で動作するの
    で最新Kernelを追いかけている
     ThinkPad T430s でもOKだった :)
    6 / 33

    View Slide

  7. Linux 5.14 を build
    Linux 5.14 を build
    BuildADebianKernelPackage - Debian Wiki
    7 / 33

    View Slide

  8. 関連パッケージの導入
    関連パッケージの導入
    $ sudo apt install build-essential flex bison fakeroot gpg2

    $ sudo apt build-dep linux

    $ sudo apt install sbsigntool mokutil # SecureBoot
    8 / 33

    View Slide

  9. kernel source の入手と展開
    kernel source の入手と展開

    $ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.14.tar.xz \

    https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.14.tar.sign

    $ unxz ./linux-5.14.tar.xz

    $ gpg --verify ./linux-5.14.tar.sign

    $ tar tvf ./linux-5.14.tar | lv

    $ tar xf ./linux-5.14.tar

    $ cd ./linux-5.14
    The Linux Kernel Archives - Signatures
    9 / 33

    View Slide

  10. update時のpatch
    update時のpatch
    kernel upgrade時に毎回tarをDLするのは無駄なのでpatchが用意され
    ている(gitはでかい……)
    2種類のpatchがある
    patch
    5.14からのpatch(5.14 → 5.14.2)
    inc. patch
    直前からのpatch( 5.14 → 5.14.1 → 5.14.2 → …… )
    10 / 33

    View Slide

  11. .config
    .config の作成
    の作成
    1 現在のkernelの .config をベースに
    2 既定値で設定
    3 手動で設定カスタマイズ
    $ cp /boot/config-`uname -r` ./.config

    $ make olddefconfig

    $ make xconfig
    1
    2
    3
    11 / 33

    View Slide

  12. .config 修正
    .config 修正
    証明書ファイルを探しに行って失敗するので .config の
    CONFIG_SYSTEM_TRUSTED_KEYS を "" にする

    時間とディスクを食うのでデバッグシンボルパッケージを生成し
    ない

    CONFIG_DEBUG_INFO を n に
    BuildADebianKernelPackage - Debian Wiki
    12 / 33

    View Slide

  13. THINK_LMI の有効化
    THINK_LMI の有効化
    CONFIG_THINKPAD_LMI を有効にしてbuildする.
    $ grep CONFIG_THINKPAD_LMI= ./.config

    CONFIG_THINKPAD_LMI=m
    13 / 33

    View Slide

  14. build & install
    build & install
    Intel Core i5-6200U, RAM 8GB, SATA SSD環境で50〜90min程
    $ make testconfig

    $ time make -j$(nproc) bindeb-pkg LOCALVERSION=-matoken

    $ sudo apt install ../linux-*image*-5.14.0*.deb
    14 / 33

    View Slide

  15. SecureBoot対応
    SecureBoot対応
    SecureBoot - Debian Wiki
    15 / 33

    View Slide

  16. MOK - Machine Owner Keyの作成
    MOK - Machine Owner Keyの作成
    (初回のみ)
    (初回のみ)
     MOKのパスとファイル名を /root/mok.* としておくことで
    /etc/dkms/sign_helper.sh によって DKMS module の署名
    が自動的に行われる

    カスタマイズした場合は自分で署名が必要

    $ openssl req -new -x509 -newkey rsa:2048 -keyout /root/mok.priv -outform DER \

    -out /root/mok.der -days 36500 -subj "/CN=My Name/" -nodes

    $ openssl x509 -inform der -in /root/mok.der -out /root/mok.pem
    $ find /lib/modules/*/updates/dkms/ -type f -print0 | \

    xargs -0 -n1 sudo /usr/lib/linux-kbuild-5.10/scripts/sign-file \

    sha256 ~root/MOK.priv ~root/MOK.der
    16 / 33

    View Slide

  17. MOKのマシンへの登録(初回の
    MOKのマシンへの登録(初回の
    み)
    み)
    $ sudo mokutil --import /root/mok.der # prompts for one-time password

    $ sudo mokutil --list-new # recheck your key will be prompted on next boot
    17 / 33

    View Slide

  18. Kernelへの署名(セルフビルド
    Kernelへの署名(セルフビルド
    kernel install毎)
    kernel install毎)
     自動化できないかな?
    $ sbsign --key /root/mok.priv --cert /root/mok.pem /boot/vmlinuz-$ver --output vmlinuz-$ver

    $ sudo mv vmlinux-$ver /boot/vmlinux-$ver
    18 / 33

    View Slide

  19. 再起動して確認
    再起動して確認
    MOK登録後初回起動時にはUEFIのMOK登録画面に遷移するので登
    録の確認やパスワードの入力を行い再起動する
    新Kernelで起動
    19 / 33

    View Slide

  20. 🐧
    🐧
    cowsay -f tux $(uname -sr) | lolcat -p 2
    20 / 33

    View Slide

  21. THINK_LMI の sysfs 確認
    THINK_LMI の sysfs 確認
    1 moduleの読み込み
    2 適当な設定以下に移動
    $ sudo modprobe -v think_lmi

    insmod /lib/modules/5.14.0-le9/kernel/drivers/platform/x86/think-lmi.ko

    $ lsmod | grep lmi

    think_lmi 24576 0

    firmware_attributes_class 16384 1 think_lmi

    wmi 36864 2 wmi_bmof,think_lmi

    $ cd /sys/class/firmware-attributes/thinklmi/attributes/IntegratedCameraAccess

    $ ls -lA

    total 0

    -rw------- 1 root root 4096 Sep 11 08:06 current_value

    -r--r--r-- 1 root root 4096 Sep 11 08:06 display_name

    -r--r--r-- 1 root root 4096 Sep 11 08:06 possible_values
    1
    2
    21 / 33

    View Slide

  22. sysfs 操作
    sysfs 操作
    1 内蔵カメラの設定
    2 現在 Enable になっていて /dev/video0 も生えている
    3 Disable,Enable に設定できる
    4 Disable に設定してみる
    5 Disable になっていて, /dev/video0 も無くなった
    $ sudo cat ./display_name

    IntegratedCameraAccess

    $ sudo cat ./current_value

    Enable

    $ sudo cat ./possible_values

    Disable,Enable

    $ echo Disable | sudo tee ./current_value

    Disable

    $ sudo shutdown -r now 'bios camera disable'

    $ sudo cat /sys/class/firmware-attributes/thinklmi/attributes/IntegratedCameraAccess/current_v
    Disable
    1
    2
    3
    4
    5
    22 / 33

    View Slide

  23. think-lmi : Userspace Utlity
    think-lmi : Userspace Utlity
    LENOVO製のUtility を見つけたのでこれも試してみた
    lenovo/thinklmi: Utility for easy access to BIOS WMI settings
    $ git clone https://github.com/lenovo/thinklmi

    $ cd thinklmi/thinklmi-user

    $ gcc -o thinklmi thinklmi.c
    23 / 33

    View Slide

  24. usage
    usage
    $ sudo ./thinklmi

    Usage: thinklmi [-g | -s | -p | -c | -d | -l | -w | getsettings| save settings | discard settin
    Option details:

    getsettings - display all available BIOS options:

    -g [BIOS option] - Get the current setting and choices for given BIOS option

    -s [BIOS option] [value] - Set the given BIOS option to given value

    -p [password] [encoding] [kbdlang] - Set authentication details.

    -c [password] [new password] [password type] [encoding] [kbdlang] - Change password.

    -d [debug setting] [option]

    -l load default settings

    -w [Admin password] [password type] [current password] [new password] - Change passwo
    -w [password type] [current password] [new password] - Change password using lmiopcod
    -t [tpm type] - Change tpm type

    save settings - save BIOS settings

    discard settings - discard loaded settings

    Notes:

    password type can be "pap" or "pop"

    encoding can be "ascii" or "scancode"

    kbdland can be "us" or "fr" or "gr"
    24 / 33

    View Slide

  25. 動作しない
    動作しない
    Linux 5.14 とLENOVO版?のthinklmiは動作が異なり sysfs の PATH が違
    うせいのよう
    Linux 5.14 → /sys/class/firmware-attributes/thinklmi/
    LENOVO → /sys/bus/wmi/drivers/think-lmi/
    $ sudo ./thinklmi getsettings

    query_apps open: No such file or directory
    25 / 33

    View Slide

  26. LENOVO版
    LENOVO版 think-lmi.ko
    think-lmi.ko で試
    で試


     Linux 5.13 でもOKだった
    $ sudo rmmod think_lmi

    $ sudo ls /sys/class/firmware-attributes/thinklmi/

    ls: cannot access '/sys/class/firmware-attributes/thinklmi/': No such file or directory

    $ cd ../thinklmi-kernel

    $ make

    $ sudo make install

    install -d /lib/modules/5.14.2-le9/extra/

    install -m 644 think-lmi.ko /lib/modules/5.14.2-le9/extra/

    install -m 644 think-lmi.conf /etc/modules-load.d

    depmod

    modprobe think-lmi

    $ lsmod | grep lmi

    think_lmi 24576 0

    wmi 36864 2 wmi_bmof,think_lmi

    $ ls /sys/bus/wmi/drivers/think-lmi/

    /sys/bus/wmi/drivers/think-lmi/

    51F5230E-9677-46CD-A1CF-C0B23EE34DB7 bind module uevent unbind
    26 / 33

    View Slide

  27. think-lmi : Userspace Utlityで設定
    think-lmi : Userspace Utlityで設定
    項目確認(1 of 3)
    項目確認(1 of 3)
    $ sudo ../thinklmi-user/thinklmi getsettings

    Total settings: 69

    000: WakeOnLAN

    001: EthernetLANOptionROM

    002: IPv4NetworkStack

    003: IPv6NetworkStack

    004: UefiPxeBootPriority

    005: WiGigWake

    006: USBBIOSSupport

    007: AlwaysOnUSB

    008: TrackPoint

    009: TouchPad

    010: FnCtrlKeySwap

    011: FnSticky

    012: FnKeyAsPrimary

    013: BootDisplayDevice

    014: SharedDisplayPriority

    015: TotalGraphicsMemory

    016: BootTimeExtension

    017: SpeedStep

    018: AdaptiveThermalManagementAC

    019: AdaptiveThermalManagementBattery

    020: CPUPowerManagement

    021: OnByAcAttach
    27 / 33

    View Slide

  28. 設定項目(2 of 3)
    設定項目(2 of 3)
    022: PasswordBeep

    023: KeyboardBeep

    024: HyperThreadingTechnology

    025: AMTControl

    026: LockBIOSSetting

    027: MinimumPasswordLength

    028: BIOSPasswordAtUnattendedBoot

    029: BIOSPasswordAtReboot

    030: BIOSPasswordAtBootDeviceList

    031: PasswordCountExceededError

    032: FingerprintPredesktopAuthentication

    033: FingerprintReaderPriority

    034: FingerprintSecurityMode

    035: FingerprintPasswordAuthentication

    036: SecurityChip

    037: TXTFeature

    038: PhysicalPresenceForTpmProvision

    039: PhysicalPresenceForTpmClear

    040: BIOSUpdateByEndUsers

    041: SecureRollBackPrevention

    042: DataExecutionPrevention

    043: VirtualizationTechnology

    044: VTdFeature

    045: EthernetLANAccess

    046: WirelessLANAccess

    047: WirelessWANAccess

    048: BluetoothAccess
    28 / 33

    View Slide

  29. 設定項目(3 of 3)
    設定項目(3 of 3)
    049: USBPortAccess

    050: MemoryCardSlotAccess

    051: SmartCardSlotAccess

    052: IntegratedCameraAccess

    053: MicrophoneAccess

    054: FingerprintReaderAccess

    055: NfcAccess

    056: WiGig

    057: BottomCoverTamperDetected

    058: InternalStorageTamper

    059: ComputraceModuleActivation

    060: SecureBoot

    061: SGXControl

    062: DeviceGuard

    063: BootMode

    064: StartupOptionKeys

    065: BootDeviceListF12Option

    066: BootOrder

    067: NetworkBoot

    068: BootOrderLock
    29 / 33

    View Slide

  30. think-lmi : Userspace Utlityでの設
    think-lmi : Userspace Utlityでの設
    定を試す
    定を試す
    さっき sysyfs を直に操作して無効にした内蔵カメラを有効にしてみた
    $ sudo ../thinklmi-user/thinklmi -g IntegratedCameraAccess

    Disable

    Disable,Enable

    $ sudo ../thinklmi-user/thinklmi -s IntegratedCameraAccess Enable

    BIOS Setting changed

    Setting will not change until reboot

    $ sudo ../thinklmi-user/thinklmi -g IntegratedCameraAccess

    Enable

    Disable,Enable
    30 / 33

    View Slide

  31. まとめ
    まとめ
    Linux 5.14からThinkPadのBIOSが設定できるようになった
    今の所LENOVO版のkernel module + Utility の組み合わせが便利
    かんたんにBIOS設定をバックアップしたり設定変更ができて便利
    そう
    会社や学校などで設定を揃えたいときなどにも使えそう
    31 / 33

    View Slide

  32. 発表時の反応など
    発表時の反応など
    LMIってなんの略だろう?
    OpenLMIはLinux Management Infrastructureなのでそれかも?
    全端末の設定を揃えたいときにネットワークブートで設定すると
    便利そう
    大量の端末をキッティングするときに,BIOS設定は手作業が入る
    からミスが起きやすい
    TUIやGUIの実BIOSのようなインターフェイスがあると便利そう
    マシンごとに対応が必要だと実装面倒そうかも
    32 / 33

    View Slide

  33. 奥付
    奥付
    発表
    発表者
    利用ソフトウェア
    ライセンス
    CC BY-NC-SA 4.0
    小江戸らぐ 9月のオフな集まり(第230回)
    Kenichiro Matohara(matoken)
    Asciidoctor Reveal.js
    33 / 33

    View Slide