文档

Alibaba Cloud Linux 2系统的ECS实例挂载Overlayfs时共用挂载目录导致挂载失败

更新时间:

问题描述

在Alibaba Cloud Linux 2系统的ECS实例中挂载Overlayfs失败。存在该问题的ECS实例有以下特征:

  • 镜像:所有的Alibaba Cloud Linux 2镜像版本

  • 内核:所有的Alibaba Cloud Linux 2内核(Cloud Kernel)

  • 执行dmesg命令,在内核日志中会出现以下错误日志的一条:

    • kernel-4.19.67-16.al7之前的版本

      overlayfs: lowerdir is in-use as upperdir/workdir
      
      overlayfs: lowerdir path overlapping in-use upperdir/workdir
      
      overlayfs: upperdir is in-use by another mount, mount with '-o index=off' to override exclusive upperdir protection.
      
      overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.
    • kernel-4.19.67-16.al7及之后的版本

      overlayfs: lowerdir is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection.
      
      overlayfs: workdir is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection.
      
      overlayfs: upperdir is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection.

问题原因

Overlayfs的挂载参数lowerdir、upperdir或workdir不能同时作为另一个挂载点的upperdir或workdir,否则可能存在未知风险。即在挂载过程中,当内核检测到以上情况时,会返回-EBUSY错误信息,同时打印错误日志。

解决方案

临时解决方法

重要
  • 使用该临时解决方法可能存在未知风险,使用之前请慎重评估。

  • Overlayfs的主要使用场景是容器服务,容器服务中一直存在多个挂载点共用同一个upperdir或workdir现象,但是系统内核支持通过关闭index特性(即指定index=off挂载参数),来规避这个问题。

  1. 确认内核版本中的报错信息。

    • kernel-4.19.67-16.al7之前的版本 执行dmesg命令后,如果您出现以下错误日志的一条,则可以参考后续步骤进行处理。

      说明

      如果您出现另外两条报错信息,本方案无法解决该问题。

      overlayfs: upperdir is in-use by another mount, mount with '-o index=off' to override exclusive upperdir protection.
      
      overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.
    • kernel-4.19.67-16.al7及之后的版本

      kernel-4.19.67-16.al7及之后的版本的错误日志都可以参考以下步骤进行处理。

  2. 执行挂载Overlayfs的命令时,指定index=off挂载参数,则可以规避以上报错,成功挂载Overlayfs。此时内核会打印以下其中一条日志。

    overlayfs: lowerdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    
    overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    
    overlayfs: workdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.

根本解决方法

  1. 在挂载Overlayfs之前,您需要执行mount命令,查看之前挂载Overlayfs的相关参数,包括每个挂载点的lowerdir、upperdir、workdir参数,其输出格式类似如下。

    overlay on /.../merged type overlay (rw,relatime,lowerdir=...,upperdir=...,workdir=...)
  2. 确认需要挂载的Overlayfs的挂载参数lowerdir、upperdir或workdir没有同时作为另一个挂载点的upperdir或workdir,即可正常挂载。

  • 本页导读 (1)
文档反馈