OpenWrt Forum Archive

Topic: Busybox init not working?

The content of this topic has been archived on 31 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm trying to get OpenWRT running on a SX551, a AR7 based modem/router. Now I have a kernel with a build in initramfs. Both the kernel and the initramfs are stripped down. There is no jffs2 partition.
The serial bootlog ends like this:

[    2.120000] TCP cubic registered
[    2.120000] Registering the dns_resolver key type
[    2.160000] Freeing unused kernel memory: 1440k freed
- preinit -
[    2.870000] PHY: fixed-0:01 - Link is Up - 100/Full
Press the [f] key and hit [enter] to enter failsafe mode
- regular preinit -
- init -
[    6.870000] PHY: fixed-0:01 - Link is Down

That's it. According to wireshark the box broadcasts one message, something like "to enter failsafe press the button now", and that's it.

With some echo's I have found that /init effectively does

. /etc/preinit
set_state init
exec /sbin/init

/etc/inittab:

::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

When I go to failsafe mode, I can execute '/etc/init.d/rcS S boot' manually, and that returns immediately, without effect.
I can bring up the network manually, but '/etc/init.d/network start' doesn't work.

What can this be? Have I stripped too much?

Some more, maybe unrelated observations:

  • /bin/sh -x doesn't work

  • root has no password. I have to execute passwd to enable logins.

  • I can start dropbear manually, but when trying to login I get a 'cannot allocate PTY'. Yet is devpts mounted on /dev/pts. When I login with 'ssh root@192.168.2.1 /bin/sh -i' I'm in.

  • I don't get any feedback on illegal commands. Maybe stderr is not connected to my serial line?

(Last edited by Mijzelf on 12 Apr 2012, 19:47)

Probably stripped too much. Preinit for example will fail if no "mtd" utility is present.
You can attach the output of the "./scripts/diffconfig.sh" command here, this allows us to quickly check your deltas against the default config.

Indeed I removed mtd, as I also haven't mtd support in my kernel.

Here is the output of ./scripts/diffconfig.sh:

CONFIG_TARGET_ar7=y
CONFIG_TARGET_ar7_None=y
CONFIG_TARGET_BOARD="ar7"
CONFIG_DEVEL=y
# CONFIG_BUSYBOX_CONFIG_BRCTL is not set
CONFIG_BUSYBOX_CONFIG_FEATURE_HAVE_RPC=y
CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_NFS=y
# CONFIG_BUSYBOX_CONFIG_FEATURE_WGET_STATUSBAR is not set
CONFIG_BUSYBOX_USE_LIBRPC=y
CONFIG_IMAGEOPT=y
CONFIG_INITOPT=y
# CONFIG_IPV6 is not set
CONFIG_KERNEL_DEBUG_INFO=y
CONFIG_KERNEL_DEBUG_KERNEL=y
# CONFIG_KERNEL_ELF_CORE is not set
CONFIG_KERNEL_KALLSYMS=y
CONFIG_KEXEC_TOOLS_TARGET_NAME="mipsel"
CONFIG_MAKE_TOOLCHAIN=y
# CONFIG_PACKAGE_crda is not set
# CONFIG_PACKAGE_dnsmasq is not set
# CONFIG_PACKAGE_firewall is not set
# CONFIG_PACKAGE_hostapd is not set
# CONFIG_PACKAGE_hotplug2 is not set
# CONFIG_PACKAGE_iptables is not set
# CONFIG_PACKAGE_iw is not set
CONFIG_PACKAGE_kexec-tools=y
# CONFIG_PACKAGE_kmod-acx-mac80211 is not set
# CONFIG_PACKAGE_kmod-atm is not set
# CONFIG_PACKAGE_kmod-cfg80211 is not set
# CONFIG_PACKAGE_kmod-crypto-core is not set
# CONFIG_PACKAGE_kmod-ipt-core is not set
CONFIG_PACKAGE_kmod-leds-gpio=y
# CONFIG_PACKAGE_kmod-mac80211 is not set
# CONFIG_PACKAGE_kmod-ppp is not set
# CONFIG_PACKAGE_libip4tc is not set
# CONFIG_PACKAGE_libnl-tiny is not set
CONFIG_PACKAGE_librpc=y
# CONFIG_PACKAGE_libuci is not set
# CONFIG_PACKAGE_libxtables is not set
# CONFIG_PACKAGE_linux-atm is not set
# CONFIG_PACKAGE_mtd is not set
# CONFIG_PACKAGE_opkg is not set
# CONFIG_PACKAGE_ppp is not set
# CONFIG_PACKAGE_swconfig is not set
# CONFIG_PACKAGE_uci is not set
# CONFIG_PACKAGE_wireless-tools is not set
CONFIG_PACKAGE_zlib=y
CONFIG_PKG_BUILD_JOBS=2
CONFIG_PKG_BUILD_PARALLEL=y
CONFIG_PREINITOPT=y
CONFIG_STRIP_KERNEL_EXPORTS=y
CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE=y
CONFIG_TARGET_INIT_ENV="SWITCH_ROOT_TMPFS=y"
# CONFIG_TARGET_INIT_SUPPRESS_STDERR is not set
CONFIG_TARGET_PREINIT_IFNAME="eth0"
CONFIG_TARGET_ROOTFS_INITRAMFS=y
CONFIG_TARGET_ROOTFS_TARGZ=y
CONFIG_USE_MKLIBS=y
CONFIG_BUSYBOX_CONFIG_FEATURE_IPV6=y
CONFIG_BUSYBOX_CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
CONFIG_BUSYBOX_CONFIG_PING6=y
# CONFIG_BUSYBOX_CONFIG_TRACEROUTE6 is not set
CONFIG_PACKAGE_kmod-lib-crc-ccitt=y

