0

I'm trying to accomplish something fairly odd, so bear with me.

I've added an external SD card to my old Droid Mini (basically just for an experiment to see whether or not I could expand the storage capability). It's currently running Lineage OS 13.

The issue is that the external SD adapter is very power hungry, and the kernel on this version (3.4.42) doesn't properly support autosuspend.

I can force the device into low power mode by unbinding the SCSI device from the USB device, but obviously it disappears if I do that.

I read that bind mounts can preserve the directory structure of the source folder even if it is removed, but I can't seem to get that to work (see here - "It is possible to unmount /some/where, in which case /else/where remains mounted.")

The idea is to wait until the USB device goes idle, then manually suspend it by unbinding it until it is needed again. However, if I unbind the device, the "stat" file I'm using to monitor idleness ALSO disappears, do I can't use that to check if activity is requested.

So my (maybe silly) idea was to make bind mount of the external card to a "virtual" USB device which doesn't disappear when the source is removed, and re-attaches it when it's needed.

Baby steps though, any ideas how I might go about preserving a "fake" drive for the system to operate through? Bind-mounts don't seem to do quite the right thing here.

Thanks, R

  • that sounds really crazy... – iBug Nov 2 '18 at 1:31
  • Yup, but the silly part is that my friend's phone with a just SLIGHTLY newer kernel autosuspends just fine, I guess that function was back ported to his kernel. – flyingfishfinger Nov 2 '18 at 1:53
  • wait for me to compose an answer, a few minutes – iBug Nov 2 '18 at 1:55
0

That sounds really crazy...

At first glance, I have a guess that while you can unmount the source directory of a bind mount, you must keep the underlying device attached for a bind mount to work.

I confirmed my guess in experiments on my OnePlus 6 (Android Linux 4.9.65) and my Ubuntu 18.04 (real Linux 4.15.0) and the result is same.

On Ubuntu, I inserted a USB flash drive (ext4 filesystem) and mounted it to /mnt/usb, and I bind mounted /mnt/usb/data to /mnt/bind

  • I unmounted /mnt/usb while keeping the flash drive attached, and I can access /mnt/bind with no error. All changes to /mnt/bind reflected to <drive root>/data (verified later).
  • Then I detached the flash drive and attempted to access /mnt/bind, and got this message:

    ls: reading directory '/mnt/bind': Input/output error
    

On my OnePlus 6, I inserted a USB flash drive via OTG (exFAT filesystem). I mounted the device /dev/block/vold/public:8:97 to /data/dev, and bind-mounted /data/dev/Android to /data/bind.

  • I unmounted /data/dev while keeping the OTG attached, and all the data remains in /data/bind and is accessible without errors.
  • Then I turned off "OTG function" in the Settings app, the Android mount point /mnt/media_rw/xxxx-xxxx disappeared, but I can still access my bind mount.
  • Next I detached the OTG drive and attempted to access /data/bind and got this:

    ls: reading directory `/data/bind`: I/O error
    

    A side note is, unlike Ubuntu, access to /data/bind remained available for around half a minute, but directories that I didn't previously visited weren't accessible anymore, only the directories that I visited before detaching the drive was still accessible.

That's it. The conclusion is in the top paragraph.

  • That makes sense. This thought actually also occurred to me, but then I realized that I'm not actually physically disconnecting the device. I'm unbinding it from /sys/bus/USB/....something by writing the device ID to the bind/unbind files, so I was hoping this would work out. I'll have to do some more experiments. – flyingfishfinger Nov 2 '18 at 2:31
  • @flyingfishfinger If my answer makes sense, would you mind marking it as accepted? :P – iBug Nov 2 '18 at 2:34
  • Let me try some permutations of this tomorrow and I'll get back to you :) – flyingfishfinger Nov 2 '18 at 2:36
  • @flyingfishfinger Good. Actions speak louder than words. – iBug Nov 2 '18 at 2:38
  • What's the difference between ejecting, unbinding and unmounting? Roughly following your steps, I can still access both /bind and /dev after I eject the drive through Settings (the /mnt/media_rw/ entry disappeared, like yours). This does not seem to be equivalent to unbinding the usb-storage driver though, since when I do that both /bind and /data turn up empty. – flyingfishfinger Nov 2 '18 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.