Prepare clean VM


The goal is to remove unnecessary files after creating a VM.
E.g. /etc/one-contex.d/* with all files in this directory and /tmp/one-context-tmp
I’ve tried using self-deleting scripts & directories with bash scripting.

For example:
(script file via context)



rpm -e one-context-4.10.0-1.noarch
rm -rf $one_dir

export currentdir

function finish {
    echo "shredding ${currentscript}"
    shred -u ${currentscript};
    if [ "$(ls -A ${currentdir})" ]; then
       echo "${currentdir} is not empty!"
        echo "${currentdir} is empty, removing!"
        rmdir ${currentdir};


trap finish EXIT

echo "exiting script"

Also i try to remove with $0 each script, but there are problem with stat, because such of them run later then another, and

How i can safetly delete this files after instantiate VM?

Issue solved.

Hi @GabrielDias,

Could you please share how you solved the issue?

Kind Regards,
Anton Todorov

Yes, of course!
As default I use contextualization script with some changes.