Retry with mtd included

I've rebuild the initramfs with mtd included. Unfortunately it didn't help.
But I managed to get some errorlogging. It turned out that stderr was redirected to /dev/null, but by executing 'exec 2>&1' I got my stderr back:

oot@(none):/etc# /etc/init.d/rcS S boot
/etc/init.d/rcS: line 19: uci_load: not found
root@(none):/etc# sysinit: mount: mounting debugfs on /sys/kernel/debug failed: Device or resourcey
sysinit: /sbin/wifi: line 192: uci_load: not found
sysinit: sh: ./base-files: line 1: uci: not found
sysinit: sh: ./base-files: line 2: uci: not found
sysinit: sh: ./base-files: line 3: uci: not found
sysinit: sh: ./base-files: line 4: uci: not found
sysinit: sh: ./base-files: line 5: uci: not found
sysinit: sh: ./network: line 30: uci: not found
sysinit: sh: uci: not found
sysinit: /etc/rc.common: line 83: uci_load: not found
sysinit: /etc/rc.common: line 462: uci_load: not found                                             
sysinit: /etc/rc.common: line 83: uci_get: not found                                               
sysinit: /etc/rc.common: line 462: uci_load: not found                                             
sysinit: /etc/rc.common: line 462: uci_load: not found                                             
sysinit: /etc/rc.common: line 83: uci_load: not found

So I suppose I have to install uci as well. Will have a look if it fits.

Right, uci is essential as well.

Unfortunately still not working. Last part of the bootlog:

[    2.180000] Freeing unused kernel memory: 1508k freed                                           
- preinit -                                                                                        
[    2.880000] PHY: fixed-0:01 - Link is Up - 100/Full                                             
Press the [f] key and hit [enter] to enter failsafe mode                                           
- regular preinit -                                                                                
- init -                                                                                           
[    6.880000] PHY: fixed-0:01 - Link is Down

The network goes down when leaving preinit, and doesn't go up again.

Now I saw that according to inittab the system is started by '/etc/init.d/rcS S boot'. When I run that manually I get:

