mirror of
https://github.com/mudler/luet.git
synced 2025-09-18 08:12:19 +00:00
Support mount with target folder in box exec
Also mount bind before pivotroot, this fixes bind mounting in general
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -63,15 +64,25 @@ func (b *DefaultBox) Exec() error {
|
||||
if err := mountDev(b.Root); err != nil {
|
||||
return errors.Wrap(err, "Failed mounting dev on rootfs")
|
||||
}
|
||||
if err := PivotRoot(b.Root); err != nil {
|
||||
return errors.Wrap(err, "Failed switching pivot on rootfs")
|
||||
}
|
||||
|
||||
for _, hostMount := range b.HostMounts {
|
||||
if err := mountBind(hostMount, b.Root); err != nil {
|
||||
target := hostMount
|
||||
if strings.Contains(hostMount, ":") {
|
||||
dest := strings.Split(hostMount, ":")
|
||||
if len(dest) != 2 {
|
||||
return errors.New("Invalid arguments for mount, it can be: fullpath, or source:target")
|
||||
}
|
||||
hostMount = dest[0]
|
||||
target = dest[1]
|
||||
}
|
||||
if err := mountBind(hostMount, b.Root, target); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Failed mounting %s on rootfs", hostMount))
|
||||
}
|
||||
}
|
||||
|
||||
if err := PivotRoot(b.Root); err != nil {
|
||||
return errors.Wrap(err, "Failed switching pivot on rootfs")
|
||||
}
|
||||
cmd := exec.Command(b.Cmd, b.Args...)
|
||||
|
||||
if b.Stdin {
|
||||
|
@@ -75,9 +75,9 @@ func mountProc(newroot string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func mountBind(hostfolder, newroot string) error {
|
||||
func mountBind(hostfolder, newroot, dst string) error {
|
||||
source := hostfolder
|
||||
target := filepath.Join(newroot, hostfolder)
|
||||
target := filepath.Join(newroot, dst)
|
||||
fstype := "bind"
|
||||
data := ""
|
||||
|
||||
@@ -90,5 +90,5 @@ func mountBind(hostfolder, newroot string) error {
|
||||
}
|
||||
|
||||
func mountDev(newroot string) error {
|
||||
return mountBind("/dev", newroot)
|
||||
return mountBind("/dev", newroot, "/dev")
|
||||
}
|
||||
|
Reference in New Issue
Block a user