1. 问题描述
嵌入式开发板,开机启动执行login,登录时候,弹出提示
login: can’t execute ‘/bin/bash’: No such file or directory
2. 问题分析
busybox支持ash、hush、msh三种shell,但是不支持bash
3. 修改方法
3.1 方法1、修改 login源码,改为 sh执行
本文的busybox版本为busybox-1.22.1
源码路径为 busybox-1.22.1/loginutils/login.c
执行login 动作在 int login_main(int argc UNUSED_PARAM, char **argv) 函数中,源码如下
/* Exec login shell with no additional parameters */
run_shell(pw->pw_shell, 1, NULL, NULL);
/* return EXIT_FAILURE; - not reached */
其中
run_shell(pw->pw_shell, 1, NULL, NULL);
pw->pw_shell 实际为shell 命令,内容为 “/bin/bash”,所以login,采用/bin/bash方式执行。
修改方法,将 /bin/bash 修改为 /bin/sh,修改后的代码如下
/* Exec login shell with no additional parameters */
//run_shell(pw->pw_shell, 1, NULL, NULL);
// modified by houfei, use the "/bin/sh" exec login, default "pw->pw_shell" is "/bin/bash"
run_shell("/bin/sh", 1, NULL, NULL);
/* return EXIT_FAILURE; - not reached */
3.2 方法2 修改rcS文件
修改etc/init.d/rcS文件的shell解析器为sh或其他。