From 9de97786488c5c33cdea8fdf934e692223f13459 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sun, 6 Dec 2020 10:00:04 -0800 Subject: [PATCH] Add bind points for /dev/ and /etc/resolv.conf into the container when exec'ing --- internal/app/wwctl/container/exec/child/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 6e906fd8..928de7a0 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -1,13 +1,15 @@ -// +build linux +// + build linux package child import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "os" + "path" "syscall" ) @@ -25,10 +27,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - syscall.Mount("", "/", "", syscall.MS_PRIVATE, "") - containerPath := container.RootFsDir(containerName) + syscall.Mount("", "/", "", syscall.MS_PRIVATE, "") + syscall.Mount("/dev", path.Join(containerPath, "/dev"), "", syscall.MS_BIND, "") + + if util.IsFile(path.Join(containerPath, "/etc/resolv.conf")) == true { + syscall.Mount("/etc/resolv.conf", path.Join(containerPath, "/etc/resolv.conf"), "", syscall.MS_BIND, "") + } + syscall.Chroot(containerPath) os.Chdir("/")