Evilmass

Openwrt 固件编译进阶

书接上上文,如果你喜欢折腾并且想定制一个自用的固件

Update-2018-03-01

强烈推荐以下这个

openwrt-ssr

openwrt-ssr-1


Requirement

Openwrt Build Root

单纯编译软件包的话可以使用 Openwrt SDK
opkg install package.ipk --force-overwrite --force-depends
可以解决内核不一致导致的安装问题,不过不太稳定

Shadowsocks-libev 依赖相关

sudo apt-get remove libsodium-dev libmbedtls-dev -y

Installation of Libsodium

export LIBSODIUM_VER=1.0.13
wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
tar xvf libsodium-$LIBSODIUM_VER.tar.gz
pushd libsodium-$LIBSODIUM_VER
./configure --prefix=/usr && make
sudo make install
popd
sudo ldconfig

Installation of MbedTLS

export MBEDTLS_VER=2.6.0
wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
pushd mbedtls-$MBEDTLS_VER
make SHARED=1 CFLAGS=-fPIC
sudo make DESTDIR=/usr install
popd
sudo ldconfig


Begin

以编译 Shadowsocks-libev、ChinaDns、dns-forwarder 进固件为例

cd chaos_calmer

OpenWrt-dist LuCI

git clone https://github.com/aa65535/openwrt-dist-luci.git package/openwrt-dist-luci
Name Depends Description
luci-app-chinadns openwrt-chinadns LuCISupport for ChinaDNS
luci-app-dns-forwarder openwrt-dns-forwarder LuCI Support for Dns-Forwarder
luci-app-resocks2 openwrt-redsocks2 LuCI Support for RedSocks2
luci-app-shadowvpn openwrt-shadowvpn LuCI Support for ShadowVPN

Shadowsocks-libev

# 添加 feeds
git clone https://github.com/shadowsocks/openwrt-feeds.git package/feeds
# 获取 shadowsocks-libev Makefile
git clone https://github.com/shadowsocks/openwrt-shadowsocks.git package/shadowsocks-libev

ChinaDns

git clone https://github.com/aa65535/openwrt-chinadns.git package/chinadns

dns-forwarder

git clone https://github.com/aa65535/openwrt-dns-forwarder.git package/dns-forwarder

luci-app-Shadowsocks

git clone https://github.com/shadowsocks/luci-app-shadowsocks.git package/luci-app-shadowsocks
# 编译 po2lmo (如果有po2lmo可跳过)
pushd package/luci-app-shadowsocks/tools/po2lmo
make && sudo make install
popd

选择要编译的包

M 代表分别编译固件和软件包
Y 代表编译进固件

Network -> chinadns
Network -> dns-forwarder
Network -> shadowsocks-libev
LuCI -> Applications -> luci-app-chinadns
LuCI -> Applications -> luci-app-dns-forwarder
LuCI -> Applications -> luci-app-shadowsocks

select-package

坑坑坑

mbedtls error

whether mbedtls supports Cipher Feedback mode or not… configure: error: MBEDTLS_CIPHER_MODE_CFB required

mbedtls-error

解决方法

wget https://raw.githubusercontent.com/openwrt/openwrt/master/package/libs/mbedtls/patches/200-config.patch -O package/libs/mbedtls/patches/200-config.patch
wget https://raw.githubusercontent.com/openwrt/openwrt/master/package/libs/mbedtls/Makefile -O package/libs/mbedtls/Makefile


libsodium error

configure: error: Wrong libsodium: version >= 1.0.4 required

libsodium-error

解决方法:sudo vim feeds/packages/libs/libsodium/Makefile

PKG_VERSION:=1.0.10
PKG_SOURCE_URL:=https://download.libsodium.org/libsodium/releases
PKG_MD5SUM:=ea89dcbbda0b2b6ff6a1c476231870dd


ccache error

C compiler cannot create executables

sudo apt-get install ccache -y


Download failed

科学上网

解决完问题之后 make menuconfig 保存一下,然后就可以开始把上述软件包编译进固件了

