[MOD] full r/w access via overlay filesystem (any ROM)

Search This thread

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
OK, here we go. Following the model from Desire thread, I made this one for Legend too.


Backgroud:

If I sum up some key points from this thread... there is no way of writing to system partition (Legend, Desire...) even if it is mounted in read-write mode. The only way of writing to system partition is via recovery mode (if you have already rooted your Legend) which makes a process of updating/testing a pain... you have to reboot your phone into recovery mode each time you want to change something on system partition. So guys at Desire subforum came up with an idea to put a writable overlay over the /system directory. This principle is very well known from live CD distros of Linux and Asus also introduced this on their EEE systems running Linux.

This method can be used not only on system partition (so we can "write" to it) but also on data partition which brings us really a neat way of point-in-time backup. Basically one could make overlay of an entire system just after the system was installed and set-up (with all software and custom settings). Then when anything goes wrong after this point, all one has to do is to wipe the directory/partition where writes were being made - no need to factory reset (wiping data partition), setting things up and installing all the apps all over again. This method can well be a better alternative of nandroid backup, because restoring from nandroid backup wipes out all partitions and restore data to them from images. And we all know that frequent repetition of this process really deteriorates non-removable NAND flash chips in our phones.


Contents:

  • shell script that does the actual /system overlay
  • statically compiled mount (for compatibility reasons)
  • auplink utility for flushing pseudo-links to writable device (not used atm)

Shell script that does the overlay is made so it can use any (first) ext2/3 partition on your sdcard. That means you can use your a2sd partition for overlay too. If a2sd is not active but you still have ext2/3 partition on your sdcard, it will be mounted and used for overlay. If you don't have ext2/3 partition on your sdcard, then internal data partition will be used instead. In this case you will have to be careful not to fill it up entirely.


Requirements:

  • rooted Legend of course ;)
  • any kernel with built-in aufs support
  • busybox
  • run-parts integrated in init.rc script (/etc/init.d)
  • a2sd script should run before the overlay script (only if you use a2sd)

(When I mention a2sd in this post I mean any a2sd; a2sd, a2sd+, apps2sd, DarkTremor, LightSabre, GoldenThrone :D)


Installation

Boot to recovery mode (ClockworkMod) and apply this update. After applying it (re)boot your phone. At this point overlay is not yet enabled. You have to issue:

Code:
adb shell aufs --enable
...to enable it and reboot your phone afterwards for changes to take effect.


Configuration

If you want to enable/disable overlay later on, issue:

Code:
adb shell aufs --disable
...to disable overlay or:

Code:
adb shell aufs --enable
...to enable overlay again. Reboot your phone for changes to take effect.

Be advised that after wiping (Factory data reset) overlay is disabled so you will have to enable it again.


Troubleshooting

Make logcat of boot process and check for errors in 1st 50 or so lines.

Warning!!!

Please, do not even try to flash this "update" if you don't know what you are doing or what things I mentioned above mean!!!
 

Attachments

  • aufs_no_kernel.zip
    189.1 KB · Views: 902
Last edited:

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
Changelog

0.7 (December 16, 2010)
  • compatibility enhancements
  • some minor changes

0.6.1 (December 2, 2010)
  • script is now calling e2fsck or e2fsck_recvy

0.6 (December 1, 2010)
  • dropped auplink binary
  • some more error handling
  • changed installation script

0.5.1 (October 4, 2010)
  • minor change in installation script

0.5 (October 4, 2010)
  • added enable/disable ability (dumfaq was here also)
  • improved error handling

0.4 (September 30, 2010)
  • updated aufs script to check if aufs support is already on
  • added statically compiled mount to support mount-move on any ROM

0.3 (September 28, 2010)
  • updated aufs script to check presence of /data/local/dosysoverlay file (to enable/disable)

0.2 (September 20, 2010)
  • updated aufs script to check availability of ext partition on SD card (thanks to dumfaq)

0.1 (September 3, 2010)
  • initial release
 
Last edited:
  • Like
Reactions: kasra_Qeshm

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
Hey Neon, this would certainly overwrite your OC kernel.

