diff --git a/initramfs/cmd/init/pkg/etc/etc.go b/initramfs/cmd/init/pkg/etc/etc.go index 21feb7f49..eaa30ae3a 100644 --- a/initramfs/cmd/init/pkg/etc/etc.go +++ b/initramfs/cmd/init/pkg/etc/etc.go @@ -11,7 +11,6 @@ import ( "strings" "text/template" - "github.com/autonomy/dianemo/initramfs/pkg/userdata" "github.com/autonomy/dianemo/initramfs/pkg/version" ) @@ -24,12 +23,6 @@ ff02::1 ip6-allnodes ff02::2 ip6-allrouters ` -const resolvConfTemplate = ` -{{- range $_, $ip := . -}} -nameserver {{ $ip }} -{{- end -}} -` - const osReleaseTemplate = ` NAME="{{ .Name }}" ID={{ .ID }} @@ -67,30 +60,12 @@ func Hosts(s, hostname, ip string) (err error) { return nil } -// ResolvConf renders a valid /etc/resolv.conf file and writes it to disk. -func ResolvConf(s string, userdata userdata.UserData) (err error) { - tmpl, err := template.New("").Parse(resolvConfTemplate) - if err != nil { +// ResolvConf symlinks /proc/net/pnp to /etc/resolv.conf. See +// https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt. +func ResolvConf(s string) (err error) { + if err = os.Symlink("/proc/net/pnp", path.Join(s, "/etc/resolv.conf")); err != nil { return } - var buf []byte - writer := bytes.NewBuffer(buf) - ip, err := DefaultGateway() - if err != nil { - return - } - nameservers := []string{ip} - if userdata.OS.Network != nil { - nameservers = append(nameservers, userdata.OS.Network.Nameservers...) - } - err = tmpl.Execute(writer, nameservers) - if err != nil { - return - } - - if err := ioutil.WriteFile(path.Join(s, "/etc/resolv.conf"), writer.Bytes(), 0644); err != nil { - return fmt.Errorf("write /etc/resolv.conf: %v", err) - } return nil } diff --git a/initramfs/cmd/init/pkg/rootfs/rootfs.go b/initramfs/cmd/init/pkg/rootfs/rootfs.go index eb976f1ab..910116c25 100644 --- a/initramfs/cmd/init/pkg/rootfs/rootfs.go +++ b/initramfs/cmd/init/pkg/rootfs/rootfs.go @@ -40,7 +40,7 @@ func Prepare(s string, userdata userdata.UserData) (err error) { return } // Create /etc/resolv.conf. - if err = etc.ResolvConf(s, userdata); err != nil { + if err = etc.ResolvConf(s); err != nil { return } // Create /etc/os-release. diff --git a/initramfs/pkg/userdata/userdata.go b/initramfs/pkg/userdata/userdata.go index 9bdd88229..bce8a93ad 100644 --- a/initramfs/pkg/userdata/userdata.go +++ b/initramfs/pkg/userdata/userdata.go @@ -57,9 +57,7 @@ type OS struct { // Network represents the operating system networking specific configuration // options. -type Network struct { - Nameservers []string `yaml:"nameservers,omitempty"` -} +type Network struct{} // Security represents the operating system security specific configuration // options.