现在的位置: 首页 > 操作系统 > 正文

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

2020年01月15日 操作系统 ⁄ 共 2626字 ⁄ 字号 评论关闭

  梳理一下制作根文件系统的多种方法,有些参考了网上的做法,仅供学习和记录。

  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

  这时候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文件系统的制作

  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

抱歉!评论已关闭.