From Openmoko

Jump to: navigation, search

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.

if [[ $# != 2 ]] || [[ ! -e "$1" ]] || [[ ! -d "$2" ]]
then echo Usage: $0 image.jffs2 directory
     exit 2
lodev=$(sudo losetup -f)  # Find unused loop device
# 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

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
if test $# != 2 -o ! -d "$2"
then echo Usage: $0 image.jffs2 directory; exit 2
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