linux内核创建ubi,Linux系统移植篇-ubi文件系统制作

本文主要的是对ubi文件系统进行制作,使用的主要工具是busybox。

构建 ubi 文件系统

一、创建根文件系统所需文件

(1)# tar -xjf busybox-1.20.2.tar.bz2

# cd busybox-1.20.2

# make menuconfig

在 Busybox Settings-->Build Options-->配置如下:

指定编译器为:arm-linux-选择 Save Configuration to an Alternate File,确定存放在.config 中。

再选择 Exit 退出

#make ARCH=arm CROSS_COMPILE=arm-linux- install

(2)然后修改_install/bin/busybox 权限:

chmod 4755 _install/bin/busybox

_install 是 busybox 的安装默认目录,在 busybox 源码的根目录下。

(3)进入到_install 目录创建 linux 需要的一些目录:

mkdir -p dev etc home lib mnt proc root sys tmp usr var/lib/misc

var/lock var/log var/run var/tmp

并修改权限:

chmod 1777 tmp

chmod 1777 var/tmp

(4)在 dev 下创建 console 和 null 设备:

mknod -m 660 console c 5 1

mknod -m 660 null c 1 3

mknod -m 660 ttySAC0 c 204 64

mknod -m 660 ttySAC1 c 204 65

mknod -m 660 ttySAC2 c 204 66

(5)将交叉编译工具里的所有库文件拷贝到 busybox 安装目录_intsll/lib 下

#cp  /usr/local/arm/crosstool-ng/crosstool_out/arm-unknown-linuxgnueabi/lib/* ./lib/ -fr

(6)在_install/etc 下创建一些配置文件

<1>fstab,内容如下:

# /etc/fstab: static file system information.

#

#

#

# file system  mount      type   options          dump   pass

#for mdev

proc           /proc      proc   defaults         0      0

sysfs          /sys       sysfs  defaults         0      0

#make sure /dev /tmp /var are tmpfs(tmpfs use ram as media) thus

can be r/w

tmpfs          /tmp       tmpfs  defaults         0      0

tmpfs          /dev       tmpfs  defaults         0      0

tmpfs          /var       tmpfs  defaults         0      0

#usbfs       /proc/bus/usb usbfs  defaults         0      0

<2>inittab,内容如下:

# see busybox/examples/inittab

# Boot-time system configuration/initialization script.

# This is run first except when booting in single-user mode.

::sysinit:/etc/init.d/rcS

#Start an "askfirst" shell on the console (whatever that may be)

#use respawn instead askfirst to make sure console always active

::respawn:-bin/sh

# Stuff to do when restarting the init process

::restart:/sbin/init

# Stuff to do before rebooting

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

::shutdown:/sbin/swapoff -a

<3>init.d/rcS,init.d 是目录,rcS 是文件,内容如下:

#!/bin/sh

#add setting here for auto start program

PATH=/sbin:/bin:/usr/sbin:/usr/bin

runlevel=S

prevlevel=N

umask 022

export PATH runlevel prevlevel

#See docs/mdev.txt

#mount all fs in fstab,proc and sysfs are must for mdev

mount -a

#create device nodes

echo /sbin/mdev > /proc/sys/kernel/hotplug

#seed all device nodes

mdev -s

#create pts directory for remote login such as SSH and telnet

mkdir -p /dev/pts

mount -t devpts devpts /dev/pts

if [ -f /etc/hostname ]; then

/bin/hostname -F /etc/hostname

fi

if [ -e /sys/class/net/eth0 ]; then

ifconfig eth0 192.168.1.15

fi

echo "etc init.d rcS done"

<4>更改 rcS 和 inittab 的权限为 777:

chmod 777 init.d/rcS

chmod 777 inittab

二、制作 ubifs 文件系统

(1)由 uboot 启动 linux 内核时,minicom 终端打印信息如下

[ 3.605000] UBI: physical eraseblock size: 16384 bytes (16 KiB)

[ 3.610000] UBI: logical eraseblock size: 15872 bytes

[ 3.615000] UBI: smallest flash I/O unit: 512

[ 3.620000] UBI: sub-page size: 256

[ 3.625000] UBI: VID header offset: 256 (aligned 256)

[ 3.630000] UBI: data offset: 512

[ 4.380000] UBI: attached mtd2 to ubi0

[ 4.385000] UBI: MTD device name: "root"

[ 4.390000] UBI: MTD device size: 60 MiB

[ 4.395000] UBI: number of good PEBs: 3840

[ 4.400000] UBI: number of bad PEBs: 0

[ 4.405000] UBI: max. allowed volumes: 92

[ 4.405000] UBI: wear-leveling threshold: 4096

[ 4.410000] UBI: number of internal volumes: 1

[ 4.415000] UBI: number of user volumes: 1

[ 4.420000] UBI: available PEBs: 0

[ 4.425000] UBI: total number of reserved PEBs: 3840

(2)制作 mkfs.ubifs,首先进入 busybox 源码包的根目录下。

#apt-get install mtd-utils //不安装的话无法使用 mkfs.ubifs

#mkfs.ubifs -r ./_install/ -m 512 -e 15872 -c 3840 -o ubifs.img

//说明:512 与 smallest flash I/O unit 对应,15872 与 logical eraseblock size 对

应,3840 与 total number of reserved PEBs 对应。

#gedit ubinize.cfg

添加如下内容

[ubifs]

mode=ubi

image=ubifs.img

vol_id=0

vol_size=60MiB

vol_type=dynamic

vol_name=rootfs

vol_flags=autoresize

#ubinize -o ubi.img -m 512 -p 16KiB -s 256 ubinize.cfg

//说明:512 与 smallest flash I/O unit 对应,16KiB 与 physical eraseblock size 对

应,256 与 sub-page size 对应。

(3)看到生成 ubifs.img 说明成功了,然后烧写文件系统,测试文件系统。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值