本帖最后由 olvolv 于 2021-12-7 20:41 编辑
对了,docker 也可以用本制作出来的rootfs,反正我用n1验证过,x86应该也没问题,命令好像是: docker import xx.rootfs.gz 有没有坑我就不知道了 以下更新于2021/7/26
好吧我又更新一回,因为我突然意识到不管是rootfs的squashfs镜像固件还是可以引导的完全的squashfs磁盘镜像固件,
都可以通过mount -o loop把openwrt的根目录挂载到一个目录中,这样我们不需要其它软件就可以打包为lxc模板
(我说的这些都是基于squashfs文件系统的镜像固件,我记得还有其它的文件系统固件,理论上应该都可以挂载)
所以想要从各位大神发布的openwrt x86固件制作成 lxc容器 罗列如下:
1,无论xxx.squashfs-rootfs.img.gz还是xxx.squashfs-combined.img.gz都先解压:gzip -d xxx.***.img.gz
2,开始mount 这根据是否是rootfs分为两种情况:
xxx.squashfs-rootfs.img.gz格式: 直接 mount -o loop xxx.squashfs-rootfs.img openwrt
xxx.squashfs-combined.img.gz格式:先 fdisk -l xxx.squashfs-combined.img.gz
fdisk -l 显示的是镜像内的分区 大的分区是openwrt的根目录,所以我们mount 的时候要从
这个分区的开始地址挂载,例如这个固件 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img.gz
fdisk 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img -l
Disk 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img: 1.6 GiB, 1657274880 bytes, 3236865 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4532fdad
Device Boot Start End Sectors Size Id Type
20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img1 * 512 131583 131072 64M 83 Linu
20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img2 132096 3236863 3104768 1.5G 83 Linu 第二分区(root目录)开始于132096扇区(sectors)每个扇区512字节,所以此分区开始于echo $((132096*512)) :67633152
mount命令为:mount -o loop,offset=67633152 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img openwrt
3,经过以上两个步骤,我们就得到了openwrt的根目录,只要打包:cd openwrt && tar zcf /var/lib/vz/template/cache/openwrt.tar.gz * (别忘了最后的星号)
4,创建lxc容器吧。。。。
本来排版就差的帖子被我改成这样 。。。
以下更新与于2021/7/25
最近想更新一下op,看中了【2021-7-17更新】OpenWrt ipv6/docker/大全版/精简版/旁路由版 丰富插件免费使用这个固件,
可惜只有 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img.gz这样的镜像文件,百度一下liunx 挂载img
找到一篇文章,根据上边挂载系统目录后,最后制作lxc模板成功,记录一下:
注意:以下操作都是在pve主机里执行的,因为lxc容器里我mount无法成功
(哎丢三落四的,这一句是后补的)首先要 gzip -d 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img.gz 解压再接着执行如下步骤:- root@pve:/home/olv/share/www/wwwroot/share/tmp# fdisk 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img -l
- Disk 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img: 1.6 GiB, 1657274880 bytes, 3236865 sectors
- Units: sectors of 1 * 512 = 512 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disklabel type: dos
- Disk identifier: 0x4532fdad
- Device Boot Start End Sectors Size Id Type
- 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img1 * 512 131583 131072 64M 83 Linu
- 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img2 132096 3236863 3104768 1.5G 83 Linu ###挂载这个大的试试
- root@pve:/home/olv/share/www/wwwroot/share/tmp# echo $((132096*512))
- 67633152
- root@pve:/home/olv/share/www/wwwroot/share/tmp# mount 20210717-Ipv6-Mini-x86-64-generic-squashfs-combined.img op -o loop,offset=67633152
复制代码 - root@pve:/home/olv/share/www/wwwroot/share/tmp/op# cd ..
- root@pve:/home/olv/share/www/wwwroot/share/tmp# cd op
- root@pve:/home/olv/share/www/wwwroot/share/tmp/op# ls
- bin dev etc lib lib64 mnt overlay proc rom root sbin sys tmp usr var www
- root@pve:/home/olv/share/www/wwwroot/share/tmp/op# tar zcf /var/lib/vz/template/cache/sirpdboy.openwrt.rootfs.tar.gz *
复制代码
6, 把sirpdboy.openwrt.rootfs.tar.gz放到pve模板目录 /var/lib/vz/template/cache 刷新下pve管理网页,应该就能看到这个模板了。
7, 网页上新建容器无法成功, 在pve控制台新建容器:
- pct create 201 local:vztmpl/sirpdboy.openwrt.rootfs.tar.gz --rootfs local-lvm:0.5 --ostype unmanaged --hostname OpenWrt --arch amd64 --cores 2 --memory 256 --swap 0 -net0 bridge=vmbr0,name=eth0
复制代码
排版太差,请谅解,以前帖子内容有几个错误,已更正
这是更新前:
纯粹记录下省的下次忘了。 安装方法是用的: [固件发布] PVE使用的LXC容器镜像openwrt-19.07.1-x86-64 ,但是没有用这里的openwrt。
用的openwrt来自: [2020-11-4]Openwrt 在线IPK随心安装 专治强迫症 超全!
我是在pve下lxc容器安装的debian里边操作的,直接在pve下应该一样,但是为了保持pve干净还是安装个容器用吧
具体:
1,新建目录:mkdir openwrt 进入cd openwrt 下载 图片中选中的镜像:wget https://openwrt.download/R20.11. ... ashfs-rootfs.img.gz
2,解压 gzip -d openwrt-x86-64-generic-squashfs-rootfs.img.gz
3,下载 unsquashfs: sudo apt install squashfs-tools
4, 解包 unsquashfs openwrt-x86-64-generic-squashfs-rootfs.img 会解压到squashfs-root目录进入 cd squashfs-root
5, 打包rootfs : tar zcf ../openwrt.rootfs.tar.gz * 这样在openwrt目录就会得到openwrt.rootfs.tar.gz 就是所谓的lxc模板了(这样的打包参数我测试可以用,有啥不妥的请指教)。
6, 放到pve模板目录sudo cp openwrt.rootfs.tar.gz /var/lib/vz/template/cache 刷新下pve管理网页,应该就能看到这个模板了。
7, 网页上新建容器无法成功, 在pve控制台新建容器:
- pct create 201 local:vztmpl/openwrt.rootfs.tar.gz --rootfs local-lvm:0.5 --ostype unmanaged --hostname OpenWrt --arch amd64 --cores 2 --memory 256 --swap 0 -net0 bridge=vmbr0,name=eth0
复制代码 8,“其它说明:关于UDP转发不可用的问题,需要PVE系统加载tproxy模块。在PVE系统下执行改命令后重启” :echo 'xt_TPROXY' > /etc/modules-load.d/tproxy.conf
只要大神发布有rootfs镜像文件,我们就可以用1-6步骤制作自己的模板,当然如果是发布的*.rootfs.tar.gz我们就可以省下1-6的步骤了。
我就安装了科学软件作为旁路由来用,其它的没测试,所以有啥bug没有也不清楚。
再次声明:纯粹记录,有啥不妥的地方请大神指教。
|