嵌入式Linux终端自动登陆

作者

QQ群:852283276
微信:arm80x86
微信公众号:青儿创客基地
B站:主页 https://space.bilibili.com/208826118

原理

查看/etc/inittab文件,

# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

# The default runlevel.
id:5:initdefault:

# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.

l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
PS0:12345:respawn:/bin/start_getty 115200 ttyPS0
hvc0:12345:respawn:/bin/start_getty 115200 hvc0
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#  :::
#

1:12345:respawn:/sbin/getty 38400 tty1

注意其中的PS0:12345:respawn:/bin/start_getty 115200 ttyPS0,调用的是bin目录的start_getty,start_getty是一个脚本,内容如下:

#!/bin/sh
if [ -f /bin/autologin ] && [ -c /dev/$2 ]
then
	/sbin/getty -l /bin/autologin -n -L $1 $2
elif [ -c /dev/$2 ]
then
	/sbin/getty -L $1 $2
fi

可以看到如果存在autologin程序,则调用autologin,这和petalinux2015.2中已经不一样了,2015.2还需要手动自启动autologin,在17.4里已经不需要了,直接把autologin放入bin目录即可。autologin内容如下,

#include 
#include 

int main(int argc, char *argv[])
{
	execlp("login", "login", "-f", "root", 0);
	return 0;
}

用2015.2的自启动方式,会输出如下错误信息,会导致串口终端Ctrl+c没反应

-sh: cannot set terminal process group (2019): Inappropriate ioctl for device
-sh: no job control in this shell

参考嵌入式ARM Linux开发板自启动,跳过输入root用户名和密码。首先准备autologin,在更改inittab文件,

PS0:2345:respawn:/sbin/getty -n -l /bin/autologin -L 115200 ttyPS0 vt100

你可能感兴趣的:(linux内核与驱动开发)