#!/bin/sh echo "makeing rootdir" mkdir rootfs cd rootfs echo "makeing dir: bin dev etc lib proc sbin sys usr" mkdir dev etc home lib mnt opt proc root sys tmp var usr mkdir var/lib var/lock var/run var/tmp mkdir usr/bin usr/lib usr/sbin lib/modules mkdir etc/init.d etc/rc.d etc/sysconfig echo "make node in dev/console dev/null" sudo mknod -m 600 dev/console c 5 1 sudo mknod -m 666 dev/null c 1 3 mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp chmod 1777 tmp chmod 1777 var/tmp echo "make direction done"
第二步:编译和安装busybox-1.17.2。进入文件夹busybox-1.17.2,用命令#cd busybox-1.17.2。
1.修改busybox-1.17.2根目录下的Makefile文件的交叉编译的路径。
#vi Makefile
将164行改为CROSS_COMPILE = arm-linux- 将190行改为ARCH = arm
2.修改menuconfig.
#make menuconfig
配置如下:
Busybox Setting --->
Build Options --->
[]Build Busybox as a static binary(no shared libs) <—编译静态库的选项
[*]Build with Large File Support (for accessing files > 2GB)
(arm-linux-) Cross Compiler prefix
Installation Options --->
[*] Don‘t use /usr
Applets links (as soft-links) --->
(/forlinx/mini2440/rootfs) BusyBox installation prefix <—进入这个选项,输入busybox的安装路径, 如:/forlinx/mini2440/rootfs
Busybox Library Tuning --->
[*] Support for /etc/networks
[*] vi-style line editing commands
[*] Tab completion
[*] Username completion
[*] Fancy shell prompts <—要选择这个选项:“Fancy shell prompts”,否则挂载文件系统后,无法正常显示命令提示符:“[\u@\h \W]#”
Editors --->进里面可选择的删掉一些功能
Linux Module Utilities --->
[ ] Simplified modutils
[*] insmod
[*] rmmod
[*] lsmod
[*] Pretty output
[*] modprobe
[*] Blacklist support
[*] depmod
--- Options common to multiple modutils
[ ] Support version 2.2/2.4 Linux kernels
[*] Support tainted module checking with new kernels
[*] Support for module.aliases file
[*] Support for module.symbols file
Linux System Utilities --->
[*] mdev
[*] Support /etc/mdev.conf
保存退出!
再执行命令
编译:#make;
安装:#make install;
第三步:复制动态库,即复制交叉编译器下的库文件到rootfs中的lib目录下。
(用以下两条命令之前要先#cd rootfs目录下)
#cp -f /4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*.so* ./lib -a
#cp -f /4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*.so* ./lib -a
注意:记得加-a否则非常大,-a可以把软连接形式保存,不用直接拷贝
附:/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*.so*是我电脑中交叉编译器的路径。其中./lib即说明是当前目录下的lib路径,可见,当前目录是rootfs/
第四步:创建roofts/etc目录下的各种配置文件,有etc/inittab;etc/init.d/rcS;etc/fstab;/etc/profile;etc/passwd; etc/shadow; etc/group; etc/hostname
如图:
1.etc/inittab内容如下
::sysinit:/etc/init.d/rcS ::askfirst:-/bin/sh ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r2.etc/init.d/rcS内容如下
#! /bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin runlevel=S prevlevel=N umask 022 export PATH runlevel prevlevel /bin/hostname tjpu2440 echo "----------mount all----------" /bin/mount -a echo /sbin/mdev>/proc/sys/kernel/hotplug mdev -s echo "**************************************" echo "**************************************" echo "Kernel version:linux-2.6.35.4" echo "Date:2015.04.04" echo "**************************************"3.etc/fstab内容如下
#device mount-point type option dump fsck order proc /proc proc defaults 0 0 none /tmp ramfs defaults 0 0 sysfs /sys sysfs defaults 0 0 mdev /dev ramfs defaults 0 0
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">4.</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">/etc/profile</span></span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">内容如下</span>
<span style="line-height: 26px;"></span><pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51);">USER=" 'id -un' " LOGNAME=$USER PS1='[\u@\h \W]#' PATH=$PATH HOSTNAME='/bin/hostname' export USER LOGNAME PS1 PATH
<pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51); line-height: 26px;"><span style="font-family: Arial;">5.</span><span style="font-family: Arial;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">etc/passwd</span></span><span style="font-family: Arial;">内容如下</span>
<pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51);">root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin
<pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51); line-height: 26px;"><span style="font-family: Arial;">6.</span><span style="font-family: Arial;"><span style="color: rgb(51, 51, 51); line-height: 26px; font-family: Arial; font-size: 18px;">etc/</span><span style="color: rgb(51, 51, 51); line-height: 26px; font-family: Arial; font-size: 18px;">shadow</span></span><span style="font-family: Arial;">内容如下</span>
<pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51);">root:$6$hnswPTgxzFaZHlLl$WMMV0Av6O6c4RA4pwpVSgcKSiURhUlP5dxF3/MKEZlGzNXhoWMQeZA1rdf1z7VQbrrmOZe7YHw1rIQmAc8BNK/:14819:0:99999:7::: bin:*:14715:0:99999:7::: daemon:*:14715:0:99999:7::: ftp:*:14715:0:99999:7::: nobody:*:14715:0:99999:7:::
<pre name="code" class="plain" style="font-family: Arial; font-size: 18px; color: rgb(51, 51, 51); line-height: 26px;"><span style="font-family: Arial;">7.</span><span style="font-family: Arial;"><span style="color: rgb(51, 51, 51); line-height: 26px; font-family: Arial; font-size: 18px;">etc/</span><span style="color: rgb(51, 51, 51); line-height: 26px; font-family: Arial; font-size: 18px;">group</span></span><span style="font-family: Arial;">内容如下</span>
<span style="font-family: Arial;"></span><pre name="code" class="plain" style="color: rgb(51, 51, 51);">root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon ftp:x:50: nobody:x:99:
<span style="color: rgb(51, 51, 51); font-family: Arial;">8.</span><span style="color: rgb(51, 51, 51); font-family: Arial;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">etc/hostname</span></span><span style="font-family: Arial;"><span style="color:#333333;">内容如下</span></span><pre name="code" class="plain" style="color: rgb(51, 51, 51);">tjpu2440对于这里说的每个文件的解译,会在文章的末尾附上。 第五步:制作yaffs2根文件系统镜像
<span style="font-family: Arial;"><span style="color:#333333;">mkyaffs2image-128M rootfs rootfs.img //128m、256m及以上的 mkyaffs2image rootfs rootfs.bin //64m的</span></span>
<span style="font-family: Arial;"><span style="color:#333333;">注:mkyaffs2image,</span></span><span style="color: rgb(51, 51, 51); font-family: Arial;">mkyaffs2image-128M</span><span style="font-family: Arial;"><span style="color:#333333;">工具放在虚拟机下ubuntu根目录的/usr/local/sbin/下;</span></span>
到此,制作动态根文件系统讲述完毕。
<h4 style="margin: 26px 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><p style="font-size: 13.63636302948px;">感谢网上的各位大牛,本博文主要参考:</p><ul style="font-size: 13.63636302948px;"><li><a target=_blank target="_blank" href="http://blog.chinaunix.net/uid-25923232-id-366019.html" style="color: rgb(51, 102, 153); text-decoration: none;">http://blog.csdn.net/zouxy09/article/details/7905238</a></li></ul></h4>
附:etc/目录下文件说明
<p style="line-height: 26px;"><span style="font-family:SimSun;font-size:14px;">在启动过程中bootloader会传递参数init=/linuxrc给内核的 main( )函数,所以在文件系统被挂在后,运行的第一个程序是linuxrc,而linuxrc是一个指向/bin/busybox的链接文件,也就 是说文件系统被挂在后运行的第一个程序是busybox。Busybox首先会解析文件/etc/inittab,这个文件中存放的是系统的配置信息,这 些配置信息指明了接下来将要启动那些程序。 </span><span style="font-family:SimSun;font-size:14px;">(1)修改文件etc/inittab如下(设定了系统在各状态下要运行的文件) </span><span style="font-family:SimSun;font-size:14px;">::sysinit:/etc/init.d/rcS </span><span style="font-family:SimSun;font-size:14px;">::askfirst:-/bin/sh </span><span style="font-family:SimSun;font-size:14px;">::ctrlaltdel:/sbin/reboot </span><span style="font-family:SimSun;font-size:14px;">::shutdown:/bin/umount -a -r </span><span style="font-family:SimSun;font-size:14px;">/etc/inittab 文件中每个条目用来定义一个子进程,并确定它的启动方法,格式如下 (参数可以为空,但是:冒号不可以省略) </span><span style="font-family:SimSun;font-size:14px;"><id>:<runlevels>:<action>:<process> </span><span style="font-family:SimSun;font-size:14px;"><id>:表示这个进程要使用的控制台(即标准输入、标准输出、标准错误设备)。如果省 略,则使用与init进程一样的控制台。 </span><span style="font-family:SimSun;font-size:14px;"><runlevels>:运行等级,对于Busybox init程序,这个字段没意义,可以省略。 </span><span style="font-family:SimSun;font-size:14px;"><action>:表示init程序如何控制这个子进程, </span><span style="font-family:SimSun;font-size:14px;"><process>: 要执行的程序,它可以是可执行程序,也可以是脚本 </span><span style="font-family:SimSun;font-size:14px;"> </span><span style="font-family:SimSun;font-size:14px;">文件etc/inittab配置条目说明如下: </span><span style="font-family:SimSun;font-size:14px;">::sysinit:/etc/init.d/rcS </span><span style="font-family:SimSun;font-size:14px;">启动系统初始化文件/etc/init.d/rcS。字段sysinit表明文件/etc/init.d/rcS在系统启动后最先执行,并且只执行一次,init进程等待它结束才继续执行其它动作。 </span><span style="font-family:SimSun;font-size:14px;">(脚本文件名一般为rc,后缀S代表单用户运行级别脚本) </span><span style="font-family:SimSun;font-size:14px;">tq2440_serial0::askfirst:-/bin/sh </span><span style="font-family:SimSun;font-size:14px;">在串口tq2440_serial0上启动askfirst动作的shell。 S3C2410的串口名在/dev下是s3c2410_serialx。此时还没有移植自己的内核,用天嵌科技的内核所以串口名为 tq2440_serial0。askfirst表明init进程先输出 “Please press Enter to actvie this console”,等用户输入回车键之后才启动-/bin/sh。 </span><span style="font-family:SimSun;font-size:14px;">::ctrlaltdel:/sbin/reboot </span><span style="font-family:SimSun;font-size:14px;"> 当按下Ctrl+Alt+Delete组合键时,init重启执行程序。字段ctrlaltdel表明当按下Ctrl+Alt+Delete组合键时,执行相应的进程。 </span><span style="font-family:SimSun;font-size:14px;">::shutdown:/bin/umount -a -r </span><span style="font-family:SimSun;font-size:14px;"> 告诉init在关机时运行umount命令卸载所有的文件系统,如果卸载失败,试图以只读方式重新挂载。字段shutdown表明在重启关闭系统命令时执行相应进程。 </span><span style="font-family:SimSun;font-size:14px;">(2)当解析完文件etc/inittab后就将启动这些进程,首先要执行的是启动脚本etc/init.d/rcS。 </span><span style="font-family:SimSun;font-size:14px;">修改文件etc/init.d/rcS如下:(此文件是“etc/inittab”中设定的系统初始化时使用的脚本,需要注意此文件需要有运行权限。) </span><span style="font-family:SimSun;font-size:14px;">#! /bin/sh </span><span style="font-family:SimSun;font-size:14px;">PATH=/sbin:/bin:/usr/sbin:/usr/bin </span><span style="font-family:SimSun;font-size:14px;">runlevel=S </span><span style="font-family:SimSun;font-size:14px;">prevlevel=N </span><span style="font-family:SimSun;font-size:14px;">umask 022 </span><span style="font-family:SimSun;font-size:14px;">export PATH runlevel prevlevel </span><span style="font-family:SimSun;font-size:14px;">/bin/hostname xiaoyi </span><span style="font-family:SimSun;font-size:14px;">echo "----------mount all----------" </span><span style="font-family:SimSun;font-size:14px;">/bin/mount -a </span><span style="font-family:SimSun;font-size:14px;">echo /sbin/mdev>/proc/sys/kernel/hotplug </span><span style="font-family:SimSun;font-size:14px;">mdev -s </span><span style="font-family:SimSun;font-size:14px;">echo "**************************************" </span><span style="font-family:SimSun;font-size:14px;">echo "**************************************" </span><span style="font-family:SimSun;font-size:14px;">echo "Kernel version:linux-2.6.30.4" </span><span style="font-family:SimSun;font-size:14px;">echo "Date:2011.03.24" </span><span style="font-family:SimSun;font-size:14px;">echo "**************************************" </span><span style="font-family:SimSun;font-size:14px;"><strong>说明如下: </strong></span><span style="font-family:SimSun;font-size:14px;">#! /bin/sh 用busybox的shell </span><span style="font-family:SimSun;font-size:14px;">PATH=/sbin:/bin:/usr/sbin:/usr/bin//shell命令的搜索路径环境变量 </span><span style="font-family:SimSun;font-size:14px;">runlevel=S //运行在单用户模式singal </span><span style="font-family:SimSun;font-size:14px;">prevlevel=N //前一个级别为n表示没有前一个级别none </span><span style="font-family:SimSun;font-size:14px;">umask 022 //权限位掩码,表示新建文件文件的默认属性-022 </span><span style="font-family:SimSun;font-size:14px;">export PATH runlevel prevlevel //将设置的变量导出到环境中 </span><span style="font-family:SimSun;font-size:14px;">/bin/hostname –F /etc/hostname //主机名,xiaoyi将出现在shell提示符中[root@xiaoyi/]# </span><span style="font-family:SimSun;font-size:14px;">/bin/mount -a //将文件etc/fstab中指明的文件系统挂载到对应挂载点上 </span><span style="font-family:SimSun;font-size:14px;">echo /sbin/mdev>/proc/sys/kernel/hotplug //用mdev来处理内核的热插拔事件。 </span><span style="font-family:SimSun;font-size:14px;">当有热插拔事件产生时, 内核就会调用位于/sbin目录的 mdev。 这时 mdev通 过环境变量中的 ACTION 和 DEVPATH,(这两个变量是系统自带的)来确定此次热插拔事件的动作以及影响了/sys 中的那个目录。接着会 看看这个目录中是否有“dev”的属性文件,如果有就利用这些信息为 这个设备在/dev 下创建设备节点文件。 </span><span style="font-family:SimSun;font-size:14px;"> </span><span style="font-family:SimSun;font-size:14px;">mdev -s //建立dev目录。以‘-s’为参数调用位于/sbin 目录下的 mdev(其实是个链接,作用是传递参数给/bin目录下的busybox 程序并调用它) ,mdev扫描 /sys/class 和/sys /block中所有的类设备目录,如果在目录中含有名为“dev”的文件,且文件中包含的是设备号,则 mdev 就利用这些信息为这个设备在/dev下 创建设备节点文件。一般只在启动时才执行一次 “mdev -s” 。 </span><span style="font-family:SimSun;font-size:14px;">(3)修改文件etc/fstab如下:(文件中提供了要自动挂载的对象) </span><span style="font-family:SimSun;font-size:14px;">#device mount-point type option dump fsck order </span><span style="font-family:SimSun;font-size:14px;">proc /proc proc defaults 0 0 </span><span style="font-family:SimSun;font-size:14px;">none /tmp ramfs defaults 0 0 </span><span style="font-family:SimSun;font-size:14px;">sysfs /sys sysfs defaults 0 0 </span><span style="font-family:SimSun;font-size:14px;">mdev /dev ramfs defaults 0 0 </span><span style="font-family:SimSun;font-size:14px;"> 在系统启动初始化文件/etc/init.d/rcS中有执行挂载命令/bin/mount -a ,这便是将文件etc/fstab中指定的文件系统挂载到对应的挂载点上。这些文件系统的挂在是执行mdev -s命令建立dev目录的前提。 </span><span style="font-family:SimSun;font-size:14px;">(4)在启动脚本etc/init.d/rcS执行完后将在串口tq2440_serial0启动一个shell。Shell启动过程中会根据文件/etc/profile配置登陆环境。 </span><span style="font-family:SimSun;font-size:14px;">文件/etc/profile修改如下: </span><span style="font-family:SimSun;font-size:14px;">USER=" 'id -un' " </span><span style="font-family:SimSun;font-size:14px;">LOGNAME=$USER </span><span style="font-family:SimSun;font-size:14px;">PS1='[\u@\h \W]#' </span><span style="font-family:SimSun;font-size:14px;">PATH=$PATH </span><span style="font-family:SimSun;font-size:14px;">HOSTNAME='/bin/hostname' </span><span style="font-family:SimSun;font-size:14px;">export USER LOGNAME PS1 PATH </span><span style="font-family:SimSun;font-size:14px;">具体说明: </span><span style="font-family:SimSun;font-size:14px;">profile文件会告诉shell使用什么语言,什么shell,命令的搜索路径等等。 </span><span style="font-family:SimSun;font-size:14px;">USER="id -un" //获取用户名id-un与whoami命令有相同的功能,打印用户名 </span><span style="font-family:SimSun;font-size:14px;">PS1='[\u@\h \W]#' //PS1指定sh提示符的格式在本环境下将是[root@xiaoyi]# </span><span style="font-family:SimSun;font-size:14px;">HOSTNAME 设置为/bin/hostname的命令输出,获取主机名 </span><span style="font-family:SimSun;font-size:14px;">export USER LOGNAME PS1 PATH 将这些变量导出到环境。 </span><span style="font-family:SimSun;font-size:14px;">PS1:提示符的设置 </span><span style="font-family:SimSun;font-size:14px;"> </span><span style="font-family:SimSun;font-size:14px;"> PS1(是数字1而不是字母l),每个版本bash的PS1变量内的特殊符号可能有些小的差异,你可以先man bash 一下。下面是FC4环境下默认的特殊符号所代表的意义: </span><span style="font-family:SimSun;font-size:14px;">\d :代表日期,格式为weekday month date,例如:"Mon Aug 1" </span><span style="font-family:SimSun;font-size:14px;">\H :完整的主机名称。例如:我的机器名称为:fc4.linux,则这个名称就是fc4.linux </span><span style="font-family:SimSun;font-size:14px;">\h :仅取主机的第一个名字,如上例,则为fc4,.linux则被省略 </span><span style="font-family:SimSun;font-size:14px;">\t :显示时间为24小时格式,如:HH:MM:SS </span><span style="font-family:SimSun;font-size:14px;">\T :显示时间为12小时格式 </span><span style="font-family:SimSun;font-size:14px;">\A :显示时间为24小时格式:HH:MM </span><span style="font-family:SimSun;font-size:14px;">\u :当前用户的账号名称 </span><span style="font-family:SimSun;font-size:14px;">\v :BASH的版本信息 </span><span style="font-family:SimSun;font-size:14px;">\w :完整的工作目录名称。家目录会以 ~代替 </span><span style="font-family:SimSun;font-size:14px;">\W :利用basename取得工作目录名称,所以只会列出最后一个目录 </span><span style="font-family:SimSun;font-size:14px;">\# :下达的第几个命令 </span><span style="font-family:SimSun;font-size:14px;">\$ :提示字符,如果是root时,提示符为:# ,普通用户则为:$ </span><span style="font-family:SimSun;font-size:14px;">默认的PS1内容为: '</span><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" id="MathJax-Element-1-Frame" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="-webkit-transition: none; transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.447em; height: 0px;"><span style="transition: none; -webkit-transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.854em 1000.002em 3.104em -0.414em); top: -2.729em; left: 0.002em;"><span class="mrow" id="MathJax-Span-2" style="transition: none; -webkit-transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mtext" id="MathJax-Span-3" style="-webkit-transition: none; transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; color: red;">\u</span><span class="texatom" id="MathJax-Span-4" style="transition: none; -webkit-transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mrow" id="MathJax-Span-5" style="transition: none; -webkit-transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mo" id="MathJax-Span-6" style="-webkit-transition: none; transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;">@</span></span></span><span class="mtext" id="MathJax-Span-7" style="-webkit-transition: none; transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; color: red;">\h</span><span class="mtext" id="MathJax-Span-8" style="-webkit-transition: none; transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; color: red;">\W</span></span></span></span></span></nobr></span></span><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" id="MathJax-Element-1-Frame" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="-webkit-transition: none; transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.447em; height: 0px;"><span style="transition: none; -webkit-transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.854em 1000.002em 3.104em -0.414em); top: -2.729em; left: 0.002em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.734em;"></span></span></span></span></nobr></span></span><span style="font-family:SimSun;font-size:14px;">\$' ,所以默认的提示符就是: [root@linux ~]#。</span> <span style="font-family:SimSun;font-size:14px;"> </span> <span style="font-family:SimSun;font-size:14px;">(5)在用户登录时将在/etc下寻找三个文件passwd ,shadow, group匹配相关信息。</span> <span style="font-family:SimSun;font-size:14px;">这三个文件修改如下:</span> <span style="font-family:SimSun;font-size:14px;">/etc/passwd</span> <span style="font-family:SimSun;font-size:14px;">root:x:0:0:root:/root:/bin/bash</span> <span style="font-family:SimSun;font-size:14px;">bin:x:1:1:bin:/bin:/sbin/nologin</span> <span style="font-family:SimSun;font-size:14px;">daemon:x:2:2:daemon:/sbin:/sbin/nologin</span> <span style="font-family:SimSun;font-size:14px;">ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin</span> <span style="font-family:SimSun;font-size:14px;">nobody:x:99:99:Nobody:/:/sbin/nologin</span> <span style="font-family:SimSun;font-size:14px;">通常在Linux系统中,用户的关键信息被存放在系统的/etc/passwd文件中,系统的每一个合法用户账号对应于该文件中的一行记录。这行记录定义了每个用户账号的属性。</span> <span style="font-family:SimSun;font-size:14px;">在该文件中,每一行用户记录的各个数据段用“:”分隔,分别定义了用户的各方面属性。各个字段的顺序和含义如下:</span> <span style="font-family:SimSun;font-size:14px;"> 注册名:口令:用户标识号:组标识号:用户名:用户主目录:命令解释程序shell</span> <span style="font-family:SimSun;font-size:14px;"> (1)注册名(login_name):用于区分不同的用户。在同一系统中注册名是唯一的。在很多系统上,该字段被限制在8个字符(字母或数字)的长度之内;并且要注意,通常在Linux系统中对字母大小写是敏感的。这与MSDOS/Windows是不一样的。</span> <span style="font-family:SimSun;font-size:14px;"> (2)口令(passwd):系统用口令来验证用户的合法性。超级用户root或某些高级用户可以使用系统命令passwd来更改系统中所有用户的口令,普通用户也可以在登录系统后使用passwd命令来更改自己的口令。</span> <span style="font-family:SimSun;font-size:14px;"> 现在的Unix/Linux系统中,口令不再直接保存在passwd文件中,通常将passwd文件中的口令字段使用一个“x”来代替,将/etc /shadow作为真正的口令文件,用于保存包括个人口令在内的数据。当然shadow文件是不能被普通用户读取的,只有超级用户才有权读取。</span> <span style="font-family:SimSun;font-size:14px;"> 此外,需要注意的是,如果passwd字段中的第一个字符是“*”的话,那么,就表示该账号被查封了,系统不允许持有该账号的用户登录。</span> <span style="font-family:SimSun;font-size:14px;"> (3)用户标识号(UID):UID是一个数值,是Linux系统中唯一的用户标识,用于区别不同的用户。在系统内部管理进程和文件保护时使用UID字段。在Linux系统中,注册名和UID都可以用于标识用户,只不过对于系统来说UID更为重要;而对于用户来说注册名使用起来更方便。在某些特定目的下,系统中可以存在多个拥有不同注册名、但UID相同的用户,事实上,这些使用不同注册名的用户实际上是同一个用户。</span> <span style="font-family:SimSun;font-size:14px;"> (4)组标识号(GID):这是当前用户的缺省工作组标识。具有相似属性的多个用户可以被分配到同一个组内,每个组都有自己的组名,且以自己的组标识号相区分。像UID一样,用户的组标识号也存放在passwd文件中。在现代的Unix/Linux中,每个用户可以同时属于多个组。除了在passwd文件中指定其归属的基本组之外,还在/etc/group文件中指明一个组所包含用户。</span> <span style="font-family:SimSun;font-size:14px;"> (5)用户名(user_name):包含有关用户的一些信息,如用户的真实姓名、办公室地址、联系电话等。在Linux系统中,mail和finger等程序利用这些信息来标识系统的用户。</span> <span style="font-family:SimSun;font-size:14px;"> (6)用户主目录(home_directory):该字段定义了个人用户的主目录,当用户登录后,他的Shell将把该目录作为用户的工作目录。在Unix/Linux系统中,超级用户root的工作目录为/root;而其它个人用户在/home目录下均有自己独立的工作环境,系统在该目录下为每个用户配置了自己的主目录。个人用户的文件都放置在各自的主目录下。</span> <span style="font-family:SimSun;font-size:14px;"> (7)命令解释程序(Shell):Shell是当用户登录系统时运行的程序名称,通常是一个Shell程序的全路径名,如/bin/bash。为了阻止一个特定用户登录系统,可用/dev/null作为其shell,或例子中的/sbin/nologin。</span> <span style="font-family:SimSun;font-size:14px;"> 需要注意的是,系统管理员通常没有必要直接修改passwd文件,Linux提供一些账号管理工具帮助系统管理员来创建和维护用户账号。</span> <span style="font-family:SimSun;font-size:14px;">/etc/group</span> <span style="font-family:SimSun;font-size:14px;">root:x:0:root</span> <span style="font-family:SimSun;font-size:14px;">bin:x:1:root,bin,daemon</span> <span style="font-family:SimSun;font-size:14px;">daemon:x:2:root,bin,daemon</span> <span style="font-family:SimSun;font-size:14px;">ftp:x:50:</span> <span style="font-family:SimSun;font-size:14px;">nobody:x:99:</span> <span style="font-family:SimSun;font-size:14px;">各标识符意义如下:</span> <span style="font-family:SimSun;font-size:14px;">群组名称:群组密码:群组ID:支持的用户名称</span> <span style="font-family:SimSun;font-size:14px;">X表示密码也存于shadow中了,例如第三行表示的意义如下:</span> <span style="font-family:SimSun;font-size:14px;">Root,bin,daemon用户都属于daemon这个群组,GID为2,如果想要把xiaoyi用户添加到这里,只要在后面添加,xiaoyi即可,注意不要空格</span> <span style="font-family:SimSun;font-size:14px;">/etc/shadow</span> <span style="font-family:SimSun;font-size:14px;">root:$6$hnswPTgxzFaZHlLl$WMMV0Av6O6c4RA4pwpVSgcKSiURhUlP5dxF3/MKEZlGzNXhoWMQeZA1rdf1z7VQbrrmOZe7YHw1rIQmAc8BNK/:14819:0:99999:7:::</span> <span style="font-family:SimSun;font-size:14px;">bin:*:14715:0:99999:7:::</span> <span style="font-family:SimSun;font-size:14px;">daemon:*:14715:0:99999:7:::</span> <span style="font-family:SimSun;font-size:14px;">ftp:*:14715:0:99999:7:::</span> <span style="font-family:SimSun;font-size:14px;">nobody:*:14715:0:99999:7:::</span> <span style="font-family:SimSun;font-size:14px;"> 这个文件用来保存各用户和群的密码。意义如下:</span> <span style="font-family:SimSun;font-size:14px;">用户名称:和passwd的相同;密码:经过加密的密码,如第一个字符是*,则表示该用户不会被登入,其他的是一些更改密码的日期限制,在这里不做解析。</span> <span style="font-family:SimSun;font-size:14px;">最后是“etc/hostname”文件,此文件在“etc/init.d/rcS”文件中设定用来提供主机名称。</span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="color:#333333;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="line-height: 26px;"><span style="color:#333333;"> </span></span></span><span style="font-family:SimSun;font-size:14px;"><span style="line-height: 26px;"><span style="color:#333333;"> </span></span></span><span style="font-family:SimSun;font-size:14px;"><span style="line-height: 26px;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span style="line-height: 26px;"> </span></span><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" id="MathJax-Element-1-Frame" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="-webkit-transition: none; transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.447em; height: 0px;"><span style="transition: none; -webkit-transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.854em 1000.002em 3.104em -0.414em); top: -2.729em; left: 0.002em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.734em;"></span></span></span></span></nobr></span></span><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.003em; border-left-style: solid; padding: 0px; margin: 0px; vertical-align: -0.331em; overflow: hidden; width: 0px; height: 1.336em;"></span></span></nobr></span></span> <span style="font-family:SimSun;font-size:12px;"> </span> </p><h3 style="line-height: 26px;"><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" id="MathJax-Element-1-Frame" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="-webkit-transition: none; transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.447em; height: 0px;"><span style="transition: none; -webkit-transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.854em 1000.002em 3.104em -0.414em); top: -2.729em; left: 0.002em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.734em;"></span></span></span></span></nobr></span><span class="MathJax" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.003em; border-left-style: solid; padding: 0px; margin: 0px; vertical-align: -0.331em; overflow: hidden; width: 0px; height: 1.336em;"></span></span></nobr></span></span><p></p></h3><div class="MathJax_Display" role="textbox" aria-readonly="true" style="text-align: center; margin: 1em 0em; position: relative; max-width: none; max-height: none; min-width: 0px; min-height: 0px; width: 708px;"><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" id="MathJax-Element-1-Frame" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="-webkit-transition: none; transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.447em; height: 0px;"><span style="transition: none; -webkit-transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.854em 1000.002em 3.104em -0.414em); top: -2.729em; left: 0.002em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.734em;"></span></span></span></span></nobr></span></span><span style="font-family:SimSun;font-size:14px;"><span class="MathJax" style="display: inline; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; -webkit-transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" style="transition: none; -webkit-transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.326em;"><span style="transition: none; -webkit-transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.003em; border-left-style: solid; padding: 0px; margin: 0px; vertical-align: -0.331em; overflow: hidden; width: 0px; height: 1.336em;"></span></span></nobr></span></span></div>
原文地址:http://blog.csdn.net/rtyu_562/article/details/44870821