ルートファイルシステム作成


ルートファイルシステムの作成大まかな内容:手作業で構築するのが最も簡略化された/devディレクトリudevを利用して完全な/devディレクトリを構築するクロスコンパイルツールチェーンを利用して、/libディレクトリを構築する手作業で/etcディレクトリを構築するbusyboxをコンパイル/インストールし、/bin、/sbin、/usr/bin、/usr/sbinディレクトリ構成系统を生成して自動的に/procディレクトリを生成する
その他の空のディレクトリの作成
1.ルートファイルシステムツリー作成/opt/下にフォルダrootfsを新規作成
[luminqi@localhost opt]$ mkdir rootfs
[luminqi@localhost opt]$ cd rootfs
[luminqi@localhost rootfs]$ mkdir -p {apps,bin,data,dev,info,proc,root,sbin,sys,tmp,var,etc/{,init.d,dropbear},mnt/{,usb,sdc,nfs,dev},usr/{,bin,sbin,lib,share},lib/{,modules/{,3.0.0}}}
[luminqi@localhost rootfs]$ tree -L 3 
.
├── apps               #  Application        
├── bin                #       ,  ls、cp 
├── data               #  data       
├── dev                #    ,  mtdblock0
├── etc                #      ,      ,  inittab 
│?? ├── dropbear      #dropbear ssh server     
│?? └── init.d        #         
├── info               #  info       
├── lib                #         
│?? └── modules       #insmod ,  /lib/modules/      
│??     └── 3.0.0     #   Linux        ,          
├── mnt                #            
│?? ├── dev           #    
│?? ├── nfs           #NFS   
│?? ├── sdc           #SD    
│?? └── usb           #U    
├── proc               #proc     ,                  ,             
├── root               #root    
├── sbin               #          ,  ifconfig、reboot 
├── sys                #sys       ,                  ,             
├── tmp                #tmpfs       ,      ,        
├── usr       
│?? ├── bin           #        ,  find、du 
│?? ├── lib           #            
│?? ├── sbin          #         
│?? └── share
└── var                #               ,      

27 directories, 0 files

2.Devディレクトリの下でデバイスファイルを作成する
カーネルがファイルシステムをマウントした後、initプロセスは/dev/consoleと/dev/nullの2つのデバイスファイルを使用してmdevを呼び出してdevを構築する必要があるため、ファイルシステムを作成するときに静的に2つのデバイスファイルを作成する必要があります.そうしないと、システム起動時にプロンプトが表示されます.
Waring:unable to open an initial console: 
[luminqi@localhost rootfs]$ sudo mknod -m666 dev/null c 1 3                     #                 ,            
[luminqi@localhost rootfs]$ sudo mknod -m666 dev/console c 5 1                  #      ,                
[luminqi@localhost rootfs]$ sudo mknod -m666 dev/ttyS0 c 4 64                   #      ,                 。
[luminqi@localhost rootfs]$ sudo mknod -m666 dev/ttySAC0 c 4 64                 #        
[luminqi@localhost rootfs]$ sudo mknod dev/mtdblock0 b 31 0                     #mtd   
[luminqi@localhost rootfs]$ sudo mknod dev/mtdblock1 b 31 1                     #mtd   
[luminqi@localhost rootfs]$ sudo mknod dev/mtdblock2 b 31 2                     #mtd   
[luminqi@localhost rootfs]$ sudo mknod dev/mtdblock3 b 31 3                     #mtd   
[luminqi@localhost rootfs]$ sudo mknod dev/mtdblock4 b 31 4                     #mtd   

3.Varディレクトリの下にシンボルリンクファイルを作成する
[luminqi@localhost rootfs]$ ln -s /tmp var/lock
[luminqi@localhost rootfs]$ ln -s /tmp var/log
[luminqi@localhost rootfs]$ ln -s /tmp var/run
[luminqi@localhost rootfs]$ ln -s /tmp var/tmp

