# 错误：自托管运行器遇到磁盘空间问题：设备上没有剩余空间

- **ID:** `cicd/github-actions-self-hosted-runner-disk-full`
- **领域:** cicd
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

自托管 GitHub Actions 运行器因累积的构建产物、缓存的 Docker 镜像或日志文件而耗尽磁盘空间

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| GitHub Actions Runner v2.311.0 | active | — | — |
| Ubuntu 22.04 LTS | active | — | — |

## 解决方案

1. ```
   Add a cleanup cron job on the runner: '0 0 * * * docker system prune -af --volumes && rm -rf /home/runner/_work/* && df -h' to remove unused Docker images and old workspace data nightly
   ```
2. ```
   Configure a pre-job step in workflows to check disk space and fail early with a message: 'df -h / | tail -1 | awk "{print \$5}" | sed "s/%//" | xargs -I {} sh -c "if [ {} -gt 85 ]; then echo \"Disk usage {}% exceeds 85%\"; exit 1; fi"'
   ```
3. ```
   Use ephemeral runners with auto-scaling that are destroyed after each job to prevent disk accumulation
   ```

## 无效尝试

- **** — Increasing runner disk size via cloud provider without cleaning existing files only delays the issue and increases cost (70% 失败率)
- **** — Manually deleting random files in /tmp may break running workflows or cause permission errors (60% 失败率)
- **** — Adding more runners without addressing disk cleanup multiplies the problem across the fleet (75% 失败率)
