Config.txt turns into empty file

First, I use osmc on raspberry pi 2 on usb power connected to the tv (which is not really recommended) and turn the pi on and off as i turn on/off the tv.

Sometimes it wont boot and there are 4 green flashing lights. I fix this by taking out the microsd card and copying config.txt from a backup and overwriting the 0/empty config.txt file on the card.

why does this happen?

is there a way to lock the config.txt file to stop it from being written to? or so that it cannot change the files contents. it seems to be only this config.txt file that is causing the boot failure.

The microSD card may be dying.

Seriously? You know you shouldn’t be doing this and then you are asking about filesystem corruption?

I guess you could try changing config.txt to read only. But there isn’t much that can protect from the corruption under-powered and pulling the plug will cause.

Ah, I missed that.

Yes – powering from the TV will cause problems.