Add option to skip kernel check for older kernels which have been patched to support multiple lower directories in overlayfs.
Fixes #24023
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"os" |
| 11 | 11 |
"os/exec" |
| 12 | 12 |
"path" |
| 13 |
+ "strconv" |
|
| 13 | 14 |
"strings" |
| 14 | 15 |
"syscall" |
| 15 | 16 |
|
| ... | ... |
@@ -21,6 +22,7 @@ import ( |
| 21 | 21 |
"github.com/docker/docker/pkg/directory" |
| 22 | 22 |
"github.com/docker/docker/pkg/idtools" |
| 23 | 23 |
"github.com/docker/docker/pkg/mount" |
| 24 |
+ "github.com/docker/docker/pkg/parsers" |
|
| 24 | 25 |
"github.com/docker/docker/pkg/parsers/kernel" |
| 25 | 26 |
|
| 26 | 27 |
"github.com/opencontainers/runc/libcontainer/label" |
| ... | ... |
@@ -92,6 +94,10 @@ func init() {
|
| 92 | 92 |
// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error. |
| 93 | 93 |
// If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned. |
| 94 | 94 |
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
|
| 95 |
+ opts, err := parseOptions(options) |
|
| 96 |
+ if err != nil {
|
|
| 97 |
+ return nil, err |
|
| 98 |
+ } |
|
| 95 | 99 |
|
| 96 | 100 |
if err := supportsOverlay(); err != nil {
|
| 97 | 101 |
return nil, graphdriver.ErrNotSupported |
| ... | ... |
@@ -103,7 +109,10 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap |
| 103 | 103 |
return nil, err |
| 104 | 104 |
} |
| 105 | 105 |
if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 {
|
| 106 |
- return nil, graphdriver.ErrNotSupported |
|
| 106 |
+ if !opts.overrideKernelCheck {
|
|
| 107 |
+ return nil, graphdriver.ErrNotSupported |
|
| 108 |
+ } |
|
| 109 |
+ logrus.Warnf("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update")
|
|
| 107 | 110 |
} |
| 108 | 111 |
|
| 109 | 112 |
fsMagic, err := graphdriver.GetFSMagic(home) |
| ... | ... |
@@ -144,6 +153,31 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap |
| 144 | 144 |
return d, nil |
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 |
+type overlayOptions struct {
|
|
| 148 |
+ overrideKernelCheck bool |
|
| 149 |
+} |
|
| 150 |
+ |
|
| 151 |
+func parseOptions(options []string) (*overlayOptions, error) {
|
|
| 152 |
+ o := &overlayOptions{}
|
|
| 153 |
+ for _, option := range options {
|
|
| 154 |
+ key, val, err := parsers.ParseKeyValueOpt(option) |
|
| 155 |
+ if err != nil {
|
|
| 156 |
+ return nil, err |
|
| 157 |
+ } |
|
| 158 |
+ key = strings.ToLower(key) |
|
| 159 |
+ switch key {
|
|
| 160 |
+ case "overlay2.override_kernel_check": |
|
| 161 |
+ o.overrideKernelCheck, err = strconv.ParseBool(val) |
|
| 162 |
+ if err != nil {
|
|
| 163 |
+ return nil, err |
|
| 164 |
+ } |
|
| 165 |
+ default: |
|
| 166 |
+ return nil, fmt.Errorf("overlay2: Unknown option %s\n", key)
|
|
| 167 |
+ } |
|
| 168 |
+ } |
|
| 169 |
+ return o, nil |
|
| 170 |
+} |
|
| 171 |
+ |
|
| 147 | 172 |
func supportsOverlay() error {
|
| 148 | 173 |
// We can try to modprobe overlay first before looking at |
| 149 | 174 |
// proc/filesystems for when overlay is supported |
| ... | ... |
@@ -566,6 +566,17 @@ options for `zfs` start with `zfs` and options for `btrfs` start with `btrfs`. |
| 566 | 566 |
Example use: |
| 567 | 567 |
$ docker daemon -s btrfs --storage-opt btrfs.min_space=10G |
| 568 | 568 |
|
| 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 |
+ |
|
| 569 | 580 |
## Docker runtime execution options |
| 570 | 581 |
|
| 571 | 582 |
The Docker daemon relies on a |