make V=s

build-success

MORE OPTIONS

修改无线配置

sudo vim package/kernel/mac80211/files/lib/wifi/mac80211.sh

$ht_capab
    # REMOVE THIS LINE TO ENABLE WIFI:
    # option disabled 1

config wifi-iface
    option device   radio$devidx
    option network  lan
    option mode     ap
    option ssid     OpenWrt
    # option encryption none
    option encryption       wpa2
    option key      test12345


root密码root

sudo vim package/base-files/files/etc/shadow

root:$1$1sASRYSc$T3z8ItGGk7LSyxpbT1fbI.:16718:0:99999:7:::


修改LUCI界面配置

sudo vim feeds/luci/modules/luci-base/root/etc/config/luci

config core 'main'
  option lang 'auto'
  option mediaurlbase '/luci-static/bootstrap'
  option resourcebase '/luci-static/resources'

config extern 'flash_keep'
  option uci '/etc/config/'
  option dropbear '/etc/dropbear/'
  option openvpn '/etc/openvpn/'
  option passwd '/etc/passwd'
  option opkg '/etc/opkg.conf'
  option firewall '/etc/firewall.user'
  option uploads '/lib/uci/upload/'

config internal 'languages'
  option en 'English'
  option zh_cn '中文 (Chinese)'

config internal 'sauth'
  option sessionpath '/tmp/luci-sessions'
  option sessiontime '3600'

config internal 'ccache'
  option enable '1'

config internal 'themes'
  option Bootstrap '/luci-static/bootstrap'

config internal 'diag'
  option dns 'openwrt.org'
  option ping 'openwrt.org'
  option route 'openwrt.org'**


系统设置

config system
        option ttylogin 0
        #设置主机名
        option hostname 'Openwrt'
        #设置时区
        option zonename 'Asia/Shanghai'
        option timezone 'CST-8'

config timeserver ntp
        list server     0.openwrt.pool.ntp.org
        list server     1.openwrt.pool.ntp.org
        list server     2.openwrt.pool.ntp.org
        list server     3.openwrt.pool.ntp.org
        option enabled 1
        option enable_server 0


修改路由连接数

sudo vim package/base-files/files/etc/sysctl.conf

net.netfilter.nf_conntrack_max=65535


额外软件包

Base system –> block-mount # 挂载设备需要

取消 dnsmasq,选择 dnsmasq-full

Kernel modules –> Block Devices –> kmod-scsi-core # 内核对 SCSI 设备的支持

Filesystems –> kmod-fs-ext4 # 额外可选 ntfs,exfat等

LED modules –> kmod-ledtrig-usbdev # USB 设备闪灯

Native Language Support –> kmod-nls-utf8 # utf8 编码格式的支持

USB Support –> kmod-usb-core kmod-usb-storage kmod-usb-storage-extras kmod-usb-uhci kmod-usb2

Libraries –> SSL –> libopenssl

LuCI –> Applications –> luci-adblock luci-app-aria2 luci-ddns luci-app-mwan3 luci-app-samba

Download Manager –> webui-aria2 yaaw

Fire Transfer –> curl wget

Utilities –> compression –> bzip2 unrar unzip zip # 压缩解压缩工具

Editors –> vim

Filesystem –> e2fsprogs # 支持ext2、ext3、ext4 等分区工具(可选ntfs-3g ntfs-3g-utils)

disc –> blkid fdisk lsblk

zoneinfo –> zoninfo-asia

dmesg # 可使用 dmesg 命令

file # 可使用 file 命令

mount-utils # 挂载助手

执行scripts/diffconfig.sh > diffconfig 保存修改内容至diffconfig文件。

刷入固件之后就可以看到我们编译好的软件了
flash-in

KCPTUN

什么?还有 KCPTUN ?路由器性能不够,树莓派也别想了,PC 运行 KCPTUN Client 然后在路由设置好 PC KCPTUN 端口运行之




这个打赏二维码好像有什么不对

支付宝
支付宝
微信
微信