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. Note that this article does not work with the "root.jffs2" file for the [[Nokia N900|N900]], as despite the filename, the N900 does not use jffs2. See http://talk.maemo.org/showpost.php?p=403015&postcount=3 for a solution for N900.
+
This article describes two methods for extending and modifying an existing tablet JFFS2 root image.
== Background ==
== Background ==
Line 43: Line 43:
  modprobe mtdblock
  modprobe mtdblock
  modprobe block2mtd
  modprobe block2mtd
-
# Note the ,128KiB is needed (on 2.6.26 at least) to set the eraseblock size.
+
  echo "/dev/loop0" > /sys/module/block2mtd/parameters/block2mtd
-
  echo "/dev/loop0,128KiB" > /sys/module/block2mtd/parameters/block2mtd
+
  modprobe jffs2
  modprobe jffs2
-
# check dmesg
 
  mount -t jffs2 /tmp/mtdblock0 /media/jffs2
  mount -t jffs2 /tmp/mtdblock0 /media/jffs2
-
# check dmesg again - if the above mount results in any errors there is a problem...
 
To unmount and cleanup:
To unmount and cleanup:
Line 58: Line 55:
Or use the [[#Shell_script_to_mount/unmount_JFFS2_using_block_device_emulating_MTD|automated shell script]].
Or use the [[#Shell_script_to_mount/unmount_JFFS2_using_block_device_emulating_MTD|automated shell script]].
-
 
-
---
 
-
 
-
Edit in 2019 - Hi. I (i336_) thought I'd leave the eraseblock size off since I'm on kernel 5.1.4.
 
-
 
-
My HDD promptly began seeking a lot for a few seconds (!), and I discovered this was because it was scrambling to keep up with the just-over-30,000 errors jffs had just dumped into syslog.
 
-
 
-
You definitely still need the ",128KiB". :)
 
=== Kernel memory emulating an MTD device ===
=== Kernel memory emulating an MTD device ===
-
 
+
To mount the JFFS2 image, you perform the following steps:
-
Note that mtdram requires 88mb of raw ram on a 2gb system to mount a ~2Mb initfs image [Faheem Pervez on -dev ml], it probably won't work well with a rootfs!
+
-
 
+
-
Use total_size=85892 for mtdram if 65536 is too little.
+
-
 
+
-
However, if you insist... to mount the JFFS2 image, you perform the following steps:
+
  mknod /tmp/mtdblock0 b 31 0
  mknod /tmp/mtdblock0 b 31 0
Line 103: Line 87:
== Repacking the image ==
== Repacking the image ==
-
[http://maemo.org/development/documentation/manuals/2-x/howto_use_flasher_rootfs/ Using the flasher utility and creating the reference root file system]
+
[http://maemo.org/development/documentation/how-tos/2-x/howto_use_flasher_rootfs.html Using the flasher utility and creating the reference root file system]
== Modifying the copy of the image ==
== Modifying the copy of the image ==
Line 115: Line 99:
  cd $HOME/myRootImage
  cd $HOME/myRootImage
  tar cvzf $HOME/myNewRootImage.tar.gz .
  tar cvzf $HOME/myNewRootImage.tar.gz .
-
 
-
== Making the actual jffs2 image ==
 
-
 
-
''This was done on a Ubuntu Hardy system and was only done to make an initfs image successfully. I can't ensure this will work (though in theory, it should do) for creating an rootfs.''
 
-
 
-
<ol><li>Install mtd-tools which contains the required mkfs.jffs2.</li></ol>
 
-
:<pre> sudo apt-get install mtd-tools </pre>
 
-
<ol start="2"><li>Run:</li></ol>
 
-
:<pre> sudo mkfs.jffs2 -r myRootImage -o myRootImage.jffs2 -e 128 -l -n </pre>
 
-
 
-
Where ''myRootImage'' is the root of your new filesystem and ''myRootImage.jffs2'' is the name of the output file. -e 128 specifies a erase size of 128 KiB. 128 KiB is the correct erase size for the initfs. It is correct for an rootfs too.
 
-
 
-
== Making the jffs2 image mount faster ==
 
-
 
-
The jffs2 image that was just created is a plain jffs2 image. That's nice and if you were to flash it, it would work fine but what you can do is use sumtool which makes an summarized JFFS2 image. An summarized JFFS2 image mounts faster than a non-summarized one.
 
-
 
-
This can be done simply with:
 
-
 
-
sumtool -i <input jffs2 image> -o <output jffs2 image> -e 128KiB -l -n
 
== Installing on the tablet ==
== Installing on the tablet ==
Line 144: Line 109:
== 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:
-
<source lang="bash">
+
<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
+
  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"
+
  KVER="2.4"
-
  BLKMTD=blkmtd
+
  BLKMTD=blkmtd
-
fi  
+
fi  
-
if [ x"${UMNT}"x = x""x ]; then
+
if [ x"${UMNT}"x = x""x ]; then
-
  if [ ! -b ${MTDBLOCK} ] ; then
+
  if [ ! -b ${MTDBLOCK} ] ; then
-
    mknod ${MTDBLOCK} b 31 0 || exit 1
+
    mknod ${MTDBLOCK} b 31 0 || exit 1
-
  fi
+
  fi
-
  lsmod | grep loop >/dev/null 2>&1
+
  lsmod | grep loop >/dev/null 2>&1
-
  if [ $? -ne 0 ]; then
+
  if [ $? -ne 0 [; then
-
    modprobe loop
+
    modprobe loop
-
    [ $? -ne 0 ] && echo "loopback loading failed" && exit 1
+
    [ $? -ne 0 ] && echo "loopback loading failed" && exit 1
-
    sleep 1
+
    sleep 1
-
  fi
+
  fi
-
  losetup ${LOOP} ${JFFSIMG} || exit 1
+
  losetup ${LOOP} ${JFFSIMG} || exit 1
-
  sleep 1
+
  sleep 1
-
  modprobe mtdblock
+
  modprobe mtdblock
-
  if [ x"${KVER}"x = x"2.4"x ]; then
+
  if [ x"${KVER}"x = x"2.4"x [; then
-
    modprobe ${BLKMTD} device=${LOOP} || exit 1
+
    modprobe ${BLKMTD} device=${LOOP} || exit 1
-
  else
+
  else
-
    modprobe ${BLKMTD} || exit 1
+
    modprobe ${BLKMTD} || exit 1
-
    echo "${LOOP}" > /sys/module/block2mtd/parameters/block2mtd
+
    echo "${LOOP}" > /sys/module/block2mtd/parameters/block2mtd
-
  fi
+
  fi
-
  sleep 1
+
  sleep 1
-
  modprobe jffs2
+
  modprobe jffs2
-
  [ ! -d ${MP} ] && mkdir -p ${MP}
+
  [ ! -d ${MP} ] && mkdir -p ${MP}
-
  mount -t jffs2 ${MTDBLOCK} ${MP} || exit 1
+
  mount -t jffs2 ${MTDBLOCK} ${MP} || exit 1
-
else
+
else
-
  umount ${MP}
+
  umount ${MP}
-
  if [ $? -ne 0 ]; then
+
  if [ $? -ne 0 ]; then
-
    echo "Cannot unmount JFFS2 at $MP" && exit 1
+
    echo "Cannot unmount JFFS2 at $MP" && exit 1
-
  fi
+
  fi
-
  modprobe -r jffs2
+
  modprobe -r jffs2
-
  modprobe -r ${BLKMTD}
+
  modprobe -r ${BLKMTD}
-
  modprobe -r mtdblock
+
  modprobe -r mtdblock
-
  sleep 1
+
  sleep 1
-
  losetup -d ${LOOP}
+
  losetup -d ${LOOP}
-
fi  
+
fi  
-
</source>
+
</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 212: Line 177:
== 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:
-
<source lang="bash">
+
<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
+
  UMNT=1
-
fi
+
fi
-
if [ x"${UMNT}"x = x""x ]; then
+
if [ x"${UMNT}"x = x""x ]; then
-
  if [ ! -b ${MTDBLOCK} ] ; then
+
  if [ ! -b ${MTDBLOCK} ] ; then
-
    mknod ${MTDBLOCK} b 31 0 || exit 1
+
    mknod ${MTDBLOCK} b 31 0 || exit 1
-
  fi
+
  fi
-
  modprobe mtdblock
+
  modprobe mtdblock
-
  modprobe mtdram total_size=65536 erase_size=256
+
  modprobe mtdram total_size=65536 erase_size=256
-
  modprobe jffs2
+
  modprobe jffs2
-
  dd if=${JFFSIMG} of=${MTDBLOCK}
+
  dd if=${JFFSIMG} of=${MTDBLOCK}
-
  [ ! -d ${MP} ] && mkdir -p ${MP}
+
  [ ! -d ${MP} ] && mkdir -p ${MP}
-
  mount -t jffs2 ${MTDBLOCK} ${MP}
+
  mount -t jffs2 ${MTDBLOCK} ${MP}
-
else
+
else
-
  umount ${MP}
+
  umount ${MP}
-
  if [ $? -ne 0 ]; then
+
  if [ $? -ne 0 ]; then
-
    echo "Cannot unmount JFFS2 at $MP" && exit 1
+
    echo "Cannot unmount JFFS2 at $MP" && exit 1
-
  fi
+
  fi
-
  modprobe -r jffs2
+
  modprobe -r jffs2
-
  modprobe -r mtdram
+
  modprobe -r mtdram
-
  modprobe -r mtdblock
+
  modprobe -r mtdblock
-
fi  
+
fi  
-
</source>
+
</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 218:
  ./mount_jffs2.sh rootfs.jffs2 unmount
  ./mount_jffs2.sh rootfs.jffs2 unmount
-
[[Category:HowTo]]
+
 
 +
[[Category:HowTos]]
[[Category:Wiki page of the day]]
[[Category:Wiki page of the day]]

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)