BeagleBone Black (Debian 12): "trap: EXIT: bad trap" from init-bottom/overlayroot in the early boot stage

Dear Developers of Debian Linux on BeagleBone series,

(This is my first post to this forum.)

Thank you very much for developing and maintaining Debian Linux on BeagleBone series.
I recently installed Debian 12 on my BeagleBone Black (== BBB) (rev. C) from the image file
“am335x-debian-12.11-base-vscode-v6.12-armhf-2025-05-29-4gb.img.xz”.
Now, that BBB is running Debian 12 in a very good way.

During the installation, I connected the BBB to the host machine (MacBook Pro) with a serial cable.
On the serial console, we have seen the following messages in the early boot stage:

Starting kernel ...

[    0.151515] l3-aon-clkctrl:0000:0: failed to disable
[   10.527512] debugfs: Directory '49000000.dma' with parent 'dmaengine' already present!
[   10.560296] gpio-of-helper ocp:cape-universal: Failed to get gpio property of 'P8_03'
[   10.560323] gpio-of-helper ocp:cape-universal: Failed to create gpio entry
[   11.013593] mdio_bus 4a101000.mdio: mii_bus 4a101000.mdio couldn't get reset GPIO
[   11.203895] omap_voltage_late_init: Voltage driver support not added
trap: EXIT: bad trap

The message “trap: EXIT: bad trap” seems to be a problem.
I investigated the problem and have found that the message comes from the script “scripts/init-bottom/overlayroot”
in “/boot/initrd.img-6.12.28-bone27”, which is expanded on RAM in the early boot stage.

The script “overlayroot” has the following contents around the line 606 as


cfgd="${TEMP_D}/configs"
mkdir -p "${cfgd}" || fail "failed to create tempdir"
trap cleanup EXIT

This line “trap cleanup EXIT” causes the message “trap: EXIT: bad trap”, since “trap” in the current “/bin/sh” on RAM
in the early boot stage does not understand the pseudo signal “EXIT”. Accordingly, I have changed “trap cleanup EXIT”
to “trap cleanup 0”.

Even after this fix, I met another problem. The script “overlayroot” has the following contents around the line 73 as

cleanup() {
        [ -d "${TEMP_D}" ] && rm -Rf "${TEMP_D}"
}

Now, “/bin/rm” does not exist in the file system expanded on RAM in the early boot stage.
In my understanding, “/bin/nuke” should be used instead of “/bin/rm”. Accordingly, I change the above code to

cleanup() {
        [ -d "${TEMP_D}" ] && if command -v nuke >/dev/null; then
            nuke "${TEMP_D}"
        else
            # shellcheck disable=SC2114                                         
            rm -rf "${TEMP_D}"
        fi
}

The script “scripts/init-bottom/udev” contains the following code fragment around the line 22
to treat a similar situation as

if command -v nuke >/dev/null; then
    nuke /dev
else
    # shellcheck disable=SC2114                                                 
    rm -rf /dev
fi

I was taught by this code fragment.

Consequently, the patch file for “scripts/init-bottom/overlayroot” becomes as follows

-----------------------------------------------------------------------------------------------------------------------
--- overlayroot.org	2025-06-06 16:08:41.744691032 +0900
+++ overlayroot	2025-06-06 16:08:41.752694872 +0900
@@ -70,7 +70,12 @@
 	exit 0; # why do we exit success?
 }
 cleanup() {
-	[ -d "${TEMP_D}" ] && rm -Rf "${TEMP_D}"
+	[ -d "${TEMP_D}" ] && if command -v nuke >/dev/null; then
+	    nuke "${TEMP_D}"
+	else
+	    # shellcheck disable=SC2114
+	    rm -rf "${TEMP_D}"
+	fi
 }
 debug() {
 	_debug "$@"
@@ -603,7 +608,7 @@
 
 cfgd="${TEMP_D}/configs"
 mkdir -p "${cfgd}" || fail "failed to create tempdir"
-trap cleanup EXIT
+trap cleanup 0
 
 # collect the different config locations into a file
 # write individual config files in $cfgd that contain
-----------------------------------------------------------------------------------------------------------------------

In order to reflect this change, I have manually modified “/boot/initrd.img-6.12.28-bone27” as

(as root)

cd /tmp/
mkdir AAA
cd AAA
zstdcat /boot/initrd.img-6.12.28-bone27 | cpio -id
mv scripts/init-bottom/overlayrootfs scripts/init-bottom/overlayrootfs.org
cp scripts/init-bottom/overlayrootfs.org scripts/init-bottom/overlayrootfs
emacs -nw scripts/init-bottom/overlayrootfs (***modify as above***)
find | cpio -o -H newc | zstd -c > ../initrd.img-6.12.28-bone27
cd ../
mv /boot/initrd.img-6.12.28-bone27 /boot/initrd.img-6.12.28-bone27.back
cp initrd.img-6.12.28-bone27 /boot/initrd.img-6.12.28-bone27

I also made the same modification to “/usr/share/initramfs-tools/scripts/init-bottom/overlayroot”
for future occasions to make “/boot/initrd.img-x.x.x-yy” by “mkinitramfs” and “update-initramfs”.

After reboot, everything seems to be fine. I do not see the message “trap: EXIT: bad trap” any more
in the early boot stage on the serial console.

Sincerely yours,
Satoshi Adachi

1 Like

Thank you for finding this!

Looking at patching this… and run up on the repo: https://git.launchpad.net/cloud-initramfs-tools that’s not a good sign… 2024-07-02…

Looking at git changelog i fixed a an issue with the cloud-initramfs-tools maintainer… For us i had built ubuntu’s version up till Debian 11… I guess i figured Debian had re-synced the repo… I fixed it 7 years ago, Debian is still pulling a tag from 13 years ago!!!

So in our Debian 10 i used 0.47ubuntu1, looks like 0.48 is in 24.04 lts… https://packages.ubuntu.com/source/noble/cloud-initramfs-tools

I merged your patch: https://github.com/beagleboard/cloud-initramfs-tools/commits/0.49-bbbio now to add it to the build.

and pushed out… i’ll build a new image…

Starting kernel ...

[    2.944086] omap_voltage_late_init: Voltage driver support not added
[    3.221906] ti-sysc 44e31000.target-module: probe with driver ti-sysc failed with error -16
[    3.237911] ti-sysc 48040000.target-module: probe with driver ti-sysc failed with error -16
[    3.275596] 48000000.interconnect:segment@200000:target-module@0:mpu@0:fck: device ID is greater than 24
[    3.287336] tilcdc 4830e000.lcdc: [drm] *ERROR* Disabling all crtc's during unload failed with -12
[    3.425152] debugfs: Directory '49000000.dma' with parent 'dmaengine' already present!
[    3.464404] target-module@4b000000:target-module@140000:pmu@0:fck: device ID is greater than 24
[    3.471764] l3-aon-clkctrl:0000:0: failed to disable
rootfs: clean, 60796/1901952 files, 668099/7650427 blocks
[   27.106661] bbbio-set-sysconf[409]: Reading the system configuration settings from /boot/firmware/sysconf.txt

Debian GNU/Linux 12 BBB ttyS0

BeagleBoard.org Debian Bookworm Base Image 2025-05-29
Support: https://bbb.io/debian
default username is [voodoo]

BBB login: 

This is the first time in years that ‘exit’ error has not been there…

Regards,

1 Like