2022年10月26日 星期三

減少 MacBook Air M1睡眠時的 SSD 硬碟寫入量

[環境]
MacBook Air (M1, 2020)、macOS 12.6、接外接電源

[情況]
某天發現 MacBook 睡眠的時間越久,SSD 硬碟的寫入量,會越來越多,
甚至有次突然就多了幾十G寫入量。

依照在 windows 的經驗,應該是睡眠時,設定成將記憶體資料寫入硬碟,
至於睡眠越久硬碟寫入量越多,可能是某些因素系統被喚醒再繼續睡眠。

簡單測試了一下,蓋上 MacBook 前,特意將軟體都關閉,使用的記憶體大幅降低後,
隔天再觀察,SSD 增加的寫入量,明顯少了。
可見睡眠將記憶體資料寫入硬碟,應該是主要因素之一。

查睡眠喚醒次數,可發現自動喚醒的次數(Dark Wake)遠超過手動喚醒(User Wake)。
% pmset -g stats
Sleep Count:1334
Dark Wake Count:1313
User Wake Count:24


[目的]
考量自己的使用習慣,我不在意睡眠睡到沒電,無法保留原本在記憶體中的狀態,因為睡眠前我都會儲存進行中的作業。
所以預計將設定改成:
  1. 睡眠時,不將記憶體資料寫入硬碟。
  2. 睡眠時,不自動喚醒。(此項最後只有大幅減少自動喚醒次數,變成 2 小時喚醒一次)

 
[處理方式]
找了相關資料,經過一段時間的觀察測試,發現自動喚醒(Dark Wake)似乎無法100%禁止。
尤其我測試的某些結果,反跟網上所述恰恰相反,不確定是否作業系統版本不同的影響。
所以最終只設定成在我目前的環境下,自動喚醒(Dark Wake)次數盡量最少。

先查看預設的電源參數設定
% pmset -g custom
Battery Power:
 Sleep On Power Button 1
 lowpowermode         0
 standby              1
 ttyskeepawake        1
 hibernatemode        3
 powernap             1
 hibernatefile        /var/vm/sleepimage
 displaysleep         2
 sleep                1
 tcpkeepalive         1
 lessbright           1
 disksleep            10
AC Power:
 Sleep On Power Button 1
 lowpowermode         0
 standby              1
 ttyskeepawake        1
 hibernatemode        3
 powernap             1
 hibernatefile        /var/vm/sleepimage
 displaysleep         10
 womp                 1
 networkoversleep     0
 sleep                1
 tcpkeepalive         1
 disksleep            10

  1. 睡眠時,不將記憶體資料寫入硬碟
    系統睡覺有兩種狀態:
    Sleep(睡眠):保持對記憶體供電,將記憶體資料保存著,斷電資料會不見。
    Hibernate(休眠):將記憶體資料寫入硬碟,斷電還會存在。

    電源參數設定值:
    hibernatemode=0,只將資料保存在記憶體。(持續對記憶體供電)
    hibernatemode=3,除了將資料保存在記憶體,也寫入硬碟。(持續對記憶體供電)
    hibernatemode=25,將記憶體資料寫入硬碟保存後,就不保留在記憶體。(不對記憶體供電)

    是否將記憶體資料寫入硬碟,也受 standby、autopoweroff 影響:
    使用電池時,在條件符合的情況下,會觸發 standby,也會進入 Hibernate,將記憶體資料寫入硬碟。
    插電源時,在條件符合的情況下,會觸發 autopoweroff,也會進入 Hibernate,將記憶體資料寫入硬碟。

    但 standby、autopoweroff 這兩個相關的設定值,要有支援才會有。
    由 pmset -g cap 可查看目前供電條件下,可設定的參數

    使用電池時,可設定的參數:
    % pmset -g cap 
    Capabilities for Battery Power:
     displaysleep
     disksleep
     sleep
     lessbright
     standby
     powernap
     ttyskeepawake
     hibernatemode
     hibernatefile
     tcpkeepalive
     lowpowermode

    插電源時,可設定的參數:
    % pmset -g cap
    Capabilities for AC Power:
     displaysleep
     disksleep
     sleep
     womp
     standby
     powernap
     ttyskeepawake
     hibernatemode
     hibernatefile
     tcpkeepalive
     lowpowermode

    可發現我的環境只有 hibernatemode、standby,沒有 autopoweroff

    我不想將記憶體資料寫入硬碟,所以將 hibernatemode、standby、autopoweroff 都設為 0
    (因為我沒有 autopoweroff 的設定,所以沒執行 sudo pmset -a autopoweroff 0 也沒差)
    % sudo pmset -a hibernatemode 0
    % sudo pmset -a standby 0
    % sudo pmset -a autopoweroff 0
    pmset 參數說明:
    -b:電池,battery
    -c:插電源,charger (wall power)
    -u:UPS
    -a:全部

  2. 睡眠時,不自動喚醒
    關閉網路喚醒:
    這可以到「系統偏好設定」->「電池」->「電源轉接器」->取消勾選「進行網路連線時喚醒電腦」
    或下指令設定
    % sudo pmset -a womp 0

    關閉 powernap 高效小睡,預設開啟 powernap 時,會讓系統趁睡眠時,醒過來做一些事:
    % sudo pmset -a powernap 0
    (官網說明,當 Mac 進入睡眠並使用電池電力時,「高效小睡」會:檢查「郵件」中的新郵件、更新「行事曆」事件、更新其他 iCloud 事件、當 Mac 插上電源轉接器時,「高效小睡」還可以進行下載軟體更新項目和執行「時光機」備份等作業。)

    到此設定,發生 DarkWake 的情況,只剩這些:
    % pmset -g log | egrep "\b(Sleep|Wake|DarkWake|Start)\s{2,}"
    .....
    2022-10-13 04:09:14 +0800 Sleep               	Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 06:09:14 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 45 secs   
    2022-10-13 06:09:59 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 08:09:59 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 42 secs   
    2022-10-13 08:10:41 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7199 secs 
    2022-10-13 10:10:40 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-13 10:11:26 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 12:11:26 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 48 secs   
    2022-10-13 12:12:14 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 14:12:14 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-13 14:13:00 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 16:13:00 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 42 secs   
    2022-10-13 16:13:42 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 18:13:42 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-13 18:14:28 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 20:14:28 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 45 secs   
    2022-10-13 20:15:13 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-13 22:15:13 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-13 22:15:59 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-14 00:15:59 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-14 00:16:45 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-14 02:16:45 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 45 secs   
    2022-10-14 02:17:30 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-14 04:17:30 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 44 secs   
    2022-10-14 04:18:14 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-14 06:18:14 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 44 secs   
    2022-10-14 06:18:58 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 7200 secs 
    2022-10-14 08:18:58 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:80%) 46 secs   
    2022-10-14 08:19:44 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:80%) 4162 secs 
    2022-10-14 09:29:06 +0800 Wake                	Wake from Deep Idle [CDNVA] : due to SMC.OutboxNotEmpty smc.70070000 lid/UserActivity Assertion Using AC (Charge:80%)


    原本要再如網上說的,設定睡眠時,關閉持續網路連線,但結果 DarkWake 反而暴增,所以最終此項不設定:
    % sudo pmset -a tcpkeepalive 0
    Warning: This option disables TCP Keep Alive mechanism when sytem is sleeping. 
    This will result in some critical features like 'Find My Mac' not to function properly.
    (關閉時,會出現警告,説將無法使用 Find My Mac)

    蓋上筆電,睡眠前
    % pmset -g stats              
    Sleep Count:628
    Dark Wake Count:616
    User Wake Count:13

    一天多後,打開筆電,自動喚醒 DarkWake 暴增兩千多次
    % pmset -g stats
    Sleep Count:3494
    Dark Wake Count:3482
    User Wake Count:14

    查看紀錄
    % pmset -g log | egrep "\b(Sleep|Wake|DarkWake|Start)\s{2,}"
    .....
    2022-10-14 09:51:06 +0800 Sleep               	Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 1718 secs 
    2022-10-14 10:19:44 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:20:29 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 1 secs    
    2022-10-14 10:20:30 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:21:15 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 0 secs    
    2022-10-14 10:21:15 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 44 secs   
    2022-10-14 10:21:59 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 1 secs    
    2022-10-14 10:22:00 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:22:45 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 0 secs    
    2022-10-14 10:22:45 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 44 secs   
    2022-10-14 10:23:29 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 1 secs    
    2022-10-14 10:23:30 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:24:15 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 0 secs    
    2022-10-14 10:24:15 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:25:00 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 1 secs    
    2022-10-14 10:25:01 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs   
    2022-10-14 10:25:46 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:80%) 0 secs    
    2022-10-14 10:25:46 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:80%) 45 secs 
    .....
    2022-10-15 22:33:01 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:79%) 0 secs    
    2022-10-15 22:33:01 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:79%) 45 secs   
    2022-10-15 22:33:46 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=disabled Using AC (Charge:79%) 1 secs    
    2022-10-15 22:33:47 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/ Using AC (Charge:79%) 20 secs   
    2022-10-15 22:34:07 +0800 Wake                	DarkWake to FullWake from Deep Idle [CDNVA] : due to HID Activity Using AC (Charge:79%)
    可發現,剛開始蓋上蓋子,有進入 sleep,但第一次 DarkWake 後,便無法進入sleep (sleep 後會馬上 DarkWake),導致 DarkWake 次數大增。

    也因為一 sleep 後馬上 DarkWake,所以幾乎都處於 DarkWake 的狀態,因此打開筆電,很容易遇到系統剛好處於 DarkWake,也有幸因此見到不同訊息的 Wake 訊息:
    之前在Sleep狀態打開筆電,是
    Wake                	Wake from Deep Idle [CDNVA] : due to SMC.OutboxNotEmpty smc.70070000 lid/UserActivity Assertion Using AC (Charge:80%)
    這次在DarkWake狀態打開筆電,是
    Wake                	DarkWake to FullWake from Deep Idle [CDNVA] : due to HID Activity Using AC (Charge:79%)


    因為 tcpkeepalive 設為 0 後,情況更嚴重,所以將 tcpkeepalive 改回 1
    % sudo pmset -a tcpkeepalive 1
    再蓋上筆電一天多,觀察紀錄,變回固定 sleep 兩小時(7200秒),才會因 rtc/Maintenance 醒過來(DarkWake)
    % pmset -g log | egrep "\b(Sleep|Wake|DarkWake|Start)\s{2,}"
    .....
    2022-10-16 03:50:42 +0800 Sleep               	Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 05:50:42 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 43 secs   
    2022-10-16 05:51:25 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 07:51:25 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 46 secs   
    2022-10-16 07:52:11 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 09:52:11 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-16 09:52:56 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 2725 secs 
    2022-10-16 10:38:21 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to SMC.OutboxNotEmpty smc.70070000 wifibt wlan/ Using AC (Charge:79%) 45 secs   
    2022-10-16 10:39:06 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 12:39:06 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-16 12:39:51 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 14:39:51 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-16 14:40:36 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 207 secs  
    2022-10-16 14:44:03 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to SMC.OutboxNotEmpty smc.70070000 wifibt wlan/ Using AC (Charge:79%) 45 secs   
    2022-10-16 14:44:48 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 16:44:48 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 44 secs   
    2022-10-16 16:45:32 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 18:45:32 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-16 18:46:17 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 20:46:17 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 46 secs   
    2022-10-16 20:47:03 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-16 22:47:03 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-16 22:47:48 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-17 00:47:48 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 45 secs   
    2022-10-17 00:48:33 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-17 02:48:33 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 44 secs   
    2022-10-17 02:49:17 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 7200 secs 
    2022-10-17 04:49:17 +0800 DarkWake            	DarkWake from Deep Idle [CDN] : due to NUB.SPMI0Sw3IRQ nub-spmi.0x02 rtc/Maintenance Using AC (Charge:79%) 46 secs   
    2022-10-17 04:50:03 +0800 Sleep               	Entering Sleep state due to 'Maintenance Sleep':TCPKeepAlive=active Using AC (Charge:79%) 2345 secs 
    2022-10-17 05:29:08 +0800 Wake                	Wake from Deep Idle [CDNVA] : due to SMC.OutboxNotEmpty smc.70070000 lid/UserActivity Assertion Using AC (Charge:79%)
    所以目前大概就是維持目前的設定,至少需兩小時才會DarkWake一次,而且硬碟寫入量也超少。

    最終的電源參數設定值:
    (注意:如果到系統偏好設定裡的電源設定,進行回復預設值操作,即使介面上沒有的設定,也會回復預設值)
    % pmset -g custom                                           
    Battery Power:
     Sleep On Power Button 1
     lowpowermode         0
     standby              0
     ttyskeepawake        1
     hibernatemode        0
     powernap             0
     hibernatefile        /var/vm/sleepimage
     displaysleep         2
     sleep                1
     tcpkeepalive         1
     lessbright           1
     disksleep            10
     SleepServices        0
    AC Power:
     Sleep On Power Button 1
     lowpowermode         0
     standby              0
     ttyskeepawake        1
     hibernatemode        0
     powernap             0
     hibernatefile        /var/vm/sleepimage
     displaysleep         10
     womp                 0
     networkoversleep     0
     sleep                1
     tcpkeepalive         1
     disksleep            10
     SleepServices        0



