<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://maemo.octonezd.me/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=121.217.111.231</id>
	<title>Maemo Wiki Mirror - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://maemo.octonezd.me/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=121.217.111.231"/>
	<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php/Special:Contributions/121.217.111.231"/>
	<updated>2026-04-22T05:42:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://maemo.octonezd.me/index.php?title=Modifying_the_root_image&amp;diff=26744</id>
		<title>Modifying the root image</title>
		<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php?title=Modifying_the_root_image&amp;diff=26744"/>
		<updated>2019-06-16T07:57:45Z</updated>

		<summary type="html">&lt;p&gt;121.217.111.231: /* Block device emulating an MTD device */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes two methods for extending and modifying an existing tablet JFFS2 root image. Note that this article does not work with the &amp;quot;root.jffs2&amp;quot; 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&amp;amp;postcount=3 for a solution for N900.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The root filesystem (rootfs) of the tablets is stored in a Journal Flash File System version 2 (JFFS2) format. It resides on one of the partitions on the flash chip in the device. Additionally, a pristine version of the rootfs can be obtained from the [http://tablets-dev.nokia.com/ Nokia official firmware] site.&lt;br /&gt;
&lt;br /&gt;
There are two ways to mount the JFFS2 image:&lt;br /&gt;
#Have a block device emulate a Memory Technology Device (MTD) via block2mtd.&lt;br /&gt;
#Have kernel memory emulate a MTD via mtdram.&lt;br /&gt;
&lt;br /&gt;
Note that for a host kernel config you need to enable mtd device support to access/enable jffs2 filesystem support.&lt;br /&gt;
&lt;br /&gt;
== Getting the JFFS2 image ==&lt;br /&gt;
First of all, we need to get the rootfs.jffs2 from the official [http://tablets-dev.nokia.com/ Nokia FIASCO image]. After downloading the FIASCO image, run this on it to unpack it (this will give you all of the individual parts of the image):&lt;br /&gt;
&lt;br /&gt;
 sudo ./flasher-3.0 --unpack  -F &amp;lt;FIASCO image&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mounting the JFFS2 image ==&lt;br /&gt;
These commands will be executed with root privileges on the host machine and not on the device itself.&lt;br /&gt;
&lt;br /&gt;
=== Block device emulating an MTD device ===&lt;br /&gt;
You must have the following kernel modules compiled and installed:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory Technology Device (MTD) support  ---&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
*CONFIG_MTD ( Memory Technology Device (MTD) support )&lt;br /&gt;
*CONFIG_MTDBLOCK ( Caching block device access to MTD devices )&lt;br /&gt;
*CONFIG_MTD_PARITIONS ( MTD partitioning support ) &lt;br /&gt;
&#039;&#039;&#039;Self-contained MTD device drivers  ---&amp;gt; &#039;&#039;&#039;&lt;br /&gt;
*CONFIG_MTD_MTDRAM ( Test driver using RAM ) &lt;br /&gt;
*CONFIG_MTD_BLOCK2MTD ( MTD using block device ) &lt;br /&gt;
&#039;&#039;&#039;Block devices  ---&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
*CONFIG_BLK_DEV_LOOP ( Loopback device support ) &lt;br /&gt;
&#039;&#039;&#039;File systems  ---&amp;gt;Miscellaneous filesystems  ---&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
*CONFIG_JFFS2_FS ( Journalling Flash File System v2 (JFFS2) support )&lt;br /&gt;
*CONFIG_JFFS2_LZO ( Advanced compression options for JFFS2 --&amp;gt; LZO compression support )&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
You will use the loopback device (/dev/loop[0-15]) to simulate a block device whose contents are from the JFFS2 image. To mount the JFFS2 image, you perform the following steps:&lt;br /&gt;
&lt;br /&gt;
 mknod /tmp/mtdblock0 b 31 0&lt;br /&gt;
 modprobe loop&lt;br /&gt;
 losetup /dev/loop0 rootfs.jffs2&lt;br /&gt;
 modprobe mtdblock&lt;br /&gt;
 modprobe block2mtd&lt;br /&gt;
 # Note the ,128KiB is needed (on 2.6.26 at least) to set the eraseblock size.&lt;br /&gt;
 echo &amp;quot;/dev/loop0,128KiB&amp;quot; &amp;gt; /sys/module/block2mtd/parameters/block2mtd&lt;br /&gt;
 modprobe jffs2&lt;br /&gt;
 # check dmesg&lt;br /&gt;
 mount -t jffs2 /tmp/mtdblock0 /media/jffs2&lt;br /&gt;
 # check dmesg again - if the above mount results in any errors there is a problem...&lt;br /&gt;
&lt;br /&gt;
To unmount and cleanup:&lt;br /&gt;
&lt;br /&gt;
 umount /media/jffs2&lt;br /&gt;
 modprobe -r block2mtd&lt;br /&gt;
 modprobe -r mtdblock&lt;br /&gt;
 losetup -d /dev/loop0&lt;br /&gt;
&lt;br /&gt;
Or use the [[#Shell_script_to_mount/unmount_JFFS2_using_block_device_emulating_MTD|automated shell script]].&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
Edit in 2019 - Hi. I (i336_) thought I&#039;d leave the eraseblock size off since I&#039;m on kernel 5.1.4.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
You definitely still need the &amp;quot;,128KiB&amp;quot;. :)&lt;br /&gt;
&lt;br /&gt;
=== Kernel memory emulating an MTD device ===&lt;br /&gt;
&lt;br /&gt;
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&#039;t work well with a rootfs!&lt;br /&gt;
&lt;br /&gt;
Use total_size=85892 for mtdram if 65536 is too little.&lt;br /&gt;
&lt;br /&gt;
However, if you insist... to mount the JFFS2 image, you perform the following steps:&lt;br /&gt;
&lt;br /&gt;
 mknod /tmp/mtdblock0 b 31 0&lt;br /&gt;
 modprobe mtdblock&lt;br /&gt;
 modprobe mtdram total_size=65536 erase_size=256&lt;br /&gt;
 modprobe jffs2&lt;br /&gt;
 dd if=/pathtoimage/rootfs.jffs2 of=/tmp/mtdblock0&lt;br /&gt;
 mkdir /media/jffs2&lt;br /&gt;
 mount -t jffs2 /tmp/mtdblock0 /media/jffs2&lt;br /&gt;
&lt;br /&gt;
To unmount and cleanup:&lt;br /&gt;
&lt;br /&gt;
 umount /media/jffs2&lt;br /&gt;
 modprobe -r jffs2&lt;br /&gt;
 modprobe -r mtdram&lt;br /&gt;
 modprobe -r mtdblock&lt;br /&gt;
&lt;br /&gt;
Or use the [[Modifying_the_root_image#Shell_script_to_mount.2Funmount_JFFS2_using_kernel_memory_emulating_MTD|automated shell script]].&lt;br /&gt;
&lt;br /&gt;
== Archiving and extracting the rootfs image ==&lt;br /&gt;
The image is now accessible under /media/jffs2. Copy the whole image to another directory. This new directory will be used for modifying the image. Extending the currently mounted JFFS2 image is not suggested. Using cp for copying the image to a working directory won&#039;t work due to special files in /media/jffs2/dev, which is why we use tar. &lt;br /&gt;
&lt;br /&gt;
 cd /media/jffs2&lt;br /&gt;
 tar cvzf /my_path/myRootImage.tar.gz .&lt;br /&gt;
 cd $HOME&lt;br /&gt;
 mkdir myRootImage&lt;br /&gt;
 cd myRootImage&lt;br /&gt;
 tar xvpzf /my_path/myRootImage.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Repacking the image ==&lt;br /&gt;
[http://maemo.org/development/documentation/manuals/2-x/howto_use_flasher_rootfs/ Using the flasher utility and creating the reference root file system]&lt;br /&gt;
&lt;br /&gt;
== Modifying the copy of the image ==&lt;br /&gt;
Now the image is successfully archived and copied. The working directory  $HOME/myRootImage can now be used for adding, changing or modifying packages.&lt;br /&gt;
&lt;br /&gt;
 cd $HOME/myRootImage&lt;br /&gt;
 dpkg -x $HOME/arm_debs/mypackage_arm.deb .&lt;br /&gt;
&lt;br /&gt;
Now we create a new tarball from the working directory of the image.&lt;br /&gt;
&lt;br /&gt;
 cd $HOME/myRootImage&lt;br /&gt;
 tar cvzf $HOME/myNewRootImage.tar.gz .&lt;br /&gt;
&lt;br /&gt;
== Making the actual jffs2 image ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This was done on a Ubuntu Hardy system and was only done to make an initfs image successfully. I can&#039;t ensure this will work (though in theory, it should do) for creating an rootfs.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Install mtd-tools which contains the required mkfs.jffs2.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
:&amp;lt;pre&amp;gt; sudo apt-get install mtd-tools &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
:&amp;lt;pre&amp;gt; sudo mkfs.jffs2 -r myRootImage -o myRootImage.jffs2 -e 128 -l -n &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &#039;&#039;myRootImage&#039;&#039; is the root of your new filesystem and &#039;&#039;myRootImage.jffs2&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
== Making the jffs2 image mount faster ==&lt;br /&gt;
&lt;br /&gt;
The jffs2 image that was just created is a plain jffs2 image. That&#039;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. &lt;br /&gt;
&lt;br /&gt;
This can be done simply with:&lt;br /&gt;
&lt;br /&gt;
sumtool -i &amp;lt;input jffs2 image&amp;gt; -o &amp;lt;output jffs2 image&amp;gt; -e 128KiB -l -n&lt;br /&gt;
&lt;br /&gt;
== Installing on the tablet ==&lt;br /&gt;
When the new tarball is created,  Using flasher and the reference root filesystem for creating JFFS2 image from the myNewRootImage.tar.gz.&lt;br /&gt;
&lt;br /&gt;
Use flasher to install the image on the tablet.&lt;br /&gt;
&lt;br /&gt;
 ./flasher-3.0 -r rootfs.jffs2 --f -R&lt;br /&gt;
&lt;br /&gt;
== Shell script to mount/unmount JFFS2 using block device emulating MTD ==&lt;br /&gt;
Create a shell script (mount_jffs2.sh) from the following:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
JFFSIMG=$1 # jffs image&lt;br /&gt;
LOOP=&amp;quot;/dev/loop1&amp;quot; # loop device&lt;br /&gt;
MP=&amp;quot;/media/jffs2&amp;quot; # mount point&lt;br /&gt;
MTDBLOCK=&amp;quot;/tmp/mtdblock0&amp;quot; # MTD device file&lt;br /&gt;
KVER=&amp;quot;2.6&amp;quot;&lt;br /&gt;
BLKMTD=&amp;quot;block2mtd&amp;quot;&lt;br /&gt;
UMNT=&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;$0&amp;quot; | grep unmount_ &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
[ $? -eq 0 ] &amp;amp;&amp;amp; UMNT=1&lt;br /&gt;
if [ $# -gt 1 -a x&amp;quot;$2&amp;quot;x = x&amp;quot;unmount&amp;quot;x ]; then&lt;br /&gt;
  UMNT=1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
uname -r | egrep &#039;^2\.6&#039; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
if [ $? -ne 0 ]; then&lt;br /&gt;
  KVER=&amp;quot;2.4&amp;quot;&lt;br /&gt;
  BLKMTD=blkmtd&lt;br /&gt;
fi &lt;br /&gt;
&lt;br /&gt;
if [ x&amp;quot;${UMNT}&amp;quot;x = x&amp;quot;&amp;quot;x ]; then&lt;br /&gt;
  if [ ! -b ${MTDBLOCK} ] ; then&lt;br /&gt;
    mknod ${MTDBLOCK} b 31 0 || exit 1&lt;br /&gt;
  fi&lt;br /&gt;
  lsmod | grep loop &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
  if [ $? -ne 0 ]; then&lt;br /&gt;
    modprobe loop&lt;br /&gt;
    [ $? -ne 0 ] &amp;amp;&amp;amp; echo &amp;quot;loopback loading failed&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    sleep 1&lt;br /&gt;
  fi&lt;br /&gt;
  losetup ${LOOP} ${JFFSIMG} || exit 1&lt;br /&gt;
  sleep 1&lt;br /&gt;
  modprobe mtdblock&lt;br /&gt;
  if [ x&amp;quot;${KVER}&amp;quot;x = x&amp;quot;2.4&amp;quot;x ]; then&lt;br /&gt;
    modprobe ${BLKMTD} device=${LOOP} || exit 1&lt;br /&gt;
  else&lt;br /&gt;
    modprobe ${BLKMTD} || exit 1&lt;br /&gt;
    echo &amp;quot;${LOOP}&amp;quot; &amp;gt; /sys/module/block2mtd/parameters/block2mtd&lt;br /&gt;
  fi&lt;br /&gt;
  sleep 1&lt;br /&gt;
  modprobe jffs2&lt;br /&gt;
  [ ! -d ${MP} ] &amp;amp;&amp;amp; mkdir -p ${MP}&lt;br /&gt;
  mount -t jffs2 ${MTDBLOCK} ${MP} || exit 1&lt;br /&gt;
else&lt;br /&gt;
  umount ${MP}&lt;br /&gt;
  if [ $? -ne 0 ]; then&lt;br /&gt;
    echo &amp;quot;Cannot unmount JFFS2 at $MP&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
  fi&lt;br /&gt;
  modprobe -r jffs2&lt;br /&gt;
  modprobe -r ${BLKMTD}&lt;br /&gt;
  modprobe -r mtdblock&lt;br /&gt;
  sleep 1&lt;br /&gt;
  losetup -d ${LOOP}&lt;br /&gt;
fi &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Make sure you chmod a+x mount_jffs2.sh to make the shell script executable.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&lt;br /&gt;
 ./mount_jffs2.sh rootfs.jffs2&lt;br /&gt;
&lt;br /&gt;
You can also use this script to unmount and unload the non-utilized kernel modules and loopback reference:&lt;br /&gt;
 ./mount_jffs2.sh rootfs.jffs2 unmount&lt;br /&gt;
&lt;br /&gt;
== Shell script to mount/unmount JFFS2 using kernel memory emulating MTD ==&lt;br /&gt;
Create a shell script (mount_jffs2.sh) from the following:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
JFFSIMG=$1 # jffs image&lt;br /&gt;
MP=&amp;quot;/media/jffs2&amp;quot; # mount point&lt;br /&gt;
MTDBLOCK=&amp;quot;/tmp/mtdblock0&amp;quot; # MTD device file&lt;br /&gt;
UMNT=&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;$0&amp;quot; | grep unmount_ &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
[ $? -eq 0 ] &amp;amp;&amp;amp; UMNT=1&lt;br /&gt;
if [ $# -gt 1 -a x&amp;quot;$2&amp;quot;x = x&amp;quot;unmount&amp;quot;x ]; then&lt;br /&gt;
  UMNT=1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ x&amp;quot;${UMNT}&amp;quot;x = x&amp;quot;&amp;quot;x ]; then&lt;br /&gt;
  if [ ! -b ${MTDBLOCK} ] ; then&lt;br /&gt;
    mknod ${MTDBLOCK} b 31 0 || exit 1&lt;br /&gt;
  fi&lt;br /&gt;
  modprobe mtdblock&lt;br /&gt;
  modprobe mtdram total_size=65536 erase_size=256&lt;br /&gt;
  modprobe jffs2&lt;br /&gt;
  dd if=${JFFSIMG} of=${MTDBLOCK}&lt;br /&gt;
  [ ! -d ${MP} ] &amp;amp;&amp;amp; mkdir -p ${MP}&lt;br /&gt;
  mount -t jffs2 ${MTDBLOCK} ${MP}&lt;br /&gt;
else&lt;br /&gt;
  umount ${MP}&lt;br /&gt;
  if [ $? -ne 0 ]; then&lt;br /&gt;
    echo &amp;quot;Cannot unmount JFFS2 at $MP&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
  fi&lt;br /&gt;
  modprobe -r jffs2&lt;br /&gt;
  modprobe -r mtdram&lt;br /&gt;
  modprobe -r mtdblock&lt;br /&gt;
fi &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Make sure you chmod a+x mount_jffs2.sh to make the shell script executable.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
 ./mount_jffs2.sh rootfs.jffs2&lt;br /&gt;
&lt;br /&gt;
You can also use this script to unmount and unload the non-utilized kernel modules:&lt;br /&gt;
 ./mount_jffs2.sh rootfs.jffs2 unmount&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Wiki page of the day]]&lt;/div&gt;</summary>
		<author><name>121.217.111.231</name></author>
	</entry>
</feed>