Topic: wonky shell on CC?

I'm trying to write a debugchumby script, but couldn't get it to run.

In the course of debugging, I decided to pop into SSH, and am getting very strange behavior indeed:

chumby:~# cd /mnt/usb
chumby:/mnt/usb# ./debugchumby
-sh: ./debugchumby: not found
chumby:/mnt/usb# ls debugchumby
debugchumby
chumby:/mnt/usb# /bin/bash
-sh: /bin/bash: not found
chumby:/mnt/usb# ls /bin/bash
/bin/bash
chumby:/mnt/usb# set
...omitted for brevity...
PATH='/bin:/sbin:/lib:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/bin:/usr/chumby/scripts'
...omitted for brevity...

Why is sh reporting that /bin/bash is not found, or the debugchumby script, or pretty much anything else?  What do I need to do to get debugchumby (and bash) to play nice on my CC?

Re: wonky shell on CC?

That's really strange.  Try doing long listings of debugchumby, bash, etc. and see if permissions look wrong, or something else noticeable.  Maybe try "#!/bin/sh" instead and see if that works for you since sh is a symlink to busybox instead of it's own executable (Keep in mind, the script you're using might use bash-isms that won't work with sh, but this might tell us a little more about your problem).

Between your "cd /mnt/usb" and the rest of the commands, did you unplug/re-plug the USB disk?  The path /mnt/usb is a symlink to /mnt/usb-XXXXXXX and maybe because something was wrong with your PWD (present working directory) busybox was giving some strange errors?  To test that theory, run "cd -; cd -" and try again.

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

When I have strange errors in shell scripts that are not explainable, then I usually check whether I used correct line endings. Wrong line endings in scripts can cause very strange behavior.

Re: wonky shell on CC?

@Materdaddy: I indeed use bash-isms, which is why I call it explicitly.  Within that code box is an exact copy/paste of the shell output other than those two omitted chunks in the "set" output.

@Christian: I wrote the file using Notepad++ and explicitly set it for UNIX-style line endings (CR only).  I actually had output it in DOS format originally, and it didn't play well on the C1; swapped the format and the C1 plays nice now, but the CC still pukes.

BusyBox v1.6.1 (2010-02-09 16:39:15 PST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

chumby:~# cd -;cd -
/root
/root
chumby:~# cd /mnt/usb
chumby:/mnt/usb# cd -;cd -
/root
/mnt/usb
chumby:/mnt/usb# ls -l
-rwxr-xr-x    1 root     root            0 Jun 12 17:11 _readme.txt
-rwxr-xr-x    1 root     root          304 Jun 15 23:21 debugchumby
drwxr-xr-x    2 root     root         2048 Jun 15 23:20 images
chumby:/mnt/usb# ./debugchumby
-sh: ./debugchumby: not found
chumby:/mnt/usb#

debugchumby is 755, so it should execute.  what bothers me is that i can't even manually invoke bash; i confirmed it's in /bin, but i try /bin/bash and i get the same "not found" BS.

chumby:/bin# ls -l /bin/bash
-rwxr-xr-x    1 root     root         3164 Dec 31  1969 /bin/bash

Re: wonky shell on CC?

The good news?  I can reproduce this on my CC at home.

The bad news?  I won't be able to look at this until at least tomorrow if nobody else figures it out.

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

Doktor Jones wrote:
chumby:/mnt/usb# /bin/bash
-sh: /bin/bash: not found
chumby:/mnt/usb# ls /bin/bash
/bin/bash

Why is sh reporting that /bin/bash is not found, or the debugchumby script, or pretty much anything else?  What do I need to do to get debugchumby (and bash) to play nice on my CC?

What's the results of "ldd /bin/bash"

On my C1 it reports

chumby:~# ldd /bin/bash
        libdl.so.2 => /lib/libdl.so.2 (0x40026000)
        libc.so.6 => /lib/libc.so.6 (0x40031000)
        /lib/ld-linux.so.3 (0x40000000)

Also what do the first few bytes look like?
eg on my C1

# hexdump -v -e '"%08_ax  "' -e '16/1 "%02X ""  "" "' -e '16/1 "%_p""\n"
' /bin/bash | head -20
00000000  7F 45 4C 46 01 01 01 00 00 00 00 00 00 00 00 00   .ELF............
00000010  02 00 28 00 01 00 00 00 04 CC 01 00 34 00 00 00   ..(.........4...
00000020  78 2F 0B 00 02 00 00 05 34 00 20 00 08 00 28 00   x/......4. ...(.
00000030  1B 00 1A 00 01 00 00 70 68 CA 0A 00 68 4A 0B 00   .......ph...hJ..
00000040  68 4A 0B 00 18 00 00 00 18 00 00 00 04 00 00 00   hJ..............
00000050  04 00 00 00 06 00 00 00 34 00 00 00 34 80 00 00   ........4...4...
00000060  34 80 00 00 00 01 00 00 00 01 00 00 05 00 00 00   4...............
00000070  04 00 00 00 03 00 00 00 34 01 00 00 34 81 00 00   ........4...4...
00000080  34 81 00 00 13 00 00 00 13 00 00 00 04 00 00 00   4...............
00000090  01 00 00 00 01 00 00 00 00 00 00 00 00 80 00 00   ................
000000a0  00 80 00 00 84 CA 0A 00 84 CA 0A 00 05 00 00 00   ................
000000b0  00 80 00 00 01 00 00 00 00 D0 0A 00 00 D0 0B 00   ................
000000c0  00 D0 0B 00 78 44 00 00 54 88 00 00 06 00 00 00   ....xD..T.......
000000d0  00 80 00 00 02 00 00 00 0C D0 0A 00 0C D0 0B 00   ................
000000e0  0C D0 0B 00 F0 00 00 00 F0 00 00 00 06 00 00 00   ................
000000f0  04 00 00 00 04 00 00 00 48 01 00 00 48 81 00 00   ........H...H...
00000100  48 81 00 00 20 00 00 00 20 00 00 00 04 00 00 00   H... ... .......
00000110  04 00 00 00 51 E5 74 64 00 00 00 00 00 00 00 00   ....Q.td........
00000120  00 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00   ................
00000130  04 00 00 00 2F 6C 69 62 2F 6C 64 2D 6C 69 6E 75   ..../lib/ld-linu

Re: wonky shell on CC?

@sweh:

chumby:~# ldd /bin/bash
-sh: ldd: not found
chumby:~# hexdump -v -e '"%08_ax  "' -e '16/1 "%02X ""  "" "' -e '16/1 "%_p""\n" ' /bin/bash | head -20
-sh: hexdump: not found
chumby:~# 

sad

Re: wonky shell on CC?

Unfortunately ldd and hexdump aren't available on the CC root filesystem since it's so much smaller, but it appears to be a valid executable:

(NOTE: Running this on another machine, not the CC itself)

~ $ file bash
bash: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.6.0, stripped

Also, cannot find the libraries directly, but strings shows this:

~ $ ~/toolchains/chumby/bin/arm-linux-nm bash
./toolchains/chumby/arm-2008q3/bin/arm-linux-nm: bash: no symbols
~ $
~ $ strings /bin/bash | grep .so
/lib/ld-linux.so.2
libm.so.6
librt.so.1
libc.so.6

My guess is now that bash wasn't re-compiled in the latest rootfs for the CC and is the cause of the problems.  The busybox executable shows different attributes:

~ $ file busybox 
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped

At the very least /lib/ld-linux.so.2 doesn't exist.  The other libraries bash wants are there, but /lib/ld-linux.so.3 is the only version present on the CC's latest rootfs.  Unfortunately since the CC rootfs is cramfs I can't easily make the change to test this theory.

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

so any thoughts on why the shell won't recognize /mnt/usb/debugchumby?  I even tried changing the shebang to #!/bin/ash (which is the shell that runs when you log into the CC), and managed to rework the entire script to be ash-compatible, but I still get the "-sh: ./debugchumby: not found" crap.  I believe I've also tried explicitly running /mnt/usb/debugchumby and get the same result.

Re: wonky shell on CC?

Does "sh debugchumby" work?

Does a *trivial" debugchumby (something like an echo) work?

Re: wonky shell on CC?

Is the script set to executable?  Maybe it's mounting the drive with the noexec flag?  Have you tried running it as "/bin/ash /mnt/usb/debugchumby"?

Re: wonky shell on CC?

I'll have to double-check that... I migrated my CC to work, where I can tinker with it in my spare time (which is plentiful at the moment because I'm still in training, but those who would be training me are busy as heck... lol).

I know the script is set to executable because:

-rwxr-xr-x    1 root     root          304 Jun 15 23:21 debugchumby

Re: wonky shell on CC?

Ok, you have something else strange going on now.  I was able to reproduce your /bin/bash problem which explained the debugchumby not running, since it was trying to use bash as it's interpreter.

I changed my script (which was a simple echo as Duane suggested) to use /bin/ash and now it runs fine.  That means something is definitely wrong with the bash executable on this root filesystem, but you've got a potentially isolated issue with your debugchumby script and ash.  Also note that I'm running these from /psp since the chumby I'm SSHing to doesn't have a USB stick in it, and it's all the way in my bedroom (I'm laaaaazy).

Maybe as Ben suggested you've got an issue with the usb being mounted as noexec... running "mount" might tell you in the options section.  The fstab doesn't show noexec as one of the flags used, but I think there's some other auto-mount script that actually does the mounting and may use different options.

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

well I've dropped Zurk's package on a USB stick and I'm bringing that in today to see if it works. If that boots, then I know my CC is capable of booting off debugchumby and that there's probably something wrong with my script somehow; if it doesn't boot, then my CC has an issue and I'll have to try and figure out what that is...

Re: wonky shell on CC?

Doktor Jones wrote:

well I've dropped Zurk's package on a USB stick and I'm bringing that in today to see if it works. If that boots, then I know my CC is capable of booting off debugchumby and that there's probably something wrong with my script somehow; if it doesn't boot, then my CC has an issue and I'll have to try and figure out what that is...

If it ends up being your CC, I'll be curious to get a tarball of the rfs or something since ash works for me.

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

Taking a quick look, it does appear that bash is broken on CC.

We didn't originally include bash on CC - we used the busybox shell for most simple things, and added miniperl to do any heavy lifting.  None of the scripts on CC rely on bash.

It looks like an incomplete version of bash got swept into the firmware somehow - the executable is only 3K which seems a bit light, considering that the bash executable on C1 is 734K.

One thing you might try is copying the bash from a C1 to your USB drive and running that one - it appears the CC has correct versions of the necessary libs.

Re: wonky shell on CC?

(Sorry, for some reason this never showed up in my "new posts" link; it was only curiousity that got me looking for it again)

If the "bash" executable on the CC refers to ld-linux.so.2 but only .so.3 exists then any script beginning #!/bin/bash will fail 'cos the bash executable itself won't run.  "not found" is the logical but confusing error message.  (Most commonly, people see this if they upload scripts from Windows systems with DOS CRLF line endings; the system will try to execute /bin/bash^M and get very confused :-))

As Duane suggests, you may need to replace bash, which probably means rebuilding cramfs.

Re: wonky shell on CC?

Well I put bash (and busybox->printf) on the USB drive, was able to successfully execute both and they ran as normal from shell... but my CC still refuses to run debugchumby on boot sad

19 (edited by servalan 2013-06-27 01:08:12)

Re: wonky shell on CC?

Doktor Jones wrote:

Well I put bash (and busybox->printf) on the USB drive, was able to successfully execute both and they ran as normal from shell... but my CC still refuses to run debugchumby on boot sad

Weird. debugchumby works fine on CC here. Mine looks like:

#!/bin/sh
cp /mnt/usb/shadow /etc/shadow
cp /mnt/usb/url_streams /psp/url_streams
cp /mnt/usb/music_order /psp/music_order
mkdir /mnt/usb2 /mnt/usb3 /mnt/usb4
/mnt/usb/sshd.sh start &

debugchumbyearly looks like

mount -t loop -o bind /psp/etc /etc
nice -n -20 /usr/sbin/httpd -h /mnt/usb/www
cp /mnt/usb/hosts /psp/hosts

There's a copy of my 'unshackled' chumby setup here:
http://www.users.on.net/~servalan/Chumb … 202013.zip

Has been working fine for yonks. Used vi to create files under cygwin. Don't remember any special permissions or other setup - it just worked.

Which USB port are you using? Mine is always in port A - not sure if that makes a diff.

Re: wonky shell on CC?

Doktor Jones wrote:

Well I put bash (and busybox->printf) on the USB drive, was able to successfully execute both and they ran as normal from shell... but my CC still refuses to run debugchumby on boot sad

When you updated, did you change the "shebang" on your debugchumby from #!/bin/bash to #!/mnt/usb/bash ?

Linux Guy - Occasional Chumby Hacker

Re: wonky shell on CC?

Yeah, tried changing the shebang line.  I can execute the debugchumby script manually just fine now (./debugchumby), but it still won't boot off it...

I've tried both A and B (though I'd expect more success with A if it were to make a difference).

Re: wonky shell on CC?

I just tested running an actual debugchumby script from USB with the shebang set to #!/mnt/usb/bash with the C1 bash on the usb stick and it worked.

Are you trying whatever complicated secret debugchumby script your final plan is, or have you tested something simple?

For example, here's my test:

#!/mnt/usb/bash

echo "TEST DEBUG CHUMBY" >> /psp/test_boot

I've run this and the file definitely appears on boot.

The reason I ask is I'm wondering if the debugchumby script is run from a point of the boot where something you're assuming is done (like a certain filesystem mounted, or service being run) isn't actually done yet and it's silently erroring out.

If you want to send me your script, I can try it on a CC that I have a serial header on so I can see the actual console output of to verify that it's not being run and simply is returning early from an error.

Linux Guy - Occasional Chumby Hacker