參考:



2022年9月27日 星期二

CentOS 安裝 NFS Server

[環境]

三台 CentOS 7:
NFS Server (192.168.0.10)
Client (192.168.0.2)
Client (192.168.0.3)


[目的]

NFS Server (192.168.0.10) 建立兩個資料夾(/home/nfsA、/home/nfsB),
開放給兩個 Client(192.168.0.2、192.168.0.3) 存取。


[步驟]

  • NFS Server
    1. 安裝 NFS
      $ yum install nfs-utils
    2. 建立要分享的資料夾
      $ mkdir /home/nfsA
      $ mkdir /home/nfsB
    3. 編輯設定檔,加入兩個要分享的資料夾,並設定兩個 Client(192.168.0.2、192.168.0.3) 有存取權限。
      $ vi /etc/exports
      設定檔內容
      /home/nfsA 192.168.0.2(rw,sync,no_root_squash,no_all_squash,no_subtree_check) 192.168.0.3(rw,sync,no_root_squash,no_all_squash,no_subtree_check)
      /home/nfsB 192.168.0.2(rw,sync,no_root_squash,no_all_squash,no_subtree_check) 192.168.0.3(rw,sync,no_root_squash,no_all_squash,no_subtree_check)
      注意:
      設定值 rw,sync,no_root_squash,no_all_squash,no_subtree_check,
      請依個人環境需求設定,可用的設定值、效果,可用 man exports 查看。
      $ man exports
      .....
      rw     Allow both read and write requests on this NFS volume.
             The default is to disallow any request which changes the filesystem.
             This can also be made explicit by using the ro option.
      .....
      sync   Reply to requests only after the changes have been committed to stable storage (see async above).
             In  releases  of nfs-utils up to and including 1.0.0, the async option was the default.
             In all releases after 1.0.0, sync is the default, and async must be explicitly requested if needed.
             To help make system administrators aware of this change, exportfs will issue a warning if neither sync nor async is specified.
      .....
      no_subtree_check
             This option disables subtree checking, which has mild security implications, but can improve reliability in some circumstances.
      
             If a subdirectory of a filesystem is exported, but the whole filesystem isn't then whenever a NFS request arrives,
             the server must check not only that  the  accessed  file  is  in  the  appropriate filesystem (which is easy) but also that it is in the exported tree (which is harder).
             This check is called the subtree_check.
      
             In  order  to  perform  this  check, the server must include some information about the location of the file in the "filehandle" that is given to the client.
             This can cause problems with accessing files that are renamed while a client has them open (though in many simple cases it will still work).
      
             subtree checking is also used to make sure that files inside directories to which only root has access can only be accessed if the filesystem is exported with no_root_squash (see  below),  even  if
             the file itself allows more general access.
      
             As  a  general guide, a home directory filesystem, which is normally exported at the root and may see lots of file renames,
             should be exported with subtree checking disabled.  A filesystem which is mostly readonly,
             and at least doesn't see many file renames (e.g. /usr or /var) and for which subdirectories may be exported, should probably be exported with subtree checks enabled.
      
             The default of having subtree checks enabled, can be explicitly requested with subtree_check.
      
             From release 1.1.0 of nfs-utils onwards, the default will be no_subtree_check as subtree_checking tends to cause more problems than it is worth.
             If you  genuinely  require  subtree  checking,  you should explicitly put that option in the exports file.
             If you put neither option, exportfs will warn you that the change is pending.
      .....
      root_squash
             Map requests from uid/gid 0 to the anonymous uid/gid.
             Note that this does not apply to any other uids or gids that might be equally sensitive,
             such as user bin or group staff.
             (client 端使用 root 操作掛載的目錄時,NFS Server 會將 client 端的 root 對應成 NFS Server 上的匿名帳號)
      no_root_squash
             Turn off root squashing. This option is mainly useful for diskless clients.
      
      all_squash
             Map all uids and gids to the anonymous user.
             Useful for NFS-exported public FTP directories, news spool directories, etc.
             The opposite option is no_all_squash, which is the default setting.
    4. 啟動服務
      $ systemctl enable rpcbind
      $ systemctl enable nfs-server
      $ systemctl enable nfs-lock
      $ systemctl enable nfs-idmap
      $ systemctl start rpcbind
      $ systemctl start nfs-server
      $ systemctl start nfs-lock
      $ systemctl start nfs-idmap
    5. 開放防火牆
      $ firewall-cmd --permanent --zone=public --add-service=nfs
      $ firewall-cmd --permanent --zone=public --add-service=mountd
      $ firewall-cmd --permanent --zone=public --add-service=rpc-bind
      $ firewall-cmd --reload
      $ firewall-cmd --list-all --zone=public
  • Client
    1. 安裝 nfs-utils、libnfsidmap,啟動 rpcbind
      $ yum install nfs-utils libnfsidmap
      $ systemctl enable rpcbind
      $ systemctl start rpcbind
    2. 掛載 NFS Server 資料夾
      • 方法1:手動掛載
        $ mkdir /mnt/nfsA
        $ mkdir /mnt/nfsB
        $ showmount -e 192.168.0.10
        $ mount -t nfs 192.168.0.10:/home/nfsA /mnt/nfsA
        $ mount -t nfs 192.168.0.10:/home/nfsB /mnt/nfsB
      • 方法2:使用 autofs 自動掛載
        [安裝 autofs]
        $ yum install autofs
        $ systemctl enable autofs.service

        [建立新檔案 /etc/auto.mymnt-nfsA,裡面寫掛載 192.168.0.10:/home/nfsA/ 的語法]
        $ vi /etc/auto.mymnt-nfsA
        檔案內容
        * -rw,bg,soft,rsize=32768,wsize=32768 192.168.0.10:/home/nfsA/&

        [建立新檔案 /etc/auto.mymnt-nfsB,裡面寫掛載 192.168.0.10:/home/nfsB/ 的語法]
        $ vi /etc/auto.mymnt-nfsB
        檔案內容
        * -rw,bg,soft,rsize=32768,wsize=32768 192.168.0.10:/home/nfsB/&


        [建立新檔案 /etc/auto.master.d/mymnt.autofs,裡面寫上面兩個掛載語法,要掛載到哪個路徑]
        $ vi /etc/auto.master.d/mymnt.autofs
        檔案內容
        /mnt/nfsA /etc/auto.mymnt-nfsA
        /mnt/nfsB /etc/auto.mymnt-nfsB


        [重啟 autofs]
        $ systemctl restart autofs

        [掛載語法說明(以 /etc/auto.mymnt-nfsA 內容為例)]
        * -rw,bg,soft,rsize=32768,wsize=32768 192.168.0.10:/home/nfsA/&
        最前面的「*」,表示 client 端 /mnt/nfsA 下的所有目錄
        最後面的「&」,表示 NFS Server 的 192.168.0.10:/home/nfsA 底下所有目錄
        「&」對應到「*」
        例如:192.168.0.10:/home/nfsA/abc 會掛載成 client 端的 /mnt/nfsA/abc




