diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index d30e512158..e24c2a5055 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -42,6 +42,10 @@ func GetQemuProvider() machine.Provider { return qemuProvider } +func getCoreOSTargetMountPath(targetMountPath string) string { + return "/mnt" + targetMountPath +} + const ( VolumeTypeVirtfs = "virtfs" MountType9p = "9p" @@ -246,7 +250,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { virtfsOptions += ",readonly" } v.CmdLine = append(v.CmdLine, []string{"-virtfs", virtfsOptions}...) - mounts = append(mounts, Mount{Type: MountType9p, Tag: tag, Source: source, Target: target, ReadOnly: readonly}) + mounts = append(mounts, Mount{Type: MountType9p, Tag: tag, Source: source, Target: getCoreOSTargetMountPath(target), ReadOnly: readonly}) } } v.Mounts = mounts @@ -479,17 +483,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error { for _, mount := range v.Mounts { fmt.Printf("Mounting volume... %s:%s\n", mount.Source, mount.Target) // create mountpoint directory if it doesn't exist - // because / is immutable, we have to monkey around with permissions - // if we dont mount in /home or /mnt - args := []string{"-q", "--"} - if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") { - args = append(args, "sudo", "chattr", "-i", "/", ";") - } - args = append(args, "sudo", "mkdir", "-p", mount.Target) - if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") { - args = append(args, ";", "sudo", "chattr", "+i", "/", ";") - } - err = v.SSH(name, machine.SSHOptions{Args: args}) + err = v.SSH(name, machine.SSHOptions{Args: []string{"-q", "--", "sudo", "mkdir", "-p", mount.Target}}) if err != nil { return err } diff --git a/pkg/specgenutil/volumes.go b/pkg/specgenutil/volumes.go index 2bd79b186a..da97e3e39f 100644 --- a/pkg/specgenutil/volumes.go +++ b/pkg/specgenutil/volumes.go @@ -126,7 +126,7 @@ func parseVolumes(volumeFlag, mountFlag, tmpfsFlag []string, addReadOnlyTmpfs bo if err != nil { return nil, nil, nil, nil, errors.Wrapf(err, "error getting absolute path of %s", mount.Source) } - mount.Source = absSrc + mount.Source = util.GetSrcMountPath(absSrc) } finalMounts = append(finalMounts, mount) } diff --git a/pkg/util/utils_darwin.go b/pkg/util/utils_darwin.go index 66ae85e9cc..e0089f6635 100644 --- a/pkg/util/utils_darwin.go +++ b/pkg/util/utils_darwin.go @@ -10,3 +10,7 @@ import ( func GetContainerPidInformationDescriptors() ([]string, error) { return []string{}, errors.New("this function is not supported on darwin") } + +func GetSrcMountPath(absolutePath string) string { + return "/mnt" + absolutePath +} diff --git a/pkg/util/utils_linux.go b/pkg/util/utils_linux.go index 1cffab19d5..bcb1513a22 100644 --- a/pkg/util/utils_linux.go +++ b/pkg/util/utils_linux.go @@ -17,6 +17,10 @@ func GetContainerPidInformationDescriptors() ([]string, error) { return psgo.ListDescriptors(), nil } +func GetSrcMountPath(absolutePath string) string { + return absolutePath +} + // FindDeviceNodes parses /dev/ into a set of major:minor -> path, where // [major:minor] is the device's major and minor numbers formatted as, for // example, 2:0 and path is the path to the device node. diff --git a/pkg/util/utils_windows.go b/pkg/util/utils_windows.go index 2732124f21..256be42857 100644 --- a/pkg/util/utils_windows.go +++ b/pkg/util/utils_windows.go @@ -41,3 +41,7 @@ func GetRuntimeDir() (string, error) { func GetRootlessConfigHomeDir() (string, error) { return "", errors.New("this function is not implemented for windows") } + +func GetSrcMountPath(absolutePath string) string { + return "/mnt" + absolutePath +}