1 分钟阅读 次阅读

OSTree 是一种强大的文件系统管理工具,广泛应用于操作系统版本控制和分发。本文总结了 OSTree 的常用命令,按功能进行分类,便于读者快速查阅。

1 仓库管理

1.1 初始化仓库

  • 初始化压缩存档模式仓库(用于远程分发):

    ostree --repo=/path/to/repo init --mode=archive-z2
    

1.1.1 仓库模式对比与选择

模式 存储形式 是否压缩 是否支持远程 pull 使用场景
bare 文件硬链接 本地开发或直接部署
bare-user 文件硬链接(非 root 用户) 非特权用户的本地开发
bare-user-only 文件硬链接(权限更严格) 更高安全性需求的本地开发
archive-z2 压缩存档 远程分发,节省存储和带宽

仓库模式选择建议

  • 本地开发和调试:使用 barebare-user 模式(根据权限需求选择)。
  • 直接部署到文件系统:使用 bare 模式。
  • 远程分发更新(如 OTA):使用 archive-z2 模式。
  • 严格文件权限控制:使用 bare-user-only 模式。

1.2 查看和管理分支

  • 列出仓库中的分支:

    ostree --repo=/path/to/repo refs
    
  • 删除分支:

    ostree --repo=/path/to/repo refs --delete <branch-name>
    

1.3 查看仓库配置

  • 查看远程仓库列表:

    ostree --repo=/path/to/repo remote list
    
  • 删除远程仓库配置:

    ostree --repo=/path/to/repo remote delete <REMOTE_NAME>
    

2 提交文件系统

2.1 提交文件系统内容

  • 将目录内容提交到特定分支:

    ostree --repo=/path/to/repo commit -b <branch-name> \
        --subject="Commit message" --tree=dir=/path/to/dir
    
  • 从挂载的 .img 文件提交文件系统内容:

    sudo mount -o loop /path/to/rootfs.img /mnt
    ostree --repo=/path/to/repo commit -b <branch-name> \
        --subject="Initial commit from img" --tree=dir=/mnt
    sudo umount /mnt
    

2.2 查看提交记录

  • 查看分支的提交历史:

    ostree --repo=/path/to/repo log <branch-name>
    

3 签出文件系统

3.1 签出分支内容

  • 签出分支最新提交到指定目录:

    ostree checkout <branch-name> /path/to/target \
        --repo=/path/to/repo
    
  • 签出特定提交到指定目录:

    ostree checkout -C <commit-hash> /path/to/target \
        --repo=/path/to/repo
    
  • 查看签出结果:

    ls /path/to/target
    

4 远程操作

4.1 添加远程仓库

  • 添加远程仓库:

    ostree remote add <remote-name> <remote-url> \
        --repo=/path/to/local/repo
    
  • 列出远程仓库的分支:

    ostree remote refs <remote-name> --repo=/path/to/local/repo
    

4.2 拉取远程数据

  • 从远程仓库拉取分支内容:

    ostree pull <remote-name> <branch-name> \
        --repo=/path/to/local/repo
    
  • 深度拉取完整提交历史:

    ostree pull <remote-name> <branch-name> \
        --repo=/path/to/local/repo --depth=-1
    
  • 生成远程仓库 summary 文件(解决分支不可见问题):

    ostree --repo=/path/to/remote/repo summary -u
    

4.3 禁用 GPG 验证

  • 如果拉取时报 GPG 验证错误,在本地仓库配置文件 /mnt/hdd/ostree_local/repo/config中禁用 GPG 验证:

    [remote "<remote-name>"]
    url=<remote-url>
    gpg-verify=false
    

5 环境变量配置

  • 临时设置仓库路径环境变量:

    export OSTREE_REPO=/path/to/repo
    
  • 永久设置环境变量(添加到 ~/.bashrc~/.zshrc 中):

    export OSTREE_REPO=/path/to/repo
    source ~/.bashrc
    

留下评论