# rm: can't remove '/tmp/balena': Resource busy

**URL:** <https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888>\
**Category:** Product support\
**Tags:** support\
**Created:** [May 8, 2023, 2:52pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888 "2023-05-08T14:52:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_n](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@thomas\_n](https://forums.balena.io/u/thomas_n)\
**Post date:** [May 8, 2023, 2:52pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/1 "2023-05-08T14:52:56Z")

</div>

I have a rather generic container I want to run on Balena (jlesage/firefox), but whenever I start it, it exits with following errors:

```auto
[Logs] [8/5/2023 16:36:51] [firefox] [cont-init] 10-clean-tmp-dir.sh: executing...
[Logs] [8/5/2023 16:36:51] [firefox] [cont-init] 10-clean-tmp-dir.sh: rm: can't remove '/tmp/balena': Resource busy
[Logs] [8/5/2023 16:36:51] [firefox] [cont-init] 10-clean-tmp-dir.sh: rm: can't remove '/tmp/resin': Resource busy
[Logs] [8/5/2023 16:36:51] [firefox] [cont-init] 10-clean-tmp-dir.sh: terminated with error 1.

```

I can’t find any information on what could be causing this. My docker-compose.yaml looks as follows:

```auto
version: '2'
volumes:
  guacamole-config:
  firefox-config:
services:
  guacamole:
    image: unsafetypin/guacamole:latest
    restart: always
    ports:
      - 80:8080
    volumes:
      - guacamole-config:/config
  firefox:
    image: jlesage/firefox:latest
    restart: never
    volumes:
      - firefox-config:/config
    ports:
      - 5800:5800
      - 5900:5900
    environment:
      - KEEP_APP_RUNNING=1
      - FF_OPEN_URL=https://www.google.com
      - SECURE_CONNECTION=0
      - VNC_PASSWORD=totallysafepassword

```

---

<div class="post-metadata">

**Author:** ![cywang117](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/cywang117/32/6307_2.png) [@cywang117](https://forums.balena.io/u/cywang117)\
**Post date:** [May 9, 2023, 6:43pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/5 "2023-05-09T18:43:10Z")

</div>

Hi,

It looks like there is a script in your firefox container that tries to remove the entirety of the `/tmp` directory. This does not work for balena, as the Supervisor bind mounts a subdirectory under `/tmp` on host into `/tmp/balena` in container for the purpose of inter-container communication via update locks, see [Update locks - Balena Documentation](https://docs.balena.io/learn/deploy/release-strategy/update-locking/) . As I’m not sure what the need for clearing the `/tmp` directory in container is, I’d recommend trying to get the contents of 10-clean-tmp-dir.sh as well as its surrounding script context to see what it’s needed for and whether you can remove the dependency yourself. Since the container you’re trying to run exits soon after each start, you may take a snapshot of the container with `balena commit` (which functions the same as `docker commit`) in order to get a snapshot image. You can then explore the snapshot with `balena run --rm -it SNAPSHOT_IMAGE` in order to see the startup order of scripts. Alternatively, if you do not wish to try to remove the dependency on the tmp script yourself, you can open an issue on the jlesage/firefox GitHub repo to ask the maintainers directly what the purpose of the /tmp directory is and whether it’s possible to not purge it on startup.

Let us know how that goes!

Thanks,  
Christina

---

<div class="post-metadata">

**Author:** ![myarmolinsky](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@myarmolinsky](https://forums.balena.io/u/myarmolinsky)\
**Post date:** [May 15, 2023, 12:30pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/7 "2023-05-15T12:30:05Z")

</div>

Hi, following up on my colleague’s previous message. Have you seen the pointers she provided on how to proceed? Reiterating the points below:

- Try to get the contents of 10-clean-tmp-dir.sh as well as its surrounding script context to see what it’s needed for and whether you can remove the dependency yourself. Since the container you’re trying to run exits soon after each start, you may take a snapshot of the container with `balena commit` (which functions the same as `docker commit`) in order to get a snapshot image. You can then explore the snapshot with `balena run --rm -it SNAPSHOT_IMAGE` in order to see the startup order of scripts.
- Alternatively, if you do not wish to try to remove the dependency on the tmp script yourself, you can open an issue on the jlesage/firefox GitHub repo to ask the maintainers directly what the purpose of the /tmp directory is and whether it’s possible to not purge it on startup.

Please let us know whether you’ve tried them (please do try them if you have not) and let us know how they went for you

---

<div class="post-metadata">

**Author:** ![thomas\_n](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@thomas\_n](https://forums.balena.io/u/thomas_n)\
**Post date:** [May 15, 2023, 12:49pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/9 "2023-05-15T12:49:04Z")

</div>

Yes, thank you both for the info. This does seem to be the cause and the resolution is clear. In this case it is quite a bit of work as the script is in the base image and not the container image itself.

Just a thought: it would be helpful if this was documented anywhere or at least more clearly as a restriction/requirement of containers.

Kind regards,

Thomas

---

<div class="post-metadata">

**Author:** ![myarmolinsky](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@myarmolinsky](https://forums.balena.io/u/myarmolinsky)\
**Post date:** [May 15, 2023, 1:29pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/10 "2023-05-15T13:29:27Z")

</div>

Glad to hear the cause has been successfully identified and the resolution is clear.

Thank you for the feedback, I’ll bring it up for internal discussion. If there is an ideal/fitting place for such information, it would indeed be beneficial to have it documented.

---

<div class="post-metadata">

**Author:** ![thomas\_n](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@thomas\_n](https://forums.balena.io/u/thomas_n)\
**Post date:** [May 17, 2023, 11:47am UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/12 "2023-05-17T11:47:13Z")

</div>

> [@myarmolinsky](#):
>
> Please let us know whether you’ve tried them (please do try them if you have not) and let us know how they went for you

Just a quick update from my part. I ended up making a new Dockerfile in which I replace the offending script `10-clean-tmp-dir.sh` with a modified version.

The new `Dockerfile`:

```auto
FROM jlesage/firefox

COPY 10-clean-tmp-dir.sh /etc/cont-init.d/10-clean-tmp-dir.sh

```

The new `10-clean-tmp-dir.sh`, saved in the same directory as the `Dockerfile`:

```auto
#!/bin/sh
#
# Clean the /tmp directory.
#

set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error.

# rm -rf /tmp/* /tmp/.[!.]* <- this was the original command

# Delete everything except for the `balena` and `resin` directories and their contents.
find /tmp -mindepth 1 ! \( -path "/tmp/balena/*" -o -path "/tmp/resin/*" \) -delete

# vim:ft=sh:ts=4:sw=4:et:sts=4

```

I’m not 100% sure of the solution as this is not really my area of expertise, but so far it seems to work without any warnings or adverse effects.

---

<div class="post-metadata">

**Author:** ![cywang117](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/cywang117/32/6307_2.png) [@cywang117](https://forums.balena.io/u/cywang117)\
**Post date:** [November 29, 2024, 8:06pm UTC](https://forums.balena.io/t/rm-cant-remove-tmp-balena-resource-busy/367888/13 "2024-11-29T20:06:31Z")

</div>

Hey @thomas_n ,

The new `clean-tmp-dir` script looks good to me. Great work on finding a solution!

I’ve clarified the necessity of the `/tmp/balena` or legacy `/tmp/resin` directories in our [docs](https://github.com/balena-os/balena-supervisor/pull/2391). Thanks for pointing this out!

Regards,  
Christina
