Latest busybox-1.28.1 make root file system

Source: Internet
Author: User
Tags mkdir

This paper is suitable for fs4412 Development Board, the kernel used is linux4.9.9.
1. SOURCE Download
BusyBox's official source download path is:
http://busybox.net/downloads/
Can download the latest busybox-1.28.1
2. Extract Source

Tar xvf busybox-1.28.1.tar.bz2

3. Access to the source directory

CD busybox-1.28.1

4. Configure BusyBox
BusyBox has already done a lot of default configuration (such as some commonly used shell commands: LS, cd,mkdir, etc.), so we just need to do a few steps to fit easily.
First, implement

Make Menuconfig

4.1 busybox The choice of libraries to run using

Settings--->
 [*] build static binary (no shared libs)   

Here select compile Compile static library does not depend on with any dynamic link library, compiled executable file busybox will be bigger but also only 1M size.
4.2 Cross-compilation tool chain selection

Settings--->
    

Choose your own tool chain based on your own platform
4.3 Choice of installation directory

Settings--->
        (./_install) Destination path for ' make install '  

Install directory Here Select the _install directory for the current directory
4.4 usr related file generation selection

Settings--->
        [] Don t USE/USR  

Note: This compilation option is selected by default and we have to manually remove it to compile the/USR-related directory.
5. Compile
Perform

Wait a few minutes for the compilation to complete.
6. Installation
Perform

Make install
The results are as follows: .....
   /_install//usr/sbin/svlogd->. /.. /bin/busybox
  ./_install//usr/sbin/telnetd->. /.. /bin/busybox
  ./_install//usr/sbin/tftpd->. /.. /bin/busybox
  ./_install//usr/sbin/ubiattach->. /.. /bin/busybox
  ./_install//usr/sbin/ubidetach->. /.. /bin/busybox
  ./_install//usr/sbin/ubimkvol->. /.. /bin/busybox
  ./_install//usr/sbin/ubirename->. /.. /bin/busybox
  ./_install//usr/sbin/ubirmvol->. /.. /bin/busybox
  ./_install//usr/sbin/ubirsvol->. /.. /bin/busybox
  ./_install//usr/sbin/ubiupdatevol->. /.. /bin/busybox
  ./_INSTALL//USR/SBIN/UDHCPD->. /.. /bin/busybox
--------------------------------------------------You'll
probably need to make your busybox Binary
setuid root to ensure all configured applets'll work
properly.
--------------------------------------------------

7. View the compiled generated files
Enter _install Directory

CD _install/
l$ ls
bin  linuxrc  sbin  usr

You can see that 4 files were generated.
You can find that the BusyBox size under/bin is 1.9M, and the other command executables are symbolic links to it.
such as execution: LS <===> busybox ls
Perform

$file bin/busybox
bin/busybox:elf 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for Gnu/linux 2.6. Stripped.

You can see the executable file BusyBox that generated the ARM architecture using the static library, that is, the installation was successful
The following steps do not operate, directly copy the above directory to the/source/rootfs under the launch of the Development Board network mount, you can find that can also enter the system and can enter the shell command (to be able to enter shell naming instructions that the shell command itself is not dynamic link, Because we haven't put the library file in the file system yet. A lot of functions (/dev also created a device node) but the function is not:
1 The system cannot run executable files that use dynamic library links (not to mention the dynamic libraries are linked by default when the system compiles), in order to reduce the size of the executable, you can use the-static option to compile and not use this option to compile and put it in the root file system. )
2/sys directory Space-Time, so we can not see the bus-device-driven information through SYSFS
3/proc Directory is empty, we can not see some kernel and process information exported kernels (Mount command View system mount situation can not see, PS command can not see the information)
4 the INIT process resolves the inittab file, so the default configuration is used
5 Unable to run our startup program, etc.
This is not tolerable for practical applications, so you will need to add other directory files.
8. Create additional directories that you need

mkdir Dev etc-lib sys proc TMP var home root mnt  