But you can always build your own with aufs support and use my overlay script (maybe you'll find some glitch in it ;)).

I would just ask you to consider putting init.d into /data/local (making symlink in /system/etc). That would ease up adding/removing/chmoding scripts inthere. I think this approach is very handy.

I have put together a little script that would look for init.d link or directory in /system/etc (or directory in /data/local) and then decide to make /data/local/init.d directory or not.

This sounds very good... But please enlighten me...

Will this only work on stock/modified stock roms.. or will this work on CM6 roms also? (Azure 1.0 etc.)

It would work on CM6 too, but you would have to copy WiFi module from stock ROM, because I didn't include it in this update. But bare in mind that CM6 is based on kernel 2.6.32 and above and we are talking 2.6.29 here!
 
Last edited:

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
Ahh one more thing. CM6 kernel should already contain AUFS support (if I'm not mistaken) so you could use just my overlay loading script and auplink binary.
 

Learners Lisence

Senior Member
Jun 28, 2010
187
4
Blayo, an alternative way for nandroid backup sounds really interesting. if included in the rom along with a few further instructions Im sure it could be brought down to the level of no-obs. Ill wait till puppy is 100% tested ;)
 
Blayo, an alternative way for nandroid backup sounds really interesting. if included in the rom along with a few further instructions Im sure it could be brought down to the level of no-obs. Ill wait till puppy is 100% tested ;)

Oh.. you can't wait.. you are the one who is ment to be doing the testing ;) .. so the rest of us are waiting for your result.

Sent from my Legend using XDA App
 

c1nu5

Member
May 21, 2010
25
2
Ahh one more thing. CM6 kernel should already contain AUFS support (if I'm not mistaken) so you could use just my overlay loading script and auplink binary.

The CM6 port from Ali Baba (Azure 1.0) contains a 2.6.29 kernel and no AUFS module... So it should work with your zip. Great work BlaY0!!!
 

Briix

Senior Member
Jul 1, 2009
108
3
Just to be sure.
This should work with Azure 1.0, right? What was that thing about the wifi?
 

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
So...basically, this will helps installing Ad-free and OpenVPN on our Legend, right?
I'm not sure what you mean... but it will certainly help you adding/removing stuff to/from /system on-the-fly...

Just to be sure.
This should work with Azure 1.0, right? What was that thing about the wifi?
It's for 2.6.29 kernel (check the thread title!) and you have to provide your own WiFi driver, because it is not included in this update. Be advised that modules/drivers versions and kernel versions can not mix most of the times. You also can not use just aufs module from this update with any non-aufs kernel (even if versions match), it just won't work.
 

dumfuq

Retired Recognized Developer
May 23, 2009
542
42
well, I got this working on my slide (I have no ext partition) however, I had to make some changes...

Code:
7,8c7,8
< RODIR=/data/sysro
< COUNT=0
---
> RODIR=/system
> COUNT=2
16c16
<  while [ ! -e /dev/block/mmcblk0p1 ]; do
---
>  while [ ! -e /dev/block/mmcblk0p$COUNT ]; do
48,49d47
< insmod /system/lib/modules/aufs.ko
< mount --move /system $RODIR
Without changing the while loop, it always detected an ext partition even though none existed.

Haven't tested it with an ext partition though.

Obviously I used my own kernel and modules.


Thanks alot.
 

james194zt

Senior Member
Nov 1, 2007
69
9
Tested on CM6.0 (Azure latest) and the ROM still works perfectly including my WiFI. I have not tested the overlay functions itself just that it did not screw up CM6.0 which it didn't!

Will let you know the results of the AUFS side of things once I have finished playing!
 

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
well, I got this working on my slide (I have no ext partition) however, I had to make some changes...

Code:
7,8c7,8
< RODIR=/data/sysro
< COUNT=0
---
> RODIR=/system
> COUNT=2
16c16
<  while [ ! -e /dev/block/mmcblk0p1 ]; do
---
>  while [ ! -e /dev/block/mmcblk0p$COUNT ]; do
48,49d47
< insmod /system/lib/modules/aufs.ko
< mount --move /system $RODIR
Without changing the while loop, it always detected an ext partition even though none existed.

Haven't tested it with an ext partition though.

Obviously I used my own kernel and modules.

Hi m8,

Thanks for the input but I think that you are missing the point why this while loop is there ;)

...it is there just to check when SD card is ready to be used. The thing is that it depends of what speed is your SD card. If you have a class 6 for example, it can be available in less than a second, but if you have stock SD card or slower one, it is available only after 2 or even 3 seconds.

But you were right about the script not doing overlay if there's SD card present and no ext partition on it so I changed it a little. here's the patch:
Code:
--- 70aufs.old	2010-09-20 10:29:49.000000000 +0200
+++ 70aufs	2010-09-20 10:28:57.000000000 +0200
@@ -26,13 +26,20 @@
  done
  if [ -z "$NOSD" ]; then
   DEV=`fdisk -l /dev/block/mmcblk0|grep Linux|head -n1|awk '{print $1}'`
-  SD=/data/sd
-  RWDIR=${SD}/sysrw
-  [ -d "$SD" ] || mkdir $SD
-  e2fsck -y $DEV
-  mount -t auto -o noatime,nodiratime $DEV $SD
-  chown 1000.1000 $SD
-  chmod 775 $SD
+  if [ -n "$DEV" ]; then
+   SD=/data/sd
+   RWDIR=${SD}/sysrw
+   [ -d "$SD" ] || mkdir $SD
+   e2fsck -y $DEV
+   mount -t auto -o noatime,nodiratime $DEV $SD
+   chown 1000.1000 $SD
+   chmod 775 $SD
+  else
+   mkdir /dev/shm
+   mount -t tmpfs -o size=4m shm /dev/shm
+   RWDIR=/data/sysrw
+   MTOPTS="xino=/dev/shm/.aufs.xino,dirs=${RWDIR}:${RODIR}=ro"
+  fi
  else
   mkdir /dev/shm
   mount -t tmpfs -o size=4m shm /dev/shm
...now it will check the availability of SD card and if it's there it will check for ext partition on it. If one is present it will prepare and mount it, otherwise it will do the overlay on data partition.

Update is also available in 1st post.
 

dumfuq

Retired Recognized Developer
May 23, 2009
542
42
Hi m8,

Thanks for the input but I think that you are missing the point why this while loop is there ;)

...it is there just to check when SD card is ready to be used. The thing is that it depends of what speed is your SD card. If you have a class 6 for example, it can be available in less than a second, but if you have stock SD card or slower one, it is available only after 2 or even 3 seconds.

But you were right about the script not doing overlay if there's SD card present and no ext partition on it so I changed it a little. here's the patch:
Code:
--- 70aufs.old    2010-09-20 10:29:49.000000000 +0200
+++ 70aufs    2010-09-20 10:28:57.000000000 +0200
@@ -26,13 +26,20 @@
  done
  if [ -z "$NOSD" ]; then
   DEV=`fdisk -l /dev/block/mmcblk0|grep Linux|head -n1|awk '{print $1}'`
-  SD=/data/sd
-  RWDIR=${SD}/sysrw
-  [ -d "$SD" ] || mkdir $SD
-  e2fsck -y $DEV
-  mount -t auto -o noatime,nodiratime $DEV $SD
-  chown 1000.1000 $SD
-  chmod 775 $SD
+  if [ -n "$DEV" ]; then
+   SD=/data/sd
+   RWDIR=${SD}/sysrw
+   [ -d "$SD" ] || mkdir $SD
+   e2fsck -y $DEV
+   mount -t auto -o noatime,nodiratime $DEV $SD
+   chown 1000.1000 $SD
+   chmod 775 $SD
+  else
+   mkdir /dev/shm
+   mount -t tmpfs -o size=4m shm /dev/shm
+   RWDIR=/data/sysrw
+   MTOPTS="xino=/dev/shm/.aufs.xino,dirs=${RWDIR}:${RODIR}=ro"
+  fi
  else
   mkdir /dev/shm
   mount -t tmpfs -o size=4m shm /dev/shm
...now it will check the availability of SD card and if it's there it will check for ext partition on it. If one is present it will prepare and mount it, otherwise it will do the overlay on data partition.

Update is also available in 1st post.


sweet thanks man. I'll give it a go tomorrow.
 

dumfuq

Retired Recognized Developer
May 23, 2009
542
42
Hi m8,

Thanks for the input but I think that you are missing the point why this while loop is there ;)

...it is there just to check when SD card is ready to be used. The thing is that it depends of what speed is your SD card. If you have a class 6 for example, it can be available in less than a second, but if you have stock SD card or slower one, it is available only after 2 or even 3 seconds.

But you were right about the script not doing overlay if there's SD card present and no ext partition on it so I changed it a little. here's the patch:

...now it will check the availability of SD card and if it's there it will check for ext partition on it. If one is present it will prepare and mount it, otherwise it will do the overlay on data partition.

Update is also available in 1st post.


Works great for non ext now, thanks. I still have to set sysro to /system and take out the mount --move or it breaks though.

What's the logic/purpose of moving the sysro anyways, I noticed they are not doing that in the desire version. Just curious.

Thanks again
 

BlaY0

Retired Recognized Developer
Sep 15, 2007
1,553
566
Medvode
The purpose of mount moving /system to some place else is that you have only one instance of "/system" in /proc/mounts eventually. If you just do the overlay over /system, you have two instances of "/system" in /proc/mounts and that causes some root apps to panic because they chose the first instance (to remount it read-write) which we don't actually want.

But as soon as you mount move /system to some place else you also loose everything that's in it (bin, xbin, lib). And since you are on CM6 (i believe), your busybox is compiled dinamically thus it depends first on /system/bin/linker and then on libraries in /system/lib. You can catch those lib deps with LD_LIBRARY_PATH variable but the problem is still /system/bin/linker absolute path which is compiled into your busybox and all other native binaries.

