步骤
初始化
会创建 rel 文件夹,带 vm 的配置和环境变量
1 | mix release.init |
指定 release
如果要生成指定的 release 的名字,则修改 mix.exs
一般不需要
1 | def project do |
运行
1 | MIX_ENV=prod mix release |
指定 vm 参数
1 | export RELEASE_DISTRIBUTION=name |
发布
最终需要的目录
1 | _build/prod/rel/$RELEASE_NAME/ |
会创建 rel 文件夹,带 vm 的配置和环境变量
1 | mix release.init |
如果要生成指定的 release 的名字,则修改 mix.exs
一般不需要
1 | def project do |
运行
1 | MIX_ENV=prod mix release |
1 | export RELEASE_DISTRIBUTION=name |
最终需要的目录
1 | _build/prod/rel/$RELEASE_NAME/ |
1 | $ tree rel |
release 脚本启动之前,可以执行任何操作
运行期加载环境变量
1 | export AAA=<%= System.get_env("ABC") %> |
测试
1 | mix release |
改到 config 目录里面去了
配置虚拟机参数,只支持编译期加载环境变量
默认只能编译期加载
1 | -kernel inet_dist_listen_min <%= System.get_env("DIST_PORT") %> |
测试
1 | DIST_PORT=5555 mix release |
运行期加载环境变量为 hack 的方式
env.sh.eex
1 | VERSION_DIR="$(ls "$RELEASE_ROOT/releases/" | head -n1)" |
vm.args.eex
1 | -kernel inet_dist_listen_min ${DIST_PORT} |
测试
1 | MIX_ENV=prod mix release |
为不同的数据类型定义通用的行为
给一些类型增加功能,而不修改原有模块
1 | defmodule DemoStruct1 do |
1 | defprotocol DemoProtocol do |
1 | defmodule Demo do |
类似面向对象的接口
1 | defmodule Demo do |
测试
1 | Demo1.say_hello("root") |
1 | require Logger |
等同于
1 | Logger.debug |
&模块名字.方法名/参数个数
1 | &__MODULE__.demo_func_name/1 |
例如
1 | demo_func = &demo_module_name.demo_func_name/1 |
官方例子
1 | defmodule Demo do |
1 | apply(__MODULE__, :demo_func_name, [123]) |
如果模块名为 string
1 | module_atom = String.to_existing_atom("Elixir.Demo") |
用来生成 rootfs
debian
1 | sudo apt install qemu-user-static debootstrap binfmt-support |
manjaro
1 | sudo pacman -S qemu-user-static debootstrap qemu-user-static-binfmt |
1 | # 用 https 的源 |
1 | sudo cp /usr/bin/qemu-arm-static ./deb_fs/usr/bin/ |
或者
1 | sudo bwrap \ |
1 | /debootstrap/debootstrap --second-stage |
1 | apt install -y neovim |
/etc/profile.d/path.sh
1 | export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
/etc/profile.d/ls.sh
1 | alias ll='ls -la --color=auto' 2>/dev/null |
/etc/profile.d/proxy.sh
1 | alias pon="export HTTP_PROXY=http://127.0.0.1:8118 HTTPS_PROXY=http://127.0.0.1:8118 ALL_PROXY=socks5://127.0.0.1:1080 NO_PROXY=localhost,127.0.0.1,10.0.2.1" |
/etc/profile.d/python.sh
1 | export PYTHONPYCACHEPREFIX=/dev/null |
~/.bashrc
1 | [[ -f /etc/profile ]] && source /etc/profile |
1 | source /etc/profile |
1 | # dd if=/dev/zero of=rootfs.ext4 bs=1M count=512 |
1 | qemu-system-arm \ |
output/target 目录先做好备份
1 | make O=output menuconfig |
设置为 overlay_fs
1 | System configuration ---> |
目录结构如下
1 | overlay_fs |
编译
1 | # 这个会处理 output/target 目录,但是不会生成 ext2 文件 |
或者
1 | make O=output -j$(nproc) |
1 | make O=output menuconfig |
设置为 overlay_fs
1 | System configuration ---> |
目录结构如下
1 | custom_fs |
post.sh
1 |
|
编译
1 | # 这个会处理 output/target 目录,但是不会生成 ext2 文件 |
或者
1 | make O=output -j$(nproc) |
1 | # uboot |
清理
1 | # 清理特定包,不删除下载的源码 |
配置好网络, tftp, nfs 等服务
启用 nfs,默认已经开启了
1 | make O=output linux-menuconfig |
1 | File systems ---> |
核心已经支持, 就算不选中, nfs 也可以加载
1 | make O=output uboot-menuconfig |
1 | Command line interface ---> |
启用 uImage, 设置加载地址
1 | make O=output menuconfig |
1 | Kernel ---> |
打包 rootfs
1 | Filesystem images ---> |
uboot 配置环境变量
1 | Bootloaders ---> |
uboot.env
内存地址一定要注意,否则可能会无法启动
1 | ipaddr=10.0.2.222 |
1 | make O=output -j$(nproc) |
1 | sudo qemu-system-arm \ |
手动,支持变量展开,需要用双引号,单引号不支持
1 | setenv ipaddr 10.0.2.222 |
用来加载内核
启动 tftp 服务
内核需要 uImage 格式,才能被 uboot 加载
1 | make LOADADDR=0x60003000 uImage -j$(nproc) |
把 output/arch/arm/boot/uImage 和 dts 放到 tftp 的目录
进入 uboot 后中断
1 | sudo qemu-system-arm \ |
手动设置变量
1 | # qemu 虚拟机 ip |
下载内核,设备树,启动
1 | tftp 0x60003000 uImage |
1 | make menuconfig |
1 | Environment ---> |
uboot.env
1 | ipaddr=10.0.2.222 |
1 | make -j$(nproc) |
1 | sudo qemu-system-arm \ |
用于加载文件系统
启动 nfs 服务,把 rootfs 文件夹放到 nfs 的根目录下
1 | make menuconfig |
1 | File systems ---> |
编译结束后,uImage 复制到 tftp 根目录
1 | make LOADADDR=0x60003000 uImage -j$(nproc) |
uboot.env
1 | ipaddr=10.0.2.222 |
1 | make -j$(nproc) |
1 | sudo qemu-system-arm \ |
手动,支持变量展开,需要用双引号,单引号不支持
1 | setenv ipaddr 10.0.2.222 |
需要编译
1 | 内核 |
1 | https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.191.tar.xz |
1 | make vexpress_defconfig |
1 | make menuconfig |
1 | # 不想要在 rootfs 里面手动 mknod,需要开这个 |
1 | make -j$(nproc) |
查看 tty
1 | cat .config | grep -i tty |
1 | CONFIG_CMDLINE="console=ttyAMA0" |
1 | qemu-system-arm \ |