目录

openwrt-x86安装步骤

推荐使用X86-64 带EFI的版本,减少很多麻烦,推荐使用combined-ext4版本,减少很多麻烦,例如:openwrt-24.10.4-x86-64-generic-ext4-combined-efi.img

不太推荐ventory加载,会有一些麻烦,比如修改启动后,busybox报告找不到的问题,很多命令失效。

直接使用rufus把img写入到一个空的u盘,然后用u盘开始安装

用u盘引导启动openwrt

自己查询当前电脑的BIOS的进入方法,改成u盘启动,在GRUB界面,如果后面卡住了黑屏,那么在进入GRUB的3秒选择节点,按【E】按键,进入grub编辑菜单,删掉:

console=ttyS0,115200n8 这段配置,然后按 【F10】保存,继续启动引导。 只需要一次即可,后面u盘引导都不需要再改了。

如果还是黑屏,狂按 回车,可能会正常显示 命令行。

安装openwrt到磁盘上

拔下当前的u盘,在u盘上的空闲容量里,新建一个fat32分区,1G即可。如果不会创建,就再找一个新u盘,格式化为fat32分区,然后把 openwrt-24.10.4-x86-64-generic-ext4-combined-efi.img 复制进去。

再次用u盘引导进入openwrt,找到img文件,一般在需要 ls -al /dev | grep sd 列出sda1 ,sdb1,之类的分区。

使用 mkdir sda1;mount /dev/sda1 sda1 这种命令,挂载分区,此时可以在sda1文件夹 看到 img镜像。

开始dd写入本地磁盘,这里内置的磁盘是:/dev/mmcblk1

dd if=openwrt-24.10.4-x86-64-generic-ext4-combined-efi.img of=/dev/mmcblk1
sync
reboot -f

使用内置磁盘引导openwrt

拔掉所有u盘,重启设备,此时不需要任何u盘引导,可以直接启动openwrt;如果之前是黑屏的,现在还是黑屏的,还需要再次处理一下GRUB配置,按【E】修改grub配置,去掉 console=ttyS0,115200n8 , 按【F10】保存,本地磁盘也只需要改一次。

如果重启还是会黑屏,则需要在 openwrt的shell里改, vi /boot/grub/grub.cfg 里直接修改。

然后重启,后面就自动进入shell模式了。

配置网络

我这里使用旁路由模式,直接修改 wan为dhcp

uci delete network.lan
uci delete network.wan
uci set network.wan=interface
uci set network.wan.proto='dhcp'
uci set network.wan.ifname='eth0'
uci commit network
/etc/init.d/network restart

先开放80防火墙,可以网页访问,就能脱离黑白屏幕

uci add firewall rule
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].dest_port='80'
uci set firewall.@rule[-1].target='ACCEPT'
uci commit firewall
/etc/init.d/firewall reload

磁盘处理

默认情况下,openwrt只会只用100M,我们需要让他使用整个硬盘。

vim expand.sh 修改脚本,输入

# Configure startup scripts
cat << "EOF" > /etc/uci-defaults/70-rootpt-resize
if [ ! -e /etc/rootpt-resize ] && type parted > /dev/null && lock -n /var/lock/root-resize
then
	ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e '$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
	ROOT_DISK="/dev/$(basename "${ROOT_BLK%/*}")"
	ROOT_PART="${ROOT_BLK##*[^0-9]}"
	parted -f -s "${ROOT_DISK}" resizepart "${ROOT_PART}" 100%
	mount_root done
	touch /etc/rootpt-resize

	if [ -e /boot/cmdline.txt ]
	then 
		NEW_UUID=`blkid ${ROOT_DISK}p${ROOT_PART} | sed -n 's/.*PARTUUID="\([^"]*\)".*/\1/p'`
		sed -i "s/PARTUUID=[^ ]*/PARTUUID=${NEW_UUID}/" /boot/cmdline.txt
	fi

	reboot
fi
exit 1
EOF
cat << "EOF" > /etc/uci-defaults/80-rootfs-resize
if [ ! -e /etc/rootfs-resize ] \
&& [ -e /etc/rootpt-resize ] \
&& type losetup > /dev/null \
&& type resize2fs > /dev/null \
&& lock -n /var/lock/root-resize
then
ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \
'$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
ROOT_DEV="/dev/${ROOT_BLK##*/}"
LOOP_DEV="$(awk -e '$5=="/overlay"{print $9}' \
/proc/self/mountinfo)"
if [ -z "${LOOP_DEV}" ]
then
LOOP_DEV="$(losetup -f)"
losetup "${LOOP_DEV}" "${ROOT_DEV}"
fi
resize2fs -f "${LOOP_DEV}"
mount_root done
touch /etc/rootfs-resize
reboot
fi
exit 1
EOF
cat << "EOF" >> /etc/sysupgrade.conf
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize
EOF

然后 chmod +x expand.sh;./expand.sh 执行,此时会自动重启,重启2次后,就会自动使用这个磁盘

后续步骤

后续所有步骤,都可以在线处理了,使用 清华源解决卡顿问题

找到openwrt的 系统-》软件包 -》 配置okpg, 找到 /etc/opkg/distfeeds.conf 的配置, 替换

https://downloads.openwrt.org  为 https://mirrors.tuna.tsinghua.edu.cn/openwrt