4.クロスコンパイラの動的ライブラリを対応するディレクトリの下にコピー
[luminqi@localhost rootfs]$ cp -af /opt/buildroot-2011.02/arm920t/usr/arm-linux/sysroot/lib/*so* lib/
[luminqi@localhost rootfs]$ cp -af /opt/buildroot-2011.02/arm920t/usr/arm-linux/lib/*so* lib/

5.etcディレクトリの下にファイルを作成する
5.1 inittabファイルの作成
[luminqi@localhost rootfs]$ cd etc/
[luminqi@localhost etc]$ vim inittab
# /etc/inittab                                                                                                                     
#
# Copyright (C) 2017 lulinux 
#
# Note: BusyBox init doesn't support runlevels.  The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use sysvinit.
#
# Format for each entry: :::
#
# id        == tty to run on, or empty for /dev/console. 
#              If specified, then /dev/$id device must exist
# runlevels == ignored, busybox doesn't support it
# action    == one of sysinit, respawn, askfirst, wait, and once
# process   == program to run

# Startup the system
# mount all the file systems specified in /etc/fstab 
::sysinit:/bin/mount -a

#Use mdev as hotplug to auto mount USB storage or SD card 
::sysinit:/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug

#Use mdev to auto generate the device node in /dev path
::sysinit:/sbin/mdev -s

#make shm, pts support
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -t devpts devpts /dev/pts

#Mount our apps/data partition
null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock3 /apps
null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock4 /data

#Set hostname 
null::sysinit:/bin/hostname -F /etc/hostname

#Enable console logon
null::respawn:/sbin/getty -L ttyS0 115200 vt100

# now run any rc scripts
null::wait:/etc/init.d/rcS

# system daemon
null::respawn:/sbin/syslogd -n
null::respawn:/sbin/klogd -n

# Stuff to do before rebooting
null::shutdown:/bin/umount /apps
null::shutdown:/bin/umount /data
null::shutdown:/bin/killall klogd
null::shutdown:/bin/killall syslogd
null::shutdown:/bin/umount -a -r
#null::shutdown:/sbin/swapoff -a

5.2/etc/init.d/rcSスクリプトの作成
[luminqi@localhost etc]$ vim init.d/rcS
#!/bin/sh

# Copyright (C) 2017 lulinux 
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#                           

for i in /etc/init.d/S??* ; do
            $i
done

5.3 NICの起動スクリプトの構成
[luminqi@localhost etc]$ vim init.d/S01_network
#!/bin/sh

ifconfig eth0 192.168.1.111 netmask 255.255.255.0 up


5.4サポート/apps/etcディレクトリの起動スクリプトの作成
[luminqi@localhost etc]$ vim init.d/S99_rcsApp
#!/bin/sh

# Copyright (C) 2017 lulinux 
#
# Start all init scripts in /apps/etc/init.d
# executing them in numerical order.
#
if (test -d /apps/etc/init.d)
    then
    for i in /apps/etc/init.d/S??* ; do
    $i
    done
fi

5.5 init.dディレクトリのファイル権限の変更
[luminqi@localhost etc]$ chmod 777 init.d/*
5.6 fstabファイルの作成
[luminqi@localhost etc]$ vim fstab
# /etc/fstab: static file system information.
# Copyright (C) 2017 lulinux 
#
#                   
#devpts          /dev/pts       devpts   defaults          0      0
#/dev/root       /              ext2     rw,noauto         0      1
proc            /proc          proc     defaults          0      0                      
tmpfs           /tmp           tmpfs    defaults          0      0
tmpfs           /dev           tmpfs    defaults          0      0
sysfs           /sys           sysfs    defaults          0      0

5.7 hostname,hosts,TZファイルの作成
[luminqi@localhost etc]$ echo "root" > hostname
[luminqi@localhost etc]$ echo "127.0.0.1      localhost" >> hosts
[luminqi@localhost etc]$ echo "MST7MDT" >> TZ
[luminqi@localhost etc]$ echo "Copyright (C) 2017 linux" >> issue   #           
5.8 profileファイルの作成
[luminqi@localhost etc]$ vim profile
# /etc/profile: system-wide .profile file for the Bourne shells.

export PATH=\
/bin:\
/sbin:\
/usr/bin:\
/usr/sbin:\
/usr/local/bin:\
/apps/bin:\
/apps/tools:\
/apps/tslib/bin\

# If running interactively, then:
if [ "$PS1" ]; then

    if [ "$BASH" ]; then
        export PS1="[\u@\h \W]\\$ "
        alias ll='/bin/ls --color=tty -laFh'
        alias ls='/bin/ls --color=tty -F'
        export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;
32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=0
1;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.png=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35
:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.d
l=01;35:*.xcf=01;35:*.xwd=01;35:';
    else
      if [ "`id -u`" -eq 0 ]; then
        export PS1='>: '
      else
        export PS1='>: '
      fi
    fi
# System Setting
    set -o vi
    alias  ll='ls -l'
    export USER=`id -un`
    export LOGNAME=$USER
    export HOSTNAME=`/bin/hostname`
    export HISTSIZE=1000
    export HISTFILESIZE=1000
    export PAGER='/bin/more '
    export EDITOR='/bin/vi'
    export INPUTRC=/etc/inputrc
    export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
    export VAR1=
    export VAR2=
    export VAR3=
    export VAR4=
    export VAR5=
    export LD_LIBRARY_PATH=/lib:/usr/lib/
# QT Extendded 4.4.3 Setting
    export QTDIR=/apps/qt-extended-4.4.3
    export QWS_MOUSE_PROTO='TSLIB:/dev/event0'
    export QWS_DISPLAY='LinuxFB:/dev/fb0'
    export QWS_DISPLAY='LinuxFB:mmWidth240:mmHeight320:0'
    export QWS_SIZE='240x320'
    export QT_PLUGIN_PATH=$QTDIR/plugins/
    export QT_QWS_FONTDIR=$QTDIR/lib/fonts
    export PATH=$QTDIR/bin:$PATH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$QTDIR/lib
# Touch Scree tslib Setting
    export TSLIB_ROOT=/apps/tslib
    export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
    export TSLIB_CALIBFILE=$TSLIB_ROOT/etc/pointercal
    export TSLIB_TSDEVICE=/dev/event0
    export TSLIB_CONSOLEDEVICE=none
    export TSLIB_FBDEVICE=/dev/fb0
fi;

5.9いくつかのプロトコルで使用されるポート番号ファイルprotocolsを作成する
[luminqi@localhost etc]$ vim protocols
# /etc/protocols:
# $Id: protocols,v 1.1.1.1 2001/09/12 19:03:24 andersee Exp $
#
# Internet (IP) protocols
#
#       from: @(#)protocols     5.1 (Berkeley) 4/17/89
#
# Updated for NetBSD based on RFC 1340, Assigned Numbers (July 1992).

ip      0       IP              # internet protocol, pseudo protocol number
icmp    1       ICMP            # internet control message protocol
igmp    2       IGMP            # Internet Group Management
ggp     3       GGP             # gateway-gateway protocol
ipencap 4       IP-ENCAP        # IP encapsulated in IP (officially ``IP'')
st      5       ST              # ST datagram mode
tcp     6       TCP             # transmission control protocol
egp     8       EGP             # exterior gateway protocol
pup     12      PUP             # PARC universal packet protocol
udp     17      UDP             # user datagram protocol
hmp     20      HMP             # host monitoring protocol
xns-idp 22      XNS-IDP         # Xerox NS IDP
rdp     27      RDP             # "reliable datagram" protocol
iso-tp4 29      ISO-TP4         # ISO Transport Protocol class 4
xtp     36      XTP             # Xpress Tranfer Protocol
ddp     37      DDP             # Datagram Delivery Protocol
idpr-cmtp       39      IDPR-CMTP       # IDPR Control Message Transport
rspf    73      RSPF            #Radio Shortest Path First.
vmtp    81      VMTP            # Versatile Message Transport
ospf    89      OSPFIGP         # Open Shortest Path First IGP
ipip    94      IPIP            # Yet Another IP encapsulation
encap   98      ENCAP           # Yet Another IP encapsulation
5.10 mdev.confファイルの作成
mdevは/etcディレクトリの下でmdevのプロファイル:mdev.confを探します.ファイルが存在しない場合は、mdev-sというコマンドを実行すると、mdev.confが見つからないことを示すメッセージが表示されます.この場合、空のmdev.confファイルを作成してこの問題を解決できます.次に、mdevを使用してuディスクとSDカードを自動的にマウントする構成/etc/mdev.confを作成します.
[luminqi@localhost etc]$ vim mdev.conf
sd[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)
sd[a-z]           0:0 0777        $(umount /mnt/usb)
ub[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)
ub[a-z]           0:0 0777        $(umount /mnt/usb)
mmcblk[0-9]p[0-9] 0:0 0777        @(mount /dev/$MDEV /mnt/sdc)
mmcblk[0-9]       0:0 0777        $(umount /mnt/sdc)

5.11ユーザーグループグループグループグループファイルの作成
[luminqi@localhost etc]$ vim group
root:x:0:root
5.12ユーザーpasswdファイルを作成します.ここではパスワードなしでログインするように設定します.
[luminqi@localhost etc]$ vim passwad
root::0:0:99999:7:::
5.13パスワードマッピングshadowファイルの作成
[luminqi@localhost etc]$ vim shadow
root:($jGZIHmtT$y8ZXoPllK12/wl51kMw4e/:0:0:99999:7:::)
6.ファイルシステムにbusyboxをインストールする
[luminqi@localhost etc] cd /opt
[luminqi@localhost opt]$ ls rootfs
apps  bin  data  dev  etc  info  lib  mnt  proc  root  sbin  sys  tmp  usr  var
[luminqi@localhost opt] sudo tar -xjf /opt/busybox-1.20.2.tar.bz2    //         
[luminqi@localhost opt] cd busybox-1.20.2
[luminqi@localhost busybox-1.20.2]$ vim Makefile
#  CROSS_COMPILER :
CROSS_COMPILE ?= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-

[luminqi@localhost busybox-1.20.2]$ vt100
[luminqi@localhost busybox-1.20.2]$ sudo make menuconfig
Busybox Settings  --->
       General Configuration  --->
             [*] Don't use /usr
       Installation Options ("make install" behavior)  --->
             What kind of applet links to install (as soft-links)  --->   //  busybox           busybox    
             (/opt/rootfs) BusyBox installation prefix
[luminqi@localhost busybox-1.20.2]$ sudo make
[luminqi@localhost busybox-1.20.2]$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped
[luminqi@localhost busybox-1.20.2]$ sudo make install
[luminqi@localhost busybox-1.20.2]$ ls /opt/rootfs
apps  bin  data  dev  etc  info  lib  linuxrc  mnt  proc  root  sbin  sys  tmp  usr  var
##linuxrcファイルを1つ多く見ました
linuxrc -> bin/busybox

7.移植dropbear 7.1まずコンパイルしてPC版を生成し、鍵を作成する際に使用する
[luminqi@localhost busybox-1.20.2]$ cd /home/luminqi/fl2440/3rdparty
[luminqi@localhost 3rdparty]$ wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.bz2
[luminqi@localhost 3rdparty]$ tar -xjf dropbear-0.53.1.tar.bz2 
[luminqi@localhost 3rdparty]$ cd dropbear-0.53.1
[luminqi@localhost dropbear-0.53.1]$ ./configure && make
[luminqi@localhost dropbear-0.53.1]$ ./dropbearkey -t rsa -f /opt/rootfs/etc/dropbear/dropbear_rsa_host_key
[luminqi@localhost dropbear-0.53.1]$ ./dropbearkey -t dss -f /opt/rootfs/etc/dropbear/dropbear_dss_host_key
[luminqi@localhost dropbear-0.53.1]$ chmod 666 /opt/rootfs/etc/dropbear/dropbear_*

7.2 ARMバージョンのコンパイル
[luminqi@localhost dropbear-0.53.1]$ make distclean
[luminqi@localhost dropbear-0.53.1]$ ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --build=i686 --host=arm-linux --disable-zlib
[luminqi@localhost dropbear-0.53.1]$ make
[luminqi@localhost dropbear-0.53.1]$ file dropbear
dropbear: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[luminqi@localhost dropbear-0.53.1]$ file dbclient
dbclient: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[luminqi@localhost dropbear-0.53.1]$ mv dbclient ssh
[luminqi@localhost dropbear-0.53.1]$ arm-linux-strip dropbear
[luminqi@localhost dropbear-0.53.1]$ arm-linux-strip ssh
[luminqi@localhost dropbear-0.53.1]$ cp dropbear ssh /opt/rootfs/usr/sbin/

[luminqi@localhost rootfs]$ ll
    60
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 apps
drwxrwxr-x. 2 luminqi luminqi 4096 3    4 00:29 bin
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 data
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:20 dev
drwxrwxr-x. 4 luminqi luminqi 4096 3    4 14:52 etc
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 info
drwxrwxr-x. 3 luminqi luminqi 4096 3    3 23:24 lib
lrwxrwxrwx. 1 root    root      11 3    4 00:29 linuxrc -> bin/busybox
drwxrwxr-x. 6 luminqi luminqi 4096 3    3 23:17 mnt
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 proc
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 root
drwxrwxr-x. 2 luminqi luminqi 4096 3    4 00:29 sbin
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 sys
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:17 tmp
drwxrwxr-x. 6 luminqi luminqi 4096 3    3 23:17 usr
drwxrwxr-x. 2 luminqi luminqi 4096 3    3 23:21 var

8.ファイルシステムで起動スクリプトを作成する
[luminqi@localhost roorfs]$ cd /opt/rootfs
[luminqi@localhost rootfs]$ vim etc/init.d/S04_dropbear
#!/bin/sh
/usr/sbin/dropbear
chmod 777 etc/init.d/S04_dropbear

ここまでルートファイルシステムの作成は完了しましたが、この時点ではフォルダであり、開発ボードに書かれたnandflashに焼くことはできません.
パッケージ」を作成し、イメージファイルの形式にします.
例:
Initramfsファイルシステムを作成する原理:上で作成したルートファイルシステム(rootfsというフォルダ)はカーネルをコンパイルしながらコンパイルされ、カーネルとイメージファイル(cpioパッケージフォーマット)を生成する.このシステムはRAM(メモリ)に基づいており、nandflash.ではなくメモリにマウントされている.jffs 2ファイルシステムを作成する.原理:ツールmkfs.jffs 2によってルートファイルシステム(rootfsというフォルダ)をイメージファイルに作成します.このシステムはflashに基づいてMTDで管理されています.以下にjffs 2イメージファイルのタイプを示します.
[luminqi@localhost opt]$ file rootfs.jffs2 
rootfs.jffs2: Linux jffs2 filesystem data little endian
ルートファイルシステムとファイルシステムについて、私はこのように理解できると思います.
ルートファイルシステムは、少なくともオペレーティングシステムを走らせるために必要なファイルの集合です.例えば、/bin、/sbinのコマンドファイル、および/etcのプロファイル、起動ファイルinittabなどです.重要なファイルが1つ欠けていると、ルートファイルシステムにはなりません.Linuxカーネルはこのファイルシステムを認めず、エラーを報告して終了し、マウントに失敗します.
ルートファイルシステムに異なる属性を与えると、ルートファイルシステムは異なるファイルシステムになります.
例えば、ルートファイルシステムjffs 2の属性(ツールmkfs.jffs 2を介して)を付与ことにより、jffs 2ファイルシステムが生成される.