[GUIDE] How to Make Persistent System Changes (crontab, etc)


#21

Yes, that should work.


#22

Again, thanks!

Now I have to figure a way to do it. Maybe using a cron entry? hmmm time to think!


#23

Update: I’ve managed to create a crontab entry, which copies a modified version of afp.conf to /etc/netatalk every 5 minutes (I wish I could just copy it once and be done with it, but I am not sure how to instract crontab to run the copy only once).

However, I strongly believe that this is a very serious issue, that Western Digital should address. It is crazy, for a consumer device, to need you to ssh to it, change the permissions manually, change the afp.conf file manually, and change ubi0_0 manually in order to set the NAS up, so that it sets safe permissions to whatever you copy to it. I have been using afp to mount disks from several different systems (including an Apple Server, a Centos-based server, an ancient Synology Cube station etc) all these afp implementations maintain the permissions of files copied, as they were in the original disk. So I have to assume that WD’s afp implementation is faulty.

Thanks are due to the participants of this discussion, for offering me the guidance to -somehow- fix a sever security issue affecting my MyCloudMirror device.


#24

Thanks for some interesting concepts!

A while ago I posted some instructions how to run a user boot script. It’s also based on crontab hack.

You will find it here: How to run a user boot script at MyCloud Gen2 (2.11.xx) devices


#25

I saw the thread, but the PR4100 and similar models have a different system architecture, requiring different methods to make persistent system changes. The most notable difference is that the My Cloud Gen 2 stores system files on a hard drive partition, while the PR4100 and similar models use NAND flash partitions. However, they all seem to share a similar or identical config.xml file structure.


#26

Thank you dswv42 for this excellent guide!

Quick question: Is there any way to add a @reboot entry to the crontab?

Thanks.


#27

I’m sure it’s possible, but I haven’t tested it.


#28

What should be the best way to add a cronjob using @reboot?

Also, how can I add a ssh key persistently?

Thanks in advance.


#29

If you have any app installed from the WD app store, you can modify the init / clean scripts to get persistent changes.

Example: persistent home directory (including .ssh dir with authorized_keys)

Go to the app directory.

cd /shares/Volume_1/Nas_Prog
ls

Pick an app, I’m using my entware package but you can use any dir that doesn’t start with an underscore.

cd entware

Prepare the home dir backup directory

mkdir -p home

Edit init.sh

vi init.sh

On app start (e.g. on boot), you want to restore your home directory to /home/root. Add this somewhere in the script. Press i to enter edit mode.

# the first argument is this application's directory
APPDIR=$1

# restore the home directory
rsync -a "${APPDIR}/home/" /home/root

Press escape to exit edit mode. Type :wq to write changes and exit.
Then edit clean.sh

vi clean.sh

On shutdown you want to backup your current home directory to {APPDIR}/home.
Press i for edit mode.

APPDIR=$1

# remove old backup
rm -rf "${APPDIR}/home"
# backup current home directory
rsync -a /home/root/ "${APPDIR}/home"

Press escape to exit edit mode. Type :wq to write changes and exit.

Now test the changes. We’ll check our if our .ash_history gets backed up. Use -a to show hidden files.

ls -a home            # nothing backed up yet
sh clean.sh .         # note the dot!
ls -a home            # tadaaaa!

#30

You say you looked at the source for xmldbc. Where did you find it?


#31

Is there absolutely no other option for scheduling jobs?

S3 backups from the GUI do not do what I need, crontab edits don’t stick, and I would rather not void the warranty. This is frustrating.


#32

Not that I’m aware of.


#33

I meant the GPL source code, as a whole, not for any specific program or module. Link below…