參考:

MacBook Air 初次使用

第一次碰 macOS(Mac OS X、OS X) 系統,在大約10年前,上班時,發現座位旁多了台全新的  iMac,原來是公司要我將這台 iMac 安裝 Windows,雙系統並存。當時照著網上的教學,裝好雙系統,但對 macOS 還是很陌生,到現在,也幾乎沒印象了。這次買了 MacBook Air  M1,記錄一下初次使用 Mac 系統,可能會用到的地方。


[硬體]

  1. 新拿到的機器,查一下記憶體、硬碟是不是自己選配的
    查記憶體大小
    上方選單列,「最左邊蘋果logo」->「關於這台 Mac」->「概覽」

    查硬碟大小
    上方選單列,「最左邊蘋果logo」->「關於這台 Mac」->「儲存空間」

  2. 系統預設,還沒自己另外裝其他軟體、尚未連上網路(網購有7天猶豫期,避免上網自動啟動保固),測試硬體是否正常
    • 兩個 TYPE C 接口:插充電線測試。
    • 視訊鏡頭:開啟內建軟體「FaceTime」或「Photo Booth」 測試。
    • 內建麥克風、喇叭:開啟內建軟體「語音備忘錄」 測試。
    • 耳機孔:是4段的TRRS,且為 CITA 規格,可拿同是 CITA 規格的耳機測試。
      插好後,一樣用內建軟體「語音備忘錄」 測試。
      (我測試時,一開始一個聲道沒聲音,原以為是耳機線斷了接觸不良,後來調整了一下系統左右聲道音量大小,突然好了,不過不確定是耳機線接觸不良,還是調整系統聲道音量大小後才恢復正常)
    • 藍芽:連手機藍芽測試。我是桌機、手機、耳機上的藍芽都連上測試。
    • Wifi:僅搜尋 wifi 訊號,切勿連上網路,避免自動註冊開始算保固。網購7天猶豫期,如果怕自動連上網,可先關閉 wifi。
    • Type C 充電線:這類線材黏黏的是常態。一開始摸到,覺得 Apple 就是與眾不同,手感奇特應該是特殊材質吧。
      後來發現筆電殼怎麼有一片類似刮傷痕跡,用手抹不掉,以為買到機王,但又想這痕跡算蠻明顯的,之前沒發現不太可能。
      此時發現剛剛摸過充電線的手黏黏的,再摸一下線,果然線黏黏的,而筆電殼有痕跡的地方,剛剛放過充電線,拿充電線貼上筆電殼一試,沒錯,痕跡是因為沾上充電線黏黏的物質,後來用衛生紙沾水擦好久,還是有些微痕跡。
      所以充電線,要避免跟其他東西接觸,後來拿了個夾鏈袋裝起來。
      上網查,據說是環保材質,無解,有的人受不了,另外買充電線,我是每次摸到,都要去洗手,個人受不了手上黏黏的,但這樣似乎不怎麼環保了。



