Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

で 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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

今回の環境 今回の環境 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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

関連パッケージの導入 関連パッケージの導入 $ sudo apt install build-essential flex bison fakeroot gpg2 $ sudo apt build-dep linux $ sudo apt install sbsigntool mokutil # SecureBoot 8 / 33

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

.config 修正 .config 修正 証明書ファイルを探しに行って失敗するので .config の CONFIG_SYSTEM_TRUSTED_KEYS を "" にする 時間とディスクを食うのでデバッグシンボルパッケージを生成し ない CONFIG_DEBUG_INFO を n に BuildADebianKernelPackage - Debian Wiki 12 / 33

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

動作しない 動作しない 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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

設定項目(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

Slide 29

Slide 29 text

設定項目(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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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