---
name: iso-build-cleanup
description: Recover disk space and reset the repo-local Clawdie ISO build workspace after an interrupted or failed FreeBSD build by inspecting tmp/output and tmp/cache, unmounting tmp/cache/mnt, detaching stale md devices, and removing safe-to-delete artifacts such as work.img and old output images while preserving useful caches for the next build.
---

# iso-build-cleanup

Use this skill when the ISO build was interrupted, disk space is low, or the
repo still has stale build state under `tmp/`. Run one command at a time and
inspect before deleting or detaching anything.

## Workspace names

Use clear language while keeping the real paths:

- `tmp/output` = output image artifacts
- `tmp/cache` = build cache
- `tmp/cache/mnt` = mounted work image; ISO-builder-specific mountpoint
- `tmp/cache/work.img` = reusable work image

Do not mount unrelated datasets, recovery filesystems, or scratch filesystems
elsewhere under repo `tmp/`.

## 1. Inspect space before deleting anything

Run from the repo root:

```sh
df -h /home/clawdie /
du -xh -d 2 tmp | sort -h | tail -n 40
ls -lh tmp/output
du -xh -d 1 tmp/cache | sort -h
ls -lah tmp/cache | sort -k5 -h | tail -n 30
find tmp/cache -maxdepth 1 -type f -ls
/sbin/mount | grep /home/clawdie/ai/clawdie-iso/tmp/cache/mnt
```

This tells you whether the space is in:

- old output artifacts
- `work.img`
- memstick slice extracts like `memstick-s2.img`
- still-mounted build filesystems

## 2. Unmount the mounted work image if present

Only run the unmounts that still exist:

```sh
sudo /sbin/umount /home/clawdie/ai/clawdie-iso/tmp/cache/mnt/proc
sudo /sbin/umount /home/clawdie/ai/clawdie-iso/tmp/cache/mnt/dev
sudo /sbin/umount /home/clawdie/ai/clawdie-iso/tmp/cache/mnt
```

If one of these says “not mounted”, continue.

## 3. Find and detach stale md devices

Inspect:

```sh
sudo /sbin/mdconfig -l
sudo /sbin/mdconfig -lv
```

Typical stuck state looks like:

```text
md0  vnode  28G  /home/clawdie/ai/clawdie-iso/tmp/cache/work.img
md1  vnode  28G  /home/clawdie/ai/clawdie-iso/tmp/cache/work.img
```

Detach the stale devices:

```sh
sudo /sbin/mdconfig -d -u md0
sudo /sbin/mdconfig -d -u md1
```

If the unit numbers differ, detach the ones pointing at `tmp/cache/work.img`.

## 4. Remove stale build-state files

Clear the work-image marker and the work image itself:

```sh
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/cache/.md_device
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/cache/work.img
```

## 5. Safe delete list

These are safe to delete when you need space, but confirm with the operator
before removing the newest commit-suffixed `.img.xz` artifact if it may be the
current test image:

```sh
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/output/*.img
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/output/*.img.xz
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/output/*.sha256
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/cache/memstick-s2.img
sudo rm -f /home/clawdie/ai/clawdie-iso/tmp/cache/memstick-s2a.img
```

Keep these if you want the next build to reuse caches:

- `tmp/cache/FreeBSD-15.0-RELEASE-amd64-memstick.img`
- `tmp/cache/FreeBSD-15.0-RELEASE-amd64-memstick.img.SHA256`
- `tmp/packages/`
- `tmp/npm-globals/`

## 6. Verify reclaimed space

Recheck:

```sh
df -h /home/clawdie /
du -xh -d 1 tmp/cache | sort -h
ls -lh tmp/output
```

If cleanup worked, `tmp/output` should be empty or much smaller, `work.img`
should be gone, and free space on `/home/clawdie` should jump significantly.

## 7. What to do next

After cleanup:

- if memstick cache is still present and healthy, rebuild with:
  `sudo ./build.sh --skip-memstick-fetch`
- if the memstick cache is gone or suspect, rebuild with:
  `sudo ./build.sh`
