使用busybox制作根文件系统的小脚本

翻出了很久很久以前使用busybox制作根文件系统的脚本程序,在此记录一下

#!/bin/bash SHELL_DIR=$(cd $(dirname ${0});pwd) cd ${SHELL_DIR} if [ "" = "$1" ];then echo "<Usage> CMD clean/nfs/ramdisk" exit fi CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}') export ARCH=arm export CROSS_COMPILE=/opt/arm-cross-compile/arm-none-linux-gnueabi-2014-05/bin/arm-none-linux-gnueabi- COMPILE_DIR=/opt/arm-cross-compile/arm-none-linux-gnueabi-2014-05/bin/ if [ "clean" = "$1" ];then make clean exit fi make clean make menuconfig make -j${CPU_NUM} make install cd ./_install/ mkdir -p dev etc mnt proc var tmp sys root lib/modules/4.8.5 #拷贝交叉编译工具的库文件,如果使用共享库编译,那么busybox运行的时候需要,这些库还可以支持运行编译器版本相差不多的应用程序 cp -a /opt/arm-cross-compile/arm-none-linux-gnueabi-2014-05/arm-none-linux-gnueabi/libc/lib/ . rm -f lib/*.a #去除符号表,节省空间,但是不能反汇编了 #${COMPILE_DIR}arm-none-linux-gnueabi-strip lib/* #创建sbin/init的配置文件/etc/inittab cat <<INITTAB_END >./etc/inittab # Boot-time system configuration/initialization script. # This is run first except when booting in single-user mode. # ::sysinit:/etc/init.d/rcS # Start an "askfirst" shell on the console (whatever that may be) ::askfirst:-/bin/sh #直接进shell #::askfirst:-/bin/login #需要登录,粗糙 #::respawn:/sbin/getty -L ttySAC2 115200 vt100 #需要登录,会调用上一句,更严谨 # Stuff to do when restarting the init process ::restart:/sbin/init # Stuff to do before rebooting ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a INITTAB_END mkdir -p ./etc/init.d/ cat <<RCS_END >./etc/init.d/rcS #!/bin/sh mount -a echo /sbin/mdev > /proc/sys/kernel/hotplug /sbin/mdev -s mkdir -p /dev/pts mount -t devpts devpts /dev/pts LIBDIR=/lib/modules/`uname -r` if [ ! -e $LIBDIR ] ; then mkdir -p $LIBDIR fi echo -e "\033[0;31;1m\t\t\t#----------------------XJ tech------------------------#\033[0m" #关闭黑屏 echo -e "\033[9;0]" > /dev/tty0 #显示光标 echo -e "\033[?25h" > /dev/tty0 #隐藏光标 echo -e "\033[?25l" > /dev/tty0 echo -e "\033[0;31;1m\t\t\t#----------------------XJ tech------------------------#\033[0m" > /dev/tty0 dmesg -n 1 if [ -e /etc/init.d/ifconfig-eth0 ] ; then /etc/init.d/ifconfig-eth0 else echo "eth0 Not enable" fi RCS_END cat <<FSTAB_END >./etc/fstab #device mount-point type options dump fsck order proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 mdev /dev tmpfs defaults 0 0 none /tmp tmpfs defaults 0 0 none /var tmpfs defaults 0 0 #for mmc /dev/mmcblk1p2 /mnt ext2 defaults 0 0 FSTAB_END cat <<PROFILE_END >./etc/profile #!/bin/sh # No core files by default ulimit -S -c 0 > /dev/null 2>&1 PS1='\u@\h:\w\$ ' PATH=$PATH:/sbin:/bin:/usr/bin:usr/sbin runlevel=S prevlevel=N umask 022 export runlevel prevlevel PS1 PATH PROFILE_END chmod +x etc/init.d/rcS if [ "nfs" == "$1" ];then #拷贝_install中的所有内容到nfs共享目录 sudo cp -a * /nfs elif [ "ramdisk" == "$1" ];then #创建ramdisk cd ../ dd if=/dev/zero of=ramdisk bs=1k count=8192 mkfs.ext2 -F ramdisk if [ ! -d /mnt/mnt_ramdisk ];then sudo mkdir /mnt/mnt_ramdisk fi sudo mount -t ext2 ramdisk /mnt/mnt_ramdisk/ sudo cp -a _install/* /mnt/mnt_ramdisk/ sudo umount /mnt/mnt_ramdisk gzip --best -c ramdisk >ramdisk.gz mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img mv ramdisk.img /tftp ############################################################################# #需要配置内核与之配合 #File system ---> # <*>Second extended fs support #Device Drivers # SCSI device support ---> # <*>SCSI disk support # Block devices ---> # <*>RAM block device support # (16)Default number of RAM disks # (8192)Default RAM disk size(kbytes) #General setup ---> # [*]Initial RAM filesystem and RAM disk (initramfs/initrd)support ############################################################################# fi

移植Busybox与构建根文件系统

BusyBox各版本下载

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/df89e589191778b107667b4d0eef11c1.html