Skip to content

Commit adfeccf

Browse files
dmcgowanTibor Vass
authored andcommitted
Allow option to override kernel check in overlay2
Add option to skip kernel check for older kernels which have been patched to support multiple lower directories in overlayfs. Fixes moby#24023 Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan) (cherry picked from commit ff98da0) Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 72274de commit adfeccf

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

daemon/graphdriver/overlay2/overlay.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"os/exec"
1212
"path"
13+
"strconv"
1314
"strings"
1415
"syscall"
1516

@@ -21,6 +22,7 @@ import (
2122
"github.com/docker/docker/pkg/directory"
2223
"github.com/docker/docker/pkg/idtools"
2324
"github.com/docker/docker/pkg/mount"
25+
"github.com/docker/docker/pkg/parsers"
2426
"github.com/docker/docker/pkg/parsers/kernel"
2527

2628
"github.com/opencontainers/runc/libcontainer/label"
@@ -92,6 +94,10 @@ func init() {
9294
// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error.
9395
// If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned.
9496
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
97+
opts, err := parseOptions(options)
98+
if err != nil {
99+
return nil, err
100+
}
95101

96102
if err := supportsOverlay(); err != nil {
97103
return nil, graphdriver.ErrNotSupported
@@ -103,7 +109,10 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
103109
return nil, err
104110
}
105111
if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 {
106-
return nil, graphdriver.ErrNotSupported
112+
if !opts.overrideKernelCheck {
113+
return nil, graphdriver.ErrNotSupported
114+
}
115+
logrus.Warnf("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update")
107116
}
108117

109118
fsMagic, err := graphdriver.GetFSMagic(home)
@@ -144,6 +153,31 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
144153
return d, nil
145154
}
146155

156+
type overlayOptions struct {
157+
overrideKernelCheck bool
158+
}
159+
160+
func parseOptions(options []string) (*overlayOptions, error) {
161+
o := &overlayOptions{}
162+
for _, option := range options {
163+
key, val, err := parsers.ParseKeyValueOpt(option)
164+
if err != nil {
165+
return nil, err
166+
}
167+
key = strings.ToLower(key)
168+
switch key {
169+
case "overlay2.override_kernel_check":
170+
o.overrideKernelCheck, err = strconv.ParseBool(val)
171+
if err != nil {
172+
return nil, err
173+
}
174+
default:
175+
return nil, fmt.Errorf("overlay2: Unknown option %s\n", key)
176+
}
177+
}
178+
return o, nil
179+
}
180+
147181
func supportsOverlay() error {
148182
// We can try to modprobe overlay first before looking at
149183
// proc/filesystems for when overlay is supported

docs/reference/commandline/dockerd.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ options for `zfs` start with `zfs` and options for `btrfs` start with `btrfs`.
566566
Example use:
567567
$ docker daemon -s btrfs --storage-opt btrfs.min_space=10G
568568

569+
#### Overlay2 options
570+
571+
* `overlay2.override_kernel_check`
572+
573+
Overrides the Linux kernel version check allowing overlay2. Support for
574+
specifying multiple lower directories needed by overlay2 was added to the
575+
Linux kernel in 4.0.0. However some older kernel versions may be patched
576+
to add multiple lower directory support for OverlayFS. This option should
577+
only be used after verifying this support exists in the kernel. Applying
578+
this option on a kernel without this support will cause failures on mount.
579+
569580
## Docker runtime execution options
570581

571582
The Docker daemon relies on a

0 commit comments

Comments
 (0)