欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

x4412最小根文件系统制作

程序员文章站 2022-07-14 19:57:31
...
1 . 根文件系统制作
可以从 http://busybox.net/downloads/

运行 Ubuntu 14.04 系统,打开命令行终端:
$ cd ~
$ mkdir busybox
$ cd busybox
解压下载的busybox1.25(根据自己选择下载文件)
$ tar xvf busybox-1.25.0.tar.bz2
//解压源码
$ cd  busybox-1.25.0
配置 busybox 源码:
$ make menuconfig
Busybox Settings --->
Build Options --->
	[*] Build BusyBox as a static binary (no shared libs)
	[ ] Force NOMMU build
	[ ] Build with Large File Support (for accessing files > 2 GB)
		(arm-none-linux-gnueabi-) Cross Compiler prefix
		() Additional CFLAGS

修改最顶层目录下的Makefiel
$ vim Makefile
 修改为如下内容
 ARCH  ?= arm
 CROSS_COMPILE ?= arm-none-linux-gnueabi-
编译源码:
$ make
安装:
busybox 默认安装路径为源码目录下的_install
$ make install
进入安装目录:
$ cd _install
$ ls
bin linuxrc sbin usr
创建其他需要的目录:
$ mkdir dev etc mnt proc var tmp sys root
添加库:
将工具链中的库拷贝到_install 目录下:
$ cp /home/linux/toolchain/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/lib/ . -a
删除静态库和共享库文件中的符号表:
$ sudo rm lib/*.a
# arm-none-linux-gnueabi-strip lib/*.so (超级用户下执行命令)
删除不需要的库,确保所有库大小不超过 4M:
$ du -mh lib/
添加系统启动文件:
在 etc 下添加文件 inittab,文件内容如下:
#this is run first except when booting in single-user mode.
::sysinit:/etc/init.d/rcS
# /bin/sh invocations on selected ttys
# start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
# stuff to do when restarting the init process
::restart:/sbin/init
# stuff to do before rebooting
::ctrlaltdel:/sbin/reboot

在 etc 下添加文件 fstab ,文件内容如下:
#device   mount-point  type     options     dump   fsck order
proc       /proc        proc    defaults      0        0
tmpfs      /tmp         tmpfs   defaults      0        0
sysfs      /sys         sysfs   defaults      0        0
tmpfs      /dev         tmpfs   dafaults      0        0

这里我们挂载的文件系统有三个 proc、sysfs 和 tmpfs 。在内核中 proc 和 sysfs 默认都支持,而
tmpfs 是没有支持的,我们需要添加 tmpfs 的支持
修改 Linux 内核配置;
$ cd ~/ kernel/linux-4.9.123
$ make menuconfig
File systems --->
	Pseudo filesystems --->
		[*] Virtual memory file system support (former shm fs)
		[*] Tmpfs POSIX Access Control Lists
重新编译内核:
$ make uImage
$ cp arch/arm/boot/uImage /tftpboot
回到创建的文件系统处,在etc下创建init.d目录,并在init.d下创建rcS文件,rcS文件内容为:
#!/bin/sh
# This is the first script called by init process
/bin/mount   -a
echo /sbin/mdev  >  /proc/sys/kernel/hotplug
/sbin/mdev   -s

为 rcS 添加可执行权限:
$ chmod +x init.d/rcS

在 etc 下添加 profile 文件,文件内容为:
#!/bin/sh
export HOSTNAME=x4412
export USER=root
export HOME=root
export PS1="[[email protected]$HOSTNAME \W]\# "
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH

至此根文件目录已经制作完成。当然如果要使用emmc或sd进行启动需要将其制作成镜像文件ext2或ext4等,然后写入硬盘分区。
下面描述一下制作ext4格式镜像文件,rootfs.img,其大小为16MB。具体步骤如下: 
1、#:mkdir rootfs_tmp #创建挂载临时文件目录
2、利用dd指令和mkfs.ext4创建ext4镜像文件
	#:dd if=/dev/zero of=rootfs.img bs=1024 count=16000
	#:mkfs.ext4 rootfs.img
3、挂载镜像文件到临时目录中
	#:mount -o loop rootfs.img rootfs_tmp/
4、将rootfs里的最小文件系统文件拷贝到临时目录里
	#:cp -rf rootfs/* rootfs_tmp/
5、卸载临时目录,完成镜像制作
	#:umount rootfs_tmp/



1 . 根文件系统制作
可以从 http://busybox.net/downloads/

运行 Ubuntu 14.04 系统,打开命令行终端:
$ cd ~
$ mkdir busybox
$ cd busybox
解压下载的busybox1.25(根据自己选择下载文件)
$ tar xvf busybox-1.25.0.tar.bz2
//解压源码
$ cd  busybox-1.25.0
配置 busybox 源码:
$ make menuconfig
Busybox Settings --->
Build Options --->
	[*] Build BusyBox as a static binary (no shared libs)
	[ ] Force NOMMU build
	[ ] Build with Large File Support (for accessing files > 2 GB)
		(arm-none-linux-gnueabi-) Cross Compiler prefix
		() Additional CFLAGS

3.1编译之前首先修改Makefiel,使用交叉编译器

$vim Makefile

 ARCH  ?= arm

 CROSS_COMPILE ?= arm-none-linux-gnueabi-
编译源码:
$ make
安装:
busybox 默认安装路径为源码目录下的_install
$ make install
进入安装目录:
$ cd _install
$ ls
bin linuxrc sbin
usr
创建其他需要的目录:
$ mkdir dev etc mnt proc var tmp sys root
添加库:
将工具链中的库拷贝到_install 目录下:
$ cp /home/linux/toolchain/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/lib/ . -a
删除静态库和共享库文件中的符号表:
$ sudo rm lib/*.a
# arm-none-linux-gnueabi-strip lib/*.so (超级用户下执行命令)
删除不需要的库,确保所有库大小不超过 4M:
$ du -mh lib/
添加系统启动文件:
在 etc 下添加文件 inittab,文件内容如下:
#this is run first except when booting in single-user mode.
::sysinit:/etc/init.d/rcS
# /bin/sh invocations on selected ttys
# start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
# stuff to do when restarting the init process
::restart:/sbin/init
# stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
在 etc 下添加文件 fstab ,文件内容如下:
#device   mount-point  type     options     dump   fsck order
proc       /proc        proc    defaults      0        0
tmpfs      /tmp         tmpfs   defaults      0        0
sysfs      /sys         sysfs   defaults      0        0
tmpfs      /dev         tmpfs   dafaults      0        0


这里我们挂载的文件系统有三个 proc、sysfs 和 tmpfs 。在内核中 proc 和 sysfs 默认都支持,而
tmpfs 是没有支持的,我们需要添加 tmpfs 的支持
修改 Linux 内核配置;
$ cd ~/ kernel/linux-4.9.123
$ make menuconfig
File systems --->
	Pseudo filesystems --->
		[*] Virtual memory file system support (former shm fs)
		[*] Tmpfs POSIX Access Control Lists
重新编译内核:
$ make uImage
$ cp arch/arm/boot/uImage /tftpboot
回到创建的文件系统处,在etc下创建init.d目录,并在init.d下创建rcS文件,rcS文件内容为:
#!/bin/sh
# This is the first script called by init process
/bin/mount   -a
echo /sbin/mdev  >  /proc/sys/kernel/hotplug
/sbin/mdev   -s

为 rcS 添加可执行权限:
$ chmod +x init.d/rcS

在 etc 下添加 profile 文件,文件内容为:
#!/bin/sh
export HOSTNAME=x4412
export USER=root
export HOME=root
export PS1="[[email protected]$HOSTNAME \W]\# "
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH


制作ext4格式镜像文件,rootfs.ext4,其大小为16MB。 

1、#:mkdir rootfs_tmp #创建挂载临时文件目录

2、利用dd指令和mkfs.ext4创建ext4镜像文件

	#:dd if=/dev/zero of=rootfs.img bs=1024 count=16000

	#:mkfs.ext4 rootfs.img

3、挂载镜像文件到临时目录中

	#:mount -o loop rootfs.img rootfs_tmp/

4、将rootfs里的最小文件系统文件拷贝到临时目录里
	#:cp -rf rootfs/* rootfs_tmp/

5、卸载临时目录,完成镜像制作

	#:umount rootfs_tmp/

相关标签: 最小文件系统