I designed hotplug script for sd-card which checks for its presence, performs fcsk, then tries to mount it, if unsuccessful it formats the card - all this is done to eliminate required human intervention in case of corrupt or inappropriate volume on the card.
My problem is the script works for about a minute, and system starts all related services, which are expected to work in card, before I ever mount the card, therefore after mounting actual open files become shadowed and not accessible, and written into the internal flash.
I can of course try to restart needed services after card mount, but part of their data already went to the internal flash. Another problem is I perform system logging onto the card, and restarting the logging will break the chain of messages.
I am ok if system would hold on with its general booting until card is checked, initialized and mounted, but I do not know/can not figure out how to do it. Maybe hotplug script is wrong location to do all the tasks.
Any ideas? Thanks!
disable the services, start them manually, after the card's mounted ?
Thanks. I have thought about it - make special package which will start during booting, and after completion will start all remaining as daemons/services. But there's a problem. One of services which must start after card initialization is logd/logread - which will put logs onto the card. One service is less than 3, but the same problem remains...
then make it start, logging to /tmp/, stop it just before the mount of the SD.
move the log file to the SD, and softlink it back to /tmp, start logd again.
Thanks! One more idea. I see
lrwxrwxrwx 1 root root 13 Aug 31 14:27 K89log -> ../init.d/log
lrwxrwxrwx 1 root root 13 Aug 31 14:27 S12log -> ../init.d/log
but if I make that new package mounting the card at S11/K90? I can't find anywhere (maybe it is so obvious?) if kernel goes to another level when previous has fully completed (e.g. all scripts at S11 finished before starting scripts at S12)?
S = start, K = kill
The lower the no, the earlier the service starts during boot, and stops during a controlled shutdown/reboot.
S01 will start before S02, but I don't think there's a guarantee S01 finishes before S02 starts.
If you edit the init.d script, you'll see the S and K values in there, if you disable a service,
the S and K soft links get deleted, then get recreated again, when the service is (re)enabled.
This is a question! I would say, if I'd develop operating system logic, I would do exactly this way otherwise sequencing has no sense. I would start all services with same number is parallel, and would not proceed to next level until all current terminate (with success or error).
It might just like that, I haven't looked into it though, 1st world problem for me,
since I don't run openwrt on my router
I suspect the mechanism must be the same for all linux operating systems.
Have you tried Extroot?
https://openwrt.org/docs/guide-user/additional-software/extroot_configuration
What I am doing right now with hotplug is similar to that, the problem is that services which are expected to write to the card start up faster than hotplug script finishes. I simply do not want to deal with stopping and restarting those services, I just want system to withhold until script initializing the card finishes.
I asked on SO too, and it seems I am facing misunderstanding in what I am asking.
The possible solution, and the best and most graceful solution, would be to make package with name S10mypackage, which would perform fsck and mount the card - if the system does not proceed to S11xxx scripts until all S10xxx, including my script, finish.
I would be surprised if it is not the case, but I need to be sure. As people say on SO, that init "shell script" executes all S* scripts "synchronously", whatever it means. So if all scripts are started at once, what is the benefit of their numbering?
Is it really worth the hassle?
The purpose is basically the same as Extroot.
And you can easily automate its setup/upgrade following the wiki.
I did some tests.
- scripts are NOT started and executed in parallel. They are being executed one by one.
- next script, even with same order number, will not start until previous finishes.
- the whole script is executed first, and then
start_service()
is called. Until it finishes next script is not executed. - shutdown is performed synchronously to the scripts: outstanding shutdown request will be delayed until current script finishes execuiton.
This is very logical behavior matching my understanding of how it must be.
Edit: now next question: when mmcblk0 is being added to the system configuration and by whom. I do not see any service explicitly referring to hotplug.
Not sure. I meant when /dev/mmcblk0 and related /sys/fs entries appear. So that I can then run block info
and mount it.
This is what I exactly did! And by doing fsck and mkfs it runs so long other services start and I have to reinvent bicycle stopping them, mounting the card, and starting them. Why bothering with all these if I can design init script which will suspend all further initialization until sdcard is initialized, checked and mounted.
Setting up another init.d
script before logger starts where I check / format / mount the card works as expected. Problem solved.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.