Image Builderでカスタムimage作成

Image Builder とは

OpenWrt Project が公式配布しているパッケージングツールです。
各機種用install imageファイルに、任意のopkgファイルを最初から含めたり、削除できます。

不要pkgを最初から除外することはもちろんですが、pkgを初期インストールすることで
後からopkgコマンドでインストールするよりもflashメモリ使用量を削減することができます。
(日本国内においては無線機能を除外したimageを生成するのは意味があります)

SDKと異なり、コンパイル済みのpkgファイルを組み合わせてimageを作成するため
低スペックのPC環境で問題ありません。VirtualBOX/VMware等の仮想マシンでも十分です。

作業用Linux準備

ubuntu,debian,CentOSなどのLinuxを準備します。アーキテクチャは x86_64が必須です。

buildに必要なパッケージをインストールします。

CentOS7の場合には以下が必要でした。
yum install git gawk gettext ncurses-devel zlib-devel openssl-devel libxslt wget
yum -y groupinstall base "Development tools" --setopt=group_package_types=mandatory,default,optional
ubuntu 18.04.2の場合は以下が必要でした。
apt-get install build-essential libncurses5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python curl

Image Builder の取得と展開

Image Builder は target 毎に分けられています。
インストールimageが置かれた階層の一番下の部分にimagebuilderのリンクが表示されているので、これをダウンロードして展開します。

「18.06.4」「ramips」用のimagebuilder をdownloadしつつカレントディレクトリに展開する場合は以下になります。
curl https://downloads.openwrt.org/releases/18.06.4/targets/ramips/mt7621/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64.tar.xz | tar Jxv

Image Builderの基本操作

1)含まれているtargetを表示します。ここで表示される機種名がPROFILE名となります。
make info
+ 出力例
current Target: "ramips (MT7621 based boards)"
Default Packages: base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools uclient-fetch logd kmod-leds-gpio kmod-gpio-button-hotplug
swconfig dnsmasq iptables ip6tables ppp ppp-mod-pppoe firewall odhcpd-ipv6only odhcp6c kmod-ipt-offload
Available Profiles:

Default:
   Default Profile
   Packages: kmod-usb-core kmod-usb3 kmod-usb-ledtrig-usbport
ew1200:
   AFOUNDRY EW1200
   Packages: kmod-ata-core kmod-ata-ahci kmod-mt76x2 kmod-mt7603 kmod-usb3 kmod-usb-ledtrig-usbport wpad-mini iwinfo
wsr-1166:
   Buffalo WSR-1166
   Packages: kmod-mt7603 kmod-mt76x2 wpad-mini iwinfo
wsr-600:
   Buffalo WSR-600
   Packages: kmod-mt7603 kmod-rt2800-pci wpad-mini iwinfo
(以下略)
→ WSR-1166DHPの場合は wsr-1166、WSR-600DHPの場合は wsr-600 が PROFILE名となる。

2)テンポラリ生成ファイルの削除 生成後のimageや中間ファイルなどを削除して綺麗な状態にします。
make clean

3)imageを生成
make image
引数を付けない場合は全機種のimageを生成します。
make image PROFILE="wsr-600"
make infoで表示されたPROFILEを指定するとその機種だけのimageを生成します。

なお、Image Builderのデフォルトでは Web-GUIのluciとuhttpdは含まれないので注意してください。

カスタムimage作成

make imageのPACKAGESパラメータでpkgファイルの増減ができます。
make image PACKAGES="pkg1 -pkg2"
とした場合、pkg1を追加して pkg2を除外します。

インストールしてもbrickするimageを生成してしまう可能性があります。
pkgの追加除外はその意味と容量を考慮して慎重に吟味してください。


WSR-600DHP用にWeb-GUIを含めて、USBや無線ドライバを除外したimageを作成する例
make image PROFILE="wsr-600" PACKAGES="kmod-mt7603 -kmod-rt2800-pci -wpad-mini -iwinfo -kmod-usb-core \
-kmod-usb-ledtrig-usbport -kmod-usb3 -kmod-cfg80211 -hostapd-common -kmod-mac80211 -kmod-mt7603 -wireless-regdb uhttpd luci"
+ 正常生成時の出力例
Building images for ramips - Buffalo WSR-600
Packages: uhttpd luci base-files busybox dnsmasq dropbear firewall fstools ip6tables iptables kernel kmod-gpio-button-hotplug kmod-ipt-offload kmod-leds-gpio libc libgcc logd mtd netifd odhcp6c odhcpd-ipv6only opkg ppp ppp-mod-pppoe swconfig uci uclient-fetch

