2025-12-07

Nvidia 顯卡在 Linux Mint / Ubuntu 的 ucsi_ccg_init failed 問題

 dmesg -H -l err 出現以下訊息:

nvidia-gpu 0000:01:00.3: i2c timeout error e0000000
ucsi_ccg 1-0008: i2c_transfer failed -110
ucsi_ccg 1-0008: ucsi_ccg_init failed - -110

這是因為NVIDIA 驅動想透過 I2C 去跟 Type-C 控制晶片(CCG)溝通,但怎麼叫都沒反應,導致一直噴錯誤到 dmesg,這通常 不會影響顯示卡正常運作,只是 log 很醜、偶爾會吵醒系統(影響待機功耗),如果你根本不用 Type-C 充電(或卡上也沒vlink / usb-c DP),可以直接禁掉ucsi_cgg模組/aux i2c/i2c bus:

#方法一,直接關掉ucsi_ccg模組
echo "blacklist ucsi_ccg" | sudo tee /etc/modprobe.d/blacklist-ucsi_ccg.conf

#方法二,關掉aux i2c
echo 'options nvidia NVreg_EnableGpuAuxI2c=0' | sudo tee /etc/modprobe.d/nvidia-fix-i2c-timeout.conf

#方法三,關掉特定 bus
dmesg | grep -i ucsi_ccg #找出哪條噴錯,通常是i2c-10 或 i2c-8
echo 'options nvidia NVreg_RegistryDwords="RMDisableAuxBus=0x10"' | sudo tee /etc/modprobe.d/nvidia-fix-i2c-timeout.conf 

#ramfs update
sudo update-initramfs -u


2025-12-06

Macbook 2012 15" (A1286) 安裝Linux Mint 22 / Ubuntu 24.04

 要解決的問題跟以下這篇差不多:
https://duckfly-tw.blogspot.com/2023/09/macbook-13-2014-ubuntu.html

但還有其它問題:

1.因Macbook 2012 (A1286)有獨顯GT650M,需手動安裝nvidia-470驅動(支援GT650M的最後一版驅動),因上游驅動都變5XX系列了,ubuntu-drivers因顯卡太舊無法安裝驅動,沒安裝nvidia閉源驅動就只能用kernel內建的nouveau開源驅動,效率肯定低。

另外要特別注意的是,nvidia-driver-470只能支援到kernel 6.8.x,再上去dkms driver會無法被新的kernel載入!因此千萬別安裝6.8以上的kernel,即使裝了沒使用也不行(因為會破壞dkms tree造成其它kernel也無法正常運作),如果裝了6.8以上的kernel,務必要移除掉,並重建dkms tree:
sudo dkms autoinstall --all

# 先完全移除 nouveau(黑名單)
sudo rmmod nouveau (若出現無法缷載dkms,略過沒關係)
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nouveau.conf"
sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nouveau.conf"
sudo update-initramfs -u

# 加 graphics-drivers PPA(專門放舊版驅動)
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-driver-470

#加裝nvidia-prime nvidia-prime-applet,這樣tool panel才會有nvidia optimus面版可以調整
sudo apt install nvidia-prime nvidia-prime-applet

# 重開機
sudo reboot

# 正確結果會顯示:NVIDIA GeForce GT 650M/PCIe/SSE2  (不再是 NVE7)
glxinfo | grep "OpenGL renderer"


2. 電源管理,安裝下面這個applesmc-next dkms,以便能設定macbook的充電上限:https://github.com/c---/applesmc-next?tab=readme-ov-file
直接複製其bash script以sudo執行後,再複製45-apple的tlp script並重開機:
sudo cp /usr/src/applesmc-next-0.1.6/45-apple /usr/share/tlp/bat.d/

之後可安裝如Battery Health ChargingSlimbook Battery來設定電池的充電上限。

3.dmesg出開以下錯誤訊息:
DMAR-IR: [Firmware Bug]: ioapic 2 has no mapping iommu, interrupt remapping will be disabled

#修改/etc/default/grub,修改開機選項
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash irqpoll intremap=off"


ref:
https://askubuntu.com/questions/767850/firmware-bug-ioapic-2-has-no-mapping-iomm-after-kernel-update

2025-03-26

bind9使用nsupdate+acme.sh申請免費憑證

1.首先要讓bind有ddns的功能,即允許外部使用key來動態更新A或TXT等record ,

先建立key:
=====================================
b=$(dnssec-keygen -a hmac-sha512 -b 512 -n USER -K /tmp foo)

