0

I have a linux media player that was very common before android's age. It is a MIPS running Linux Venus 2.6.12.6 and has 2 sata, 2 usb and 1 sdcard port. Since the flash memory is very limited, I installed optware, ssh and nano on sdcard and put in

ln -s /tmp/usbmounts/sdb1/opt /opt

The sdcard can remain plugged for good since I won't use sdcard for media. It works very well if I do not have other usb plugged or if I plug other usb after boot. But if I plug other usb before boot, the sdcard port always be mounted to sdc or sdd and of course the link won't work. I (kind of) resolved this by putting a script at boot to locate /opt and link accordingly. However, I found that there is other activity that can change the mount point after boot.

The player mainly runs a software called Dvdplayer. This software has a menu on screen for user to choose media to play. Every time when this menu is called up, the mount point seems to change, EVEN WITHOUT any additional usb plug in. Say if after boot, my sdcard is mounted to sdb, after calling up the menu, it changed to sdc (sdb has nothing). Calling up the menu again, it becomes sdd (sdb and sdc has nothing). Call the menu the 3rd time, it goes back to sdc and then to and fore between sdc and sdd, never sdb again.

Searching the internet, I understand this is hotplugging and I am able to locate the software. But different from the usual linux hotplug, the softare is an executable elf file instead of a script, and I cannot find any system variables related the hotplug, such as SUBSYSTEM, ACTION, PRODUCT, TYPE, INTERFACE, DEVICE etc. Instead, it has a sequence number in /sys/kernel/hotplug_seqnum. It has empty folders like /tmp/lock/hotplug/convert_tmp, ...mount_tmp, ...rename_tmp and ...volume_lock. mount_tmp is the only folder that has its date changed, but still is always empty.

I've tried to trap the hotplug by moving the /sbin/hotplug to /sbin/sbin/hotplug and put in my own hotplug script in /sbin/hotplug. The script looks like this

mount / -o remount,rw
echo $* >> /usr/local/etc/init.d/hotplug.log
/sbin/sbin/hotplug $*

But it doesn't work: after calling the menu, nothing was logged and all plug-in mounts were lost.

All I wanted to do now is to trap the hotplug activities and relink my /opt correctly. Appreciate any help or a better method of ensuring the correct link for /opt.

0

Better to explicitly say that this is a shell script and I wish to use ${@} instead of $*:

#!/bin/sh
mount -o remount,rw /
echo ${@} >/tmp/log.txt
echo >>/tmp/log.txt
env >>/tmp/log.txt # if /tmp is writable or tmpfs
exec /sbin/sbin/hotplug "${@}"

If the system is sane, this should work. Many embedded, however, are not. Beware.

| improve this answer | |
  • thank you for the reply. Tried the script but problem remains. Lost all plug-in mounts and nothing logged. Any other idea? – senderj Dec 5 '15 at 7:40
  • Do you have persistent tmpfs mounted somewhere? Was /tmp/log.txt (or whatever) being created? If that embedded system is filled with vendor bloatware then you have little chances to get it work in a sane way. Most "Chinese" embeddeds are just a clusterhacks in both kernel and userland just to "make it work", without any care to make it perform sane, no matter router, phone or player. – user140866 Dec 5 '15 at 11:54
  • FYI, script I posted works for me, I used mips embedded board with my custom firmware, with busybox mdev. I placed script in place of /sbin/mdev. When I inserted usb flash, it made / rw, logged block argument and some environment variables supplied by kernel. Then script executed /bin/busybox mdev "${@}" and flash storage appeared as /dev/sda. – user140866 Dec 5 '15 at 12:01
  • You can also check contents of /proc/sys/kernel/hotplug and even repoint the hotplug helper to your script by writing the value into it. But, as I said, there are clusterhacks chinese firmwares that even can !!watch!! this file for changes and force original value back before you notice with their own binaryware. So, I say again: beware of hardware which lie to you. – user140866 Dec 5 '15 at 12:07
  • it works. @siblynx thanks for the advise. I think I have to go back to linux 101. I always thought that the first line is a comment. But without it, in my case the script does not work. – senderj Dec 7 '15 at 5:27

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.