Android partitions, kernels explained
Here are the standard partitions on an Android phone: /misc - not sure what this is for. /boot - bootloader, kernel /recovery - holds the recovery program (either clockworkmod or RA recovery for a rooted Evo) /system - operating system goes here: Android, Sense, boot animation, Sprint crapware, busybox, etc /cache - cached data from OS usage /data - user applications, data, settings, etc. The below partitions are not android-specific. They are tied to the hardware of the phone, but the kernel may have code allowing Android to interact with said hardware. /radio - the phone's radio firmware, controls cellular, data, GPS, bluetooth. /wimax - firmware for Sprint's flavor of 4G, WiMax. During the rooting process, a critical piece of the process is disabling a security system built into the bootloader that protects these partitions from accidental (or intentional) modification. This is what's referred to as "unlocking NAND." The security system can be set to active or inactive. S-ON means the security is in place (NAND locked). S-OFF means the security is off (NAND unlocked). When S-OFF, you have the ability to modify all partitions. With S-ON, you only have write access to /cache and /data. Everything else is read-only.
When you flash a custom ROM, that ROM typically includes a kernel and an OS. That means the /boot and /system partitions will be modified at a minimum.
When you do a factory reset (AKA: wipe, hard reset, factory wipe, etc.), you are erasing the /data and /cache partitions. Note that a factory reset does NOT put your phone back to its factory state from an OS standpoint. If you've upgraded to froyo, you will stay on froyo, because the OS lives in /system, and that is not touched during a factory reset.
所以所谓的”factory reset”并不是真正意义上的reset，而是”data reset”。只有root了才有可能做到真正的reset吧？
The SD card can also be partitioned to include a section dedicated to storing user apps. To create the partition, your SD card needs to be formatted.
More information about Android partitions
Linux/UNIX type systems have one top level file structure. The top level is called root, and is designated by /. There are no drive letters, and the files and folders under / are not necessarily all stored in the same physical location. From this point on, the root of the file system will just be referred to as /. There really isn't much under / by itself. It's generally a small partition. In order to use other partitions, Android must make these partitions available under /. There is a special directory called /dev. In order to use partitions found in /dev, the system must mount them under /.
There are two very important conclusions: 1) The system mounts and unmounts partitions at boot and shutdown. If you pull the battery out while the system is running or use a poorly written app to reboot the phone, partitions are still mounted, and if the system is writing to them, you could easily corrupt something. Granted, sometimes this is necessary if the phone becomes unresponsive. It's more likely to be a problem if repeatedly done. 2) Ever wonder why you cannot access the sdcard while the phone is connected to a computer as a disk drive? It's because the computer is mounting the sdcard partition so that you can see it there. What does that mean? It means Windows, Linux, etc. (whatever OS you have on your computer) has direct access to that physical media. No two operating systems can have direct control over physical media at the same time. It would result in massive data corruption. You may be wondering how it's possible to share drives or partitions in the networking world. You can do so because the Computer that has the physical media is still the only host that can physically read and write to the media. Sharing of the data is done at a much higher level and is controlled by the operating system.
Linux based systems have a file called fstab. That file is a mapping of physical partitions and their mountpoints, along with options it needs to know when mounting said partitions. It uses this file to mount partitions at boot time. So, the fact that you don't have to mount /system, /boot, /data, etc. yourself is because the system does it for you.
The partition mounted as /data is mounted as rw. It has to be, otherwise the system would be all but unusable. You wouldn't be able to install apps, change settings, etc. Do not confuse this with file permissions. That is a different discussion for a different time, but at least understand this - file and directories have certain permissions that allow the file owner, the group the file owner belongs to, and everyone else specific access to said file. The point is that a partition must be mounted as rw in order for write permissions to work. If you have permission to write to a file on a partition, but it is mounted as ro, it will not work.
这个区分了mount option和file permission之间的关系。这是两种不同的限制方式，mount option是针对整个文件系统的，而file permission只针对一个文件或是文件夹。也就是说，即使你某个文件有write权限，如果整个文件系统的mount option是ro，那么文件也是不可写的。
The System Partition
The partition mounted as /system is automatically mounted as read only. It's like this because, even with root (the unlocked ability to make changes to the partition mounted as /system) it's dangerous to make changes there if you do not know what you are doing. When you flash a ROM from recovery, it wipes that partition, and writes new contents to it. Recovery scripts, however, are smart enough to mount this partition in rw mode. If you are going to make changes to /system while booted up in Android, you must have /system mounted as rw. Otherwise, you will just get permission errors even thought you have root level permissions.
To do this, you must remount the partition under /system as rw. There are many ways of doing this. All of them are system-wide. What that means is, if you use an app to remount /system as rw, the entire system and any other app will see it such until you reboot the phone or remount it as ro. Root explorer, for example, has an option in the top right corner to mount whatever file system you are currently browsing as either rw or ro depending on what it's currently mounted as. Basically, it toggles between rw and ro. There is also an app in the marketplace called "Mount /system (rw /ro)", which will do that as well if you don't have root explorer. Let's look at it in a little more detail, though.
一般来说，如果你要将/system分区remount成rw的话，一般是要有root权限的，上文中说有一个app叫”Mount /system (rw /ro)”的不要root explorer，这个我没有搞太清楚。
Should you want to remount the partition mounted under /system as rw using the command line from a terminal emulator, you would run this: $ su mount -o remount,rw -t yaffs2 /dev/block/mtdblock4 /system
-o is the option used to specify certain special mount options. a comma separated list following -o are the options you want to specify for mounting. remount means that the file system you are mounting is already mounted, and you want to specify some other options. rw means that you want /system to be mounted in read/write mode. -t yaffs2 is the filesystem type of the partition. /dev/block/mtdblock4 is the logical location of the partition itself under /dev as previously explained. /system is the location under / where the files belonging to the mtdblock4 partition will be made accessible.
To see how /system is currently mounted: $ mount | grep /system You will see something like: /dev/block/mtdblock4 /system yaffs2 ro 0 0 Having an understanding of how this works will help you determine ways of saving space and making the most of your available storage. The three major partitions are /data, /system, and /cache. A majority of your 1 GB of internal storage is used by these. The partitions sizes are set when the partitions are created. By default, this is how they are partitioned: /system – 350 MB /data – 430 MB /cache – 160 MB As you can see, you only have 430 MB for apps and data. That’s less than half of the advertised space. There are numerous apps on the market that will display the free space available on each partition, but it can be done from the command line as well by typing this: $ df -h You will probably notice that both /system and /cache have a lot of free space. As it turns out, most of that free space rarely gets used, and cannot be used by you for apps, at all. It’s wasted space. Cache, of course, will show mostly free space, but it’s necessary for things like OTAs, which will download to that directory. It does need to be somewhat large, but not that big. In any case, there are ways of having more space available than just 430 MB. The best place to start is a2sd.
A2sd, Apps2sd, and File System Types
With all of this knowledge in mind, you can probably get a better understanding of how something like a2sd works. A2sd is a system devised to move all installed applications to the sdcard. This is by no means the same thing as the built-in froyo apps2sd.
With Froyo apps2sd: The developer of a certain app specify that it is allowed to be moved to the sdcard. Even when it is, if the app has widgets, those widgets will not be available once the app is on the sdcard. Why? Because the sdcard is unmounted once the phone is connected to a computer as a disk drive. If widgets belonging to such an app were on the homescreen at that time, they would stop working. Google designed Android to avoid such a case by just making those widgets unavailable.
Only a part of the app is moved, not the entire thing. If you've ever looked at at an app that has been moved to the sdcard in manage applications, you will see that it still is taking up space on internal storage (in /data). The reason this happens goes back to file system types.
Linux based systems have a certain number of file system types that it can use. Windows has its own as well. The sdcard needs to be formatted in a file system that is basically universal. This means that no matter what kind of computer you plug the phone into, plus the phone itself, you need to be able to view/modify the contents of the card. That file system is fat32. Both Linux and Windows can view/modify said contents. BUT, Linux (Android) can't execute anything off of a fat32 partition. Its use of it is somewhat limited. That being said, Android cannot move an entire app to the sdcard in its stock condition, as it would be moving it to a fat32 file system, where it would not be able to execute it.
因为一个手机上的sdcard可能会被mount在不同的系统中（比如windows, mac, linux），所以sdcard上的文件系统必须得足够universal。所以sdcard的文件系统一般是fat32，因为它可以被linux和windows都看到，但它有一个很大的限制就是不能再上面运行任何东西。也就是说应用程序运行的部分是不能被移到sdcard上的，否则它就无法被运行了。
A2sd has none of these issues, and gets around them in a fairly creative way. The sdcard, in stock state, has one partition, which is this fat32 partition. You still need a majority of the card to have this fat32 partition for the purpose of using it normally, but a2sd must use a partition type that is native to Linux. So, the first thing you must do to use a2sd is partition the card into two separate partitions. This can be done in recovery. Once it is done partitioning, it formats the two partitions using a particular file system. The bigger partition, which the user will continue to see as /sdcard and keep all of there data, remains fat32. The smaller partition (usually made between 512 MB and 1 GB) is formatted in the ext3 file system. This ext3 file system type is native to Linux. What does this mean? It means that Android can use that partition on the sdcard the exact same way it could internal storage.
a2sd的原理是这样的，它将sdcard分成了两个区，一个比较大的继续当fat32用，存放正常数据，另一个将其格式化为ext3格式，就可以达到所谓的”native to linux”了。
Doesn't Android have to mount this new ext3 partition just like it does internal storage partitions and the normal fat32 sdcard partition? Why, yes it does. It mounts the partition just like any other partition, but it makes the mount point /system/sd. Once you've created the ext3 partition, you can browse /system/sd. It will look just like a directory in internal storage, but since it's a mountpoint, when you view it, you're looking on the sdcard, just in the smaller, ext3 partition. Having done this, you've basically fooled the system into thinking you have more internal storage. The issue is that Android will look for apps in two main places - /data/app and /system/app. if you just stuck an apk (Android application) in /system/sd, Android system would never find it, as it will never look there. For those interested in seeing how the sdcard partitions are mounted, run these two commands: $ mount | grep /sdcard $ mount | grep /system/sd The output for /system/sd, for example, looks like: /dev/block/mmcblk0p2 on /system/sd type ext3 (rw,noatime,nodiratime,errors=continue,data=writeb ack) Both of those commands, though, will show how the fat32 sdcard partition is mounted (/mnt/sdcard) and how the ext3 sdcard partition is mounted (/system/sd). As you can see, mmcblk0p2 is the ext partition, while the majority of the card (the fat32 partition) is mmcblk0p1. Another quick important point is that /system/sd is mounted as rw so that you can make changes. Remember this - if a partition is mounted as ro (/system) but a directory under it is used as a mountpoint (/system/sd) you will still be able to write to whatever is mounted under that second directory as long as the partition is mounted as rw. That being said, you can leave /system mounted as ro, and still always make changes to /system/sd.
The first thing a2sd does is move all applications from /data/app and /data/app-secure to /system/sd/app and /system/sd/app-secure. Remember that with just this step, the system would not see apps anymore. At this point, a2sd makes use of something called a symlink. a2sd removes the /data/app and /data/app-secure directories, then creates symlinks (shortcuts) called /data/app and /data/app-secure that point to directories in /system/sd for apps. This means that the system will continue to look in /data/app and /data/app-secure for apps, but will be directed to /system/sd. Basically, the system doesn't care where files actually are. It only cares that it can find them where it knows to look.
A2sd can also be used to move dalvik cache to the sdcard. It does this in exactly the same manner as moving apps. Dalvik cache is normally stored in /data/dalvik-cache. A2sd creates a directory in /system/sd for dalvik-cache, then creates a /data/dalvik-cache symlink that points to the real location.
As dalvik cache is stored in /data by default, it takes up your usable storage, needlessly. That is why it can be moved to the sdcard ext3 partition. If you choose to, though, it can also be moved to the /cache partition. /cache is normally just unused space on internal storage that is way bigger than it needs to be. Thus, dalvik cache can be moved there instead, too. The idea is the same, but it doesn't use symlinks. It does some creative work with the mount command to make the system look there for it.
Other Space Saving Options
Some people do not want to use a2sd, as they do not have good enough sdcards and are not interested in buying a new one. A2sd will not work well with a slower card, such as the one that comes stock with the Evo. However, it is possible to reclaim some of the unusable internal storage. If you remember, /data, /system, and /cache make up a majority of your internal storage. They can be resized with this mod.