How to run a boot script at MyCloud Gen2 (2.11.xx) devices
Disclaimer: The following can brick your device. Please use only if you are fit with crontabs and unix shell scripting.
The latest myclouds are rather closed systems. You can change some settings with the web dashboard, but everything else you do on a shell level will be gone after reboot.
User @Fox_exe has done some amazing work to set up a chroot debian environment parallel to the built in system. But after reboot you have to set it up again by hand from shell.
Running a user boot script is not available. Except if you use the following hack.
ssh into your mycloud. cd to /usr/local/config.
The file config.xml contains the settings you locally set up from the dash board.
You will find some cron entries in config.xml. We will „abuse“ one cron entry to run our boot script
Save your original crontab. Run „crontab -l > crontab.orig“
This will run your boot script immediatly after reboot when crond starts.
Your boot script must do the following steps:
recover original crontab
make sure script it is not run twice
do whatever you want after boot
My boot script looks like that:
#! /bin/sh
CRONTAB=/var/spool/cron/crontabs/root
CONFIG=/usr/local/config
BOOTRUN=/tmp/bootscript-run
# Remove boot-script from crontab and
# recover crontab
cd $CONFIG
cp crontab.orig $CRONTAB
# don't run twice
if [ -f $BOOTRUN ]; then exit 0
fi
touch $BOOTRUN
# boot code comes here
# root profile
cp profile.local $HOME/.profile
# other user jobs
That’s it. Your boot script will be run rather early in the boot process (when crond starts up). You may need some delay (sleep) to wait until your mycloud is fully booted and running.
After a firmware upgrade, you may need to set it up again. So save your scripts!
Need save script to Data Volue (/mnt/HD_a2) for save it after firmware upgrade (Cron job saved automatically)
Dont forget to make your script executable!
Note: Later i update my chroot script for this start method.
It is important to always recover the original crontab as a first step in the script. Because there are some WD maintenance scripts running at midnight which will read the hacked crontab from the xml-file and put it back in place. Then your boot script would run again.
My script outlined above will take care of those problems.
And one more: WD/busybox crond does not understand “@reboot” in crontab. Therefore use “* * * * *”.
Hi guys.
I really need your help…
I’m in trouble with my new my cloud gen 2 firmware 2.21.111.
I have 2 main problems.
1 - Into the dashboard there isn’t a shutdown button. Really it is there, but hidden.
I found a way to show it through a little change in a css file. But the mycloud restore the original one at every reboot.
2 - I want to update the twonky server at the version 8. Similar, I found a way to resolve my problem, but the mycloud restore the original one at every reboot also.
I found our post about a script to launch some changes at the boot.
Can you help me to create a script to launch some command at boot? Simply rename some directories or files and replace the original with my own modified stuff.
I tried to understand your script, but I’m afraid to brick the my cloud, so I need an exchange of views with you.
The following thread, while it is discussing the older first gen v4.x My Cloud, details a method of upgrading Twonky on a My Cloud. You may want to see if that method will work on v2.x and let us know how it goes. One or two posts in that thread mention the v2.x firmware and some possible issues.
It should be noted that upgrading Twonky is not officially supported by WD and doing so may cause problems with the My Cloud and or its firmware. And as always using SSH may potentially void the My Cloud warranty.
Hi Bennon.
Unfortunately this method doesn’t work with gen2 mycloud, because it has a read-only file system, unlike the gen1.
Every reboot delete the modified files and twonky too.
Correct. While you CAN actually upgrade the Twonky program, it is the reboot that apparently overwrites some newer Twonky files. I assume you’ve pulled down and are using the specific WD v2.x version listed on the Twonky 8.3 page: http://www.twonkyforum.com/downloads/8.3/
I’d assume, not having a v2.x version to actually look at, that the files being used to overwrite the updated Twonky files are coming from some other location within the My Cloud firmware. Perhaps one could overwrite those backup files, so each time the reboot is performed the newer files are simply rewritten over the top of the existing files. Or if possible, copy the files that are being replaced at reboot to another location then, if possible, issue a copy command after the My Cloud replaces those files during the reboot process. Don’t know about the v2.x firmware, which is the topic of this thread, but with the v4.x firmware there is a user file (/etc/rc2.d/S98user-start) one can use to perform such actions as copying file back that WD might replace during boot or firmware upgrade.
Hi @Fox_exe.
Thank you very much for your help!
I used your guide and wdcrack and my first problem is solved! Fantastic!
Now I have some questions for you.
1 - How can I create/modify apps?
2 - How can I update the version of twonky that saves itself every reboot? (config included if possible).
3 - What is the apkg.sign file?
4 - There are some commands that I can use at every reboot to optimize the system?
There i a builtin feature of the gen2 that will run a mfg_start on reboot. If a mounted USB is named mfg_WDMYCLOUD and contains a file called fun_plug. You can see this code in /usr/ocal/modules/script/system_init.
1 - Ok, found it.
2 - my first problem. I installed the tar.gz under ubuntu, but I didn’t find how to launch the program. also, there isn’t a source for twonky or other dlna in it.
3 - Ok understood
4 - I asked if there is already a list of tested useful command to insert into the init.sh file (for example in your wdcrack )
I have some problem to use the same login id twice. So I must change every time. There is a way to send a private message into the forum?
Yes but it typically involves using SSH to modify or replace the existing My Cloud OS with an alternate OS. Use the forum search feature, magnifying glass upper right, to find other discussions on using alternate media servers and other features. Here are several past discussions:
Note: Such modifications are NOT supported by WD and if one isn’t careful they can “brick” their My Cloud rendering it inoperable and requiring an “unbrick”.
I was able to run the debian chroot services via the package and guide provided by FOX_EXE - thank you very much FOX_EXE.
However, now am trying to run this chroot services automatically after every restart…I followed the guide above but still unsure I am doing the right job…
Can someone please guide me through this?
Basically, I have the chroot executable (.sh) file placed in /mnt/HD/HD_a2/chroot and need this to auto run after every restart.
I am sorry, I believe I have confused you …I want to know the procedure to auto run the following command, “/mnt/HD/HD_a2/chroot/chroot-debian.sh start”, everytime WD MY Cloud Gen2 starts or reboot.