From cfacb4d5208e7bfa590ff568a37bceb05fe9af4a Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 2 Jul 2024 15:31:55 +0200 Subject: [PATCH] mount /sys and /run during container exec Also unify mounting of sys, run, proc, and dev as occuring within the chroot and without bind mounts from the host. Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + .../app/wwctl/container/exec/child/main.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3b340c..4fffdf0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Capture "broken" symlinks during container build. #1267 - Fix the issue that removing lines during wwctl overlay edit didn't work. #1235 - Fix the issue that new files created with wwctl overlay edit have 755 permissions. #1236 +- Mount `/sys` and `/run` during `wwctl container exec`. #1287 ## v4.5.4, 2024-06-12 diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 62d09a20..a6502111 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -135,11 +135,6 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { } } - err = syscall.Mount("/dev", path.Join(containerPath, "/dev"), "", syscall.MS_BIND, "") - if err != nil { - return errors.Wrap(err, "failed to mount /dev") - } - for _, mntPnt := range mountPts { err = syscall.Mount(mntPnt.Source, path.Join(containerPath, mntPnt.Dest), "", syscall.MS_BIND, "") if err != nil { @@ -166,9 +161,17 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { return errors.Wrap(err, "failed to chdir") } - err = syscall.Mount("/proc", "/proc", "proc", 0, "") - if err != nil { - return errors.Wrap(err, "failed to mount proc") + if err := syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, ""); err != nil { + return errors.Wrap(err, "failed to mount /dev") + } + if err := syscall.Mount("sysfs", "/sys", "sysfs", 0, ""); err != nil { + return errors.Wrap(err, "failed to mount /sys") + } + if err := syscall.Mount("proc", "/proc", "proc", 0, ""); err != nil { + return errors.Wrap(err, "failed to mount /proc") + } + if err := syscall.Mount("tmpfs", "/run", "tmpfs", 0, ""); err != nil { + return errors.Wrap(err, "failed to mount /run") } os.Setenv("PS1", ps1Str)