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

梳理一下制作根文件系统的多种方法,有些参考了网上的做法,如有侵权,请联系博主删除,以下博文仅供学习和记录。

1、打包成xxx.img的方法

ep:  make_ext4fs -s -l 512M -a path rootfs.img rootfs

参数列表具体含义
-s表示去除分区中的空数据,也即生成的 img 为实际数据,而不是-l 指定的大小
-l表示生成xxx.img的分区大小
-a表示在根文件系统中的挂载点(可以是绝对路径,也可以是相对路径)
rootfs.img最终的输出文件就是rootfs.img
rootfs为源文件(可以是个目录,也可以是个镜像)

2、ramdisk的制作和解压

解压:

假设被加压的ramdisk为ramdisk.img

mv ramdisk.img ramdisk.img.gz
gunzip ramdisk.img.gz
mkdir test
mv ramdisk.img.gz test
cd test
cpio -iv <ramdisk.img

这时候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.img

3、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个数为1900
mount -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  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Engineer-Bruce_Yang

谢谢您

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值