Mount ubifs

From wiki.network-crawler.de
Jump to: navigation, search

Load the following modules

# modprobe mtdblock
# modprobe ubi
# modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15

Note: NAND simulator (nandsim) is an extremely useful debugging and development tool which simulates NAND flashes in RAM or a file. Look at http://www.linux-mtd.infradead.org/faq/nand.html to get more information

Have a look on your environment

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00400000 00020000 "mtdram test device"
mtd4: 10000000 00020000 "NAND simulator partition 0"

# ls -la /dev/mtd*
crw-rw---- 1 root root 90, 0 2010-02-17 11:02 /dev/mtd0
crw-rw---- 1 root root 90, 1 2010-02-17 11:02 /dev/mtd0ro
crw-rw---- 1 root root 90, 8 2010-02-17 12:08 /dev/mtd4
crw-rw---- 1 root root 90, 9 2010-02-17 12:08 /dev/mtd4ro
brw-rw---- 1 root disk 31, 0 2010-02-17 11:07 /dev/mtdblock0
brw-rw---- 1 root disk 31, 4 2010-02-17 12:08 /dev/mtdblock4

Tranfer it directly to the block device

# dd if=rootfs.jffs2 of=/dev/mtdblock4 bs=2048
74688+0 records in
74688+0 records out
152961024 bytes (153 MB) copied, 8.38595 s, 18.2 MB/s

# ubiattach /dev/ubi_ctrl -m 4
UBI device number 0, total 2048 LEBs (264241152 bytes, 252.0 MiB), available 0 LEBs (0 bytes), LEB size 129024 bytes (126.0 KiB)

# ls -la /dev/ubi*
crw-rw---- 1 root root 252,  0 2009-12-01 19:06 /dev/ubi0
crw-rw---- 1 root root 252,  1 2009-12-01 19:06 /dev/ubi0_0
crw-rw---- 1 root root  10, 58 2009-12-01 19:05 /dev/ubi_ctrl

# mount -t ubifs ubi0_0 /mnt/1/

Note: I used Ubuntu 9.04 with a custom kernel, but it should work with standard kernel, too. My device to test was a n900. I refered to the maemo wiki for this information

Get /usr folder

cd /mnt/
tar cjf usr_2009SE_3.2010.02.tar.bz2 -C 1/ usr/

Scp and Extract it on your n900. Then add a link

# cd /mnt/1
# rm -R usr/
# ln -sf /home/usr usr

It should look like this:

# ls -la
total 4
drwxr-xr-x 21 root root 1504 2010-02-17 13:01 .
drwxr-xr-x  4 root root 4096 2010-02-17 12:53 ..
drwxr-xr-x  2 root root 3920 2010-01-25 17:42 bin
drwxr-xr-x  2 root root  160 2010-01-25 17:51 boot
drwxr-xr-x  2 root root  160 2010-01-25 17:39 cdrom
drwxr-xr-x  3 root root 3808 2010-01-25 17:44 dev
drwxr-xr-x  2 root root  160 2010-01-25 17:39 .dev
drwxr-xr-x 73 root root 7560 2010-01-25 17:51 etc
drwxr-xr-x  2 root root  160 2010-01-25 17:39 floppy
drwxr-xr-x  2 root root  160 2010-01-25 17:43 home
drwxr-xr-x  2 root root  160 2010-01-25 17:39 initrd
drwxr-xr-x  8 root root 6200 2010-01-25 17:51 lib
drwxr-xr-x  3 root root  224 2010-01-25 17:43 media
drwxr-xr-x  2 root root  160 2010-01-25 17:39 mnt
lrwxrwxrwx  1 root root    9 2010-01-25 17:43 opt -> /home/opt
drwxr-xr-x  2 root root  160 2010-01-25 17:39 proc
drwxr-xr-x  2 root root  296 2010-01-25 17:43 root
drwxr-xr-x  2 root root 5808 2010-01-25 17:43 sbin
drwxr-xr-x  2 root root  160 2010-01-25 17:39 srv
drwxr-xr-x  2 root root  160 2010-01-25 17:39 sys
drwxrwxrwt  2 root root  160 2010-01-25 17:39 tmp
lrwxrwxrwx  1 root root    9 2010-02-17 13:01 usr -> /home/usr
drwxr-xr-x 14 root root  936 2010-01-25 17:47 var

Write it back (n900)

# mkfs.ubifs -m 2048 -e 129024 -c 2047 -r /mnt/1/ rootfs_ubifs.jffs2

# cat > cfg.ini
[rootfs]
mode=ubi
image=rootfs_ubifs.jffs2
vol_id=0
vol_size=160MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1

# ubinize -o rootfs_new.jffs2 -p 128KiB -m 2048 -s 512 cfg.ini

# ./flasher-3.5 -f -R -r rootfs_new.jffs2

Note: you can get mkfs.ubifs from squeeze or updated jaunty