嵌入式Linux/Android根文件系统制作的几种方法(未完)

2019-07-12 17:09发布

梳理一下制作根文件系统的多种方法,有些参考了网上的做法,如有侵权,请联系博主删除,以下博文仅供学习和记录。1、打包成xxx.img的方法ep:  make_ext4fs -s -l 512M -a path rootfs.img rootfs参数列表具体含义-s表示去除分区中的空数据,也即生成的 img 为实际数据,而不是-l 指定的大小-l表示生成xxx.img的分区大小-a表示在根文件系统中的挂载点(可以是绝对路径,也可以是相对路径)rootfs.img最终的输出文件就是rootfs.imgrootfs为源文件(可以是个目录,也可以是个镜像)2、ramdisk的制作和解压解压:
假设被加压的ramdisk为ramdisk.imgmv ramdisk.img ramdisk.img.gz gunzip ramdisk.img.gz mkdir test mv ramdisk.img.gz test cd test cpio -iv 这时候test目录下就是解压完成的ramdisk文件压缩:
假设被压缩的目录为test,压缩完成的rd是r-u.img#mkdir /mnt/loop #dd if=/dev/zero of=/tmp/loop_tmp bs=1k count=15360 #mke2fs –F –v –m 0 /tmp/loop_tmp #mount –o loop /tmp/loop_tmp /mnt/loop #cp -af test/* /mnt/loop #umount /mnt/loop #gzip –v9 /tmp/loop_tmp #mv /tmp/loop_tmp ramdisk.img #mkimage -A arm -O linux -T ramdisk -C none -a 0x51000000 -e 0x51000040 -n "ramdisk" -d ramdisk.img r-u.img3、ubi文件系统的制作命令命令解析flash_eraseall /dev/mtd7使用这个命令擦除,可能会提示这个命令过时了。可以用flash_erase替换ubiattach -m 7 -O 2048将mtd7 关联到/dev/ubi0 VID offset 为2048 ubimkvol /dev/ubi0 -N rootfs -S 1900制作ubi系统逻辑卷 卷名rootfs  LEB个数为1900mount -t ubifs /dev/ubi0_0 /mnt将ubi文件系统(ubifs)挂载到/mnt目录下Linux启动时的参数列表的设置root=uib0:rootfs rw ubi.mtd=7,2048就可以挂载为根4、使用busybox方法制#!/bin/bash #yuanxin.yang develop 2015-07-05 #文件系统和Busybox的路径====>可自己定制 FILESYSTEM=/Softwave/filesystem #定义自己制作的文件系统存放的位置 BUSYBOX=/Softwave/arm/busybox-1.17.2 #Busybox源码包的位置,上网下载然后解压 LIBS=/usr/local/arm/4.5.1/arm-none-linux-gnueabi #交叉编译相关的库文件的位置,使用自己下载的版本 #判断文件是否存在 如果存在 就删除 if [ -d $FILESYSTEM ] then rm -rf $FILESYSTEM &>/dev/null mkdir $FILESYSTEM &>/dev/null else mkdir $FILESYSTEM &>/dev/null fi #拷贝busybox相关的文件 if ! cp -rf $BUSYBOX/_install/* $FILESYSTEM &>/dev/null then echo "cp busybox failed..." exit 1 fi #拷贝库 if ! cp -rf $LIBS/lib/ $FILESYSTEM/ &>/dev/null then echo "copy libs fair...." exit 1 fi #拷贝etc if ! cp -rf $BUSYBOX/examples/bootfloppy/etc $FILESYSTEM &>/dev/null then echo "copy etc fair..." exit 1 fi #创建Linux相关目录 cd $FILESYSTEM &>/dev/null mkdir boot mnt root sys var net proc tmp dev home opt &>/dev/null #修改配置文件 echo > $FILESYSTEM/etc/fstab #修改etc/profile文件 echo "# /etc/profile: system-wide .profile file for the Bourne shells" > $FILESYSTEM/etc/profile echo "echo "==========================="" >> $FILESYSTEM/etc/profile echo "echo "Welcom to Linux System"" >> $FILESYSTEM/etc/profile echo "echo "==========================="" >> $FILESYSTEM/etc/profile echo "export PS1="[yuanxin@Linux W] # "" >> $FILESYSTEM/etc/profile #修改 etc/init.d/rcS echo "#! /bin/sh" > $FILESYSTEM/etc/init.d/rcS echo "/bin/mount -n -t proc none /proc" >> $FILESYSTEM/etc/init.d/rcS echo "/bin/mount -n -t sysfs none /sys " >> $FILESYSTEM/etc/init.d/rcS echo "/bin/mount -t ramfs none /dev " >> $FILESYSTEM/etc/init.d/rcS echo "/bin/mount -n -t ramfs none /tmp " >> $FILESYSTEM/etc/init.d/rcS echo "/sbin/mdev -s" >> $FILESYSTEM/etc/init.d/rcS #配置nfs服务 if ! grep "$FILESYSTEM" /etc/exports &>/dev/null then echo "/filesystem *(rw,sync,no_root_squash)" >> /etc/exports fi #启动服务 iptables -F &>/dev/null service rpcbind restart service nfs restart echo "make filesystem ok....." exit 0