diff --git a/config/types.go b/config/types.go index e1fa12a5..7fde37ee 100644 --- a/config/types.go +++ b/config/types.go @@ -94,6 +94,7 @@ type RancherConfig struct { CloudInit CloudInit `yaml:"cloud_init,omitempty"` Debug bool `yaml:"debug,omitempty"` RmUsr bool `yaml:"rm_usr,omitempty"` + NoSharedRoot bool `yaml:"no_sharedroot,omitempty"` Log bool `yaml:"log,omitempty"` ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"` Disable []string `yaml:"disable,omitempty"` diff --git a/images/02-console/docker-init b/images/02-console/docker-init index d02bc809..974dfb71 100755 --- a/images/02-console/docker-init +++ b/images/02-console/docker-init @@ -19,4 +19,10 @@ for i in /opt/bin /usr/local/bin; do fi done +mount --make-shared / + +if [ "$(grep '/var/lib/docker /var/lib/docker ' /proc/self/mountinfo | awk '{print $9}')" = "rootfs" ]; then + export DOCKER_RAMDISK=1 +fi + exec /usr/bin/dockerlaunch $DOCKER_BIN "$@" $DOCKER_OPTS >>/var/log/docker.log 2>&1 diff --git a/init/init.go b/init/init.go index 5efb9b5b..722aa24d 100644 --- a/init/init.go +++ b/init/init.go @@ -11,6 +11,7 @@ import ( "syscall" log "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/mount" "github.com/rancher/docker-from-scratch" "github.com/rancher/os/config" "github.com/rancher/os/util" @@ -179,6 +180,28 @@ func isInitrd() bool { return int64(stat.Type) == TMPFS_MAGIC || int64(stat.Type) == RAMFS_MAGIC } +func setupSharedRoot(c *config.CloudConfig) (*config.CloudConfig, error) { + if !c.NoSharedRoot { + return c, nil + } + + if isInitrd() { + for _, i := range []string{"/mnt", "/media"} { + if err := os.Mkdir(i, 0755); err != nil { + return c, err + } + if err := mount.Mount("tmpfs", i, "tmpfs", "rw"); err != nil { + return c, err + } + if err := mount.MakeRShared(i); err != nil { + return c, err + } + } + return c, nil + } + return c, mount.MakeShared("/") +} + func RunInit() error { os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin") if isInitrd() { @@ -218,9 +241,7 @@ func RunInit() error { return c, dockerlaunch.PrepareFs(&mountConfig) }, initializeSelinux, - func(c *config.CloudConfig) (*config.CloudConfig, error) { - return c, syscall.Mount("", "/", "", syscall.MS_SHARED|syscall.MS_REC, "") - }, + setupSharedRoot, sysInit, }