# Contextualization run every time boot

**URL:** <https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140>\
**Category:** Product Support\
**Created:** [April 14, 2017, 10:14am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140 "2017-04-14T10:14:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![telecast](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/telecast/32/6187_2.png) [@telecast](https://forum.opennebula.io/u/telecast)\
**Post date:** [April 14, 2017, 10:14am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/1 "2017-04-14T10:14:01Z")

</div>

Hi All!  
My VM created from contextualization Image (Centos 7)  
I noticed that dropped my keys which was manually adding after first start my VM.  
I think that scripts of contextualization run every time boot (after reboot) and recreated my authorized\_keys file.  
Is it normal action for contextualization and how it to avoid (Is it have way to disable automatically autostart vmcontext after first boot VM)?

Thank you!  
telecast

---

<div class="post-metadata">

**Author:** ![cloudrck](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@cloudrck](https://forum.opennebula.io/u/cloudrck)\
**Post date:** [April 16, 2017, 12:50am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/2 "2017-04-16T00:50:35Z")

</div>

As far as I know you either need to use contextualization or not. I don’t think you can mix and match. So you’ll need to add the keys via Sunstone, or disable _Add SSH contextualization_ in the Context settings for that VM.

Someone can correct me if I’m wrong

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 16, 2017, 5:51pm UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/3 "2017-04-16T17:51:30Z")

</div>

you can add or edit existing scripts in /etc/one.context.d/ to achieve what you want

---

<div class="post-metadata">

**Author:** ![ranjith](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ranjith/32/5081_2.png) [@ranjith](https://forum.opennebula.io/u/ranjith)\
**Post date:** [April 17, 2017, 10:39am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/4 "2017-04-17T10:39:13Z")

</div>

I want to execute the startup scripts to be executed only the first time VM boot. I dont want the init script to be executed everytime VM boot (reboot). How can I achieve this?

---

<div class="post-metadata">

**Author:** ![knawnd](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/knawnd/32/6119_2.png) [@knawnd](https://forum.opennebula.io/u/knawnd)\
**Post date:** [April 17, 2017, 11:00am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/5 "2017-04-17T11:00:03Z")

</div>

One of the possible way is to create some file at certain location during first boot and check its existence before execution of startup scripts.

---

<div class="post-metadata">

**Author:** ![ranjith](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ranjith/32/5081_2.png) [@ranjith](https://forum.opennebula.io/u/ranjith)\
**Post date:** [April 17, 2017, 12:56pm UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/6 "2017-04-17T12:56:56Z")

</div>

I tried your suggestion. The files is getting created on boot. However for the second boot time, looks like the files is not present. It gets deleted upon boot. Is there any specific folder where the files will be persistent(permanent) across boot.

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 17, 2017, 6:08pm UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/7 "2017-04-17T18:08:06Z")

</div>

where you try to write? I think that for ex. /root/ will be fine

---

<div class="post-metadata">

**Author:** ![ranjith](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ranjith/32/5081_2.png) [@ranjith](https://forum.opennebula.io/u/ranjith)\
**Post date:** [April 18, 2017, 3:02am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/8 "2017-04-18T03:02:30Z")

</div>

I tried creating a file in /root/, even after that its not working. This is my startup script in context:

```
#!/bin/bash
FILE=\"/root/x.txt\"
if [-f \"$FILE\"];
then
   echo \"File $FILE exist.\"
else
   echo \"File $FILE does not exist\" >&2
   sudo echo \"some file content\" > /root/x.txt
   sudo apt-get install cmatrix
fi

```

Is anything wrong with this script?

---

<div class="post-metadata">

**Author:** ![ranjith](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ranjith/32/5081_2.png) [@ranjith](https://forum.opennebula.io/u/ranjith)\
**Post date:** [April 18, 2017, 4:41am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/9 "2017-04-18T04:41:26Z")

</div>

Hi. I have tried to create a file in /home/ directory. It works. Is this the right way?

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 18, 2017, 9:28am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/10 "2017-04-18T09:28:36Z")

</div>

there is no defined way, it’s up to you.

---

<div class="post-metadata">

**Author:** ![ranjith](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ranjith/32/5081_2.png) [@ranjith](https://forum.opennebula.io/u/ranjith)\
**Post date:** [April 18, 2017, 10:14am UTC](https://forum.opennebula.io/t/contextualization-run-every-time-boot/4140/11 "2017-04-18T10:14:44Z")

</div>

Thank you feldsam:slight\_smile:
