There are two issues with respect to your script :-

1. You make a copy of it. That will require a huge space somewhere.
2. Do you propose to replace it while it is in active use, or you put it offline first ?

The ideal place to have a script written for it is in minirt.gz, when one can specify a cheat code to increase the persistent file size. The script shall determine if there is enough room for the size increase. If yes, it shall expand it without making a copy, while it has not been mounted yet.

But this very risky without making a copy of it. The script has to be absolutely robust to handle all possible errors.