添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

前言

半年前折腾软路由, all in one esxi 又是网卡直连,又是硬盘直通的。 结果前段时间改wallpass2的配置, 发现保存配置就恢复默认。
莫名其妙的bug, 想着重启看看,结果openwrt在虚拟机重启,直接重装了, 有点莫名其妙.

所以, 狠下心,直接不搞花里胡哨, 平平淡淡才是真. 裸机装Openwrt原版.

Openwrt

前期准备

安装Finnix到U盘

https://www.finnix.org 下载最新的 Finnix 系统镜像,然后将其写入 U 盘。

写盘工具 Rufus

过程就省略了,下载镜像后选择镜像,然后默认就行.

下载OpenWRT 镜像

官方提供了多种格式的 Image Files

  • combined-ext4.img.gz:包含引导信息、rootfs(ext4 格式)、内核以及相关分区信息的硬盘镜像,可以 dd 写入某个磁盘。
  • combined-squashfs.img.gz:包含引导信息、rootfs(squashfs 格式)、内核以及相关分区信息的硬盘镜像。
  • generic-rootfs.tar.gz:rootfs 包含的所有文件。
  • rootfs-ext4.img.gz:rootfs(ext4 格式) 分区镜像,可以 dd 到某个分区或者 mount -o 到某个目录。
  • rootfs-squashfs.img.gz:rootfs(squashfs 格式) 分区镜像,可以 dd 写入某个分区或者 mount -o 挂载到目录。
  • vmlinuz:内核
  • ext4 与 squashfs 格式的区别:

  • ext4 格式的 rootfs 可以扩展磁盘空间大小,而 squashfs 不能。
  • squashfs 格式的 rootfs 可以使用重置功能(恢复出厂设置),而 ext4 不能。
  • 实际上squashfs我也扩了.

    国内镜像源也有, 比如清华? https://mirror.sjtu.edu.cn/openwrt/releases/

    安装 OpenWRT

    插入安装Finnix系统U盘, 并且启动.

    启动 sshd & 配置密码

    1
    2
    3
    4
    5
    6
    7
    # 下面两个命令, 因为是回忆所以忘了, 反正能启动就行
    systemctl start sshd
    or
    service sshd start

    # 配置密码
    passwd root

    连接ssh发送镜像

    1
    2
    3
    wget https://mirror.sjtu.edu.cn/openwrt/releases/22.03.4/targets/x86/64/openwrt-22.03.4-x86-64-generic-squashfs-combined.img.gz

    scp openwrt-22.03.4-x86-64-generic-squashfs-combined.img.gz root@xxx:~

    通过 lsblk 命令确认哪个设备名是软路由的硬盘。

    1
    2
    3
    4
    5
    6
    7
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    loop0 7:0 0 342.6M 1 loop /usr/lib/live/mount/rootfs/filesystem.squashfs
    sda 8:0 0 14.9G 0 disk
    sdb 8:16 1 7.5G 0 disk
    ├─sdb1 8:17 1 411M 0 part /usr/lib/live/mount/medium
    └─sdb2 8:18 1 2.9M 0 part
    zram0 253:0 0 1.9G 0 disk [SWAP]

    将 OpenWRT 系统镜像写入 sda 标识的硬盘里。 注意数据会被擦空,别写错了.

    1
    2
    tar zxvf openwrt-22.03.4-x86-64-generic-squashfs-combined.img.gz
    dd if=openwrt-22.03.4-x86-64-generic-squashfs-combined.img bs=1M of=/dev/sda

    注意了, 到这里我们直接结束就行了, 有些教程会在这里告诉你重新分配硬盘。 但是我试过几次, 每次都失败, 弄的系统也无法开机. 貌似最新的版本, 磁盘的格式变成了overlay。后面我们可以扩容。先不要在这里操作.

    还没研究透,可以看看官方文档: https://openwrt.org/docs/guide-user/additional-software/extroot_configuration

    配置OpenWRT

    磁盘扩容

    官方文档: https://openwrt.org/docs/guide-user/advanced/expand_root

    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # Configure startup scripts
    cat << "EOF" > /etc/uci-defaults/70-rootpt-resize
    if [ ! -e /etc/rootpt-resize ] \
    && type parted > /dev/null \
    && lock -n /var/lock/rootpt-resize
    then
    BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)"
    BOOT_PART="${BOOT_DEV##*[^0-9]}"
    DISK_DEV="${BOOT_DEV%${BOOT_PART}}"
    parted -l ---pretend-input-tty << EOI
    ok
    fix
    EOI
    parted -s "${DISK_DEV%p}" resizepart "$((BOOT_PART+1))" 100%
    touch /etc/rootpt-resize
    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/rootpt-resize
    then
    BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)"
    BOOT_PART="${BOOT_DEV##*[^0-9]}"
    DISK_DEV="${BOOT_DEV%${BOOT_PART}}"
    ROOT_DEV="${DISK_DEV}$((BOOT_PART+1))"
    ROOT_TYPE="$(ubus call system board \
    | jsonfilter -e "$['rootfs_type']")"
    case "${ROOT_TYPE}" in
    (ext4) LOOP_DEV="$(losetup -f)"
    losetup "${LOOP_DEV}" "${ROOT_DEV}" ;;
    (squashfs) LOOP_DEV="$(losetup -n -l \
    | sed -n -e "\|\s.*\s${ROOT_DEV#/dev}\s.*$|{s///p;q}")" ;;
    esac
    resize2fs -f "${LOOP_DEV}"
    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
    1
    2
    3
    4
    5
    6
    # Install packages
    opkg update
    opkg install parted losetup resize2fs

    # Expand root partition/filesystem
    sh /etc/uci-defaults/70-rootpt-resize

    执行脚本自动扩容即可.

    插件安装

    主题:

  • luci-theme-argon
  • luci-app-argon-config
  • luci-i18n-base-zh-cn
  • luci-i18n-opkg-zh-cn
  • 剩下根据自己喜好安装.

    科学配置

    之前配置是这样的.

    这样分流国内走国内DNS, 海外走海外DNS. 但是有个缺点,就是我海外dns在hk,机器在hk倒是没什么,但如果在美国就有点蛋疼了。

    正好这次重装, 换个口味, 试试clash.

    Clash配置管理

    换到clash, 配置又是一个头疼的地方. 因为我还在用v2ray, 所以一个配置需要兼容两个 v2ray 和 clash 订阅。并且订阅规则尽量有一个能保存的地方, 不然下次重装保留的配置都没了, 所以最好不要在Openwrt配置. 那我就需要一个git仓库.

    原文作者: Momo

    原文链接: https://mo.xmomo521.top/2023/04/10/记录一次OpenWrt重装和一些配置/

    发表日期: April 10th 2023, 9:28:50 pm

    更新日期: April 10th 2023, 10:15:56 pm

    版权声明:本文采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可

    CATALOG
    1. 1. 前言
    2. 2. Openwrt
      1. 2.1. 前期准备
        1. 2.1.1. 安装Finnix到U盘
        2. 2.1.2. 下载OpenWRT 镜像
      2. 2.2. 安装 OpenWRT
      3. 2.3. 配置OpenWRT
        1. 2.3.1. 磁盘扩容
        2. 2.3.2. 插件安装
    3. 3. 科学配置
    4. 4. Clash配置管理
    2、在博客根目录(注意不是archer根目录)执行以下命令:
    npm i hexo-generator-json-content --save
    3、在根目录_config.yml里添加配置: jsonContent: meta: false pages: false posts: title: true date: true path: true text: false raw: false content: false slug: false updated: false comments: false link: false permalink: false excerpt: false categories: true tags: true