构建最小linux 文件系统 一

2019-07-13 04:30发布

基于busybox构建最小linux 文件系统 一

可从busybox官网 https://busybox.net/ 下载busybox
本文中使用的是busybox-1.27.1
具体制作步骤如下: 1.手动创建基本目录与文件
手动创建基本文件,在这里把手动需要创建的文件制作成脚本 如下 #!/bin/bash echo "------Create rootfs directons start...--------" rm -rf rootfs mkdir rootfs cd rootfs echo "--------Create root,dev....----------" mkdir root dev etc boot tmp var sys proc lib mnt home usr mkdir etc/init.d etc/rc.d etc/sysconfig mkdir usr/sbin usr/bin usr/lib usr/modules echo "make node in dev/console dev/null" sudo mknod -m 600 dev/console c 5 1 sudo mknod -m 600 dev/null c 1 3 mkdir dev/pts -p mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp mkdir var/lib var/lock var/run var/tmp var/log chmod 1777 tmp chmod 1777 var/tmp # create etc config /etc/inittab echo -e "::sysinit:/etc/init.d/rcS " >etc/inittab echo -e "::askfirst:-/bin/sh " >>etc/inittab echo -e "::ctrlaltdel:/sbin/reboot " >>etc/inittab echo -e "::shutdown:/bin/umount -a -r " >>etc/inittab # create etc config /etc/init.d/rcs echo -e "#! /bin/sh " >etc/init.d/rcS echo -e "mount -t sysfs none /sys " >>etc/init.d/rcS echo -e "mount -t proc none /proc " >>etc/init.d/rcS echo -e "mount -t tmpfs tmpfs /tmp" >>etc/init.d/rcS echo -e "/bin/hostname -F /etc/sysconfig/HOSTNAME " >>etc/init.d/rcS echo -e "mdev -s " >>etc/init.d/rcS chmod +x etc/init.d/rcS # create etc config /etc/fstab echo -e "proc /proc proc defaults 0 0 " >etc/fstab echo -e "sysfs /sys sysfs defaults 0 0 " >>etc/fstab echo -e "devtmpfs /dev devtmpfs defaults 0 0 " >>etc/fstab echo -e "tmpfs /tmp tmpfs defaults 0 0 " >>etc/fstab echo -e "tmpfs /var tmpfs defaults 0 0 " >>etc/fstab echo -e "none /dev/pts devpts defaults 0 0 " >>etc/fstab # create etc config /etc/group echo -e "root:x:0: " >etc/group # create etc config /etc/passwd echo -e "root:x:0:0:root:/root:/bin/sh " >etc/passwd # create etc config /etc/profile echo -e "PATH=/bin:/sbin:/usr/bin:/usr/sbin " >etc/profile echo -e "export PATH " >>etc/profile echo -e "#set hostname " >>etc/profile echo -e "HOSTNAME='/bin/hostname' " >>etc/profile echo -e "export HOSTNAME " >>etc/profile echo -e "# Set PS1 " >>etc/profile echo -e "PS1='u@h:w\$ ' " >>etc/profile echo -e "export PS1 " >>etc/profile # create etc config /etc/sysconfig/HOSTNAME echo -e "hostname " >etc/sysconfig/HOSTNAME echo "-------make direction done---------" 2.编译busybox $ tar zxvf busybox-1.27.1.tar.bz2 $ cd busybox-1.27.1 $ export ARCH=arm $ export CROSS_COMPILE=arm-linux-gnueabi- $ make defconfig $ sed -i.orig 's/^#.*CONFIG_STATIC.*/CONFIG_STATIC=y/' .config $ make $ make CONFIG_PREFIX=rootfs_dir install (指定安装目录,上面脚本创建的rootfs 所在的目录比如 /home/xxx/xxx/rootfs) 等待编译安装结束,基本文件系统制作完毕。 启动开发板看制作的文件系统: 这里写图片描述 未完待续。。。