# 'apt update' doesn't work on raspberrypi3 and raspberry-pi2 #11447

**URL:** <https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402>\
**Category:** Product support\
**Tags:** raspberrypi3\
**Created:** [December 3, 2021, 1:48pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402 "2021-12-03T13:48:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![antmak](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@antmak](https://forums.balena.io/u/antmak)\
**Post date:** [December 3, 2021, 1:48pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/1 "2021-12-03T13:48:15Z")

</div>

Hi! I tried to use balenalib/rpi-raspbian:buster , balenalib/raspberry-pi2:buster , balenalib/raspberrypi3:buster. The first one works fine, but the latter two don’t work. I can’t complete `apt update` command. My hosts are on several places (Europe and Asia).

Could you help me with it, please?

reproduce:

```auto
# on amd64 host
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
$ docker run --rm -it balenalib/raspberrypi3:buster bash
...
apt update
<geting stuck here>

```

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [December 20, 2021, 6:43pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/4 "2021-12-20T18:43:43Z")

</div>

Hello, we’ve been able to reproduce this on true armv7 hardware so it seems to not be related to emulation.

```auto
balena run --rm -it balenalib/raspberrypi3:buster apt-get update

Digest: sha256:5d7ff4a4990c2d60663683626c9be7e6ff3b78272aa8ba07fe118cd910d5c0c4
Status: Downloaded newer image for balenalib/raspberrypi3:buster
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]             
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]                                       
Get:4 http://archive.raspberrypi.org/debian buster InRelease [32.6 kB]                                                                             
Get:5 http://archive.raspbian.org/raspbian buster InRelease [15.0 kB]                                           
0% [Working]

```

However, the same base image when used in a Dockerfile as `FROM` command seems to work, so something about the docker build vs run context seems to matter.

```auto
FROM balenalib/raspberrypi3:buster
RUN apt-get update

```

```auto
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM balenalib/raspberrypi3:buster
 ---> e9b6b7ca4bec
Step 2/2 : RUN apt-get update
 ---> [Warning] The requested image's platform (linux/arm/v7) does not match the detected host platform (linux/amd64) and no specific platform was requested
 ---> Running in f312d0626b8e
Here are a few details about this Docker image (For more information please visit https://www.balena.io/docs/reference/base-images/base-images/): 
Architecture: ARM v7 
OS: Debian Buster 
Variant: run variant 
Default variable(s): UDEV=off 
Extra features: 
- Easy way to install packages with `install_packages <package-name>` command 
- Run anywhere with cross-build feature (for ARM only) 
- Keep the container idling with `balena-idle` command 
- Show base image details with `balena-info` command
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://archive.raspbian.org/raspbian buster InRelease [15.0 kB]
Get:5 http://archive.raspberrypi.org/debian buster InRelease [32.6 kB]
Get:6 http://security.debian.org/debian-security buster/updates/main armhf Packages [306 kB]
Get:7 http://deb.debian.org/debian buster/main armhf Packages [7698 kB]
Get:8 http://deb.debian.org/debian buster-updates/main armhf Packages [14.4 kB]
Get:9 http://archive.raspbian.org/raspbian buster/main armhf Packages [13.0 MB]
Get:10 http://archive.raspbian.org/raspbian buster/rpi armhf Packages [1360 B]
Get:11 http://archive.raspbian.org/raspbian buster/contrib armhf Packages [58.8 kB]
Get:12 http://archive.raspbian.org/raspbian buster/non-free armhf Packages [104 kB]
Get:13 http://archive.raspbian.org/raspbian buster/firmware armhf Packages [1232 B]
Get:14 http://archive.raspberrypi.org/debian buster/main armhf Packages [393 kB]
Fetched 21.9 MB in 17s (1288 kB/s)
Reading package lists...
Removing intermediate container f312d0626b8e
 ---> d2546a2d6436
Successfully built d2546a2d6436

```

I’m still investigating but perhaps someone in the community has seen this.

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [December 20, 2021, 7:06pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/5 "2021-12-20T19:06:23Z")

</div>

I’ve narrowed it down to `bash` vs `sh` in the base image. If you specify `sh` as your shell command it seems to work. Likewise if you change your shell in your Dockerfile to `SHELL ["/bin/bash, "-c"]` it will break.

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [December 21, 2021, 2:07pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/7 "2021-12-21T14:07:03Z")

</div>

So I need to keep investigating, but it seems that the error is avoided when using `/bin/sh` as the cmd since this is actually a wrapper script that prints balena-info before executing `/bin/sh.real`. So the workaround is to not use bash as your command but instead use sh until we figure out why this is.

This is also fully reproducible on amd64 images, so this seems to be an issue with apt running as pid 1, but we will have to see why that is.

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [December 21, 2021, 6:20pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/12 "2021-12-21T18:20:58Z")

</div>

Hey @antmak, we’ve narrowed this down to an issue with the temporary shim we install over /bin/sh to print image details before restoring the original sh binary. `apt-get update` calls `apt-key` which execs another process (via the function ExecGPGV) which is the one that needs sh to be a shell. If sh is not an actual shell, thousands of processes will be spawned all trying to do the same thing (verify a key), and this could/does halt the system. My laptop crashed a few times while testing this if I forgot to kill the container process.

I have opened a GH issue to re-evaluate how we have implemented this shim in our base images. In the meantime, some of the known workarounds are:

- call sh first so the binary is restored before apt calls it (`docker run --rm -it balenalib/raspberrypi:buster sh apt-get update`)
- don’t specify bash as a shell at all, and allow the default shell to run once (`docker run --rm -it balenalib/raspberrypi:buster apt-get update`)
- start the container shell with sh and run apt after the shell starts (`docker run --rm -it balenalib/raspberrypi:buster sh`)

Again this only impacts the very first execution of `/bin/sh`. If any other commands like an interactive shell run first, the apt command will end up using the real binary. It’s only when skipping the initial sh shell that apt has to deal with it and fails.

---

<div class="post-metadata">

**Author:** ![frederikheld](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@frederikheld](https://forums.balena.io/u/frederikheld)\
**Post date:** [May 9, 2023, 12:55pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/16 "2023-05-09T12:55:29Z")

</div>

Hey @klutchell ,

I’m having the same issue with the `balenalib/raspberry-pi2-debian-node:18-run` image on `docker build`. Might be related, although @antmak had the issue with `docker run`.

Was this ever fixed?

I tried to add `SHELL ["/bin/sh", "-c"]` to the top of my Dockerfile but it did not help.

Cheers  
Fred

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [May 9, 2023, 1:25pm UTC](https://forums.balena.io/t/apt-update-doesnt-work-on-raspberrypi3-and-raspberry-pi2-11447/350402/17 "2023-05-09T13:25:19Z")

</div>

Hey @frederikheld, here is the GitHub issue which is not closed, but I had left a note that it should have been resolved by an upstream change.

> <https://github.com/balena-io-library/base-images/issues/637>
>
> The \`/bin/sh\` shim: 
> https://github.com/balena-io-library/base-images/blob/47c8…8b4ad6d39ebe8bfc2fea02296e06c2a4e482/balena-base-images/armv7hf/debian/buster/build/Dockerfile#L138-L141
> breaks \`apt\`
> 
> To reproduce:
> \`\`\`
> docker run --rm -it balenalib/armv7hf-debian:buster-build /bin/bash
> root@26979267a1d6:/# apt-get update
> Get:1 http://deb.debian.org/debian buster InRelease \[121 kB\]
> Get:2 http://deb.debian.org/debian buster-updates InRelease \[49.3 kB\]
> Get:3 http://security.debian.org/debian-security buster/updates InRelease \[65.4 kB\]
> 0% \[Working\]   
> \`\`\`
> It will \_hang\_ at this point -- actually \`/bin/sh.real /bin/sh /usr/bin/apt-key ....\` will fork itself indefinitely (until it exhaust the process table)
> 
> As workaround I added 
> \`\`\`
> RUN \[\[-f /bin/sh.real \]\] && rm /bin/sh && mv /bin/sh.real /bin/sh
> \`\`\`
> as first step in my Dockerfiles...

Can you provide a stripped down version of your Dockerfile, and the exact issue you are seeing?
