Editing Modifying the root image
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | This article describes two methods for extending and modifying an existing tablet JFFS2 root image | + | {{Midgard article}} |
+ | |||
+ | |||
+ | This article describes two methods for extending and modifying an existing tablet JFFS2 root image. | ||
== Background == | == Background == | ||
Line 5: | Line 8: | ||
There are two ways to mount the JFFS2 image: | There are two ways to mount the JFFS2 image: | ||
- | #Have a block device emulate a Memory Technology Device (MTD) via block2mtd. | + | #Have a block device emulate a Memory Technology Device (MTD) via blkmtd (v2.4.x Linux kernels) or block2mtd (v2.6.x Linux kernels) |
- | #Have kernel memory emulate a MTD via mtdram | + | #Have kernel memory emulate a MTD via mtdram |
- | + | ||
- | + | ||
== Getting the JFFS2 image == | == Getting the JFFS2 image == | ||
Line 21: | Line 22: | ||
You must have the following kernel modules compiled and installed: | You must have the following kernel modules compiled and installed: | ||
- | + | *CONFIG_MTD (mtdcore) | |
- | *CONFIG_MTD ( | + | *CONFIG_MTD_PARITIONS (mtdpart) |
- | + | *CONFIG_MTD_MTDRAM (mtdram) | |
- | *CONFIG_MTD_PARITIONS ( | + | *CONFIG_MTD_BLOCK2MTD (block2mtd) |
- | + | *CONFIG_BLK_DEV_LOOP (loop) | |
- | *CONFIG_MTD_MTDRAM ( | + | |
- | *CONFIG_MTD_BLOCK2MTD ( | + | |
- | + | ||
- | *CONFIG_BLK_DEV_LOOP ( | + | |
- | + | ||
- | + | ||
- | + | ||
I suggest you do not make these modules statically linked into the kernel. It is more practical to be able to unload these modules when not needed or when you want to start over from scratch. | I suggest you do not make these modules statically linked into the kernel. It is more practical to be able to unload these modules when not needed or when you want to start over from scratch. | ||
Line 43: | Line 37: | ||
modprobe mtdblock | modprobe mtdblock | ||
modprobe block2mtd | modprobe block2mtd | ||
- | + | echo "/dev/loop0" > /sys/module/block2mtd/parameters/block2mtd | |
- | echo "/dev/loop0 | + | |
modprobe jffs2 | modprobe jffs2 | ||
- | |||
mount -t jffs2 /tmp/mtdblock0 /media/jffs2 | mount -t jffs2 /tmp/mtdblock0 /media/jffs2 | ||
- | |||
To unmount and cleanup: | To unmount and cleanup: | ||
Line 57: | Line 48: | ||
losetup -d /dev/loop0 | losetup -d /dev/loop0 | ||
- | Or use the [[ | + | Or use the [[Shell_script_to_mount/usmount_JFFS2_using_block_device_emulating_MTD|automated shell script]]. |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
=== Kernel memory emulating an MTD device === | === Kernel memory emulating an MTD device === | ||
- | + | To mount the JFFS2 image, you perform the following steps: | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
mknod /tmp/mtdblock0 b 31 0 | mknod /tmp/mtdblock0 b 31 0 | ||
Line 89: | Line 67: | ||
modprobe -r mtdram | modprobe -r mtdram | ||
modprobe -r mtdblock | modprobe -r mtdblock | ||
- | |||
- | |||
== Archiving and extracting the rootfs image == | == Archiving and extracting the rootfs image == | ||
Line 101: | Line 77: | ||
cd myRootImage | cd myRootImage | ||
tar xvpzf /my_path/myRootImage.tar.gz | tar xvpzf /my_path/myRootImage.tar.gz | ||
- | |||
- | |||
- | |||
== Modifying the copy of the image == | == Modifying the copy of the image == | ||
Line 115: | Line 88: | ||
cd $HOME/myRootImage | cd $HOME/myRootImage | ||
tar cvzf $HOME/myNewRootImage.tar.gz . | tar cvzf $HOME/myNewRootImage.tar.gz . | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
== Installing on the tablet == | == Installing on the tablet == | ||
Line 141: | Line 95: | ||
./flasher-3.0 -r rootfs.jffs2 --f -R | ./flasher-3.0 -r rootfs.jffs2 --f -R | ||
+ | |||
== Shell script to mount/unmount JFFS2 using block device emulating MTD == | == Shell script to mount/unmount JFFS2 using block device emulating MTD == | ||
Create a shell script (mount_jffs2.sh) from the following: | Create a shell script (mount_jffs2.sh) from the following: | ||
- | < | + | <pre> |
- | #!/bin/sh | + | #!/bin/sh |
- | JFFSIMG=$1 # jffs image | + | JFFSIMG=$1 # jffs image |
- | LOOP="/dev/loop1" # loop device | + | LOOP="/dev/loop1" # loop device |
- | MP="/media/jffs2" # mount point | + | MP="/media/jffs2" # mount point |
- | MTDBLOCK="/tmp/mtdblock0" # MTD device file | + | MTDBLOCK="/tmp/mtdblock0" # MTD device file |
- | KVER="2.6" | + | KVER="2.6" |
- | BLKMTD="block2mtd" | + | BLKMTD="block2mtd" |
- | UMNT="" | + | UMNT="" |
- | echo "$0" | grep unmount_ >/dev/null 2>&1 | + | echo "$0" | grep unmount_ >/dev/null 2>&1 |
- | [ $? -eq 0 ] && UMNT=1 | + | [ $? -eq 0 ] && UMNT=1 |
- | if [ $# -gt 1 -a x"$2"x = x"unmount"x ]; then | + | if [ $# -gt 1 -a x"$2"x = x"unmount"x ]; then |
- | + | UMNT=1 | |
- | fi | + | fi |
- | uname -r | egrep '^2\.6' >/dev/null 2>&1 | + | uname -r | egrep '^2\.6' >/dev/null 2>&1 |
- | if [ $? -ne 0 ]; then | + | if [ $? -ne 0 ]; then |
- | + | KVER="2.4" | |
- | + | BLKMTD=blkmtd | |
- | fi | + | fi |
- | if [ x"${UMNT}"x = x""x ]; then | + | if [ x"${UMNT}"x = x""x ]; then |
- | + | if [ ! -b ${MTDBLOCK} ] ; then | |
- | + | mknod ${MTDBLOCK} b 31 0 || exit 1 | |
- | + | fi | |
- | + | lsmod | grep loop >/dev/null 2>&1 | |
- | + | if [ $? -ne 0 [; then | |
- | + | modprobe loop | |
- | + | [ $? -ne 0 ] && echo "loopback loading failed" && exit 1 | |
- | + | sleep 1 | |
- | + | fi | |
- | + | losetup ${LOOP} ${JFFSIMG} || exit 1 | |
- | + | sleep 1 | |
- | + | modprobe mtdblock | |
- | + | if [ x"${KVER}"x = x"2.4"x [; then | |
- | + | modprobe ${BLKMTD} device=${LOOP} || exit 1 | |
- | + | else | |
- | + | modprobe ${BLKMTD} || exit 1 | |
- | + | echo "${LOOP}" > /sys/module/block2mtd/parameters/block2mtd | |
- | + | fi | |
- | + | sleep 1 | |
- | + | modprobe jffs2 | |
- | + | [ ! -d ${MP} ] && mkdir -p ${MP} | |
- | + | mount -t jffs2 ${MTDBLOCK} ${MP} || exit 1 | |
- | else | + | else |
- | + | umount ${MP} | |
- | + | if [ $? -ne 0 ]; then | |
- | + | echo "Cannot unmount JFFS2 at $MP" && exit 1 | |
- | + | fi | |
- | + | modprobe -r jffs2 | |
- | + | modprobe -r ${BLKMTD} | |
- | + | modprobe -r mtdblock | |
- | + | sleep 1 | |
- | + | losetup -d ${LOOP} | |
- | fi | + | fi |
- | </ | + | </pre> |
Make sure you chmod a+x mount_jffs2.sh to make the shell script executable. | Make sure you chmod a+x mount_jffs2.sh to make the shell script executable. | ||
Line 209: | Line 164: | ||
You can also use this script to unmount and unload the non-utilized kernel modules and loopback reference: | You can also use this script to unmount and unload the non-utilized kernel modules and loopback reference: | ||
./mount_jffs2.sh rootfs.jffs2 unmount | ./mount_jffs2.sh rootfs.jffs2 unmount | ||
+ | |||
== Shell script to mount/unmount JFFS2 using kernel memory emulating MTD == | == Shell script to mount/unmount JFFS2 using kernel memory emulating MTD == | ||
Create a shell script (mount_jffs2.sh) from the following: | Create a shell script (mount_jffs2.sh) from the following: | ||
- | < | + | <pre> |
- | #!/bin/sh | + | #!/bin/sh |
- | JFFSIMG=$1 # jffs image | + | JFFSIMG=$1 # jffs image |
- | MP="/media/jffs2" # mount point | + | MP="/media/jffs2" # mount point |
- | MTDBLOCK="/tmp/mtdblock0" # MTD device file | + | MTDBLOCK="/tmp/mtdblock0" # MTD device file |
- | UMNT="" | + | UMNT="" |
- | echo "$0" | grep unmount_ >/dev/null 2>&1 | + | echo "$0" | grep unmount_ >/dev/null 2>&1 |
- | [ $? -eq 0 ] && UMNT=1 | + | [ $? -eq 0 ] && UMNT=1 |
- | if [ $# -gt 1 -a x"$2"x = x"unmount"x ]; then | + | if [ $# -gt 1 -a x"$2"x = x"unmount"x ]; then |
- | + | UMNT=1 | |
- | fi | + | fi |
- | if [ x"${UMNT}"x = x""x ]; then | + | if [ x"${UMNT}"x = x""x ]; then |
- | + | if [ ! -b ${MTDBLOCK} ] ; then | |
- | + | mknod ${MTDBLOCK} b 31 0 || exit 1 | |
- | + | fi | |
- | + | modprobe mtdblock | |
- | + | modprobe mtdram total_size=65536 erase_size=256 | |
- | + | modprobe jffs2 | |
- | + | dd if=${JFFSIMG} of=${MTDBLOCK} | |
- | + | [ ! -d ${MP} ] && mkdir -p ${MP} | |
- | + | mount -t jffs2 ${MTDBLOCK} ${MP} | |
- | else | + | else |
- | + | umount ${MP} | |
- | + | if [ $? -ne 0 ]; then | |
- | + | echo "Cannot unmount JFFS2 at $MP" && exit 1 | |
- | + | fi | |
- | + | modprobe -r jffs2 | |
- | + | modprobe -r mtdram | |
- | + | modprobe -r mtdblock | |
- | fi | + | fi |
- | </ | + | </pre> |
Make sure you chmod a+x mount_jffs2.sh to make the shell script executable. | Make sure you chmod a+x mount_jffs2.sh to make the shell script executable. | ||
Line 253: | Line 209: | ||
./mount_jffs2.sh rootfs.jffs2 unmount | ./mount_jffs2.sh rootfs.jffs2 unmount | ||
- | [[Category: | + | |
- | [[Category:Wiki page of the | + | [[Category:HowTos]] |
+ | [[Category:Midgard wiki]] | ||
+ | [[Category:Wiki page of the Day]] |
Learn more about Contributing to the wiki.