busybox制作根文件系统

#!/bin/bash


# https://releases.linaro.org/components/toolchain/binaries/6.2-2016.11/armeb-linux-gnueabi/gcc-linaro-6.2.1-2016.11-i686_armeb-linux-gnueabi.tar.xz
# tar –xvf gcc-linaro-6.2.1-2016.11-i686_armeb-linux-gnueabi.tar.xz
# mv gcc-linaro-6.2.1-2016.11-i686_armeb-linux-gnueabi /usr/local/arm-linux-gnueabi
# [ grep -q arm-linux-gnueabi /etc/profile ] || echo "PATH=$PATH:/usr/local/arm-linux-gnueabi/bin" >> /etc/profile

wget https://busybox.net/downloads/busybox-1.27.2.tar.bz2

[ -d busybox-1.27.2 ] && rm -rf busybox-1.27.2

tar -xvf busybox-1.27.2.tar.bz2

pushd busybox-1.27.2
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install
popd

make_etc()
{
	[ -d etc ] && rm -rf etc
	mkdir etc
	mkdir -p etc/init.d
	mkdir -p etc/sysconfig
	
	cat > etc/inittab < etc/fstab <                       
proc              /proc              proc      defaults       0         0
sysfs             /sys               sysfs     defaults       0         0
tmpfs             /tmp               tmpfs     defaults       0         0
tmpfs             /dev               tmpfs     defaults       0         0
var               /dev               tmpfs     defaults       0         0
ramfs             /dev               ramfs     defaults       0         0
debugfs           /sys/kernel/debug  debugfs   defaults       0         0
EOF

	
	cat > etc/profile < etc/init.d/rcS < /proc/sys/kernel/hotplug
mdev -s
mkdir -p /var/lock
mkdir -p /var/run

/bin/hostname -F /etc/sysconfig/HOSTNAME
EOF
	
	chmod 755 etc/init.d/rcS
	echo vexpress > etc/sysconfig/HOSTNAME
}

[ -d rootfs ] && rm -rf rootfs
[ -d rootfs.ext3 ] && rm -rf rootfs.ext3
mkdir rootfs

mkdir -p rootfs/proc
mkdir -p rootfs/sys
mkdir -p rootfs/tmp
mkdir -p rootfs/root
mkdir -p rootfs/var
mkdir -p rootfs/mnt

mkdir -p rootfs/dev
mknod rootfs/dev/tty1 c 4 1
mknod rootfs/dev/tty2 c 4 2
mknod rootfs/dev/tty3 c 4 3
mknod rootfs/dev/tty4 c 4 4
mknod rootfs/dev/console c 5 1
mknod rootfs/dev/null c 1 3

cp -arf /usr/local/arm-linux-gnueabi/arm-linux-gnueabi/libc/lib rootfs/
cp -arf busybox-1.27.2/_install/* rootfs/

make_etc
mv etc rootfs/

dd if=/dev/zero of=rootfs.ext3 bs=1M count=128
mkfs.ext3 -F rootfs.ext3

mkdir tmpfs
mount -t ext3 rootfs.ext3 tmpfs -o loop
cp -arf rootfs/* tmpfs/

umount tmpfs && rm -rf tmpfs

 

你可能感兴趣的:(嵌入式开发,C/Linux,C)