# State scrips cleanup in Yocto

**URL:** <https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449>\
**Category:** General Discussions\
**Tags:** yocto, state-scripts, mender-client\
**Created:** [January 10, 2025, 9:48am UTC](https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449 "2025-01-10T09:48:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![filcopetti](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/filcopetti/32/2375_2.png) [@filcopetti](https://hub.mender.io/u/filcopetti)\
**Post date:** [January 10, 2025, 9:48am UTC](https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449/1 "2025-01-10T09:48:34Z")

</div>

Hi,  
I’m developing yocto images. I need to run some state scripts based on the customer, so on some images mender needs to run script ArtifactInstall\_Leave\_11 while in some images it needs to run script ArtifactInstall\_Leave\_11 + ArtifactInstall\_Leave\_12 .  
To do so, I’ve created two packages in the image, where package A installs ArtifactInstall\_Leave\_11 while package B installs ArtifactInstall\_Leave\_12 .

If I run the build for image with package A+B I correctly get ArtifactInstall\_Leave\_11 + ArtifactInstall\_Leave\_12 , but if then I build the image with only package A I also get ArtifactInstall\_Leave\_11 + ArtifactInstall\_Leave\_12 .  
If I remove manually the file: tmp/deploy/images//mender-state-scripts/ArtifactInstall\_Leave\_12  
then In the image I get only ArtifactInstall\_Leave\_11.

Do you know why this happens and how I can get rid of this behavior? is there a way to get the state scripts cleaned among builds?

Thanks!

---

<div class="post-metadata">

**Author:** ![filcopetti](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/filcopetti/32/2375_2.png) [@filcopetti](https://hub.mender.io/u/filcopetti)\
**Post date:** [January 13, 2025, 8:37am UTC](https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449/2 "2025-01-13T08:37:06Z")

</div>

just to be more clear, I think there is a BUG in the state scripts:  
If I remove a package containing a state script this won’t be removed from a image build later on.

Filippo

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [January 14, 2025, 8:14am UTC](https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449/3 "2025-01-14T08:14:02Z")

</div>

Hi @filcopetti,

Thanks for the report, I’ll try to reproduce and understand the behavior. The underlying reason is probably that the state scripts are _not_ part of the image, but just bundled into the artifact. My guess is that this causes some “interesting” effects.

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![filcopetti](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/filcopetti/32/2375_2.png) [@filcopetti](https://hub.mender.io/u/filcopetti)\
**Post date:** [January 14, 2025, 8:29am UTC](https://hub.mender.io/t/state-scrips-cleanup-in-yocto/7449/4 "2025-01-14T08:29:55Z")

</div>

Thanks Josef,

Only later I noted the red note here:  
[https://docs.mender.io/operating-system-updates-yocto-project/image-customization/state-scripts](https://docs.mender.io/operating-system-updates-yocto-project/image-customization/state-scripts)  
Ok, this fixes the issue but dramatically increases the building time, I believe there are better ways to implement this feature

many thanks,  
Filippo
