8

I have a .img file that uses the yaffs2 filesystem (an Android partition image) that I want to mount. I can't seem to do it with the mount command. How can I do this? I'm using Ubuntu 12.04.

Also, I don't want to extract it (I know how to do that using unyaffs). I want to mount it.

2
  • Is it a boot.img or system.img file?
    – mfisch
    Dec 30, 2012 at 4:33
  • @mfisch system.img file. boot.img isn't yaffs2. And I don't want to extract it, I want to mount it.
    – gsgx
    Dec 30, 2012 at 5:12

5 Answers 5

15

Ubuntu currently does not support YAFFS2. There is a feature request to package the YAFFS2 kernel module, which would provide mount support for the filesystem: [needs-packaging] yaffs2.

Kernel support

Thus, currently, if you need mount support you will have to compile it yourself. The YAFFS website has instructions for compiling a Linux kernel with YAFFS support (using Precise 32-bit):

The Ubuntu wiki also has general information on compiling your own kernel.

Extract and rebuild

Alternatively, try using yaffs2utils to extract and rebuild the image.

Note that due to a bug, you must specify the --yaffs-ecclayout option or it will silently fail. So to extract, try something like

git clone https://code.google.com/p/yaffs2utils/
cd yaffs2utils && make && cd ..
./yaffs2utils/unyaffs2 --yaffs-ecclayout system.img tempdir

Theoretically you can also rebuild the image using mkyaffs2, but I couldn't get it to work (the result wasn't bootable).

Yaffey

I found a program, Yaffey, that lets you edit a YAFFS2 image using a GUI:

Yaffey

While the home page says it's Windows-only, with a trivial change it compiles on Ubuntu Precise. To do so:

  1. Install dependencies: sudo apt-get install qt-sdk
  2. hg clone https://code.google.com/p/yaffey/
  3. In the file yaffey/yaffs2/yaffs_guts.h, change the line

    typedef unsigned loff_t;
    

    to

    #include <stdlib.h>
    
  4. Compile: cd yaffey && qmake && make
  5. Run ./yaffey.
  6. Open your image, make your desired changes, and save (it refuses to overwrite; you have to select a different filename).

When I tried it, the resulting image booted successfully in the Android emulator.

2
  • Thanks for recommending Yaffey and providing details of the patch needed to compile it on Linux!
    – qris
    Sep 9, 2013 at 15:09
  • How to build on Mac: github.com/danielkutik/yaffey
    – Daniel K
    Aug 12, 2015 at 4:39
4

0. yaffs2 OR ext4

Android originally used YAFFS2 as the file system. After Android 2.3, the file system became ext4.

from https://stackoverflow.com/questions/23946910/

1. detect image type

file system.img
system.img: VMS Alpha Exectutable

// this is yaffs2 image

file system.img
system.img: data

//this maybe ext4 sparse image

blkid -pO 40 system.img 
system.img: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" VERSION="1.0" TYPE="ext4" USAGE="filesystem"

//yes, it's ext4 sparse image

//40 = sizeof(struct sparse_header) + sizeof(struct chunk_header)

ref: simg2img source code

2. simg2img for ext4 sparse image

It's a sparse filesystem, I think you'll need to unsparsify it first using simg2img. You can download it as part of ext4_utils which I have posted on here for when I used it on the Nexus7 images. Unpack the image and mount as follows:

Unpack:

./simg2img rootfs.img rootfs.ext4

Mount:

sudo mount -o loop rootfs.ext4 tmpmnt/

Once you've unpacked it and hacked it, you rebuild it using make_ext4fs. You should probably read the blog entry I made about hacking the Nexus7 image as it covers most of this and the script it references may be useful.

5
  • Thanks for the answer but I don't think it will work. simg2img only outputs "Bad Magic". Googling told me that this happens when you use it on anything that's not a compressed ext4 image, and yaffs2 isn't a compressed ext4 image.
    – gsgx
    Dec 30, 2012 at 6:09
  • 1
    Sorry I completely missed that, did you try the unyaffs2 tool? code.google.com/p/unyaffs/downloads/…
    – mfisch
    Dec 30, 2012 at 16:16
  • Yea, I was able to extract it with unyaffs, but since that's not really mounting I can't accept this answer. I guess it's not currently possible. Btw, you have an interesting blog :)
    – gsgx
    Dec 30, 2012 at 22:55
  • 1
    I've also read, but not tried, that you can compile yaffs2 support into your kernel and just mount it like that. Maybe the simplest solution here is to mount it on an Android device?
    – mfisch
    Dec 31, 2012 at 1:35
  • I feel the change from yaffs2 to ext4 was caused by emmc, correct me if I am wrong.
    – Bill Zhao
    Nov 26, 2021 at 18:00
2

I thought I would update this with Ubuntu 13. I had to make some changes to get it to compile that I hope will help others.

  1. Edit yaffey.pro and under

    QT += core gui

    Add

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

  2. Edit MainWindow.cpp and search/replace:

    setResizeMode with setSectionResizeMode

  3. Edit YaffTreeView.cpp and under

    #include <QDebug>

    Add

    #include <QMimeData>

You should then be able to compile.

1
1

After following nospam & Mechanical Snail's steps I also had to make this change in main.cpp

change:

#include <QtGui/QApplication>

to:

#include <QtWidgets/QApplication>

Then it finally compiled

0

just for users deal with ext4 sparse image (android system.img)


0. yaffs2 OR ext4

Android originally used YAFFS2 as the file system. After Android 2.3, the file system became ext4.

from https://stackoverflow.com/questions/23946910/

1. detect image type

file system.img
system.img: VMS Alpha Exectutable

// this is yaffs2 image

file system.img
system.img: data

//this maybe ext4 sparse image

blkid -pO 40 system.img 
system.img: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" VERSION="1.0" TYPE="ext4" USAGE="filesystem"

//yes, it's ext4 sparse image

//40 = sizeof(struct sparse_header) + sizeof(struct chunk_header)

ref: simg2img source code

2. simg2img for ext4 sparse image

as mfisch's answer.

convert sparse image to raw image:

./simg2img system.img system_raw.img

mount:

sudo mount -t ext4 system_raw.img tmpmnt/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .