1. Are you ready for the Galaxy S20? Here is everything we know so far!
Thread Status:
Not open for further replies.

More information about Android partitions

Discussion in 'Android Devices' started by akazabam, Feb 16, 2011.

  1. akazabam

    akazabam Android Expert
    Thread Starter

    This thread is meant to be a supplement to novox77's thread on partitions and kernels, found here. This is strictly an informational thread, and does not include an actual guide for accomplishing anything. It will, however, provide some background on some of the inner workings of Android, hopefully. Read novox77's thread, first, before reading this information. Novox77 and I decided it would be better to make a separate thread for this, but Mod's, if you feel otherwise, please merge them.

    I. The Basics

    Every operating system has a way of viewing and manipulating the filesystem(s) available to it. In the case of Windows, you have designated drive letters which represent the physical drives or partitions on a drive. Under each drive, you have folders and files. Those folders and files are data on each one of those specific drives. It's all very concise and obvious as to what data exists on what drive. There *are* things you can do complicate this, but this is not a discussion about Windows.

    Android does not work anything like Windows, however, as it is a Linux based system. 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. Let me just take a very brief detour here. The top level file system is called root. When we say root in this case, we are not talking about the root user or root level permissions. When you root the phone, we're talking about have permissions to do things as the root user and make changes we couldn't otherwise do. The word root is used for different things. When you hear the word root used with filesystems, we mean the top level.

    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. Under this directory, you will find logical representations of partitions and resources available to the system. These, on their own, are just device files. These files exist solely so that the system knows they exist. You cannot try to view anything in them. So, in order to use partitions found in /dev, the system must mount them under /. This means the system must take a physical or logical media where you have some data stored, and make it available.

    II. Mounting

    When the system (or the user) initiates this process of mounting, a directory (folder) must exist somewhere under / for the partition to be mounted to. It can be directly under / or in a nested directory under /. We call this a mountpoint. What it means is that an empty directory will be designated to show the contents (data) of a partition. So, we say that internal storage is partitioned with various partitions such as /boot, /system, /data, /cache, etc. What this really means is that these partitions are all a part of internal storage, but have been logically separated so that the system sees them as separate as different physical media (i.e. partitions), but are then all mounted (made accessible) in one logical location. If you browse files on /system, then browse file on /data, you're under the root filesystem in both cases, but are looking in two different actual locations.

    This type of thing is certainly not limited to partitions on internal storage. Any time you have a different physical media, it must be mounted under / just like any other partition. For example, you have a directory under / called /sdcard. That is a symlink (shortcut) to /mnt/sdcard, which is a mountpoint for the sdcard. More information on symlinks and how they work later. For now, just understand that it's basically a shortcut. Anyway, its partition can be found in /dev, as well, albeit in a different location. It is mounted under /mnt, accessible under /, all the same. The reason it's mounted under /mnt rather than / is because Linux based systems usually use /mnt for external device mounts. It doesn't have to, though. It could be mounted directly under / as /sdcard. It would still work. In any case, think of viewing the sdcard this way in the same manner that you would connect a usb flash drive to a Windows computer. When you do that, Windows sees the physical drive, then creates a letter drive for you to view it's contents. The principle is the same in that Android sees the physical media, but it mounts it in the same logical location (/) as all the other mountpoints. From a user's perspective, on Android, all the mountpoint directories look like they may as well be on the same media, even though they are not. On a Windows computer, when you are done with a flash drive, you have to tell it to safely eject the hardware. On Android (Linux), you have to do something similar, called unmount. If you do that to the sdcard, you will no longer be able to view /sdcard. Though you could create a directory under / called sdcard, it wouldn't have anything in it, and would be just a directory on internal storage until you remount the sdcard. Typically, the system mounts and unmounts partitions automatically when necessary.

    There are two very important conclusions made from the above:

    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.

    III. Mount Options

    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. It uses options it's told to use, though. There are various options that can be specified, but it is out of the scope of this explanation. What is important, though, is the designation between read/write (rw) and read-only (ro). This option is specified at boot time for automatically mounted partitions.

    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. Those permissions can be either the ability to read the file, write (modify) to the file, or execute it. The same goes for directories (though executing a directory doesn't make sense). 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.


  2. akazabam

    akazabam Android Expert
    Thread Starter

    IV. 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.

    Should you want to remount the partition mounted under /system as rw using the command line from a terminal emulator, you would run this:

    mount -o remount,rw -t yaffs2 /dev/block/mtdblock4 /system

    The "su" command is how you get root level permissions at the command line. You cannot change how a partition is mounted without it. Let's break down the second command:

    • mount is the generic command used to view or modify currently mounted partitions or any media for that matter.
    • -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. You would leave this out if the filesystem was not mounted yet. As /system has to be mounted by virtue of the fact that you're using the system, you must specify the option to remount.
    • rw means that you want /system to be mounted in read/write mode. By default, it is read-only, as previously explained.
    • -t yaffs2 is the filesystem type of the partition. It's not that important for this explanation. Just understand that a partition must be formatted with a particular file system, which basically means how files are stored. Each operating system has the ability to understand certain file system types. More on this later.
    • /dev/block/mtdblock4 is the logical location of the partition itself under /dev as previously explained. Should you want to mount a different partition, you would replace this line with it.
    • /system is the location under / where the files belonging to the mtdblock4 partition will be made accessible. In the case of a remount, these last two strings should not change from how it is currently mounted. For example, if /system was mounted as /asdfasdf (just an example), you should not use remount to then mount it as /system. You'd stick with /asdfasdf. Just a point to remember; it will always be /system in this case. This is not the case if you
    TodWulff, spiderplant0, hno3 and 12 others like this.
  3. akazabam

    akazabam Android Expert
    Thread Starter

    VI. 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.

    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.

    Now, You might be asking yourself at this point, 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=writeback)

    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.

    Anyway, a2sd is how you use this new ext3 partition. 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. Think of a symlink as a shortcut in Windows. When you create file in a particular folder, then make a shortcut to that file from a different folder, it exists in the first folder, but is accessible from the second folder. The same holds true for folders. A symlink is basically the same thing. So, 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. How it actually works is out of the scope of this information.

    VII. 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.

    That process is only recommended for advanced users and only under certain circumstances. Should you decide to move all apps and app data to the sdcard using a2sd, there is no purpose in resizing the partitions. Very little else goes in /data. Basically, either use a2sd to its fullest extent or resize partitions. Don’t do both.
    TodWulff, hno3, sdrawkcab25 and 14 others like this.
  4. akazabam

    akazabam Android Expert
    Thread Starter

    Reserved just in case.
  5. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    thanx akazabam. this is a lot of info. that i'm trying to absorb. i will have to read this a few times to fully understand everything. i have been wanting to learn a littleabout linux and this is a good start. thanx for putting this out there.
  6. stevcha

    stevcha Android Expert

    WOW!! That's a ton of info!! Thanks for the write up
  7. akazabam

    akazabam Android Expert
    Thread Starter

    I hope it was useful :). If anything isn't clear, or doesn't make sense, let me know so I can reword it. I'll be adding more information to this eventually, as well.
    hno3 and ocnbrze like this.
  8. stevcha

    stevcha Android Expert

    Is it possible to set up an external swap partition? Any 3rd party apps thatcan do it easily?
  9. akazabam

    akazabam Android Expert
    Thread Starter

    Yes to the first question. When you partition the card, you can create a small swap partition that can be used by a2sd. You don't really *need* to, though. As for apps, you can create a swap file, kind of like how windows does it, using something like this. It really shouldn't be necessary, and there are conflicting reports that doing the latter is more harmful than helpful. I suggest you research it before doing it. In any case, to use the a2sd method, you need a2sd set up with an ext partition on the card. I don't believe swapper needs anything special other than root.
    stevcha likes this.
  10. stevcha

    stevcha Android Expert

    If I use the Mount /system (rw /ro) app to enable rw will running the "fix permissions" setting in Clockwork or ROM manager revert everything back to read only?
  11. akazabam

    akazabam Android Expert
    Thread Starter

    No, it shouldn't. Basically, all directories and files have file permissions. It means the access a certain person or group has to a file or directory. You can have read, write, or execute. Each file or directory will have placeholders that look like this ----------. If you saw something like that, it would mean nobody had access. That's pointless. In any case, the first - means it's a file. If it was a "d" instead, it would mean it was a directory. The following nine dashes are placeholders for permissions for the owner of the file (first three dashes), the group the owner is in (the second three dashes) and everyone else (the last three dashes). So, it's basically three sets of three dashes. Each placeholder is either a dash or a letter for whatever that place represents. The first dash would be a "r". If it's there, it means you have permission to read. The second dash would be a "w". That means you can write. The third dash would be a "x" and means you can execute (really only applicable to files that can be executed). So, if you see something like -rwxr-xr-x, that would mean a file can be read, written to, and executed by the owner of the file, read and executed by the group, and read and executed by everyone else. Android has special users and groups that certain files have to be owned by. Sometimes, certain things you can do with root will mess up these permissions. If that happens, the system cannot run certain things correctly. That's what the fix permissions option is meant to fix.

    This is not the same thing as a filesystem being mounted as ro or rw. That will override permissions. So, if you have root, and you have *permission* to write to /system, you can't until the filesystem is mounted in read/write mode. Fixing permissions will affect permissions only, and not how a filesystem is mounted. If you want to remount /system as ro, you have to select the option that app, or use the terminal emulator (or use any other app that has a toggle). Or you could just reboot.

    I probably repeated a bunch of other information I already wrote down, so the short answer, again, is no, selecting the option to fix permissions shouldn't affect that. To be honest, you want to leave it mounted in rw for only as long as you need it.
    stevcha likes this.
  12. stevcha

    stevcha Android Expert

    Thanks!! So with that app should I leave the "Mount system dir for r/w access at boot" unchecked?
  13. akazabam

    akazabam Android Expert
    Thread Starter

    Yeah, I see no good reason to mount /system as rw at boot. There's too much potential to break things. I see it as a tool that you should use only when you need it.
    hno3, dannymur and stevcha like this.
  14. dannymur

    dannymur Android Enthusiast

    Well Thank You akazabam.......:)

    All this has been very useful and presented in a very readable format.

    Speaking of format, this is why I stumbled into this forum, I usually hang out in ZTE Blade/OSF, and I had a problem after formatting my little 2G SD card, which came with FAT16.

    I am using App2SD, and Mod Install Location to "force" as many apps as I could onto the SD.

    Well, after the Format, my restore of the SD did not go well, and I lost a lotta apps.

    This was because the back-up tool I used did not actually copy the real contents of the /mnt/sdcard/.android_secure.....which are the apps of course.

    So, the restore did not work out too well.

    When my new 16G SD card arrives this week, I will be exploring the possibilities you have referred to with A2SD, which seems quite exciting really.

    Anyway, thanx again for the above, I will check out all your posts, and perhaps learn something....


  15. 3club

    3club Member

    Wow, akazabam, thanks! That was the most readable guide I've ever seen on such technical material. You wouldn't happen to have any other tutorials, would you? I'm interested in learning more about the booting process, bootloaders, kernels, what resides where and what loads what and when.
  16. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    thanx for bringing this awesome thread back. i do not think that akazabam is round very much any more. he is the god of these forums in my opinion. and unfortunately you will not see many threads that he has started himself. this is just one of a few that he has done. most of the info he gives out are just in answering posts.
  17. Granite1

    Granite1 Zercron Encrusted Tweezer

    Akazabam is the man, unfortunately he hasn't been seen around the forum on a couple months. He was moving and stated he wouldn't be around for a while. Guess he still doesn't have time. No one knows. Epic loss for the EVO community none the less. He was a library, knew everything! Truly very missed. :(
    ocnbrze likes this.
  18. 3club

    3club Member

    He has a gift, no doubt! Guess we can't hog him all to ourselves!
  19. This information is exactly what I was looking for to understand Android's innards. As a long-time Linux user, the stuff about partitions and mounting I was fairly familiar with, but I had no idea until I read this post how they work in Android. So, a fantastic post, and one that I read with many thanks!
    ocnbrze likes this.
  20. Granite1

    Granite1 Zercron Encrusted Tweezer

    Exactly what I thought the first time I read it. :)

    I think we need to link this thread in the root guide for future reference. Too good of a thread to disappear in the void!
    ocnbrze likes this.
  21. I agree!
  22. Granite1

    Granite1 Zercron Encrusted Tweezer

    Done. Linked under general info in the root guide. :)
  23. new optimus

    new optimus Android Expert

    Glad I saw this, much of it I had already learned in one form or another but having it all laid out like this is very good.
    ocnbrze likes this.
  24. Thanks :)
  25. rmivuxgc

    rmivuxgc Newbie

    I m having Galaxy Pocket attached via USb cable in debug mode, using ADB shell via PC. When i enter mount | grep /system the result is grep: not found. So kindly let me out of here. Also i wan to know the mount point of /system.

    Once again thanks a lot:)

HTC EVO 4G Forum

The HTC EVO 4G release date was June 2010. Features and Specs include a 4.3" inch screen, 8MP camera, 512GB RAM, Snapdragon S1 processor, and 1500mAh battery.

June 2010
Release Date

Share This Page