Querying an overlayfs

6,719

The kernel exposes the (full list of) mount options via /proc/mounts. For overlayfs, this includes the lowerdir and upperdir options:

$ cd /tmp
$ mkdir lower upper overlay
$ sudo mount -t overlayfs -o lowerdir=/tmp/lower,upperdir=/tmp/upper none /tmp/overlay
$ tail -n 1 /proc/mounts
none /tmp/overlay overlayfs rw,relatime,lowerdir=/tmp/lower,upperdir=/tmp/upper 0 0

In the general case, parsing this can be tricky as the paths themselves may contain spaces and commas which are used as field separators in the filesystem information. If you can assume that there are no spaces or commas in the paths, you might be able to manage with something like:

$ LOWER=$(tail -n 1 /proc/mounts | egrep -om1 'lowerdir=[^, ]*' | sed s/lowerdir=//)
$ UPPER=$(tail -n 1 /proc/mounts | egrep -om1 'upperdir=[^, ]*' | sed s/upperdir=//)
$ echo $LOWER $UPPER
/tmp/lower /tmp/upper
Share:
6,719

Related videos on Youtube

enzo1959
Author by

enzo1959

Updated on September 18, 2022

Comments

  • enzo1959
    enzo1959 over 1 year

    I'm looking for a way to query a mounted overlay filesystem (overlayfs) in order to check it's upper and lower directory, but until now I haven't found any suitable command for that. Is there is a way to do such a check ?

    I mounted the overlayfs with a command like the one below:

    mount -t overlayfs -o lowerdir=/mnt/root-ro,upperdir=/data/root-rw overlayfs-root ${rootmnt}
    

    The mount command didn't give me enough information:

    root@ubuntu12:~# mount -l
    overlayfs-root on / type overlayfs (rw)
    /dev/sda1 on /mnt/root-ro type ext4 (ro,relatime,data=ordered) [ROOT]
    /dev/sdb1 on /data type ext4 (rw,errors=remount-ro) [DATA]
    
    • Celada
      Celada almost 11 years
      Which type of "overlay" filesystem are you using?
    • enzo1959
      enzo1959 almost 11 years
      I'm using overlayfs
    • Celada
      Celada almost 11 years
      Oh! I didn't realize there was a filesystem actualy called "overlayfs". I'm only familiar with aufs and unionfs. The latter two do provide an easy way to query what their underlying branches are, but I wouldn't know about overlayfs.
    • enzo1959
      enzo1959 almost 11 years
      Please Celada, tell me about the method suitable for aufs and unionfs so I can check if something similar is working also for overlayfs
    • Celada
      Celada almost 11 years
      aufs: Under /sys/fs/aufs can be found one directory per instance of currently mounted aufs filesystem. Inside each directory, there are files br0, br1, and so on, which contain the names of each of the branches of that aufs instance.
    • enzo1959
      enzo1959 almost 11 years
      Thank for the answer. Unlikely I didn't find nothing similar for overlayfs.
  • enzo1959
    enzo1959 almost 11 years
    I see that some tutorial told that, that moiunt will shoe the detail of mounted overlayfs, but in practise, on ubuntu 12, the mount give me not enought info.
  • Programster
    Programster over 8 years
    note that in Ubuntu you would need to add mkdir workdir and add workdir=/tmp/workdir to the options in the mount command.