示例#1
0
func (p linux) bindMountDir(mountSource, mountPoint string) error {
	bindMounter := boshdisk.NewLinuxBindMounter(p.diskManager.GetMounter())
	mounted, err := bindMounter.IsMounted(mountPoint)

	if !mounted && err == nil {
		err = bindMounter.Mount(mountSource, mountPoint)
		if err != nil {
			return bosherr.WrapErrorf(err, "Bind mounting %s dir over %s", mountSource, mountPoint)
		}
	} else if err != nil {
		return err
	}

	return bindMounter.RemountInPlace(mountPoint, "-o", "nodev", "-o", "noexec", "-o", "nosuid")
}
示例#2
0
func (p linux) SetupHomeDir() error {
	mounter := boshdisk.NewLinuxBindMounter(p.diskManager.GetMounter())
	isMounted, err := mounter.IsMounted("/home")
	if err != nil {
		return bosherr.WrapError(err, "Setup home dir, checking if mounted")
	}
	if !isMounted {
		err := mounter.Mount("/home", "/home")
		if err != nil {
			return bosherr.WrapError(err, "Setup home dir, mounting home")
		}
		err = mounter.RemountInPlace("/home", "-o", "nodev")
		if err != nil {
			return bosherr.WrapError(err, "Setup home dir, remount in place")
		}
	}
	return nil
}
示例#3
0
func (p linux) SetupTmpDir() error {
	systemTmpDir := "/tmp"
	boshTmpDir := p.dirProvider.TmpDir()
	boshRootTmpPath := path.Join(p.dirProvider.DataDir(), "root_tmp")

	err := p.fs.MkdirAll(boshTmpDir, tmpDirPermissions)
	if err != nil {
		return bosherr.WrapError(err, "Creating temp dir")
	}

	err = os.Setenv("TMPDIR", boshTmpDir)
	if err != nil {
		return bosherr.WrapError(err, "Setting TMPDIR")
	}

	err = p.changeTmpDirPermissions(systemTmpDir)
	if err != nil {
		return err
	}

	// /var/tmp is used for preserving temporary files between system reboots
	_, _, _, err = p.cmdRunner.RunCommand("chmod", "0700", "/var/tmp")
	if err != nil {
		return bosherr.WrapError(err, "chmod /var/tmp")
	}

	if p.options.UseDefaultTmpDir {
		return nil
	}

	_, _, _, err = p.cmdRunner.RunCommand("mkdir", "-p", boshRootTmpPath)
	if err != nil {
		return bosherr.WrapError(err, "Creating root tmp dir")
	}

	bindMounter := boshdisk.NewLinuxBindMounter(p.diskManager.GetMounter())
	mounted, err := bindMounter.IsMounted(systemTmpDir)

	if !mounted && err == nil {
		// change permissions
		_, _, _, err = p.cmdRunner.RunCommand("chmod", "0700", boshRootTmpPath)
		if err != nil {
			return bosherr.WrapError(err, "Chmoding root tmp dir")
		}

		// mount
		err = bindMounter.Mount(boshRootTmpPath, systemTmpDir, "-o", "nodev", "-o", "noexec", "-o", "nosuid")
		if err != nil {
			return bosherr.WrapError(err, "Bind mounting root tmp dir over /tmp")
		}

		// change permissions for mount point
		err = p.changeTmpDirPermissions(systemTmpDir)
		if err != nil {
			return err
		}
	} else if err != nil {
		return err
	}

	return nil
}