名称 | Name: ostree
版本 | Version: 1.0.0
作者 | Author: OS Build Agent
领域 | Domain: Atomic System Updates (Fedora/RHEL CoreOS)
专业的 OSTree 原子化系统更新管理技能,支持不可变基础设施、原子更新、版本回滚等现代系统管理功能。
Professional OSTree atomic system update management skill supporting immutable infrastructure, atomic updates, version rollback, and modern system management features.
bash
# RHEL/Fedora
dnf install ostree rpm-ostree
# openSUSE
zypper install ostree
# Debian/Ubuntu
apt-get install ostree
bash
# 系统仓库 (bare-user)
# System repo (bare-user)
ostree --repo=/ostree/repo init --mode=bare-user
# 归档仓库 (archive-z2)
# Archive repo (archive-z2)
ostree --repo=/path/to/repo init --mode=archive-z2
# bare 仓库
# Bare repo
ostree --repo=/path/to/repo init --mode=bare
bash
# 初始化系统仓库
# Initialize system repository
ostree --repo=/ostree/repo init --mode=bare-user
# 初始化归档仓库
# Initialize archive repository
ostree --repo=/var/www/html/repo init --mode=archive-z2
# 配置仓库
# Configure repository
cat > /ostree/repo/config << EOF
[core]
repo_version=1
mode=bare-user
[remote "fedora"]
url=https://ostree.fedoraproject.org
gpg-verify=true
EOF
bash
# 创建提交
# Create commit
ostree commit \
--repo=/path/to/repo \
--branch=fedora/x86_64/server \
--subject="Initial commit" \
--tree=dir=/path/to/rootfs
# 从目录树创建提交
# Create commit from directory tree
ostree commit \
--repo=/path/to/repo \
--branch=main \
--subject="Update packages" \
--tree=dir=/var/www/html/rootfs
# 查看提交历史
# View commit history
ostree log --repo=/ostree/repo fedora/x86_64/server
# 显示提交详情
# Show commit details
ostree show --repo=/ostree/repo fedora/x86_64/server
# 删除提交
# Delete commit
ostree prune --repo=/path/to/repo --ref=main
bash
# 导入 GPG 密钥
# Import GPG key
ostree remote gpg-import \
--repo=/ostree/repo \
fedora \
--stdin < /path/to/gpg-key
# 签名提交
# Sign commit
ostree sign \
--repo=/path/to/repo \
--gpg-key=KEYID \
fedora/x86_64/server
# 验证提交
# Verify commit
ostree verify \
--repo=/ostree/repo \
fedora/x86_64/server
# 添加远程仓库(带签名验证)
# Add remote with signature verification
ostree remote add \
--repo=/ostree/repo \
fedora \
https://ostree.fedoraproject.org/repo \
--gpg-verify
bash
# 查看部署状态
# View deployment status
ostree admin status
# 部署新版本
# Deploy new version
ostree admin deploy --os=fedora fedora/x86_64/server
# 切换部署
# Switch deployment
ostree admin switch --os=fedora fedora/x86_64/server
# 回滚到上一版本
# Rollback to previous version
ostree admin rollback
# 清理旧部署
# Cleanup old deployments
ostree admin undeploy 1
# 设置下次启动版本
# Set next boot version
ostree admin set-origin --os=fedora fedora
# 查看部署历史
# View deployment history
journalctl -b -1
bash
# 添加远程仓库
# Add remote repository
ostree remote add \
--repo=/ostree/repo \
fedora \
https://ostree.fedoraproject.org/repo
# 列出远程仓库
# List remote repositories
ostree remote list --repo=/ostree/repo
# 删除远程仓库
# Remove remote repository
ostree remote delete \
--repo=/ostree/repo \
fedora
# 拉取更新
# Pull updates
ostree pull \
--repo=/ostree/repo \
--remote=fedora \
fedora/x86_64/server
# 拉取最新提交
# Pull latest commit
ostree pull \
--repo=/ostree/repo \
--remote=fedora \
--depth=1 \
fedora/x86_64/server
# 推送提交
# Push commits
ostree push \
--repo=/path/to/repo \
--remote=origin \
main
bash
# 列出所有分支
# List all branches
ostree refs --repo=/path/to/repo
# 创建分支
# Create branch
ostree refs --repo=/path/to/repo \
--create=feature/new-feature
# 删除分支
# Delete branch
ostree refs --repo=/path/to/repo \
--delete=feature/old-feature
# 重命名分支
# Rename branch
ostree refs --repo=/path/to/repo \
--rename=old/new
# 显示分支内容
# Show branch content
ostree ls --repo=/path/to/repo fedora/x86_64/server
bash
# 叠加安装包
# Layer packages
rpm-ostree install vim wget curl
# 卸载叠加包
# Remove layered packages
rpm-ostree uninstall vim
# 查看叠加包
# View layered packages
rpm-ostree status
# 替换包
# Replace packages
rpm-ostree override replace https://example.com/package.rpm
# 安装本地 RPM
# Install local RPM
rpm-ostree install ./package.rpm
bash
# 检查更新
# Check for updates
rpm-ostree upgrade --check
# 执行更新
# Perform update
rpm-ostree upgrade
# 回滚更新
# Rollback update
rpm-ostree rollback
# 重新部署当前版本
# Redeploy current version
rpm-ostree rebase :current
# 切换到不同分支
# Switch to different branch
rpm-ostree rebase fedora/x86_64/silverblue
bash
# 从 Kickstart 创建
# Create from Kickstart
rpm-ostree compose tree \
--repo=/path/to/repo \
--ref=fedora/x86_64/custom \
--compose=/path/to/compose.json \
/path/to/manifest.json
# 容器构建
# Container build
rpm-ostree compose container \
--repo=/path/to/repo \
--ref=fedora/x86_64/custom \
fedora-custom:latest
# 导出为 ISO
# Export to ISO
rpm-ostree compose image \
--repo=/path/to/repo \
fedora/x86_64/custom \
./output.iso
bash
# 创建自定义仓库配置
# Create custom repo config
cat > /etc/ostree/remotes.d/custom.conf << EOF
[remote "custom"]
url=https://ostree.example.com/repo
gpg-verify=true
gpg-keypath=/etc/pki/ostree/gpg-keys
EOF
# 创建分支策略
# Create branch policy
cat > /etc/ostree/branches.conf << EOF
[branch "fedora/x86_64/*"]
collection-id=org.fedoraproject
EOF
bash
# 自动化部署脚本
# Automated deployment script
cat > /usr/local/bin/ostree-deploy.sh << 'EOF'
#!/bin/bash
set -e
# 拉取最新提交
# Pull latest commit
ostree pull --repo=/ostree/repo --remote=fedora fedora/x86_64/server
# 部署
# Deploy
ostree admin deploy --os=fedora fedora/x86_64/server
# 清理
# Cleanup
ostree admin undeploy 1
ostree prune --repo=/ostree/repo
echo "Deployment complete"
EOF
chmod +x /usr/local/bin/ostree-deploy.sh
bash
# 查看 OSTree 日志
# View OSTree logs
journalctl -u ostree-remount
journalctl -u rpm-ostreed
# 监控系统状态
# Monitor system status
watch -n 5 'ostree admin status'
# 检查仓库健康
# Check repo health
ostree fsck --repo=/ostree/repo
命令Command描述Descriptionostree initinitialize初始化仓库Initialize repoostree commitcommit创建提交Create commitostree loglog查看日志View logostree showshow显示提交Show commitostree refsrefs管理分支Manage branchesostree remoteremote远程管理Remote managementostree pullpull拉取提交Pull commitsostree pushpush推送提交Push commitsostree verifyverify验证提交Verify commit
命令Command描述Descriptionostree admin statusstatus部署状态Deployment statusostree admin deploydeploy部署系统Deploy systemostree admin rollbackrollback回滚Rollbackostree admin switchswitch切换版本Switch versionostree admin undeployundeploy删除部署Remove deployment
命令Command描述Descriptionrpm-ostree statusstatus系统状态System statusrpm-ostree upgradeupgrade系统升级System upgraderpm-ostree rollbackrollback回滚Rollbackrpm-ostree installinstall安装包Install packagerpm-ostree uninstalluninstall卸载包Uninstall packagerpm-ostree rebaserebase切换分支Switch branch
bash
# 查看详细状态
# View detailed status
ostree admin status --verbose
# 检查仓库完整性
# Check repo integrity
ostree fsck --repo=/ostree/repo
# 清理并重新部署
# Clean and redeploy
rpm-ostree cleanup -b
rpm-ostree upgrade
bash
# 重新导入密钥
# Re-import keys
ostree remote gpg-import --repo=/ostree/repo fedora
# 检查密钥
# Check keys
ostree remote gpg-list-keys --repo=/ostree/repo fedora
MIT License