abiosoft/colima · error
failed to remove existing resolv.conf: %w
Error message
failed to remove existing resolv.conf: %w
What it means
Step in the guest DNS setup where the existing /etc/resolv.conf is removed (`sudo rm -f /etc/resolv.conf`) so Colima can replace it with a stub pointing at the in-guest dnsmasq. Failure means the rm command failed inside the guest: immutable/attrib-protected resolv.conf (common on hardened images), read-only /etc, or a failing sudo/SSH channel.
Source
Thrown at environment/vm/lima/dns.go:91
// set dnsmasq listening interface and address
fmt.Fprintln(&buf, "interface=eth0")
fmt.Fprintln(&buf, "listen-address="+internalIP)
fmt.Fprintln(&buf, "bind-interfaces")
// 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
- Retry after a full stop/start of the VM.
- If using a custom image, ensure /etc/resolv.conf is a regular writable file (not immutable, not a bind mount).
- Switch DNS configuration to a mode that does not rewrite guest resolv.conf (e.g. plain host resolvers via `--dns`), letting the step be skipped.
- Recreate the profile (`colima delete && colima start`) when the guest is corrupted.
Defensive patterns
Strategy: validation
Validate before calling
// with custom guest images, ensure resolv.conf is a plain writable file // colima ssh -- lsattr /etc/resolv.conf (no 'i' flag) // colima ssh -- mount | grep resolv.conf (not ro bind mount)
Prevention
- Don't chattr +i resolv.conf in custom images
- Avoid DNS modes that rewrite guest resolv.conf on hardened images
- Prefer official images
When it happens
Trigger: Custom or hardened guest images where /etc/resolv.conf is chattr +i or bind-mounted read-only; NetworkManager/systemd-resolved holding the file; broken sudo in the guest. Only triggered in DNS modes that install dnsmasq in the guest.
Common situations: Users forcing modified disk images; container Linux variants managing resolv.conf; guest corrupted after abrupt host sleep/shutdown.
Related errors
- failed to write 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/5c0da01e57ecde45.
Report an issue: GitHub.