Add a library file under the 9.lib directory
Need to copy the library copy of the Cross tool chain to this directory (here is a copy of the dynamic library because of the general program so that dynamic compilation requires the Board dynamic library support, static library is generally used in the static compilation of the compile phase, because the work of the Cross compilation on the PC so do not need a static library, This can also reduce the size of the root file system:

cp/home/linux/tool_chain/arm-2010.09/arm-none-linux-gnueabi/libc/lib/*.so*. -A

Slimming library files (removing symbol tables and debugging information):

Arm-none-linux-strip *

View file type It's been thin.

$file ld-2.11.1.so
ld-2.11.1.so:elf 32-bit LSB Shared Object, ARM, version 1 (SYSV), dynamically linked, stripped

Add configuration file under 10.etc directory
10.1 Add profile

#!/bin/sh
export Hostname=liebao
export user=root export
home=home
export ps1= "[$USER @ $HOSTNAME \w] \# "
path=/bin:/sbin:/usr/bin:/usr/sbin
ld_library_path=/lib:/usr/lib: $LD _library_path
export PATH LD _library_path

The entry system shows the following:

...
Please press Enter to activate this console.
[root@liebao:/]#
[root@liebao:/] #cd
[root@liebao:/home]#
[root@liebao:/home] #echo $PATH
/bin:/ Sbin:/usr/bin:/usr/sbin

You can see that we have customized the command prompt, and the CD has entered our home directory homes and exported environment variables.
10.2 Adding Inittab and RCS files
1) in etc under the Add File Inittab, the contents of the document are as follows:

#this is run except booting in Single-user mode.
:: Sysinit:/etc/init.d/rcs
#/bin/sh on sel  ected TTYs
# start an ' Askfirst ' shell on the console (whatever, May)
:: askfirst:-/bin/sh
# Stuff to Do when restarting the init process
:: restart:/sbin/init
# Stuff Todo before rebooting:
: Ctrlaltdel:/sbi N/reboot

This is the configuration file that is parsed by the Init process, and this configuration file determines which process to execute and when.
2) Create ETC/INIT.D directory

mkdir ETC/INIT.D

Enter ETC/INIT.D
Create a file RCS This is a startup script (which allows you to put some scripts or programs that need to be executed when the system starts)
Write a statement such as:

echo "Welcome to Linux" > RcS

Add executable permissions:

chmod +x RcS

Reboot the development Board to see the print, print out the statement that the configuration file configuration is successful, you can add your own executable program.
10.3 Add fstab File
In order for that system to automatically mount some files, need a fstab file, dev under the Create Fstab file:

Touch Fstab

The contents of the document are as follows:

#device  mount-point    type     options   dump   fsck order
sysfs    /sys          sysfs     Defaults    0       0
proc/     proc         proc      defaults    0       0 tmp/      tmp          TMPFS     Defaults    0       0
tmp/      dev          tmpfs     defaults    0       0

Specifies the mounted file system.
The file system we hang here has three proc, Sysfs, and TMPFS, which are supported by default proc and Sysfs in the kernel, and TMPFS is unsupported and we need to add TMPFS support
To modify the kernel configuration:

$ make menuconfig
file systems--->
       Pseudo filesystems--->
              [*] Virtual Memory file system support (form ER shm fs)
              [*] TMPFS POSIX Access control Lists

Recompile the kernel (in fact, the linux4.9 kernel we are using is already configured).

To add an automatic mount command to the startup script/etc/init.s/rcs:

/bin/mount-a
/bin/mkdir/dev/pts
/bin/mount-t devpts devpts/dev/pts

The first sentence is: The/etc/fstab file will be executed
The 23rd sentence is: To create a virtual devpts file system for the pseudo terminal equipment (when we use Telnet or SSH, etc. when the login system will automatically/dev/pts/under the creation of/DEV/PTS/0,/DEV/PTS/1, such as the terminal)
Reboot the development board and execute the Mount command:

[root@liebao:/] #mount
172.16.21.104:/source/rootfs on/type NFS (rw,relatime,vers=2,rsize=4096,wsize=4096, Namlen=255,hard,nolock,proto=udp,timeo=11,retrans=3,sec=sys,mountaddr=172.16.21.104,mountvers=1,mountproto=udp , local_lock=all,addr=172.16.21.104)
Devtmpfs on/dev type DEVTMPFS (rw,relatime,size=469156k,nr_inodes=117289, mode=755)
Sysfs on/sys type Sysfs (rw,relatime)
proc On/proc type proc (rw,relatime) tmpfs on/tmp
type Tmpf S (rw,relatime)
devpts on/dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)

Mount the file system we need to mount, this time to view/sys and/proc under the corresponding files (then the PS command can be read from the proc process-related information).
10.4 Enable Mdev function
The above basically realized the file system should have the function, but we know that "Linux everything is File", the access to the device is abstracted to the file access, so there is the concept of device file node, so you need to create a device node to access the device, manually create unrealistic, Linux uses the UDEV mechanism to automatically create device nodes, using small mdev in embedded to read kernel information to create device files.
Add in/etc/init.d/rcs:

/sbin/mdev >/proc/sys/kernel/hotplug
/sbin/mdev-s

The first sentence: To set the kernel hot-swappable, when the device is hot-swappable call/sbin/mdev
The second sentence: for all the device nodes generated by the kernel support under/dev
When the development Board is restarted, the system Mdev scans the files under/sys/dev/block and/sys/dev/char to automatically create device nodes.
Add device files under 11.dev directory
You need to create two device files:

Mknod/dev/console C 5 1
mknod/dev/null C 1 3

In fact, not creating these two file systems can also be created automatically.

Now our system is completely ready to use, and the function is basically perfect.

Note: For porting the linux4.9.9 kernel, see "porting the latest linux4.9.9 kernel (Fit fs4412 platform)":
http://blog.csdn.net/liebao_han/article/details/79436819
The content of the article continues to be updated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.