Detailed steps for porting busybox to build a minimal root file system

Detailed steps for porting busybox to build a minimal root file system

Busybox: A Swiss Army knife filled with small commands.

STEP 1: Create a directory structure

Create the root file system directory, mainly including the following directories

/dev /etc /lib /usr /var /proc /tmp /home /root /mnt /bin /sbin /sys
#mkdir /home/rootfs
#cd /home/rootfs
#mkdir dev etc lib usr var proc tmp home root mnt sys

STEP 2: Use busybox to build /bin /sbin linuxrc

Enter the busybox-1.16.1 directory and execute

#make defconfig
#make menuconfig
Busybox Setting ----->
 Build Options -----> 
  //1 Choose to compile busybox statically [*]Build BusyBox as a static binary (no shared libs) 
  //2. Specify the cross compiler as (/usr/local/arm/4.3.2/bin/arm-linux-)Cross Compiler prefix
Installation Options -----> (Select the directory to store the generated files, or you can put them directly in rootfs without copying)

  //3. Select Don't use /usr 
Busybox Library Tuning---> 
 [*]Username completion 
 [*]Fancy shell prompts 
 [*]Query cursor position from terminal 
  //4. The compiled busybox shell command interpreter supports displaying the current path and host information

Save and exit

#make #make install

In the busybox directory, you will see the _install directory, which contains three files: /bin /sbin and linuxrc. Copy these three directories or files to the rootfs folder created in the first step.

#cp bin/ sbin/ linuxrc /home/rootfs -ra

Remember to bring the -a parameter, because most of the bin directory is links. If you don't bring the -a parameter, it will be copied accordingly after copying, and it will no longer be in the form of a link.

STEP 3 Build the etc directory: (mainly etc/inittab file, etc/init.d/rcs, etc/fstab)

1) Enter the etc directory of the root file system rootfs and perform the following operations:

Copy Busybox-1.16.1/examples/bootfloopy/etc/* to the current directory

 #cp –r busybox-1.16.1/examples/bootfloopy/etc/* rootfs/etc

Modify inittab, (create other subprocesses based on it)

The original file is:

1 ::sysinit:/etc/init.d/rcS 2 ::respawn:-/bin/sh 
    3 tty2::askfirst:-/bin/sh 4 ::ctrlaltdel:/bin/umount -a -r

After modification:

---(1): Start the computer without logging in, and directly open the shell (the number in front is the line number)

1 ::sysinit:/etc/init.d/rcS 
        2 #::respawn:-/bin/sh 
        3 #::respawn:-/bin/login 
        4 console::askfirst:-/bin/sh 
        5 #tty2::askfirst:-/bin/sh 6 ::ctrlaltdel:/bin/umount -a -r

---(2): You need to log in to boot up (the number in front is the line number)

 1 ::sysinit:/etc/init.d/rcS 
        2 #::respawn:-/bin/sh 
      3 ::respawn:-/bin/login 
        4 #console::askfirst:-/bin/sh 
       5 #tty2::askfirst:-/bin/sh 
       6 ::ctrlaltdel:/bin/umount -a -r

2) Copy /etc/passwd, /etc/group, /etc/shadow on the virtual machine to rootfs/etc

  # cp /etc/passwd rootfs/etc
  # cp /etc/group rootfs/etc 
  # cp /etc/shadow roofs/etc

Modify the following three files and only save the items related to root. The content will vary depending on the specific situation.

Change passwd to root:x:0:0:root:/root:/bin/sh, which means only save items related to root, and finally change it to /bin/ash.

Change group to root:x:0:root

Modify shadow to root:$1$x9yv1WlB$abJ2v9jOlOc9xW/y0QwPs.:14034:0:99999:7:::

When logging into the development board, you need to enter your username and password, which is the same as the virtual machine.

3) Modify profile

PATH=/bin:/sbin:/usr/bin:/usr/sbin //Executable program environment variable export LD_LIBRARY_PATH=/lib:/usr/lib //Dynamic link library environment variable /bin/hostname osee
  USER="`id -un`"
  LOGNAME=$USER
  HOSTNAME='/bin/hostname'
  PS1='[\u@\h \W]# ' //Display host name, current path and other information:

4) Modify the etc/init.d/rc.S file (add automatic execution commands) #! /bin/sh

/bin/mount -n -t ramfs ramfs /var 
   /bin/mount -n -t ramfs ramfs /tmp
  /bin/mount -n -t sysfs none /sys
  /bin/mount -n -t ramfs none /dev
  /bin/mkdir /var/tmp
  /bin/mkdir /var/modules
  /bin/mkdir /var/run
  /bin/mkdir /var/log
  /bin/mkdir -p /dev/pts //Required by telnet service /bin/mkdir -p /dev/shm //Required by telnet service #echo /sbin/mdev > /proc/sys/kernel/hotplug //USB automatic mounting requires /sbin/mdev -s //Start mdev to automatically create device file nodes under /dev /bin/mount -a 
  ########Configure Network#################################
  /sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0
  /sbin/ifconfig eth0 192.168.1.70
  /sbin/ifconfig eth0 netmask 255.255.255.0
  /sbin/route add default gw 192.168.1.1 eth0
  /sbin/ifconfig eth1 192.168.1.71 netmask 255.255.255.0
  /sbin/route add default gw 192.168.1.1 eth1

5) Modify the etc/fstab file and add the following file to mount the proc tmpfs file system

#device mount-point type options dump fsck order
  none /dev/pts devpts mode=0622 0 0
  tmpfs /dev/shm tmpfs defaults 0 0
  proc /proc proc defaults 0 0

STEP 4 Build the lib directory:

(~/at91/x-tools/arm-zch-linux-gnueabi/arm-zch-linux-gnueabi/sysroot/lib, I just copy the SO file in this directory)

1 )#cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib

Copy the following dynamic libraries to rootfs/lib

#cp *so* roofs/lib -a

2 )#cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib

Copy the following dynamic libraries to rootfs/lib

#cp ./libstdc++.so.* rootfs/lib -a

STEP 5 Build the lmdev directory:

Method 1: Statically create device files cat /proc/devices

mknod console c 5 1
mknod null c 1 3
mknod ttySAC0 c 204 64
mknod mtdblock0 b 31 0

Method 2: Use mdev to create a device file

Make sure your kernel sets CONFIG_SYSFS CONFIG_TMPFS

When the kernel starts, mdev is automatically run

Modify etc/fstab to automatically mount the root file system. Modify etc/init.d/rcS to add commands to run automatically.

Summarize

The above is the detailed steps of transplanting busybox to build a minimum root file system introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Transplanting the mkfs.vfat command in busybox under Linux system
  • Docker uses busybox to create a base image
  • Telnet is moved to busybox-extras in Alpine image
  • What to do if the Android device does not recognize the awk command and lacks busybox

<<:  Mysql updates certain fields of another table based on data from one table (sql statement)

>>:  Detailed comparison of Ember.js and Vue.js

Recommend

How to disable web page styles using Firefox's web developer

Prerequisite: The web developer plugin has been in...

MySQL SQL statement analysis and query optimization detailed explanation

How to obtain SQL statements with performance iss...

Summary of commonly used CSS encapsulation methods

1. pc-reset PC style initialization /* normalize....

Tutorial on using the frameset tag in HTML

Frameset pages are somewhat different from ordina...

The difference and usage of LocalStorage and SessionStorage in vue

Table of contents What is LocalStorage What is Se...

Specific usage of textarea's disabled and readonly attributes

disabled definition and usage The disabled attrib...

Summary of seven MySQL JOIN types

Before we begin, we create two tables to demonstr...

Comparison of the efficiency of different methods of deleting files in Linux

Test the efficiency of deleting a large number of...

Analysis and application of irregular picture waterfall flow principle

The layout problem of irregular picture walls enc...

Implementing timed page refresh or redirect based on meta

Use meta to implement timed refresh or jump of th...

Solutions to VMware workstation virtual machine compatibility issues

How to solve VMware workstation virtual machine c...

Introduction to the use of the indeterminate property of the checkbox

When we use the folder properties dialog box in Wi...

innodb_flush_method value method (example explanation)

Several typical values ​​of innodb_flush_method f...