Unifi Udr Loss Apps After Reformat Sd Card

versions

  • UniFi OS UDR 2.5.11
  • UniFi Network 7.2.94
  • UniFi Protect 2.2.2

context

由於 UDR 必須要安裝 SD 卡才能讓監視器隨時都錄影,買了張增你強的股票代理的 SanDisk Extreme microSDXC card 256 GB,求的是代理商提供的終身保固。

好不容易把 UDR 隨附的 SD 卡槽卸除工具從儲物間中翻出來,很輕鬆的卸除卡槽,但安裝 SD 卡時又遇到問題,卡片沒辦法整個平貼進卡槽,我也不敢太大力硬塞 SD 卡,擔心一個粗魯就讓終身保固掰了;最後是找到一個角度可以讓 SD 卡卡進卡槽 (會有ㄎㄚ一聲,請放心不是我的卡片斷掉),成功將 SD 卡安裝進 UDR。

安裝後 reboot 了 UDR (安裝文件沒特別說要 reboot),之後想說來 format 一下 SD 卡好了,沒想到就帶來一連串的問題…Orz

situation

reboot 後,我是透過 iOS 的 Unifi Network app 來操作 console,進入方式為 Settings -> Console,接著會開啟內嵌瀏覽器,瀏覽器會打開 Console Management 的頁面。

打開 Console Management 左邊的漢堡,進入 Storage 頁面後就可以看到 Reformat SD Card,按下去後會有確認視窗,確定要刪除後,視窗還會到數 10 秒讓你有機會反悔。

format 後,Network app 開始有異常的 reload 且無法正常操作,開啟 Protect app 也無法正常使用,找不到 Console,重新 scan 也無法正常找到 UDR。

接著透過電腦連線至區網內的 Unifi Console,在 Updates 頁面發現 Network 跟 Protect 一直是 Stopped 的狀態,點了 Start 的按鈕也無效,app 無法正常啟動;嘗試透過網址訪問 Network app 也失敗。

後來逛到 Storage 頁面,才發現 Reformat SD Card 左邊的 Reformat Storage 有個提示,游標 hover 上去會跳出對話框,內容是 “Reformatting will delete all data stored on this console’s hard disk drive(s).",這時才驚覺,Reformat SD Card 該不會是連同 UDR 內建 SSD 的資料一起砍了吧…

坑人的提示

solution

假設上面的推論是對的,那麼要修復的方向就是:

  1. Unifi Console 格式化硬碟後,Network 不能正常啟動,淦!
  2. Unifi Console 格式化硬碟後,Protect 不能正常啟動,淦!

Unifi Console 格式化硬碟後,Network 不能正常啟動,淦!

餵狗的關鍵字:unifi Network stopped

找到這則問題 UniFi “Network” application keeps starting & stopping - can’t access network controls

解法之一是開啟 Console 的 SSH 並連進去修復,就先試看看這招。

支線:透過 SSH 進入 UDR

回到 Console Management,在 System 頁面的 Console Controls 區塊中,啟用 SSH 並設定密碼,請寄好這組密碼,等下會用到。

在終端機透過 SSH client [1] 連線至 UDR,指令是 ssh root@${Unifi Console 的 IP},假如你的 Unifi Console 的 IP 是 192.168.168.1,那就輸入 ssh [email protected]

如果有正常連線的話,終端機會提示你輸入密碼,請輸入先前在 Console Controls 啟用 SSH 時所設定的密碼,密碼正確的話應該會出現下面的訊息:

Linux Dream-Router 4.4.198-ui-mtk #1 SMP PREEMPT Mon Aug 1 14:25:10 CST 2022 aarch64

Firmware version: v2.5.11

  ___ ___      .__________.__
 |   |   |____ |__\_  ____/__|
 |   |   /    \|  ||  __) |  |   (c) 2010-2022
 |   |  |   |  \  ||  \   |  |   Ubiquiti Inc.
 |______|___|  /__||__/   |__|
            |_/                  https://www.ui.com

      Welcome to UniFi Dream Router!

********************************* NOTICE **********************************
* By logging in to, accessing, or using any Ubiquiti product, you are     *
* signifying that you have read our Terms of Service (ToS) and End User   *
* License Agreement (EULA), understand their terms, and agree to be       *
* fully bound to them. The use of CLI (Command Line Interface) can        *
* potentially harm Ubiquiti devices and result in lost access to them and *
* their data. By proceeding, you acknowledge that the use of CLI to       *
* modify device(s) outside of their normal operational scope, or in any   *
* manner inconsistent with the ToS or EULA, will permanently and          *
* irrevocably void any applicable warranty.                               *
***************************************************************************

基本上就是問你 blah blah blah 你同不同意,當然是同意啦哪次不同意。

好了我們終於進去一點點了,接下來可以開始修復 Network app 無法正常啟動的狀況。

修復 Network app 無法正常啟動的狀況

根據文章的教學,下指令 apt-get upgrade,跑完後會出現下面的訊息:

root@Dream-Router:~#  apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

回到 Console Management,在 Updates 頁面查看 Network app 的狀況,就發現他好了!狀態是 Up to Date,嘗試打開 Network app,在電腦跟手機上都可以正常使用,太感動了…

Unifi Console 格式化硬碟後,Protect 不能正常啟動,淦!

修好了 Network 後,想說 Protect 是不是也順便修好了,但天不從人願QQ

於是繼續餵狗,關鍵字:unifi protect stopped working

找到這則問題 UniFi Protect stopped working after uninitiated update

一樣透過 SSH client 連進去 UDR,開始玩耍。

首先官方請提問者到 /srv/ 這個目錄撈 log 給他們,我也好奇的跑進去翻了一下XD

unifi 這個目錄下的 log 應該是 Network app 的,裡面可以看到 AP 的 logs。

至於 Protect app 的 log 則是在 /srv/unifi-protect/logs 這個目錄底下,裡面的 log 蠻值得挖出來看的,本質上跟 IoT 架構很類似,可以從 log 裡看出這些主從關係;另外有趣的是,我在 api.log 發現 /api/events 這隻 api 的 payload 直接塞了一串 SQL query…XD

api payload 有 SQL query

扯遠了,繼續修。

接著官方建議提問者下這段指令 apt-get update; apt-get install unifi-protect -y ,我執行後的訊息如下:

root@Dream-Router:~# apt-get update; apt-get install unifi-protect -y
Ign:1 http://deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org stretch/updates InRelease [59.1 kB]
Hit:3 http://deb.debian.org/debian stretch-updates InRelease
Hit:4 http://deb.debian.org/debian stretch-backports InRelease
Hit:5 http://deb.debian.org/debian stretch Release
Hit:6 https://apt.artifacts.ui.com stretch InRelease
Fetched 59.1 kB in 2s (25.8 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
unifi-protect is already the newest version (2.2.2).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

接著一樣回到 Console Management,在 Updates 頁面查看 Protect app 的狀況,發現他也好了~~

從電腦、手機上分別確認 Protect app 的狀況,也都如預期般正常運行,夭壽讚!

Summary

沒事不要亂 format,Unifi Console 的 UI 扣 20 分,根本就誤導使用者。

SSH 用完後記得關掉,沒要用就把門關好,不要開比較好。

Refs

[1]: 我的 OS 是 Windows 10,使用的終端機是 powershell 4.0@Windows Terminal,安裝的 SSH client 是 OpenSSH client。

comments powered by Disqus