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
Related videos on Youtube
Author by
enzo1959
Updated on September 18, 2022Comments
-
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 almost 11 yearsWhich type of "overlay" filesystem are you using?
-
enzo1959 almost 11 yearsI'm using overlayfs
-
Celada almost 11 yearsOh! 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 almost 11 yearsPlease Celada, tell me about the method suitable for aufs and unionfs so I can check if something similar is working also for overlayfs
-
Celada almost 11 yearsaufs: Under
/sys/fs/aufs
can be found one directory per instance of currently mounted aufs filesystem. Inside each directory, there are filesbr0
,br1
, and so on, which contain the names of each of the branches of that aufs instance. -
enzo1959 almost 11 yearsThank for the answer. Unlikely I didn't find nothing similar for overlayfs.
-
-
enzo1959 almost 11 yearsI 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 over 8 yearsnote that in Ubuntu you would need to add
mkdir workdir
and addworkdir=/tmp/workdir
to the options in the mount command.