上一次中,我们制作了jffs2文件系统,实现了普通分区jffs2的挂载,这一次,我们同样实现了ubifs文件系统的挂载,可以来尝试一下ubifs下普通分区的挂载。
Nandflash分区情况
MTD设备分区情况
~ >: cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "mtdblock0 u-boot 1MB"
mtd1: 00f00000 00020000 "mtdblock1 kernel 15MB"
mtd2: 02800000 00020000 "mtdblock2 rootfs 40MB"
mtd3: 05000000 00020000 "mtdblock3 apps 80MB"
mtd4: 05000000 00020000 "mtdblock4 data 80MB"
mtd5: 02800000 00020000 "mtdblock5 backup 40MB"
linux内核分区
~ >: cat /proc/partitions
major minor #blocks name
31 0 1024 mtdblock0
31 1 15360 mtdblock1
31 2 40960 mtdblock2
31 3 81920 mtdblock3
31 4 81920 mtdblock4
31 5 40960 mtdblock5
分区对应的块设备
~ >: ls -l /dev/mtdblock*
brw-rw---- 1 root root 31, 0 Jan 1 00:00 /dev/mtdblock0
brw-rw---- 1 root root 31, 1 Jan 1 00:00 /dev/mtdblock1
brw-rw---- 1 root root 31, 2 Jan 1 00:00 /dev/mtdblock2
brw-rw---- 1 root root 31, 3 Jan 1 00:00 /dev/mtdblock3
brw-rw---- 1 root root 31, 4 Jan 1 00:00 /dev/mtdblock4
brw-rw---- 1 root root 31, 5 Jan 1 00:00 /dev/mtdblock5
建立UBI卷
以mtdblock3为例,以ubifs文件格式挂载到/apps挂载点上
擦除对应分区
~ >: flash_eraseall /dev/mtd3
Erasing 128 Kibyte @ 5000000 - 100% complete.
当前设备
~ >: ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi_ctrl
~ >: ubiattach
BusyBox v1.27.1 (2018-04-03 02:25:34 PDT) multi-call binary.
Usage: ubiattach -m MTD_NUM [-d UBI_NUM] [-O VID_HDR_OFF] UBI_CTRL_DEV
Attach MTD device to UBI
-m MTD_NUM MTD device number to attach
-d UBI_NUM UBI device number to assign
-O VID_HDR_OFF VID header offset
~ >:
建立关联
~ >: ubiattach -m 3 -d 3 /dev/ubi_ctrl
UBI: attaching mtd3 to ubi3
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
UBI: empty MTD device detected
UBI: max. sequence number: 0
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd3 to ubi3
UBI: MTD device name: "mtdblock3 apps 80MB"
UBI: MTD device size: 80 MiB
UBI: number of good PEBs: 640
UBI: number of bad PEBs: 0
UBI: number of corrupted PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available PEBs: 630
UBI: total number of reserved PEBs: 10
UBI: number of PEBs reserved for bad PEB handling: 6
UBI: max/mean erase counter: 0/0
UBI: image sequence number: 759054630
UBI: background thread "ubi_bgt3d" started, PID 972
~ >: ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi3 /dev/ubi_ctrl
~ >:
建立UBI卷
~ >: ubimkvol -m -n 0 -N apps /dev/ubi3
~ >: ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi3 /dev/ubi3_0 /dev/ubi_ctrl
~ >: ubimkvol
BusyBox v1.27.1 (2018-04-03 02:25:34 PDT) multi-call binary.
Usage: ubimkvol -N NAME [-s SIZE | -m] UBI_DEVICE
Create UBI volume
-a ALIGNMENT Volume alignment (default 1)
-m Set volume size to maximum available
-n VOLID Volume ID. If not specified,
assigned automatically
-N NAME Volume name
-s SIZE Size in bytes
-t TYPE Volume type (static|dynamic)
~ >:
文件系统挂载
挂载ubi3(即mtdblock3)到/apps挂载点上
~ >: mount -t ubifs -o sync,noatime,rw ubi3:apps /apps/
UBIFS: default file-system created
UBIFS: mounted UBI device 3, volume 0, name "apps"
UBIFS: file system size: 80123904 bytes (78246 KiB, 76 MiB, 621 LEBs)
UBIFS: journal size: 3999744 bytes (3906 KiB, 3 MiB, 31 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root: 3784449 bytes (3695 KiB)
~ >: mount
rootfs on / type rootfs (rw)
ubi0:rootfs on / type ubifs (rw,relatime)
proc on /proc type proc (rw,relatime)
usbfs on /proc/bus/usb type usbfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime)
ramfs on /tmp type ramfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
ubi3:apps on /apps type ubifs (rw,sync,noatime)
卸载和重挂载
卸载解除关联
~ >: umount /apps/
UBIFS: un-mount UBI device 3, volume 0
~ >: ubidetach -d 3 /dev/ubi_ctrl
UBI: mtd3 is detached from ubi3
~ >: ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi_ctrl
重新建立关系
~ >: ubiattach -m 3 -d 3 /dev/ubi_ctrl
UBI: attaching mtd3 to ubi3
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
UBI: max. sequence number: 12
UBI: attached mtd3 to ubi3
UBI: MTD device name: "mtdblock3 apps 80MB"
UBI: MTD device size: 80 MiB
UBI: number of good PEBs: 640
UBI: number of bad PEBs: 0
UBI: number of corrupted PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 1
UBI: available PEBs: 0
UBI: total number of reserved PEBs: 640
UBI: number of PEBs reserved for bad PEB handling: 6
UBI: max/mean erase counter: 2/1
UBI: image sequence number: 759054630
UBI: background thread "ubi_bgt3d" started, PID 992
~ >: ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi3 /dev/ubi3_0 /dev/ubi_ctrl
再次关联问题
~ >: ubimkvol -m -n 0 -N apps /dev/ubi3
ubimkvol: UBI_IOCMKVOL: Invalid argument
当再次关联ubi3到mtd3下的时候,发现再次建立UBI卷出错。这也意味着,如果之前已经用ubimkvol建立UBI卷的分区再次挂载时不需要在执行该命令,也就是ubimkvol针对一个分区只能做一次,除非使用flash_eraseall重新格式化。
版权声明:本文为klaus_x原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。