2009年(11)
分类: LINUX
2009-10-23 12:18:24
Linux根文件系统制作脚本
mkroot: 产生根文件系统目录结构及相关文件
#! /bin/bash ### User Configuration ### # Busybox top-directory BUSYBOX_DIR=../busybox-1.15.0 # Shared library directory and files LIB_DIR=/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib LIBS="ld-linux.so.3 ld-2.8.so libc.so.6 libc-2.8.so" # Support mdev? 1 : yes 0 : no MDEV_ENALBE=1 # Prompt PROMPT='"[AT9260]# "' # Network configuration IP_CFG='192.168.12.34 netmask 255.255.255.0' HOST='AT9260' ### User Configuration End ### echo 'Clean...' if [ -d rootdir ]; then rm -rf rootdir fi echo 'Create root directory...' mkdir rootdir echo 'Copy busybox files...' cp -rd $BUSYBOX_DIR/_install/* rootdir/ cd rootdir echo 'Make sub directory...' mkdir -p dev etc etc/init.d sys proc lib var tmp usr/lib usr/etc echo 'Copy shared library...' for LIB in $LIBS do cp -d $LIB_DIR/$LIB lib/ done echo 'Make device node...' cd dev # The following 2 lines must present mknod -m 755 console c 5 1 mknod -m 755 ram0 b 1 0 if [ $MDEV_ENALBE -ne 1 ]; then # The following lines can be removed if support "mdev"(MDEV_ENALBE=1) mknod -m 755 tty c 5 0 mknod -m 755 tty0 c 4 0 mknod -m 755 tty1 c 4 1 mknod -m 755 ttyS0 c 4 64 mknod -m 755 ttyS1 c 4 65 mknod -m 755 null c 1 3 mknod -m 755 zero c 1 5 fi echo 'Make configutation files...' cd ../etc # /etc/ inittab touch inittab chmod 644 inittab echo '# System initialization' >> inittab echo '::sysinit:/etc/init.d/rcS' >> inittab echo '' >> inittab echo '# Shell' >> inittab echo '::respawn:-/bin/sh' >> inittab echo '' >> inittab echo '# Shutdown' >> inittab echo '::shutdown:/bin/umount -a -r' >> inittab echo '' >> inittab echo '# Restart' >> inittab echo '::ctrlaltdel:/sbin/reboot' >> inittab echo '' >> inittab # /etc/fstab touch fstab chmod 644 fstab echo 'proc /proc proc defaults 0 0' >> fstab echo 'sysfs /sys sysfs defaults 0 0' >> fstab # /etc/profile touch profile chmod 755 profile echo '#! /bin/sh' >> profile echo 'USER=root' >> profile echo 'LOGNAME=$USER' >> profile echo "HOSTNAME=$HOST" >> profile echo "PS1=$PROMPT" >> profile echo 'PATH=/bin:/sbin:/usr/bin:/usr/sbin' >> profile echo '' >> profile echo 'export USER LOGNAME HOSTNAME PS1 PATH' >> profile echo '' >> profile # /etc/init.d/rcS cd init.d touch rcS chmod 755 rcS echo '# Mount all file system...' >> rcS echo '/bin/mount -a' >> rcS echo '' >> rcS echo '# Configure network interface' >> rcS echo '/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0' >> rcS echo '/sbin/ifconfig eth0 down' >> rcS echo "/sbin/ifconfig eth0 $IP_CFG" >> rcS echo '/sbin/ifconfig eth0 up' >> rcS echo '' >> rcS # Add "mdev" support if [ $MDEV_ENALBE -eq 1 ]; then echo '# Add mdev support' >> rcS echo '/bin/mount -t tmpfs mdev /dev' >> rcS echo '/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug ' >> rcS echo '/sbin/mdev -s' >> rcS fi echo '' >> rcS echo 'Root file system crete OK! ' echo 'Please run ./mkrd to make and install ramdisk image.' |
mkrd:生成根文件系统镜像(适合于ramdisk)
#! /bin/bash DEST_DIR=/tftpboot echo "Make ramdisk and mount it..." dd if=/dev/zero of=ramdisk bs=1024 count=8192 mke2fs -m 0 -F ramdisk if [ ! -d mnt ]; then mkdir mnt fi mount -o loop ramdisk mnt echo "Copy files.." cp -rd rootdir/* mnt/ umount mnt echo "Make and install ramdisk image.." cat ramdisk | gzip -9 > ramdisk.gz cp -f ramdisk.gz $DEST_DIR/ramdisk.bin ls -l $DEST_DIR/ramdisk.bin rm -f ramdisk ramdisk.gz echo "OK!" |