在 OpenWRT 上布建 Container (LXC)

在 OpenWRT 上布建 Container 的運算環境

Container 是一種虛擬運算的技術,和 Virtual Machine (虛擬機) 的技術不同,Container 只進行部分的虛擬化 (例如: 使用者權限、硬碟空間、記憶體區間,等),並且,所有的 Container 都使用相同的作業系統核心,以減少虛擬化的負擔。Container 技術中,最廣為人知的應該是 docker 的技術,我們可以以下圖來說明 Container 和 VM 的差別:

圖中,我們可以看到,所有的 Container 都共用相同的作業系統,而 docker 則用以見控並排程系統資源予上層的 Container (App) 來使用,同理,一個 Container 就像是作業系統上的一支程式般,可以輕量的在 Linux 系統上執行。考慮到 Container 輕量的特性,因此,也可以在 OpenWRT 這種嵌入式的 Linux 系統上使用,而在 OpenWRT 上已有實作的 Container 套件稱為 LXC (LinuX Container)。

首先,我們先透過 opkg 安裝 lxc-checkconfig,此套件能夠檢查此裝置是否可以支援 lxc 的相關功能, opkg 將自動抓取相依的套件,包含: lxc、lxc-common。

# opkg install  lxc-checkconfig
Installing lxc-checkconfig (2.1.1-1) to root...
Downloading http://download.gl-inet.com/releases/packages-3.x/ar71xx/packages/lxc-checkconfig_2.1.1-1_mips_24kc.ipk
Installing lxc (2.1.1-1) to root...
Downloading http://download.gl-inet.com/releases/packages-3.x/ar71xx/packages/lxc_2.1.1-1_mips_24kc.ipk
Installing lxc-common (2.1.1-1) to root...
Downloading http://download.gl-inet.com/releases/packages-3.x/ar71xx/packages/lxc-common_2.1.1-1_mips_24kc.ipk
Configuring lxc.
Configuring lxc-common.
Configuring lxc-checkconfig.

之後透過指令進行檢查:

# lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
lxc-checkconfig: unable to retrieve kernel configuration

Try recompiling with IKCONFIG_PROC, installing the kernel headers,
or specifying the kernel configuration path with:
  CONFIG=<path> lxc-checkconfig

結果顯示此 OpenWRT 在編譯時,並沒有將 IKCONFIG_PROC 的功能開啟,因此,不支援 LXC 的功能。要解決此問題的方法必須重新編譯 OpenWRT 的 kernel,這部分的設定可以參考第二篇參考資料。考慮到這可能要重刷目前所使用的系統,因此先擱置,以後若有機會會更新這一部分的進度。

順便補充說明一下,目前已經有人實作出 LXC 在 OpenWRT 上的執行環境,並成立一個專屬的開發平台稱為: Turris Omnia,此實驗平台也是建立在 OpenWRT 之上,並提供和 LuCi (OpenWRT 的網頁介面) 整合的 LXC 運算服務,若有興趣在 WiFi AP 上玩 LXC 的功能,可以參考。

參考資料:

Last updated