cat > /etc/named/keys/update.key <<EOF
key "mykey" {
    algorithm hmac-sha512;
    secret "$(awk '/^Key/{print $2}' /tmp/$b.private)";
};
EOF
rm -f /tmp/$b.{private,key}

===把key檔路徑include進named的設定中==
include "/etc/named/keys/update.key";
=====================================
然後把domain獨立切出一個zone(範例是只允許TXT紀錄,因為只是要用來申請免費憑證):

=====================================
zone "yourdomain.com" {
    type master;
    file "/path/to/your/zone/file"; 
    update-policy {
        grant "mykey" subdomain yourdomain.com. TXT;
    };
};
==zone file,若無dns沒a紀錄沒有關係=======================

$TTL 86400
@   IN  SOA     ns.yourdomain.com. admin.yourdomain.com. (
                2023101001 ; Serial number
                3600       ; Refresh interval (one hour)
                1800       ; Retry interval (30 minutes)
                1209600    ; Expire time (two weeks)
                86400      ; Minimum TTL (one day)
)

@  IN A 1.2.3.4
* IN A 1.2.3.4
=====================================

安裝acme.sh(一般使用者即可,當然用root會更方便些):
curl https://get.acme.sh | sh -s email=my@yourdomain.com

wget -O -  https://get.acme.sh | sh -s email=my@yourdomain.com

建立帳號並決定使用哪個免費憑證服務(預設zerossl):
acme.sh  --register-account  -m myemail@yourdomain.com --server zerossl
如要用letsencrypt的話:
acme.sh --set-default-ca  --server letsencrypt
acme.sh  --register-account  -m myemail@yourdomain.com --server letsencrypt

設定讓acme.sh自動更新:
acme.sh --upgrade --auto-upgrade

開始申請憑證(此範例為申請wildcard憑證),此處的key格式要與named include的一樣就可以了:
export NSUPDATE_SERVER="dns.yourdomain.com"
export NSUPDATE_KEY="/path/to/your/update.key"
export NSUPDATE_ZONE="yourdomain.com"

~/.acme.sh/acme.sh --issue --dns dns_nsupdate -d yourdomain.com -d *.yourdomain.com --renew-hook "/path/to/install_cert.sh"

上面指令中的install_cert.sh即憑證renew成功後要執行的動作(複製憑證+重啟web):
憑證申請成功後,先手動複製憑證+重啟web(做第一次即可)
~/.acme.sh/acme.sh --install-cert -d yourdomain.com --key-file /certs/path/yourdomain.com/key.pem --fullchain-file /certs/path/yourdomain.com/fullchain.pem --reloadcmd "sudo systemctl restart nginx.service"

因為要讓一般使用者可以重新啟動web server,需加上sudoer:
#/etc/sudoers.d/acme_install_cert
username ALL=(ALL) NOPASSWD: /bin/systemctl restart nginx.service

這樣以後每60天會自動renew憑證,且會自動複製憑證並重啟web server。

其它:
安裝acme.sh時,會自動在使用者的crontab加上以下指令,固定每天檢查憑證:
51 1 * * * "/home/username/.acme.sh"/acme.sh --cron --home "/home/username/.acme.sh" > /dev/null

~/.acme.sh/account.conf 在申請憑證完後,會把一開始export的環境變數儲存在這裡,其它設定也會放在這個檔

~/.acme.sh/yourdomain.com_ecc/yourdomain.com.conf 會放一些跟這個網域有關的設定,如
Le_API=使用的憑證廠商api
Le_RenewHook=renew hook
Le_RealKeyPath=key要複製的路徑
Le_RealFullChainPath=fullchain要複製的路徑
Le_ReloadCmd=重啟指令

ref:
https://github.com/acmesh-official/acme.sh/wiki/dnsapi#7-use-nsupdate-to-automatically-issue-cert
https://github.com/acmesh-official/acme.sh/wiki/Server
https://ezbox.idv.tw/180/bind-ddns-dynamic-dns/
https://cwza.github.io/my_blog/2015/12/02/Bind9%E7%9A%84Dynamic-Dns-Update%E8%A8%AD%E5%AE%9A%E7%AD%86%E8%A8%98/
https://ithelp.ithome.com.tw/articles/10062006
https://n.sfs.tw/content/index/11984?u=
https://bugs.launchpad.net/ubuntu/+source/bind9/+bug/2015176
https://www.hobrasoft.cz/en/blog/bravenec/acme-sh-renew-hook