mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-27 03:46:19 +08:00
Add --no-pivot option for containers on ramdisk
This adds a `--no-pivot` cli flag to runc so that a container's rootfs can be located ontop of ramdisk/tmpfs and not fail because you cannot pivot root. This should be a cli flag and not part of the spec because this is a detail of the host/runtime environment and not an attribute of a container. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -158,9 +158,16 @@ var allowedDevices = []*configs.Device{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateOpts struct {
|
||||||
|
CgroupName string
|
||||||
|
UseSystemdCgroup bool
|
||||||
|
NoPivotRoot bool
|
||||||
|
Spec *specs.Spec
|
||||||
|
}
|
||||||
|
|
||||||
// CreateLibcontainerConfig creates a new libcontainer configuration from a
|
// CreateLibcontainerConfig creates a new libcontainer configuration from a
|
||||||
// given specification and a cgroup name
|
// given specification and a cgroup name
|
||||||
func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *specs.Spec) (*configs.Config, error) {
|
func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
|
||||||
// runc's cwd will always be the bundle path
|
// runc's cwd will always be the bundle path
|
||||||
rcwd, err := os.Getwd()
|
rcwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -170,14 +177,16 @@ func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *sp
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
spec := opts.Spec
|
||||||
rootfsPath := spec.Root.Path
|
rootfsPath := spec.Root.Path
|
||||||
if !filepath.IsAbs(rootfsPath) {
|
if !filepath.IsAbs(rootfsPath) {
|
||||||
rootfsPath = filepath.Join(cwd, rootfsPath)
|
rootfsPath = filepath.Join(cwd, rootfsPath)
|
||||||
}
|
}
|
||||||
config := &configs.Config{
|
config := &configs.Config{
|
||||||
Rootfs: rootfsPath,
|
Rootfs: rootfsPath,
|
||||||
Readonlyfs: spec.Root.Readonly,
|
NoPivotRoot: opts.NoPivotRoot,
|
||||||
Hostname: spec.Hostname,
|
Readonlyfs: spec.Root.Readonly,
|
||||||
|
Hostname: spec.Hostname,
|
||||||
Labels: []string{
|
Labels: []string{
|
||||||
"bundle=" + cwd,
|
"bundle=" + cwd,
|
||||||
},
|
},
|
||||||
@@ -211,7 +220,7 @@ func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *sp
|
|||||||
if err := setupUserNamespace(spec, config); err != nil {
|
if err := setupUserNamespace(spec, config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, err := createCgroupConfig(cgroupName, useSystemdCgroup, spec)
|
c, err := createCgroupConfig(opts.CgroupName, opts.UseSystemdCgroup, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
11
restore.go
11
restore.go
@@ -73,6 +73,10 @@ using the runc checkpoint command.`,
|
|||||||
Name: "no-subreaper",
|
Name: "no-subreaper",
|
||||||
Usage: "disable the use of the subreaper used to reap reparented processes",
|
Usage: "disable the use of the subreaper used to reap reparented processes",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "no-pivot",
|
||||||
|
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
imagePath := context.String("image-path")
|
imagePath := context.String("image-path")
|
||||||
@@ -93,7 +97,12 @@ using the runc checkpoint command.`,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
config, err := specconv.CreateLibcontainerConfig(id, context.GlobalBool("systemd-cgroup"), spec)
|
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
|
||||||
|
CgroupName: id,
|
||||||
|
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
|
||||||
|
NoPivotRoot: context.Bool("no-pivot"),
|
||||||
|
Spec: spec,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
4
start.go
4
start.go
@@ -53,6 +53,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
|
|||||||
Name: "no-subreaper",
|
Name: "no-subreaper",
|
||||||
Usage: "disable the use of the subreaper used to reap reparented processes",
|
Usage: "disable the use of the subreaper used to reap reparented processes",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "no-pivot",
|
||||||
|
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
bundle := context.String("bundle")
|
bundle := context.String("bundle")
|
||||||
|
7
utils.go
7
utils.go
@@ -175,7 +175,12 @@ func createPidFile(path string, process *libcontainer.Process) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcontainer.Container, error) {
|
func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcontainer.Container, error) {
|
||||||
config, err := specconv.CreateLibcontainerConfig(id, context.GlobalBool("systemd-cgroup"), spec)
|
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
|
||||||
|
CgroupName: id,
|
||||||
|
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
|
||||||
|
NoPivotRoot: context.Bool("no-pivot"),
|
||||||
|
Spec: spec,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user