[Sony Xperia X Performance ROMs, Kernels, Recoverie] AdrianDC:
Note about MultiROM and SDCardFS devices

Here's a general note about MultiROM that involves issues with SDCardFS usage:

More and more devices OEMs are starting to use SDCardFS enabled by default on their releases.

Depending on the device and installations, we started finding random behaviours of MultiROM secondary ROMs.

Basically the issue is that a booted secondary ROM using SDCardFS would prevent access to the "Internal Storage",

mostly visible by an "unmounted" internal storage and mostly all Google applications failing in sequence.

A more in-depth search shows that running an "ls -l" on the internal storage paths

fail directly with an "-EXDEV" > "cross-device linkage" error, which means the original and target devices don't match.

The SDCardFS kernel driver is actually returning this -EXDEV failure when it detects such an issue.

Going a step further means comparing which partitions are mounted where, through "mount".

We can confirm SDCardFS is being used by the ROM through the following outputs :

/data/media on /mnt/runtime/default/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,multiuser,allow_utime_grp)

/data/media on /storage/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,multiuser,allow_utime_grp)

/data/media on /mnt/runtime/read/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,multiuser,allow_utime_grp)

/data/media on /mnt/runtime/write/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,multiuser,allow_utime_grp)

However, it also means that /data/media is "mounted" as an sdcardfs file system in the regular internal storage paths.

And the interesting part concerning MultiROM is that we actually mount /data/media on our own to match our paths.

On a "working" secondary installation, we have this type of mount :

/dev/block/mmcblk0p54 on /data/media type ext4 (rw,seclabel,relatime,noauto_da_alloc,errors=panic,data=ordered)

However on a "failing with -EXDEV" secondary installation, we have this type of mount :

/dev/block/mmcblk0p54 on /data/media/0 type ext4 (rw,seclabel,relatime,noauto_da_alloc,errors=panic,data=ordered)

As we can see, the internal partition is being mounted on /data/media/0, which is not an issue by itself,

but the fact the /data/media is later mounted as internal storage means that we're creating a cross-device linkage:

/data/media is owned by the /data partition, running from our external storage with MultiROM, and its sub-path ./0 is on the Internal,

whereas the working situation is that /data/media is directly owned by its original partition hence no cross-device linkage.

Now the question would be : Why the mounted path differs ?

The "multirom_create_media_link" function handles the internal storage mounting (https://github.com/multirom-dev/multirom/commit/c9bd12186baa6911d46138c6c77379c6c3eaa767)

A proper output of this function in the kernel logs is "multirom: Making media dir: api 25, media_new 1, /realdata/media to /data/media"

and a faulty one for SDCardFS to work is "Making media dir: api 25, media_new 0, /realdata/media to /data/media/0"

This was never an issue since 4+ years because the paths and loop would be invisibly used,

and the missing path created through the recursive mkdir hence path resolution was never an issue.

On the other hand, SDCardFS prevents this linkage therefore introducing the issue.

An initial fix can be found here, tested on the Xperia X Performance with and without an internal storage matching the issue.

https://github.com/multirom-dev/multirom/pull/11/commits/81295cd6971317d955cb0c78b41d147b891a601b

The change is also valid for non-sdcardfs devices, tested on Sony 8960 for example, since the path is used the same way.

I wrote this in public here in case other MultiROM devs or new maintainers would face such an issue,

and would not (yet) use our "multirom-dev" sources for updated MultiROM projects.