「捯饬记录」使用image builder为K2简单打包一个openwrt固件

记录时间:2020 年 2 月 1 日

关键词:OpenWrt imagebuilder K2 package 固件打包

K2在openwrt官方支持的固件列表里为psg1218a,如果没有做任何硬改,直接使用官方的固件也很不错。另外相比从源码开始编译,使用imagebuilder来做简单的固件定制更方便快捷体积小(其实就是提前把软件包集成在固件中)。

此记录全程以K2路由器为例,其他路由器需要找到相对应的下载地址,请灵活变通。另外要注意涉及的下载、镜像地址和脚本可能在未来过时或失效。

使用imagebuilder打包

  1. 下载image builder

在清华镜像站下载image builder https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/

K2的19.07.1版本在https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/19.07.1/targets/ramips/mt7620/

文件名为openwrt-imagebuilder-19.07.1-ramips-mt7620.Linux-x86_64.tar.xz

直接使用文件管理器,解压这个压缩包到主目录,打开解压出的这个文件夹。

图片

  1. 在当前目录下右键打开终端,执行以下指令更换一下清华源
    1
    sed -i 's#downloads.openwrt.org#mirrors.tuna.tsinghua.edu.cn/openwrt#' repositories.conf
  2. 安装必要的软件
    1
    sudo apt-get install build-essential libncurses5-dev libncursesw5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python
  3. 执行并找到目标配置的名称,k2为psg1218a,其实就是官方固件文件名中的设备名称
    1
    make info
  4. 开始打包,可以在PACKAGES后自行添加需要的软件包
    1
    make image PROFILE="psg1218a" PACKAGES="luci luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn"
    速度比较快,完成后,固件就在当前目录中的bin文件夹内
    如果不满意,需要再次打包时,先执行一下make clean,再进行make image。

另外还可以添加一些除官方源外的其他源或者下载好位于本地的package,具体可以参考官方的说明

利用GitHub Actions自动打包

方便快捷,就是下载回来有点难。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
name: OpenWrt image builder
on: 
  push:
    branches: 
      - master
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: 初始化
      env:
        DEBIAN_FRONTEND: noninteractive
        #可修改imagebuilder下载地址
        DOWNLOAD_URL: https://downloads.openwrt.org/releases/19.07.1/targets/ramips/mt7620/openwrt-imagebuilder-19.07.1-ramips-mt7620.Linux-x86_64.tar.xz
        
      run: |
        sudo apt-get install build-essential libncurses5-dev libncursesw5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python
        wget -O /tmp/imagebuilder.tar.xz $DOWNLOAD_URL
        sudo xz -d /tmp/imagebuilder.tar.xz
        sudo tar -C /tmp -xvf /tmp/imagebuilder.tar
    - name: 打包固件
      run: |
        #在PROFILE中填写配置的设备名 在PACKAGES中添加需要的软件包
        cd /tmp/$(ls /tmp | grep 'openwrt-imagebuilder')
        sudo make image PROFILE="psg1218a" PACKAGES="luci luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn ssmtp wireguard luci-app-wireguard luci-i18n-wireguard-zh-cn"
        cp -r bin /tmp
    - name : 上传固件
      uses: actions/upload-artifact@master
      with:
        name: image
        path: /tmp/bin

参考

OpenWrt.org-Using the Image Builder: https://openwrt.org/docs/guide-user/additional-software/imagebuilder

imagebuilder快速编译OpenWrt固件使用教程+高级自定义+在线编译: https://www.right.com.cn/forum/thread-522029-1-1.html

Openwrt 国内源配置 · DarkGod’ Blog:https://www.dazhuanlan.com/2019/10/17/5da7cdea1f0c8/