root@(none):/# exec 2>&1                                                                           
root@(none):/# ifconfig eth0 down                                                                  
[   20.880000] PHY: fixed-0:01 - Link is Down                                                      
root@(none):/# ps                                                                                  
  PID USER       VSZ STAT COMMAND                                                                  
    1 root      1456 S    {init} /bin/sh /init                                                     
    2 root         0 SW   [kthreadd]                                                               
    3 root         0 SW   [ksoftirqd/0]                                                            
    4 root         0 SW   [kworker/0:0]                                                            
    5 root         0 SW   [kworker/u:0]                                                            
    6 root         0 SW<  [khelper]                                                                
    7 root         0 SW   [sync_supers]                                                            
    8 root         0 SW   [bdi-default]                                                            
    9 root         0 SW<  [kblockd]                                                                
   10 root         0 SW<  [rpciod]                                                                 
   11 root         0 SW   [kworker/0:1]                                                            
   12 root         0 SW   [kswapd0]                                                                
   13 root         0 SW<  [nfsiod]                                                                 
   14 root         0 SW   [kworker/u:1]                                                            
   57 root      1376 S    telnetd -l /bin/login.sh                                                 
   61 root      1372 S    lock /tmp/.failsafe                                                      
   62 root      1384 S    ash --login                                                              
   68 root         0 SW   [kworker/0:2]                                                            
   69 root      1380 R    ps                                                                       
root@(none):/# /etc/init.d/rcS S boot                                                              
root@(none):/#                                                                                     
root@OpenWrt:/# ps                                                                                 
  PID USER       VSZ STAT COMMAND                                                                  
    1 root      1456 S    {init} /bin/sh /init                                                     
    2 root         0 SW   [kthreadd]                                                               
    3 root         0 SW   [ksoftirqd/0]                                                            
    4 root         0 SW   [kworker/0:0]                                                            
    5 root         0 SW   [kworker/u:0]                                                            
    6 root         0 SW<  [khelper]                                                                
    7 root         0 SW   [sync_supers]                                                            
    8 root         0 SW   [bdi-default]                                                            
    9 root         0 SW<  [kblockd]                                                                
   10 root         0 SW<  [rpciod]                                                                 
   11 root         0 SW   [kworker/0:1]                                                            
   12 root         0 SW   [kswapd0]                                                                
   13 root         0 SW<  [nfsiod]                                                                 
   14 root         0 SW   [kworker/u:1]                                                            
   57 root      1376 S    telnetd -l /bin/login.sh                                                 
   61 root      1372 S    lock /tmp/.failsafe                                                      
   62 root      1384 S    ash --login                                                              
   68 root         0 SW   [kworker/0:2]                                                            
   72 root      1416 S    {rcS} /bin/sh /etc/init.d/rcS S boot                                     
   74 root      1380 S    logger -s -p 6 -t sysinit                                                
  123 root      1372 S    /sbin/klogd                                                              
  140 root      1436 S    {S50dropbear} /bin/sh /etc/rc.common /etc/rc.d/S50dr                     
  141 root       960 R    /usr/bin/dropbearkey -t rsa -f /tmp/dropbear/dropbea                     
  162 root      1384 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.ope                     
  165 root      1380 R    ps

Apparently this works fine, as dropbear and ntpd are started. But it didn't bring up the network. But starting network manually:

root@OpenWrt:/# /etc/init.d/network start                                                          
root@OpenWrt:/# [   78.880000] PHY: fixed-0:01 - Link is Up - 100/Full

What happens?

And I can't use the network to login. Trying to login using telnet:

[user@EEE2 tmp]$ telnet 192.168.1.1
Trying 192.168.1.1...
Connected to 192.168.1.1 (192.168.1.1).
Escape character is '^]'.
Connection closed by foreign host.

And telnetd is gone. For logging in via ssh I first have to set a password, and then I get:

[user@EEE2 tmp]$ ssh root@192.168.1.1
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
root@192.168.1.1's password: 
PTY allocation request failed on channel 0
shell request failed on channel 0
[user@EEE2 tmp]$ ssh root@192.168.1.1 /bin/sh -i
root@192.168.1.1's password: 


BusyBox v1.19.4 (2012-04-07 15:31:41 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/root # sh: /usr/bin/X11/xauth: not found
/bin/sh: can't access tty; job control turned off

/root # mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,size=14784k)
devpts on /dev/pts type devpts (rw,noatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)

Why are there no PTY's?

Sorted it. Had to include hotplug2, and enable hotplug in the kernel

The discussion might have continued from here.