How to run a user boot script at MyCloud Gen2 (2.11.xx) devices

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.

  1. ssh into your mycloud. cd to /usr/local/config.
    The file config.xml contains the settings you locally set up from the dash board.

  2. You will find some cron entries in config.xml. We will „abuse“ one cron entry to run our boot script

  3. Save your original crontab. Run „crontab -l > crontab.orig“

  4. Edit config.xml. Find the entry for „stime“

  5. Edit this entry to run your boot script.

     		<stime>                                          
                                 <count>1</count>   
                                 <item id="1">
                                         <method>3</method>
                                         <1>*</1>
                                         <2>*</2>
                                         <3>*</3>                   
                                         <4>*</4>                       
                                         <5>*</5>
                                         <run>/usr/local/config/boot-script &amp;</run>
                                 </item>                            
                         </stime>           
    
  6. This will run your boot script immediatly after reboot when crond starts.

  7. 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!

5 Likes

Excellent idea! And why I haven’t guessed?

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.

2 Likes

One more hint:

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 “* * * * *”.

1 Like

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.

Thank you very much.

Bye

D

1 Like

In short: Use my “workaround” to enable all blocked stuff, then - make your own app or modify mine.

1 Like

Hi Fox_exe!

Thank you very much for your answer.

I followed your w.a. and it works for the shutdown button.
But I don’t undestand how to update twonky now…

1 Like

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.

https://community.wd.com/t/wd-my-cloud-twonky-server/157258

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.

1 Like

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.

@Fox_exe
What does wdcrack app do?

1 Like

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/

So far no one has posted a solution to the v2.x reboot issue in the following Twonky forum thread: http://www.twonkyforum.com/viewtopic.php?f=8&t=31310

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.

1 Like

The last reply in that post was mine.
:smiley:
same unsolved problem…

1 Like

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?

Thanks a lot

D

1 Like
  1. Download “Third party app GPL sources” from WD website. There is mksapkg tool for build WD App package
  2. Make “App” (Use any of GPL “sources” as base).
  3. apkg.sign & apkg.xml automatically generated by mksapkg tool, based on apkg.rc data
  4. Hmm… If you found something usefyl - add it to init.sh in any app (This file executed firs after reboot / while OS boot)

For unpack compiled apkg (app) use 7zip (He can automatically skip header info).
About fil structure inside app:

  • apkg.rc - Main file, info about this app
  • before_apkg.sh - Script, run before apkg install
  • preinst.sh - Preinstall script, exec before install.sh, but after before_apkg.sh
  • init.sh - exec every time, when OS start.
  • Install.sh & remove.sh - install/remove scripts
  • start.sh & stop.sh - For control app (exec when user change “enable this app” checkbox in web gui)
  • web/desc.xml - localisation file / app info (For web gui)
  • web/app_name.png - app icon for web gui
  • web/index.html - App web page for control.
1 Like

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.

RAC

1 Like

Hi @Fox_exe.

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 :slight_smile: )

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?

Bye

1 Like

is there a possibility to change townky with another dlna server? for example plex or minidlna.

1 Like

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:

https://community.wd.com/t/wd-mycloud-gen2-chroot-transmission-and-minidlna/148686

https://community.wd.com/t/app-minidlna-original-patched-for-firmware-v4-10-2015/94354

https://community.wd.com/t/clean-os-debian-openmediavault-and-other-firmwares/93714

https://community.wd.com/t/using-plex-media-server-with-my-cloud/94429/13

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”.

2 Likes

I was able to run the debian chroot services via the package and guide provided by FOX_EXE - thank you very much FOX_EXE. :smiley:

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.

1 Like

In simple - Create /etc/init.d/** script and enable it via update-rc.d.

Ps: Chroot start script just runs all scripts from /etc/rc3.d/

1 Like

I am sorry, I believe I have confused you :frowning:…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.

1 Like

Look here: /mnt/HD/HD_a2/Nas_Apps/WDCrack/start.sh

1 Like