Downloading http://downloads.openwrt.org/releases/18.06.4/targets/ramips/mt7621/packages/Packages.gz
Updated list of available packages in /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/build_dir/target-mipsel_24kc_musl/root-ramips/../../../../../mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/openwrt_core
Downloading http://downloads.openwrt.org/releases/18.06.4/packages/mipsel_24kc/base/Packages.gz
Updated list of available packages in /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/build_dir/target-mipsel_24kc_musl/root-ramips/../../../../../mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/openwrt_base
Downloading http://downloads.openwrt.org/releases/18.06.4/packages/mipsel_24kc/luci/Packages.gz
Updated list of available packages in /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/build_dir/target-mipsel_24kc_musl/root-
(中略)
Installing packages...
Installing libc (1.1.19-1) to root...
Installing libgcc (7.3.0-1) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/libgcc_7.3.0-1_mipsel_24kc.ipk.
Configuring libgcc.
Configuring libc.
Installing kernel (4.14.131-1-94e97c3b21ec52cb72cec4eaff828985) to root...
Configuring kernel.
Installing uhttpd (2018-11-28-cdfc902a-3) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/uhttpd_2018-11-28-cdfc902a-3_mipsel_24kc.ipk.
Installing libubox (2018-07-25-c83a84af-2) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/libubox_2018-07-25-c83a84af-2_mipsel_24kc.ipk.
Installing libjson-c (0.12.1-2) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/libjson-c_0.12.1-2_mipsel_24kc.ipk.
Installing libblobmsg-json (2018-07-25-c83a84af-2) to root...
(中略)
Installing kmod-pppox (4.14.131-1) to root...
Downloading file:packages/kmod-pppox_4.14.131-1_mipsel_24kc.ipk
Installing kmod-pppoe (4.14.131-1) to root...
Downloading file:packages/kmod-pppoe_4.14.131-1_mipsel_24kc.ipk
Installing swconfig (11) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/swconfig_11_mipsel_24kc.ipk.
Installing uci (2019-05-17-f199b961-1) to root...
Copying /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/dl/uci_2019-05-17-f199b961-1_mipsel_24kc.ipk.
Package uclient-fetch (2018-11-24-3ba74ebc-1) installed in root is up to date.
Configuring libubox.
Configuring libuclient.
Configuring uclient-fetch.
Configuring libpthread.
Configuring opkg.
(省略)
Configuring luci.
Configuring kmod-ipt-offload.
Configuring ppp-mod-pppoe.

Finalizing root filesystem...

Building images...
Unable to open feeds configuration at /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/scripts/feeds line 48.
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on /mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/root.squashfs, block size 262144.
Pseudo file "/dev" exists in source filesystem "/mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64/build_dir/target-mipsel_24kc_musl/root-ramips/dev".
Ignoring, exclude it (-e/-ef) to override.
[================================================================================================================================/] 815/815 100%
Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
       compressed data, compressed metadata, compressed fragments, no xattrs
       duplicates are removed
Filesystem size 1650.79 Kbytes (1.61 Mbytes)
       33.53% of uncompressed filesystem size (4923.54 Kbytes)
Inode table size 7698 bytes (7.52 Kbytes)
       21.17% of uncompressed inode table size (36364 bytes)
Directory table size 10834 bytes (10.58 Kbytes)
       47.92% of uncompressed directory table size (22608 bytes)
Number of duplicate files found 90
Number of inodes 1105
Number of files 817
Number of fragments 17
Number of symbolic links 182
Number of device nodes 1
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 105
Number of ids (unique uids + gids) 1
Number of uids 1
       unknown (0)
Number of gids 1
       unknown (0)
3590+1 records in
3590+1 records out
1838508 bytes (1.8 MB, 1.8 MiB) copied, 0.0155138 s, 119 MB/s
3301+1 records in
3301+1 records out
1690410 bytes (1.7 MB, 1.6 MiB) copied, 0.0124893 s, 135 MB/s
padding image to 0035e000
padding image to 00360000
padding image to 00380000
Calculating checksums...
root@ad85ca661bbd:/mnt/openwrt-imagebuilder-18.06.4-ramips-mt7621.Linux-x86_64#

生成されたimageは bin/targets/以下にあります。
+
find bin/
bin/
bin/targets
bin/targets/ramips
bin/targets/ramips/mt7621
bin/targets/ramips/mt7621/openwrt-18.06.4-ramips-mt7621-wsr-600-squashfs-sysupgrade.bin
bin/targets/ramips/mt7621/openwrt-18.06.4-ramips-mt7621-device-wsr-600.manifest
bin/targets/ramips/mt7621/sha256sums
manifest ファイルには依存関係を含めてインストールされたpkg名が記載されています。

上記のWSR-600DHPの例では生成されたファイルは 公式と比較して およそ767KB削減されました。
ls -al openwrt-18.06.4-ramips-mt7621-wsr-600-squashfs-sysupgrade.bin
-rw-r--r--. 1 root root 3670188  7月 15 01:22 openwrt-18.06.4-ramips-mt7621-wsr-600-squashfs-sysupgrade.bin

  • 参考リンク
(公式サイト)Using the Image Builder
(外部サイト)OpenWrt Image Builder に挑戦 (webarchive)
+ タグ編集
  • タグ:
  • openwrt
  • imagebuilder
  • WSR-600DHP

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2019年07月15日 20:50