mirror of
https://github.com/rancher/os.git
synced 2025-09-20 10:03:59 +00:00
Make shared mount work in an initrd
This commit is contained in:
@@ -94,6 +94,7 @@ type RancherConfig struct {
|
|||||||
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
||||||
Debug bool `yaml:"debug,omitempty"`
|
Debug bool `yaml:"debug,omitempty"`
|
||||||
RmUsr bool `yaml:"rm_usr,omitempty"`
|
RmUsr bool `yaml:"rm_usr,omitempty"`
|
||||||
|
NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
|
||||||
Log bool `yaml:"log,omitempty"`
|
Log bool `yaml:"log,omitempty"`
|
||||||
ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
|
ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
|
||||||
Disable []string `yaml:"disable,omitempty"`
|
Disable []string `yaml:"disable,omitempty"`
|
||||||
|
@@ -19,4 +19,10 @@ for i in /opt/bin /usr/local/bin; do
|
|||||||
fi
|
fi
|
||||||
done
|
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
|
exec /usr/bin/dockerlaunch $DOCKER_BIN "$@" $DOCKER_OPTS >>/var/log/docker.log 2>&1
|
||||||
|
27
init/init.go
27
init/init.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/rancher/docker-from-scratch"
|
"github.com/rancher/docker-from-scratch"
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
"github.com/rancher/os/util"
|
"github.com/rancher/os/util"
|
||||||
@@ -179,6 +180,28 @@ func isInitrd() bool {
|
|||||||
return int64(stat.Type) == TMPFS_MAGIC || int64(stat.Type) == RAMFS_MAGIC
|
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 {
|
func RunInit() error {
|
||||||
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
|
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
|
||||||
if isInitrd() {
|
if isInitrd() {
|
||||||
@@ -218,9 +241,7 @@ func RunInit() error {
|
|||||||
return c, dockerlaunch.PrepareFs(&mountConfig)
|
return c, dockerlaunch.PrepareFs(&mountConfig)
|
||||||
},
|
},
|
||||||
initializeSelinux,
|
initializeSelinux,
|
||||||
func(c *config.CloudConfig) (*config.CloudConfig, error) {
|
setupSharedRoot,
|
||||||
return c, syscall.Mount("", "/", "", syscall.MS_SHARED|syscall.MS_REC, "")
|
|
||||||
},
|
|
||||||
sysInit,
|
sysInit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user