abiosoft/colima · error

failed to create dnsmasq config directory: %w

Error message

failed to create dnsmasq config directory: %w

What it means

Part of the in-guest DNS setup when the VM is configured to run its own DNS resolver: Colima runs `sudo mkdir -p /etc/dnsmasq.d` inside the guest via SSH. Failure means the guest command returned non-zero: sudo unavailable/broken, guest filesystem read-only, or the SSH session itself failing. This wraps errors from the setupDNS path (surfaces to the user as 'error setting up DNS').

Source

Thrown at environment/vm/lima/dns.go:81

		dnsServers = nil
		for _, dns := range conf.Network.DNSResolvers {
			dnsServers = append(dnsServers, dns.String())
		}
	}
	for _, dns := range dnsServers {
		fmt.Fprintf(&buf, "server=%s", dns)
		fmt.Fprintln(&buf)
	}
	fmt.Fprintln(&buf) // for cleaner output

	// 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)
	}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Retry `colima start`; transient guest boot/SSH races usually clear on a clean restart (`colima stop && colima start`).
  2. If using a custom disk image, verify it includes sudo and a systemd-based Linux userspace, or switch back to the official image.
  3. Check earlier log lines for SSH/bootstrap failures and address those first (the DNS step rarely fails alone).
  4. As a workaround, simplify DNS config (plain `--dns 1.1.1.1` without the in-guest resolver mode) so dnsmasq setup is skipped.
Defensive patterns

Strategy: retry

Try / catch

Go: if err := vm.Start(ctx, conf); err != nil { if strings.Contains(err.Error(), "error setting up DNS") && strings.Contains(err.Error(), "dnsmasq config directory") { /* retry once after stop; guest boot race */ } }

Prevention

When it happens

Trigger: Starting with a DNS setting that enables dnsmasq in the guest (e.g. `--dns` with resolved delegate) while the guest image is broken, the bootstrap of the VM is incomplete, or SSH to the guest is flaky mid-start. Also if the guest OS variant lacks sudo or systemd.

Common situations: Custom disk images (forced, unverified) missing expected tooling; VM still booting when the post-start action runs; resource exhaustion in the guest making command execution fail.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/2f05ce1fd144746d. Report an issue: GitHub.