不小心翻出了很久很久以前使用busybox製作根文件系統的腳本程式,在此記錄一下 !/bin/bash SHELL_DIR=$(cd $(dirname ${0});pwd) cd ${SHELL_DIR} if [ "" = "$1" ];then echo " CMD clean/nfs/ram ...
不小心翻出了很久很久以前使用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