以 root 用戶執行以下命令或者有 root 權限的用戶
sudo apt update -y sudo apt install -y ack antlr3 aria2 asciidoc autoconf automake autopoint binutils bison build-essential \ bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \ git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev \ libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \ mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip libpython3-dev qemu-utils \ rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
以下命令以普通用戶執行,不要用 root
# 下載源碼(-b 指定分支/標籤、 --single-branch 僅下載單個分支/標籤、 --depth=1 只下載最新的一次提交 ) git clone -b v23.05.3 --single-branch --depth=1 https://github.com/openwrt/openwrt.git or git clone -b v23.05.3 --single-branch --depth=1 git://git.openwrt.org/openwrt/openwrt.git # 進入到該目錄 cd openwrt
自行編譯時,會出現內核的魔法值不一樣,需要完成如下修改:
echo '47964456485559d992fe6f536131fc64' > vermagic
修改完成後效果如下:
define Kernel/Configure/Default rm -f $(LINUX_DIR)/localversion $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target # copy CONFIG_KERNEL_* settings over to .config.target awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target $(SCRIPT_DIR)/package-metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set $(call Kernel/SetNoInitramfs) rm -rf $(KERNEL_BUILD_DIR)/modules cmp -s $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev || { \ cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config; \ cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev; \ } $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(KERNEL_MAKE) $(if $(findstring uml,$(BOARD)),ARCH=$(ARCH)) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | $(MKHASH) md5 > $(LINUX_DIR)/.vermagic cp $(TOPDIR)/vermagic $(LINUX_DIR)/.vermagic endef
非必要
1. # 編輯配置文件 2. vim package/base-files/files/bin/config_generate +315 3. # 修改時區為 CST-8 4. set system.@system[-1].timezone='CST-8' 5. # 再在下一行添加如下內容 6. set system.@system[-1].zonename='Asia/Shanghai'
非必要
默認管理IP為 192.168.1.1 ,可以根據自己的需求進行修改
1. # 編輯配置文件 2. vim package/base-files/files/bin/config_generate +165 3. # 修改如下內容 4. lan) ipad=${ipaddr:-"192.168.188.1"} ;;
因編譯須要很久, 萬一ssh斷了不會影響編譯。建議使用 screen
screen為多重視窗管理程序。此處所謂的視窗,是指一個全屏幕的文字模式畫面。通常只有在使用telnet登入主機或是使用老式的終端機時,才有可能用到screen程序。
# install apt-get install -y screen
語法 screen [-AmRvx -ls -wipe][-d <作業名稱>][-h <行數>][-r <作業名稱>][-s <shell>][-S <作業名稱>] 參數說明: -A 將所有的視窗都調整為目前終端機的大小。 -d<作業名稱> 將指定的screen作業離線。 -h<行數> 指定視窗的緩衝區行數。 -m 即使目前已在作業中的screen作業,仍強制建立新的screen作業。 -r<作業名稱> 恢復離線的screen作業。 -R 先試圖恢復離線的作業。若找不到離線的作業,即建立新的screen作業。 -s<shell> 指定建立新視窗時,所要執行的shell。 -S<作業名稱> 指定screen作業的名稱。 -v 顯示版本信息。 -x 恢復之前離線的screen作業。 -ls或--list 顯示目前所有的screen作業。 -wipe 檢查目前所有的screen作業,並刪除已經無法使用的screen作業。
screen -S openwrt -h 100000
# Expamile screen -S {screenName} # Re-attach screen -r {screenShellId_or_screenShellName} # List screen shells screen -ls
cd openwrt // 清除 bin 目錄 make clean // 清除 bin 目錄 + 清除交叉編譯工具及工具鏈目錄 make dirclean // 清除所有相關的東西,包括下載的軟件包,配置文件,feed內容等 make distclean
更新 feeds 包
./scripts/feeds update -a ./scripts/feeds install -a
Defconfig
執行以下命令打開菜單配置
make menuconfig
Target System (x86) ---> (X) x86 guration ---> Subtarget (x86_64) ---> (X) x86_64 Target Profile (Generic x86/64) ---> (X) Generic x86/64
選定好target後再執行defconfig
這會產生標準的設定,包含檢查相依性和建置的環境等。 會檢查相依性,是否有安裝遺漏的並再執行一次。
再重新執行以下命令打開菜單配置
make defconfig
建議選項
Target System (x86) ---> (X) x86 guration ---> Subtarget (x86_64) ---> (X) x86_64 Target Profile (Generic x86/64) ---> (X) Generic x86/64 LuCI --> Collections --> <*> luci Applications--> <*> luci-app-ddns <*> luci-app-firewall Themes-->全選 Base system --> <*> dnsmasq
# 直接編譯 make # 帶輸出debug信息編譯 make V=99 # 帶輸出debug信息並且並行編譯。N為你想使用的cpu核數。如果不帶參數默認是1。 make -j N V=99 # 如果編譯過程中報錯了,需要使用單線程模式,確認出錯的地方,然後排查(註:有時候單線程就不報錯了) make V=s -j1
編譯完成後,鏡像文件地址是: ./bin/targets/x86/64/
ext4 與 squashfs 格式的區別:
https://w2x.me/2019/03/13/openwrt-x86%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/
If you are using a Windows PC, you will need a program to extract the raw disk image from the compressed archive you downloaded.
Then you will need to open the raw image file with a program that can write it on the drive you want to install OpenWrt on.
A good free and opensource archiver program you can use is 7zip.
A good free and opensource raw disk image writer program you can use is Win32 Disk Imager , there is also Etcher .
[7zip]
https://www.7-zip.org/
[Win32 Disk Imager]
https://sourceforge.net/projects/win32diskimager/
[Etcher]
https://www.balena.io/etcher/
Same as with Windows.
The archiver program recommended by 7zip on MacOS is Keka
A good free and opensource raw disk image writer program you can use is Etcher .
[Keka]
https://www.keka.io/en/
[Etcher]
https://www.balena.io/etcher/
gunzip openwrt-x86-generic-combined-ext4.img.gz qemu-img convert -f raw -O vmdk openwrt-x86-generic-combined-ext4.img openwrt-x86-generic-combined-ext4.vmdk
qemu:
yum -y install qemu-img