There is actually only one solutions to this problem and that is to get statically built busybox, copy it to let say /data/bin and call this busybox from script.

I will add to 1st post that statically built busybox is imperative.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    OK, here we go. Following the model from Desire thread, I made this one for Legend too.


    Backgroud:

    If I sum up some key points from this thread... there is no way of writing to system partition (Legend, Desire...) even if it is mounted in read-write mode. The only way of writing to system partition is via recovery mode (if you have already rooted your Legend) which makes a process of updating/testing a pain... you have to reboot your phone into recovery mode each time you want to change something on system partition. So guys at Desire subforum came up with an idea to put a writable overlay over the /system directory. This principle is very well known from live CD distros of Linux and Asus also introduced this on their EEE systems running Linux.

    This method can be used not only on system partition (so we can "write" to it) but also on data partition which brings us really a neat way of point-in-time backup. Basically one could make overlay of an entire system just after the system was installed and set-up (with all software and custom settings). Then when anything goes wrong after this point, all one has to do is to wipe the directory/partition where writes were being made - no need to factory reset (wiping data partition), setting things up and installing all the apps all over again. This method can well be a better alternative of nandroid backup, because restoring from nandroid backup wipes out all partitions and restore data to them from images. And we all know that frequent repetition of this process really deteriorates non-removable NAND flash chips in our phones.


    Contents:

    • shell script that does the actual /system overlay
    • statically compiled mount (for compatibility reasons)
    • auplink utility for flushing pseudo-links to writable device (not used atm)

    Shell script that does the overlay is made so it can use any (first) ext2/3 partition on your sdcard. That means you can use your a2sd partition for overlay too. If a2sd is not active but you still have ext2/3 partition on your sdcard, it will be mounted and used for overlay. If you don't have ext2/3 partition on your sdcard, then internal data partition will be used instead. In this case you will have to be careful not to fill it up entirely.


    Requirements:

    • rooted Legend of course ;)
    • any kernel with built-in aufs support
    • busybox
    • run-parts integrated in init.rc script (/etc/init.d)
    • a2sd script should run before the overlay script (only if you use a2sd)

    (When I mention a2sd in this post I mean any a2sd; a2sd, a2sd+, apps2sd, DarkTremor, LightSabre, GoldenThrone :D)


    Installation

    Boot to recovery mode (ClockworkMod) and apply this update. After applying it (re)boot your phone. At this point overlay is not yet enabled. You have to issue:

    Code:
    adb shell aufs --enable
    ...to enable it and reboot your phone afterwards for changes to take effect.


    Configuration

    If you want to enable/disable overlay later on, issue:

    Code:
    adb shell aufs --disable
    ...to disable overlay or:

    Code:
    adb shell aufs --enable
    ...to enable overlay again. Reboot your phone for changes to take effect.

    Be advised that after wiping (Factory data reset) overlay is disabled so you will have to enable it again.


    Troubleshooting

    Make logcat of boot process and check for errors in 1st 50 or so lines.

    Warning!!!

    Please, do not even try to flash this "update" if you don't know what you are doing or what things I mentioned above mean!!!
    2
    I'm already back from vacation...

    I made some adjustments to the script... can you help me test it?

    Just flash it over and put back the original 04modules.

    EDIT: Updated script was moved to 1st post.
    1
    Changelog

    0.7 (December 16, 2010)
    • compatibility enhancements
    • some minor changes

    0.6.1 (December 2, 2010)
    • script is now calling e2fsck or e2fsck_recvy

    0.6 (December 1, 2010)
    • dropped auplink binary
    • some more error handling
    • changed installation script

    0.5.1 (October 4, 2010)
    • minor change in installation script

    0.5 (October 4, 2010)
    • added enable/disable ability (dumfaq was here also)
    • improved error handling

    0.4 (September 30, 2010)
    • updated aufs script to check if aufs support is already on
    • added statically compiled mount to support mount-move on any ROM

    0.3 (September 28, 2010)
    • updated aufs script to check presence of /data/local/dosysoverlay file (to enable/disable)

    0.2 (September 20, 2010)
    • updated aufs script to check availability of ext partition on SD card (thanks to dumfaq)

    0.1 (September 3, 2010)
    • initial release
    1
    Hang on for day or two, I have already prepared a new version that should solve this problem.

    Sent from my HTC Legend
    1
    Hang on for day or two, I have already prepared a new version that should solve this problem.

    Sent from my HTC Legend

    Sweet! Will be waiting patiently. Was coming to see if this was in progress already :) Glad to hear that it is.

    Sent from my ROOTED myTouch 3G Slide using the XDA App