abiosoft/colima · error
failed to write resolv.conf: %w
Error message
failed to write resolv.conf: %w
What it means
After removing the old resolv.conf, Colima writes a generated replacement ('# Generated by Colima\n\nnameserver <internalIP>') so guest lookups go through the in-guest dnsmasq listening on the internal IP. This error means that write (`cat > /etc/resolv.conf` via sudo over SSH) failed, leaving the guest temporarily without a resolv.conf if removal already succeeded.
Source
Thrown at environment/vm/lima/dns.go:97
// ensure dnsmasq config directory exists
if err := l.RunQuiet("sudo", "mkdir", "-p", "/etc/dnsmasq.d"); err != nil {
return fmt.Errorf("failed to create dnsmasq config directory: %w", err)
}
// write config to dnsmasq directory
if err := l.Write("/etc/dnsmasq.d/01-colima.conf", buf.Bytes()); err != nil {
return fmt.Errorf("failed to write dnsmasq config: %w", err)
}
// remove existing resolv.conf file
if err := l.RunQuiet("sudo", "rm", "-f", "/etc/resolv.conf"); err != nil {
return fmt.Errorf("failed to remove existing resolv.conf: %w", err)
}
// replace resolv.conf with a custom one
resolvConf := fmt.Sprintf("# Generated by Colima\n\nnameserver %s\n", internalIP)
if err := l.Write("/etc/resolv.conf", []byte(resolvConf)); err != nil {
return fmt.Errorf("failed to write resolv.conf: %w", err)
}
// restart dnsmasq service to apply changes
if err := l.RunQuiet("sudo", "systemctl", "restart", "dnsmasq"); err != nil {
return fmt.Errorf("failed to restart dnsmasq service: %w", err)
}
return nil
}
View on GitHub (pinned to c3a5f9184d)
Solutions
- Immediately retry `colima stop && colima start` so the whole DNS setup re-runs and restores resolv.conf.
- Fix guest filesystem issues (space, immutability) if the error repeats (`colima ssh -- lsattr /etc/resolv.conf; sudo chattr -i /etc/resolv.conf`).
- Use a simpler DNS mode that skips in-guest dnsmasq.
- Recreate the VM if the guest remains broken.
Defensive patterns
Strategy: retry
Try / catch
Go: on resolv.conf write failure, immediately schedule stop/start so DNS setup re-runs; if persistent, treat guest as corrupted and recreate profile.
Prevention
- Keep guest filesystem writable and with free space
- Never Ctrl-C colima during post-start actions
- Verify custom images don't protect /etc/resolv.conf
When it happens
Trigger: Same class as the remove step: read-only or immutable /etc/resolv.conf target, full guest disk, sudo/SSH failure mid-write. Because the previous step already deleted the file, a failure here can leave DNS fully broken inside the guest until restarted.
Common situations: Hardened/custom images protecting resolv.conf; disk-full guests; SSH instability; interrupted colima start (Ctrl-C) during post-start actions.
Related errors
- failed to remove existing resolv.conf: %w
- failed to write dnsmasq config: %w
- failed to create dnsmasq config directory: %w
- failed to restart dnsmasq service: %w
- cannot read file '%s': %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/92d95a9f6dceebba.
Report an issue: GitHub.