[註冊&保固]
  1. 連上網路後,線上查保固
    複製這台 MacBook Air 序號
    上方選單列,「最左邊蘋果logo」->「關於這台 Mac」->「概覽」,將序號複製下來
  2. 上官網用序號查詢
  3. 蘋果官網」->「支援服務」->「保固及維修」->「查看您的 Apple 產品是否符合資格」,貼上序號查詢。

    我第一天連上網路查詢時,查詢結果出現「購買日期未經驗證」


    隔天再查即可查到保固資料,且保固日期是從連上網那天開始計算。

  4. 上方選單列,「最左邊蘋果logo」->「關於這台 Mac」->「支援」,這邊也可以查到保固到期日
    最初官網上查詢結果是「購買日期未經驗證」時,這邊資訊是顯示保固到 7 月多,後來官網上有保固資料後,這邊也變為新的日期 9 月 2 日。

  5. 可以上網後,立即註冊、登入 APPLE ID,以開啟 iCloud 同步,避免硬體損壞時,資料遺失。
    「系統偏好設定」->「登入」,照著指示建立帳號、登入
    https://support.apple.com/zh-tw/HT204316  (在 Mac 上建立 Apple ID) 



[系統&軟體]
  1. 上方工具列,顯示電源電量百分比
    「系統偏好設定」->「Dock與選單列」->「電池(選單列)」,勾選「顯示百分比」
  2. Dock 圖示滑過時放大
    「系統偏好設定」->「Dock與選單列」,勾選「放大」
  3. Finder 工具列圖示顯示文字
    打開Finder,「顯示方式」->「自訂工具列」->「顯示」選「圖像與文字」
  4. 調整觸控板點擊力道、軌跡速度(指標速度)
    「系統偏好設定」->「觸控式軌跡板」
  5. 開啟防火牆
    「系統偏好設定」->「安全性與隱私權」->「防火牆」
    預設關閉,按左下角的鎖頭,將鎖頭打開後,可進行修改。
  6. 檔案剪下貼上
    先「command」+「C」複製 ->再「command」+「option」+「V」,多了 option 即為剪下貼上效果
  7. 截圖
    • 整個螢幕:「shift」+「command」+「3」
    • 部分螢幕:「shift」+「command」+「4」
      拖曳十字線(選取範圍)、空白鍵(移動選取範圍)、ESC鍵(取消)
    • 視窗、選單:「shift」+「command」+「4」+「space」
      指標變相機圖示移動選擇目標、按目標同時按「option」(排除視窗陰影)、ESC鍵(取消)
    • 打開截圖APP:「shift」+「command」+「5」
      除了上述的截圖功能、還能錄製螢幕
  8. 刪除指標後面文字:「fn」+「del」
  9. 安裝軟體(應用程式、APP)
    • 從 App Store 安裝
    • 自行從網路下載安裝檔(以下為遇過的情況)
      • .dmg 檔:執行後(打開),如果裡面是 .app 檔,照提示畫面拖曳至應用程式資料夾即可
      • .xip 檔:執行後,解壓縮出 .app 檔,一樣放到應用程式
      • .pkg 檔(也可能 .dmg  檔打開後,裡面是放  .pkg 檔):執行後,類似 windows 軟體的安裝方式
    • 自行從網路下載的軟體,初次執行會詢問是一個從 Internet 下載的 APP,確定要打開嗎?

    • 放到應用程式資料夾的軟體,才會出現在啟動台中
  10. 移除程式(應用程式、APP)
    • 從 App Store 安裝的:開啟「啟動台」,按「option」,圖示晃動(未晃動表示是自行下載安裝,或為 Mac 必要APP),出現小叉叉的,表示是從 APP Store 安裝的,按小叉叉,可移除。
    • 自行從網路下載安裝的:
      「Finder」->「應用程式」->找到要移除的程式,丟到垃圾桶。
      有的裝完後,會有一個反安裝程式,有反安裝程式的,則執行反安裝程式。
  11. 顯示桌面:「command」+「F3」或 「觸控板四指外撥」
    目前所有視窗會隱藏到桌面邊緣灰色地帶,點桌面邊緣灰色地帶或任一個軟體,所有視窗又會顯示。
  12. 鎖定螢幕:「control」+「command」+「Q」
  13. 切換:啟動台 <--> 一般視窗畫面 <--> 顯示桌面
    四指外撥 --> (但在全螢幕畫面,四指外撥無法顯示桌面)
    四指靠攏 <--
  14. 視窗切換
    「command」+「tab」只能在不同 APP 間切換
    要找出某一個特定視窗:
    • 方法一:先「command」+「tab」切換到該 APP,再「command」+「~」依序切換同一 APP 內的視窗(缺點:無法預覽視窗)。
    • 方法二:「F3」或「三指往上推」,叫出所有視窗畫面(指揮中心)。(缺點:視窗多時縮圖會很小,若要找的視窗外觀不明顯,不容易找到)
    • 方法三:觸控板設定開啟「App Expose」功能手勢。「三指往下推」會顯示目前 APP 的所有視窗,要切換到其他 APP 可用三指左右滑的手勢。
  15. 對應 windows 的 Home、End、Page Up、Page Down
    Home:「fn」+「左鍵」或「command」+「上鍵」
    End:「fn」+「右鍵」或「command」+「下鍵」
    Page Up:「fn」+「上鍵」
    Page Down:「fn」+「下鍵」
  16. 輸入特殊符號(注音輸入法下)
    • 方法一:直接按鍵盤上的符號,若先不按 Enter 確定輸入,先按「空白鍵」的話,會出現更多類似符號可選。
    • 方法二:「option」+「shift」+「B」,叫出符號表,按「tab」「可在最近使用」、「符號」、「顏文字」間切換。
  17. 輸入表情符號和其他符號(注音輸入法下)
    叫出表情符號和其他符號:「control」+「command」+「space」
    下一個分類:「tab」
    上一個分類:「 tab」+「shift」
  18. 輸入全形英文
    • 全形大寫英文:按住「shift」,再輸入英文
    • 全形小寫英文:按住「option」,再輸入英文
    • 以上兩點,輸入後,不按 Enter 確定輸入,而先按「空白鍵」的話,會出現該字母的全形大寫、全形小寫,以供可選。
  19. 軟體開啟、關閉
    • 結束軟體(會關閉該軟體所有視窗):「command」+「Q」
    • 軟體目前視窗最小化:「command」+「M」
    • 軟體目前視窗隱藏:「command」+「H」
    • 軟體目前視窗關閉:「command」+「W」,視窗左上角叉叉
      如果瀏覽器設定『開啟時』要保留上一次開啟的視窗、分頁,若使用『關閉視窗』,則視窗關閉了,瀏覽器軟體其實沒結束,所以再按一次瀏覽器軟體,會開一個新視窗,裡面啥都沒有。
  20. 應用程式沒有回應、強制結束應用程式:
    「command」+「option」+「ESC」
    會開啟執行中的應用程式列表,無回應的軟體會註明,可強制結束該軟體。
    (我第一次遇到,也是第一次用 MacBook 處理事情的時候,當時用文字編輯器,編輯這篇文章草稿,純文字 .txt 檔案。連按快速鍵儲存時,突然看到滑鼠游標變成一個彩色圈圈轉不停,一開始以為是正常的,但等了許久都沒停。後來突然想到曾看到一個推薦 Mac 系統的影片,説 Mac 上軟體當掉,滑鼠還可以動,不像 windows 滑鼠不能用,先不論這說法是否正確,但這倒是提醒我,這該不會是軟體當掉吧,避免我繼續傻等。)
  21. 打開 spotlight 搜尋:
    「command」+「space」,或按鍵盤「F4(放大鏡圖示)」
  22. 建立「.txt」純文字檔案:
    打開內建「文字編輯」軟體,「格式」->「製作純文字格式」
  23. Finder 顯示副檔名:
    「Finder」->「偏好設定」->「進階」,勾選「顯示所有檔案副檔名」
  24. 「.xip」副檔名:壓縮檔。雙擊會解壓縮。類似 windows 的 zip 檔。
    自行下載的軟體,如果是這種格式,解壓縮後,會產生一個「.app」副檔名的檔案,將之拖曳到應用程式,完成安裝。
  25. 「.dmg」副檔名:類似 windows 的 iso 映像檔。
    下載的軟體如果是這種格式,雙擊後,會自動掛載(mount)這個映像檔後開啟。

    指令「df -l」或「diskutil list」,可看到 mount 到系統的映像檔。
    % diskutil list
    ......
    
    /dev/disk4 (disk image):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     Apple_partition_scheme                        +95.8 MB    disk4
       1:        Apple_partition_map ⁨⁩                        32.3 KB    disk4s1
       2:                  Apple_HFS ⁨Chrome Remote Deskto...⁩ 95.7 MB    disk4s2
                        (free space)                         1.0 TB     -
    
    ......
    
    /dev/disk6 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +1.6 GB     disk6
                                     Physical Store disk5s1
       1:                APFS Volume ⁨krita⁩                   819.6 MB   disk6s1


    Finder 的「位置」也會有目前掛載的列表,可按右邊倒三角的退出圖示,卸載掛載(unmount)。


    桌面上也會出現掛載的磁碟映像檔,按右鍵選單(快速鍵選單),也有退出的操作。
  26. 「.app」副檔名:Application Bundle(應用程式包)。
    Bundles(綑綁包)的一種,Bundles是一種特殊的資料夾,裡面有標準化層次結構的目錄,包含可執行代碼和該代碼使用的資源。

    Package(包):Finder 會將特殊的資料夾,例如附檔名(.app, .bundle, .framework, .plugin, .kext),用單個文件的形式,呈現給使用者。
  27. 安裝套件管理工具 Homebrew
    官網 https://brew.sh
    執行官網提供的安裝指令
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    ==> Checking for `sudo` access (which may request your password)...
    Password:
    (輸入密碼繼續)
    
    ==> This script will install:
    /opt/homebrew/bin/brew
    /opt/homebrew/share/doc/homebrew
    /opt/homebrew/share/man/man1/brew.1
    /opt/homebrew/share/zsh/site-functions/_brew
    /opt/homebrew/etc/bash_completion.d/brew
    /opt/homebrew
    ==> The following new directories will be created:
    /opt/homebrew/bin
    /opt/homebrew/etc
    /opt/homebrew/include
    /opt/homebrew/lib
    /opt/homebrew/sbin
    /opt/homebrew/share
    /opt/homebrew/var
    /opt/homebrew/opt
    /opt/homebrew/share/zsh
    /opt/homebrew/share/zsh/site-functions
    /opt/homebrew/var/homebrew
    /opt/homebrew/var/homebrew/linked
    /opt/homebrew/Cellar
    /opt/homebrew/Caskroom
    /opt/homebrew/Frameworks
    ==> The Xcode Command Line Tools will be installed.
    
    Press RETURN/ENTER to continue or any other key to abort:
    (按 ENTER 繼續)
    
    
    ==> /usr/bin/sudo /usr/bin/install -d -o root -g wheel -m 0755 /opt/homebrew
    ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
    ==> /usr/bin/sudo /bin/chmod ug=rwx /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
    ==> /usr/bin/sudo /bin/chmod go-w /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
    ==> /usr/bin/sudo /usr/sbin/chown xyz /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
    ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
    ==> /usr/bin/sudo /usr/sbin/chown -R xyz:admin /opt/homebrew
    ==> /usr/bin/sudo /bin/mkdir -p /Users/xyz/Library/Caches/Homebrew
    ==> /usr/bin/sudo /bin/chmod g+rwx /Users/xyz/Library/Caches/Homebrew
    ==> /usr/bin/sudo /usr/sbin/chown -R xyz /Users/xyz/Library/Caches/Homebrew
    ==> Searching online for the Command Line Tools
    ==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
    ==> Installing Command Line Tools for Xcode-14.0
    ==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-14.0
    Software Update Tool
    
    Finding available software
    
    Downloading Command Line Tools for Xcode
    (這邊等 Command Line Tools for Xcode 下載完)
    
    
    Installing Command Line Tools for Xcode
    Done with Command Line Tools for Xcode
    Done.
    ==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
    Password:
    (輸入密碼繼續)
    
    ==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
    ==> Downloading and installing Homebrew...
    remote: Enumerating objects: 216404, done.
    remote: Counting objects: 100% (343/343), done.
    remote: Compressing objects: 100% (240/240), done.
    remote: Total 216404 (delta 91), reused 332 (delta 84), pack-reused 216061
    Receiving objects: 100% (216404/216404), 60.64 MiB | 588.00 KiB/s, done.
    Resolving deltas: 100% (159127/159127), done.
    From https://github.com/Homebrew/brew
     * [new branch]          dependabot/bundler/Library/Homebrew/activesupport-6.1.7  -> origin/dependabot/bundler/Library/Homebrew/activesupport-6.1.7
     * [new branch]          dependabot/bundler/Library/Homebrew/rspec-expectations-3.11.1 -> origin/dependabot/bundler/Library/Homebrew/rspec-expectations-3.11.1
     * [new branch]          dependabot/bundler/Library/Homebrew/rspec-support-3.11.1 -> origin/dependabot/bundler/Library/Homebrew/rspec-support-3.11.1
     * [new branch]          dependabot/bundler/Library/Homebrew/rubocop-performance-1.15.0 -> origin/dependabot/bundler/Library/Homebrew/rubocop-performance-1.15.0
     * [new branch]          dependabot/bundler/Library/Homebrew/rubocop-rspec-2.13.1 -> origin/dependabot/bundler/Library/Homebrew/rubocop-rspec-2.13.1
     * [new branch]          master                                                   -> origin/master
     * [new branch]          sorbet-files-update                                      -> origin/sorbet-files-update
     * [new tag]             0.1                                                      -> 0.1
     * [new tag]             0.2                                                      -> 0.2
     * [new tag]             0.3                                                      -> 0.3
     * [new tag]             0.4                                                      -> 0.4
     * [new tag]             0.5                                                      -> 0.5
     * [new tag]             0.6                                                      -> 0.6
     * [new tag]             0.7                                                      -> 0.7
     * [new tag]             0.7.1                                                    -> 0.7.1
     * [new tag]             0.8                                                      -> 0.8
     * [new tag]             0.8.1                                                    -> 0.8.1
     * [new tag]             0.9                                                      -> 0.9
     * [new tag]             0.9.1                                                    -> 0.9.1
     * [new tag]             0.9.2                                                    -> 0.9.2
     * [new tag]             0.9.3                                                    -> 0.9.3
     * [new tag]             0.9.4                                                    -> 0.9.4
     * [new tag]             0.9.5                                                    -> 0.9.5
     * [new tag]             0.9.8                                                    -> 0.9.8
     * [new tag]             0.9.9                                                    -> 0.9.9
     * [new tag]             1.0.0                                                    -> 1.0.0
     * [new tag]             1.0.1                                                    -> 1.0.1
     * [new tag]             1.0.2                                                    -> 1.0.2
     * [new tag]             1.0.3                                                    -> 1.0.3
     * [new tag]             1.0.4                                                    -> 1.0.4
     * [new tag]             1.0.5                                                    -> 1.0.5
     * [new tag]             1.0.6                                                    -> 1.0.6
     * [new tag]             1.0.7                                                    -> 1.0.7
     * [new tag]             1.0.8                                                    -> 1.0.8
     * [new tag]             1.0.9                                                    -> 1.0.9
     * [new tag]             1.1.0                                                    -> 1.1.0
     * [new tag]             1.1.1                                                    -> 1.1.1
     * [new tag]             1.1.10                                                   -> 1.1.10
     * [new tag]             1.1.11                                                   -> 1.1.11
     * [new tag]             1.1.12                                                   -> 1.1.12
     * [new tag]             1.1.13                                                   -> 1.1.13
     * [new tag]             1.1.2                                                    -> 1.1.2
     * [new tag]             1.1.3                                                    -> 1.1.3
     * [new tag]             1.1.4                                                    -> 1.1.4
     * [new tag]             1.1.5                                                    -> 1.1.5
     * [new tag]             1.1.6                                                    -> 1.1.6
     * [new tag]             1.1.7                                                    -> 1.1.7
     * [new tag]             1.1.8                                                    -> 1.1.8
     * [new tag]             1.1.9                                                    -> 1.1.9
     * [new tag]             1.2.0                                                    -> 1.2.0
     * [new tag]             1.2.1                                                    -> 1.2.1
     * [new tag]             1.2.2                                                    -> 1.2.2
     * [new tag]             1.2.3                                                    -> 1.2.3
     * [new tag]             1.2.4                                                    -> 1.2.4
     * [new tag]             1.2.5                                                    -> 1.2.5
     * [new tag]             1.2.6                                                    -> 1.2.6
     * [new tag]             1.3.0                                                    -> 1.3.0
     * [new tag]             1.3.1                                                    -> 1.3.1
     * [new tag]             1.3.2                                                    -> 1.3.2
     * [new tag]             1.3.3                                                    -> 1.3.3
     * [new tag]             1.3.4                                                    -> 1.3.4
     * [new tag]             1.3.5                                                    -> 1.3.5
     * [new tag]             1.3.6                                                    -> 1.3.6
     * [new tag]             1.3.7                                                    -> 1.3.7
     * [new tag]             1.3.8                                                    -> 1.3.8
     * [new tag]             1.3.9                                                    -> 1.3.9
     * [new tag]             1.4.0                                                    -> 1.4.0
     * [new tag]             1.4.1                                                    -> 1.4.1
     * [new tag]             1.4.2                                                    -> 1.4.2
     * [new tag]             1.4.3                                                    -> 1.4.3
     * [new tag]             1.5.0                                                    -> 1.5.0
     * [new tag]             1.5.1                                                    -> 1.5.1
     * [new tag]             1.5.10                                                   -> 1.5.10
     * [new tag]             1.5.11                                                   -> 1.5.11
     * [new tag]             1.5.12                                                   -> 1.5.12
     * [new tag]             1.5.13                                                   -> 1.5.13
     * [new tag]             1.5.14                                                   -> 1.5.14
     * [new tag]             1.5.2                                                    -> 1.5.2
     * [new tag]             1.5.3                                                    -> 1.5.3
     * [new tag]             1.5.4                                                    -> 1.5.4
     * [new tag]             1.5.5                                                    -> 1.5.5
     * [new tag]             1.5.6                                                    -> 1.5.6
     * [new tag]             1.5.7                                                    -> 1.5.7
     * [new tag]             1.5.8                                                    -> 1.5.8
     * [new tag]             1.5.9                                                    -> 1.5.9
     * [new tag]             1.6.0                                                    -> 1.6.0
     * [new tag]             1.6.1                                                    -> 1.6.1
     * [new tag]             1.6.10                                                   -> 1.6.10
     * [new tag]             1.6.11                                                   -> 1.6.11
     * [new tag]             1.6.12                                                   -> 1.6.12
     * [new tag]             1.6.13                                                   -> 1.6.13
     * [new tag]             1.6.14                                                   -> 1.6.14
     * [new tag]             1.6.15                                                   -> 1.6.15
     * [new tag]             1.6.16                                                   -> 1.6.16
     * [new tag]             1.6.17                                                   -> 1.6.17
     * [new tag]             1.6.2                                                    -> 1.6.2
     * [new tag]             1.6.3                                                    -> 1.6.3
     * [new tag]             1.6.4                                                    -> 1.6.4
     * [new tag]             1.6.5                                                    -> 1.6.5
     * [new tag]             1.6.6                                                    -> 1.6.6
     * [new tag]             1.6.7                                                    -> 1.6.7
     * [new tag]             1.6.8                                                    -> 1.6.8
     * [new tag]             1.6.9                                                    -> 1.6.9
     * [new tag]             1.7.0                                                    -> 1.7.0
     * [new tag]             1.7.1                                                    -> 1.7.1
     * [new tag]             1.7.2                                                    -> 1.7.2
     * [new tag]             1.7.3                                                    -> 1.7.3
     * [new tag]             1.7.4                                                    -> 1.7.4
     * [new tag]             1.7.5                                                    -> 1.7.5
     * [new tag]             1.7.6                                                    -> 1.7.6
     * [new tag]             1.7.7                                                    -> 1.7.7
     * [new tag]             1.8.0                                                    -> 1.8.0
     * [new tag]             1.8.1                                                    -> 1.8.1
     * [new tag]             1.8.2                                                    -> 1.8.2
     * [new tag]             1.8.3                                                    -> 1.8.3
     * [new tag]             1.8.4                                                    -> 1.8.4
     * [new tag]             1.8.5                                                    -> 1.8.5
     * [new tag]             1.8.6                                                    -> 1.8.6
     * [new tag]             1.9.0                                                    -> 1.9.0
     * [new tag]             1.9.1                                                    -> 1.9.1
     * [new tag]             1.9.2                                                    -> 1.9.2
     * [new tag]             1.9.3                                                    -> 1.9.3
     * [new tag]             2.0.0                                                    -> 2.0.0
     * [new tag]             2.0.1                                                    -> 2.0.1
     * [new tag]             2.0.2                                                    -> 2.0.2
     * [new tag]             2.0.3                                                    -> 2.0.3
     * [new tag]             2.0.4                                                    -> 2.0.4
     * [new tag]             2.0.5                                                    -> 2.0.5
     * [new tag]             2.0.6                                                    -> 2.0.6
     * [new tag]             2.1.0                                                    -> 2.1.0
     * [new tag]             2.1.1                                                    -> 2.1.1
     * [new tag]             2.1.10                                                   -> 2.1.10
     * [new tag]             2.1.11                                                   -> 2.1.11
     * [new tag]             2.1.12                                                   -> 2.1.12
     * [new tag]             2.1.13                                                   -> 2.1.13
     * [new tag]             2.1.14                                                   -> 2.1.14
     * [new tag]             2.1.15                                                   -> 2.1.15
     * [new tag]             2.1.16                                                   -> 2.1.16
     * [new tag]             2.1.2                                                    -> 2.1.2
     * [new tag]             2.1.3                                                    -> 2.1.3
     * [new tag]             2.1.4                                                    -> 2.1.4
     * [new tag]             2.1.5                                                    -> 2.1.5
     * [new tag]             2.1.6                                                    -> 2.1.6
     * [new tag]             2.1.7                                                    -> 2.1.7
     * [new tag]             2.1.8                                                    -> 2.1.8
     * [new tag]             2.1.9                                                    -> 2.1.9
     * [new tag]             2.2.0                                                    -> 2.2.0
     * [new tag]             2.2.1                                                    -> 2.2.1
     * [new tag]             2.2.10                                                   -> 2.2.10
     * [new tag]             2.2.11                                                   -> 2.2.11
     * [new tag]             2.2.12                                                   -> 2.2.12
     * [new tag]             2.2.13                                                   -> 2.2.13
     * [new tag]             2.2.14                                                   -> 2.2.14
     * [new tag]             2.2.15                                                   -> 2.2.15
     * [new tag]             2.2.16                                                   -> 2.2.16
     * [new tag]             2.2.17                                                   -> 2.2.17
     * [new tag]             2.2.2                                                    -> 2.2.2
     * [new tag]             2.2.3                                                    -> 2.2.3
     * [new tag]             2.2.4                                                    -> 2.2.4
     * [new tag]             2.2.5                                                    -> 2.2.5
     * [new tag]             2.2.6                                                    -> 2.2.6
     * [new tag]             2.2.7                                                    -> 2.2.7
     * [new tag]             2.2.8                                                    -> 2.2.8
     * [new tag]             2.2.9                                                    -> 2.2.9
     * [new tag]             2.3.0                                                    -> 2.3.0
     * [new tag]             2.4.0                                                    -> 2.4.0
     * [new tag]             2.4.1                                                    -> 2.4.1
     * [new tag]             2.4.10                                                   -> 2.4.10
     * [new tag]             2.4.11                                                   -> 2.4.11
     * [new tag]             2.4.12                                                   -> 2.4.12
     * [new tag]             2.4.13                                                   -> 2.4.13
     * [new tag]             2.4.14                                                   -> 2.4.14
     * [new tag]             2.4.15                                                   -> 2.4.15
     * [new tag]             2.4.16                                                   -> 2.4.16
     * [new tag]             2.4.2                                                    -> 2.4.2
     * [new tag]             2.4.3                                                    -> 2.4.3
     * [new tag]             2.4.4                                                    -> 2.4.4
     * [new tag]             2.4.5                                                    -> 2.4.5
     * [new tag]             2.4.6                                                    -> 2.4.6
     * [new tag]             2.4.7                                                    -> 2.4.7
     * [new tag]             2.4.8                                                    -> 2.4.8
     * [new tag]             2.4.9                                                    -> 2.4.9
     * [new tag]             2.5.0                                                    -> 2.5.0
     * [new tag]             2.5.1                                                    -> 2.5.1
     * [new tag]             2.5.10                                                   -> 2.5.10
     * [new tag]             2.5.11                                                   -> 2.5.11
     * [new tag]             2.5.12                                                   -> 2.5.12
     * [new tag]             2.5.2                                                    -> 2.5.2
     * [new tag]             2.5.3                                                    -> 2.5.3
     * [new tag]             2.5.4                                                    -> 2.5.4
     * [new tag]             2.5.5                                                    -> 2.5.5
     * [new tag]             2.5.6                                                    -> 2.5.6
     * [new tag]             2.5.7                                                    -> 2.5.7
     * [new tag]             2.5.8                                                    -> 2.5.8
     * [new tag]             2.5.9                                                    -> 2.5.9
     * [new tag]             2.6.0                                                    -> 2.6.0
     * [new tag]             2.6.1                                                    -> 2.6.1
     * [new tag]             2.6.2                                                    -> 2.6.2
     * [new tag]             2.7.0                                                    -> 2.7.0
     * [new tag]             2.7.1                                                    -> 2.7.1
     * [new tag]             2.7.2                                                    -> 2.7.2
     * [new tag]             2.7.3                                                    -> 2.7.3
     * [new tag]             2.7.4                                                    -> 2.7.4
     * [new tag]             2.7.5                                                    -> 2.7.5
     * [new tag]             2.7.6                                                    -> 2.7.6
     * [new tag]             2.7.7                                                    -> 2.7.7
     * [new tag]             3.0.0                                                    -> 3.0.0
     * [new tag]             3.0.1                                                    -> 3.0.1
     * [new tag]             3.0.10                                                   -> 3.0.10
     * [new tag]             3.0.11                                                   -> 3.0.11
     * [new tag]             3.0.2                                                    -> 3.0.2
     * [new tag]             3.0.3                                                    -> 3.0.3
     * [new tag]             3.0.4                                                    -> 3.0.4
     * [new tag]             3.0.5                                                    -> 3.0.5
     * [new tag]             3.0.6                                                    -> 3.0.6
     * [new tag]             3.0.7                                                    -> 3.0.7
     * [new tag]             3.0.8                                                    -> 3.0.8
     * [new tag]             3.0.9                                                    -> 3.0.9
     * [new tag]             3.1.0                                                    -> 3.1.0
     * [new tag]             3.1.1                                                    -> 3.1.1
     * [new tag]             3.1.10                                                   -> 3.1.10
     * [new tag]             3.1.11                                                   -> 3.1.11
     * [new tag]             3.1.12                                                   -> 3.1.12
     * [new tag]             3.1.2                                                    -> 3.1.2
     * [new tag]             3.1.3                                                    -> 3.1.3
     * [new tag]             3.1.4                                                    -> 3.1.4
     * [new tag]             3.1.5                                                    -> 3.1.5
     * [new tag]             3.1.6                                                    -> 3.1.6
     * [new tag]             3.1.7                                                    -> 3.1.7
     * [new tag]             3.1.8                                                    -> 3.1.8
     * [new tag]             3.1.9                                                    -> 3.1.9
     * [new tag]             3.2.0                                                    -> 3.2.0
     * [new tag]             3.2.1                                                    -> 3.2.1
     * [new tag]             3.2.10                                                   -> 3.2.10
     * [new tag]             3.2.11                                                   -> 3.2.11
     * [new tag]             3.2.12                                                   -> 3.2.12
     * [new tag]             3.2.13                                                   -> 3.2.13
     * [new tag]             3.2.14                                                   -> 3.2.14
     * [new tag]             3.2.15                                                   -> 3.2.15
     * [new tag]             3.2.16                                                   -> 3.2.16
     * [new tag]             3.2.17                                                   -> 3.2.17
     * [new tag]             3.2.2                                                    -> 3.2.2
     * [new tag]             3.2.3                                                    -> 3.2.3
     * [new tag]             3.2.4                                                    -> 3.2.4
     * [new tag]             3.2.5                                                    -> 3.2.5
     * [new tag]             3.2.6                                                    -> 3.2.6
     * [new tag]             3.2.7                                                    -> 3.2.7
     * [new tag]             3.2.8                                                    -> 3.2.8
     * [new tag]             3.2.9                                                    -> 3.2.9
     * [new tag]             3.3.0                                                    -> 3.3.0
     * [new tag]             3.3.1                                                    -> 3.3.1
     * [new tag]             3.3.10                                                   -> 3.3.10
     * [new tag]             3.3.11                                                   -> 3.3.11
     * [new tag]             3.3.12                                                   -> 3.3.12
     * [new tag]             3.3.13                                                   -> 3.3.13
     * [new tag]             3.3.14                                                   -> 3.3.14
     * [new tag]             3.3.15                                                   -> 3.3.15
     * [new tag]             3.3.16                                                   -> 3.3.16
     * [new tag]             3.3.2                                                    -> 3.3.2
     * [new tag]             3.3.3                                                    -> 3.3.3
     * [new tag]             3.3.4                                                    -> 3.3.4
     * [new tag]             3.3.5                                                    -> 3.3.5
     * [new tag]             3.3.6                                                    -> 3.3.6
     * [new tag]             3.3.7                                                    -> 3.3.7
     * [new tag]             3.3.8                                                    -> 3.3.8
     * [new tag]             3.3.9                                                    -> 3.3.9
     * [new tag]             3.4.0                                                    -> 3.4.0
     * [new tag]             3.4.1                                                    -> 3.4.1
     * [new tag]             3.4.10                                                   -> 3.4.10
     * [new tag]             3.4.11                                                   -> 3.4.11
     * [new tag]             3.4.2                                                    -> 3.4.2
     * [new tag]             3.4.3                                                    -> 3.4.3
     * [new tag]             3.4.4                                                    -> 3.4.4
     * [new tag]             3.4.5                                                    -> 3.4.5
     * [new tag]             3.4.6                                                    -> 3.4.6
     * [new tag]             3.4.7                                                    -> 3.4.7
     * [new tag]             3.4.8                                                    -> 3.4.8
     * [new tag]             3.4.9                                                    -> 3.4.9
     * [new tag]             3.5.0                                                    -> 3.5.0
     * [new tag]             3.5.1                                                    -> 3.5.1
     * [new tag]             3.5.10                                                   -> 3.5.10
     * [new tag]             3.5.2                                                    -> 3.5.2
     * [new tag]             3.5.3                                                    -> 3.5.3
     * [new tag]             3.5.4                                                    -> 3.5.4
     * [new tag]             3.5.5                                                    -> 3.5.5
     * [new tag]             3.5.6                                                    -> 3.5.6
     * [new tag]             3.5.7                                                    -> 3.5.7
     * [new tag]             3.5.8                                                    -> 3.5.8
     * [new tag]             3.5.9                                                    -> 3.5.9
     * [new tag]             3.6.0                                                    -> 3.6.0
     * [new tag]             3.6.1                                                    -> 3.6.1
    HEAD is now at 427f6465e Merge pull request #13847 from Homebrew/sponsors-maintainers-man-completions
    ==> Tapping homebrew/core
    remote: Enumerating objects: 1267364, done.
    remote: Counting objects: 100% (80/80), done.
    remote: Compressing objects: 100% (34/34), done.
    remote: Total 1267364 (delta 48), reused 75 (delta 46), pack-reused 1267284
    Receiving objects: 100% (1267364/1267364), 512.21 MiB | 1.68 MiB/s, done.
    Resolving deltas: 100% (873795/873795), done.
    From https://github.com/Homebrew/homebrew-core
     * [new branch]              master     -> origin/master
    HEAD is now at 42183cab7ff darcs: build with `ghc@8.10` (#110470)
    Warning: /opt/homebrew/bin is not in your PATH.
      Instructions on how to configure your shell for Homebrew
      can be found in the 'Next steps' section below.
    ==> Installation successful!
    
    ==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
    Read the analytics documentation (and how to opt-out) here:
      https://docs.brew.sh/Analytics
    No analytics data has been sent yet (nor will any be during this install run).
    
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    
    ==> Next steps:
    - Run these two commands in your terminal to add Homebrew to your PATH:
        echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xyz/.zprofile
        eval "$(/opt/homebrew/bin/brew shellenv)"
    - Run brew help to get started
    - Further documentation:
        https://docs.brew.sh

    安裝完,出現「Warning: /opt/homebrew/bin is not in your PATH.」
    提示目前 Homebrew 指令目錄,沒在使用者環境變數 PATH 中
    需再執行兩行指令,將 Homebrew 指令目錄加入使用者環境變數
    執行前:
    % echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
    執行後
    % echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xyz/.zprofile
    % eval "$(/opt/homebrew/bin/brew shellenv)"
    % echo $PATH                               
    /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
    可發現 /opt/homebrew/bin 加入到 PATH 環境變數中了
    (.zprofile 是 zsh shell 的環境設定檔之一,最初沒有)

    查一下目前 Homebrew 版本
  28. % brew -v
    Homebrew 3.6.1
    Homebrew/homebrew-core (git revision 42183cab7ff; last commit 2022-09-13)
  29. 安裝 smartmontools 套件,查看硬碟健康狀態(SMART)
    使用 Homebrew 安裝 smartmontools
    % brew install smartmontools

    查看第一顆硬碟健康狀態
    % smartctl -a /dev/disk0
    smartctl 7.3 2022-02-28 r5338 [Darwin 21.6.0 arm64] (local build)
    Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF INFORMATION SECTION ===
    ......
    
    === START OF SMART DATA SECTION ===
    SMART overall-health self-assessment test result: PASSED
    
    SMART/Health Information (NVMe Log 0x02)
    Critical Warning:                   0x00
    Temperature:                        34 Celsius
    Available Spare:                    100%
    Available Spare Threshold:          99%
    Percentage Used:                    0%
    Data Units Read:                    617,112 [315 GB]
    Data Units Written:                 490,616 [251 GB]
    Host Read Commands:                 10,125,391
    Host Write Commands:                6,667,937
    Controller Busy Time:               0
    Power Cycles:                       84
    Power On Hours:                     4
    Unsafe Shutdowns:                   7
    Media and Data Integrity Errors:    0
    Error Information Log Entries:      0
    
    Read 1 entries from Error Information Log failed: GetLogPage failed: system=0x38, sub=0x0, code=745
  30. 查看目前所有電源的設置計畫
    % pmset -g custom                                              
    Battery Power:
     Sleep On Power Button 1
     lowpowermode         0
     standby              1
     ttyskeepawake        1
     hibernatemode        3
     powernap             1
     hibernatefile        /var/vm/sleepimage
     displaysleep         2
     sleep                1
     tcpkeepalive         1
     lessbright           1
     disksleep            10
    AC Power:
     Sleep On Power Button 1
     lowpowermode         0
     standby              1
     ttyskeepawake        1
     hibernatemode        3
     powernap             1
     hibernatefile        /var/vm/sleepimage
     displaysleep         10
     womp                 1
     networkoversleep     0
     sleep                1
     tcpkeepalive         1
     disksleep            10
  31. Safari 開發者工具:
    「Safari」->「偏好設定」->「進階」,勾選「在選單列中顯示『開發』選單」


2022年9月17日 星期六

[書籤小工具] Youtube 的 shorts 影片改成正常影片

[方法]
將網址中的「/shorts/」改成「/watch?v=


[書籤小工具]
將以下連結拉到書籤,加入書籤,當成書籤小工具 (bookmarklet),要轉換網址時點擊此書籤即可
Youtube 的 shorts 影片改成正常影片


此書籤小工具的JavaScript程式碼如下:
location.href=location.href.replace('/shorts/','/watch?v=')


2022年9月10日 星期六

Linux SMB 掛載失敗(CIFS VFS: Dialect not supported by server)

環境:
一台NAS提供 SMB 服務
一台Linux(CentOS 7)使用 autofs 掛載 NAS 上的 SMB 資料夾

問題:
掛載 NAS 上的 SMB 資料夾失敗,查看 /var/log/messages,發現錯誤訊息
localhost kernel: No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.
localhost kernel: CIFS VFS: Dialect not supported by server. Consider specifying vers=1.0 or vers=2.0 on mount for accessing older servers
localhost kernel: CIFS VFS: cifs_mount failed w/return code = -95

原因:
掛載時沒指定使用哪個 SMB 版本連線,預設使用更安全的版本 SMB2.1 或之後(SMB3)的版本
但 SMB Server (NAS) 不支援新版本


解決:
  1. 方法一:
    到 NAS 上看 SMB 服務,將 SMB 版本設定成 SMB2.1 或之後(SMB3)的版本後即可。
  2. 方法二:如果 SMB Server,不支援新版本。就只能將連線版本指定成較低的版本。
    例如,原本
    testDir -fstype=cifs,rw,suid,dir_mode=0777,file_mode=0666,username=帳號,password=密碼 ://192.168.0.10/testDir
    指定使用低版本 vers=2.0,則改成
    testDir -fstype=cifs,rw,suid,dir_mode=0777,file_mode=0666,vers=2.0,username=帳號,password=密碼 ://192.168.0.10/testDir



其他:
  • Linux(CentOS 7) 使用 nmap 掃描 SMB Server,查 SMB Server支援的版本
    使用 yum install nmap 安裝的版本若太低,用到的指令(smb-protocols)不支援
    可到 https://nmap.org/ ,用官網提供的 rpm 檔安裝
    # rpm -ivh https://nmap.org/dist/nmap-7.92-1.x86_64.rpm
    # nmap -p139,445 --script smb-protocols 192.168.0.10
    Starting Nmap 7.92 ( https://nmap.org )
    Nmap scan report for 192.168.0.10
    Host is up (0.00062s latency).
    
    PORT    STATE SERVICE
    139/tcp open  netbios-ssn
    445/tcp open  microsoft-ds
    
    Host script results:
    | smb-protocols:
    |   dialects:
    |     NT LM 0.12 (SMBv1) [dangerous, but default]
    |     2.0.2
    |     2.1
    |     3.0
    |     3.0.2
    |_    3.1.1
    
    Nmap done: 1 IP address (1 host up) scanned in 0.77 seconds
  • Windows(Win10) 查詢目前 SMB 連線版本
    使用系統管理員身分執行 Windows PowerShell
    > Get-SmbConnection
    ServerName ShareName UserName     Credential   Dialect NumOpens
    ---------- --------- --------     ----------   ------- --------
    NAS        aaa       PC\user      PC\user      3.1.1   2



參考: