OpenWrt指南

PVE环境下OpenWrt扩容

按照官方指南在 PVE 下安装 OpenWrt,磁盘容量为镜像的容量,也就 100+M,实际可用几十 M,为了安装更多软件,需要对此进行扩容

安装 OpenWrt 步骤参考:略

具体方法:

  1. 在 PVE 管理界面,找到 OpenWrt 虚拟机,点击左侧菜单“Hardware”,然后找到系统镜像的“Hard Disk”,点击选中,再点击菜单“Disk Action”,点击“Resize”,增加磁盘大小,PVE 设置完成
  2. SSH 连接 OpenWrt 虚拟机
  3. 按照OpenWrt 官方扩容指南扩容
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Install packages
opkg update
opkg install parted losetup resize2fs blkid

# Download expand-root.sh
wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"

# Source the script (creates /etc/uci-defaults/70-rootpt-resize and /etc/uci-defaults/80-rootpt-resize, and adds them to /etc/sysupgrade.conf so they will be re-run after a sysupgrade)
. ./expand-root.sh

# Resize root partition and filesystem (will resize partiton, reboot resize filesystem, and reboot again)
sh /etc/uci-defaults/70-rootpt-resize
  1. 执行完成之后,会自动重启,登录 OpenWrt 网页,点击概览即可查看扩容已经生效

配置 IP 和 DNS

编辑配置文件

1
vim /etc/config/network

找到对应接口,修改 ipaddr 和增加 dns

1
2
3
4
5
6
7
config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ip6assign '60'
        list ipaddr '192.168.68.23/24'
        option gateway '192.168.68.1'
        option dns '119.29.29.29'

重启网卡

1
 /etc/init.d/network restart

安装软件

界面:

依次点击"System",“Software”就可以找到软件安装界面,使用之前需要点击“Update lists”获取软件包列表

终端:

1
2
opkg update
opkg install 软件包名字

关闭防火墙

1
2
3
4
5
# 阻止防火墙服务开机自动启动
/etc/init.d/firewall disable

# 关闭防火墙
/etc/init.d/firewall stop

openwrt 定时任务失效

要在 OpenWrt 系统开机后执行某个脚本,可以通过以下步骤实现:

  1. 创建脚本 首先,创建你希望在开机时执行的脚本。例如,创建一个名为 myscript.sh 的脚本:
1
2
touch /usr/bin/myscript.sh
chmod +x /usr/bin/myscript.sh

在脚本中添加你需要执行的命令:

1
2
3
#!/bin/sh
# your commands here
echo "Script is running!" >> /tmp/myscript.log
  1. 编辑 /etc/init.d/ 目录/etc/init.d/ 目录下创建一个启动脚本。可以命名为 myscript
1
2
touch /etc/init.d/myscript
chmod +x /etc/init.d/myscript
  1. 编辑启动脚本 用文本编辑器打开 /etc/init.d/myscript,并添加以下内容:
1
2
3
4
5
6
7
8
#!/bin/sh /etc/rc.common

# This script will run at startup
START=99  # Start order, higher means later

start() {
    /usr/bin/myscript.sh
}
  1. 启用启动脚本 使脚本在启动时自动运行:
1
/etc/init.d/myscript enable
  1. 重启系统 重启 OpenWrt 系统,确认脚本是否在开机时执行:
1
reboot
  1. 检查输出 重启后,可以检查日志文件 /tmp/myscript.log,确认脚本是否成功执行。

通过这些步骤,您可以确保在 OpenWrt 系统开机后自动执行指定的脚本。

问题合集

openwrt 重启丢失定时任务

版本:lanlan-op 11.25.2023 by 蓝蓝定制-可爱赞助用户 / LuCI Master git-24.322.44728-ebf6bee

解决办法:删除 reboot 包,系统-软件包-搜索过滤 reboot关键字,删除,重启,再编辑定时任务,再重启查看是否消失。

网站总访客数:Loading
网站总访问量:Loading

-->