Jffs2

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m
(Restoring losetup method, as it is the only way to modify the jffs2 image.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Mounting a JFFS2 image ==
 
 
=== Using a loopback device ===
 
=== Using a loopback device ===
Make the MTD block device
+
This method of mounting a jffs2 image file allows you to make modifications to the mounted filesystem, which will take effect in the file itself.
  mknod /dev/mtdblock0 b 31 0
+
<pre>
 +
#!/bin/bash
 +
if [[ $# != 2 ]] || [[ ! -e "$1" ]] || [[ ! -d "$2" ]]
 +
then echo Usage: $0 image.jffs2 directory
 +
    exit 2
 +
fi
 +
lodev=$(sudo losetup -f)  # Find unused loop device
 +
mtnum=0
 +
mtdev=mtdblock$mtnum
 +
# If we have udev, the mtd device appears automatically. Otherwise, create it:
 +
# [[ -b "/dev/$mtdev" ]] || sudo mknod "/dev/$mtdev" b 31 $mtnum
 +
sudo losetup "$lodev" "$1"  # Associate the loop device with the image file
 +
sudo modprobe block2mtd
 +
echo "$lodev" | sudo tee /sys/module/block2mtd/parameters/block2mtd
 +
sudo mount -t jffs2 "/dev/$mtdev" "$2"
 +
</pre>
 +
To reset everything later, assuming "loop0" was used with mountpoint "mymount":
 +
sudo umount mymount
 +
sudo rmmod block2mtd
 +
sudo losetup -d /dev/loop0
  
Associate the jffs2 file with a loopback device
+
=== Using mtdram ===
  losetup /dev/loop0 /path/to/jffs2/file/eg/Om200Y.MM-gtaNN-YYYYMMDD.rootfs.jffs2
+
An alternative way is used in the following script. Any modifications made in this mount will have no effect on the file itself.
  
Load the block2mtd module
 
modprobe block2mtd
 
 
Tell the module which loopback device to use
 
echo /dev/loop0 >/sys/module/block2mtd/parameters/block2mtd
 
 
Make a mount point for the file system
 
  mkdir /mnt/jffs2
 
 
Mount the file system
 
mount -t jffs2 /dev/mtdblock0 /mnt/jffs2/
 
 
 
=== Using mtdram ===
 
An alternative way is used in the following script:
 
 
  if test `id -u` != 0
 
  if test `id -u` != 0
 
  then echo "Must be root"; exit 2
 
  then echo "Must be root"; exit 2
 
  fi
 
  fi
  if test $# != 2 -o ! -d $2
+
  if test $# != 2 -o ! -d "$2"
 
  then echo Usage: $0 image.jffs2 directory; exit 2
 
  then echo Usage: $0 image.jffs2 directory; exit 2
 
  fi
 
  fi
Line 33: Line 36:
 
  modprobe mtdchar
 
  modprobe mtdchar
 
  modprobe jffs2
 
  modprobe jffs2
  s=$(ls -s $1)
+
  s=$(ls -s "$1")
 
  s=${s% *}
 
  s=${s% *}
 
  echo modprobe mtdram total_size=$s
 
  echo modprobe mtdram total_size=$s
 
  modprobe mtdram total_size=$s
 
  modprobe mtdram total_size=$s
  dd if=$1 of=/dev/mtd0
+
  dd if="$1" of=/dev/mtd0
  mount -t jffs2 /dev/mtdblock0 $2
+
  mount -t jffs2 /dev/mtdblock0 "$2"
 +
 
 +
To reset this, simply
 +
umount mymount
 +
rmmod mtdram
 +
[[Category:Advanced End User]]

Latest revision as of 06:18, 5 June 2010

[edit] Using a loopback device

This method of mounting a jffs2 image file allows you to make modifications to the mounted filesystem, which will take effect in the file itself.

#!/bin/bash
if [[ $# != 2 ]] || [[ ! -e "$1" ]] || [[ ! -d "$2" ]]
then echo Usage: $0 image.jffs2 directory
     exit 2
fi
lodev=$(sudo losetup -f)  # Find unused loop device
mtnum=0
mtdev=mtdblock$mtnum
# If we have udev, the mtd device appears automatically.  Otherwise, create it:
# [[ -b "/dev/$mtdev" ]] || sudo mknod "/dev/$mtdev" b 31 $mtnum
sudo losetup "$lodev" "$1"  # Associate the loop device with the image file
sudo modprobe block2mtd
echo "$lodev" | sudo tee /sys/module/block2mtd/parameters/block2mtd
sudo mount -t jffs2 "/dev/$mtdev" "$2"

To reset everything later, assuming "loop0" was used with mountpoint "mymount":

sudo umount mymount
sudo rmmod block2mtd
sudo losetup -d /dev/loop0

[edit] Using mtdram

An alternative way is used in the following script. Any modifications made in this mount will have no effect on the file itself.

if test `id -u` != 0
then echo "Must be root"; exit 2
fi
if test $# != 2 -o ! -d "$2"
then echo Usage: $0 image.jffs2 directory; exit 2
fi
rmmod mtdram
modprobe mtdcore
modprobe mtdblock
modprobe mtdchar
modprobe jffs2
s=$(ls -s "$1")
s=${s% *}
echo modprobe mtdram total_size=$s
modprobe mtdram total_size=$s
dd if="$1" of=/dev/mtd0
mount -t jffs2 /dev/mtdblock0 "$2"

To reset this, simply

umount mymount
rmmod mtdram
Personal tools

Mounting a JFFS2 image

Using a loopback device

Make the MTD block device

mknod /dev/mtdblock0 b 31 0 

Associate the jffs2 file with a loopback device

losetup /dev/loop0 /path/to/jffs2/file/eg/Om200Y.MM-gtaNN-YYYYMMDD.rootfs.jffs2

Load the block2mtd module

modprobe block2mtd 

Tell the module which loopback device to use

echo /dev/loop0 >/sys/module/block2mtd/parameters/block2mtd

Make a mount point for the file system

 mkdir /mnt/jffs2

Mount the file system

mount -t jffs2 /dev/mtdblock0 /mnt/jffs2/


Using mtdram

An alternative way is used in the following script:

if test `id -u` != 0
then echo "Must be root"; exit 2
fi
if test $# != 2 -o ! -d $2
then echo Usage: $0 image.jffs2 directory; exit 2
fi
rmmod mtdram
modprobe mtdcore
modprobe mtdblock
modprobe mtdchar
modprobe jffs2
s=$(ls -s $1)
s=${s% *}
echo modprobe mtdram total_size=$s
modprobe mtdram total_size=$s
dd if=$1 of=/dev/mtd0
mount -t jffs2 /dev/mtdblock0 $2