从PVE的KVM转向CT用LXC装openwrt

网络 · 2020-12-05 · 5484 人浏览

最近在Proxmox上用LXC虚拟了一个debian,资源占用很小,想着是否能实现openwrt,一搜果然有,为什么用LXC见这篇。 具体设置主要按照 论坛里 这个方法,但是里面有几个地方笔误了,踩完坑补充记录下。 一开始用的 官方 版本, 结果发现间歇断网, 后来测试下来发现 原帖采取的 这个干净版本非常不错,还能在线装各种插件,不用去搜专门的ipk, 也不像一些编译好的版本多了很多用不上的功能 这个版本原作者已不再维护,后来自己用github云编译了一个版本, 见下文。

以下为整理的具体步骤,基本比较完善和详细:

  • 解压 gzip -d openwrt-x86-64-generic-squashfs-rootfs.img.gz
  • 对得到的img进行解包(没有软件就 sudo apt install squashfs-tools

    unsquashfs openwrt-x86-64-generic-squashfs-rootfs.img
  • 进入目录,重新打包为模板

    cd squashfs-root
    tar zcf ../openwrt201117.rootfs.tar.gz *

    约为24M,上传或复制到PVE对应目录,一般为/var/lib/vz/template/cache。
    [info]一开始几次压缩后都只有9k,有问题,后来在完整的linux下执行就对了[/info]

  • 进入PVE shell中,创建LXC,据说web中创建CT方式会不好用,没测试。

    pct create 202 local:vztmpl/openwrt201117.rootfs.tar.gz --rootfs local-lvm:1 --ostype unmanaged --hostname CTOpenWrt --arch amd64 --cores 2 --memory 512 --swap 0 -net0 bridge=vmbr0,name=eth0

    相关参数可自行定义local-lvm可以设硬盘为更大,单位是G,我这为1G。

  • 进入web控制台启动CT。设置IP等等,安装插件。

    uci set network.lan.ipaddr=[lan ip]
    uci set network.lan.gateway=[上级路由ip]
    uci set network.lan.dns=[上级路由ip]
    uci commit 
    /etc/init.d/network restart 
  • 安装完adguard home和paswal后基本占用很低,不像VM模式下都有5%的CPU。 观察稳定运行几天试试,iperf可以跑满千兆。
  • 2020.12.06 映射宿主机目录 ,100是ID,最后mp=是LXC中目录地址

    pct set 100 -mp0 /mnt/bindmounts/shared,mp=/shared 
  • 容器lxc开启tun-br,可使用zerotier等

    # pve主机编辑lxc文件, vi /etc/pve/lxc/2001.conf ,最后加入
    lxc.cgroup.devices.allow = c 10:200 rwm
    lxc.hook.autodev = sh -c "modprobe tun; cd ${LXC_ROOTFS_MOUNT}/dev; mkdir net; mknod net/tun c 10 200; chmod 0666 net/tun"
    
    # 进入lxc执行,重启后生效
    cd /dev
    mkdir net
    mknod net/tun c 10 200
    chmod 0666 net/tun
    reboot
  • 2022.02.23/24 github action云编译精简并转到bypass套件,DNSfilter和pushbot。 rootfs下载: x86 https://molezz.lanzouj.com/iCrI300l2g3i 密码:5gfz 。 N1 https://molezz.lanzouj.com/i2B5300l2lch 密码:4bay
  • 2021.06.14 利用github action云编译了一个rootfs,可直接作为模板创建lxc。 https://molezz.lanzoui.com/ilrvlq7vduh 密码:7y6v

openwrt

Proxmox lxc openwrt pve

Buy Me a Coffee

支付宝 支付宝
微信 微信
取消回复
  1. WING 2022-01-01

    谢谢分享,使用模版导入PVE,开启op成功,可以愉快的出国了!

  2. molezz (作者)  2021-10-22

    这个0614版本用到现在4个月了。 我在pve7底下再试了下,没再现你的问题? 命令“pct create 202 /mnt/pve/nas/template/cache/openwrt614.rootfs.tar.gz --rootfs local:1 --ostype unmanaged --hostname CTOpenWrt --arch amd64 --cores 2 --memory 512 --swap 0 -net0 bridge=vmbr0,name=eth0” 。 可以直接创建和启动。 如果不行你看看这个帖子? error code和你一样
    https://programmerah.com/solved-pve7-0run_buffer-316-script-exited-with-status-1-33759/

  3. molezz (作者)  2021-10-21

    我要看下,另外是否pve7,编辑了conf文件?

  4. Js 2021-10-20

    现在无法启动了。下载不到你开头提到的那个rootfs.img.gz。下载了你网盘里面的。但是没法启动了。

    run_buffer: 316 Script exited with status 1
    lxc_init: 816 Failed to run lxc.hook.pre-start for container "104"
    __lxc_start: 2007 Failed to initialize container "104"
    TASK ERROR: startup for container '104' failed

    有办法解决吗?

Theme Jasmine by Kent Liao