[Q] Mounting & Changing Permissions Using Terminal Emulator on Android Phone - Galaxy Y GT-S5360 and Duos 6102 Q&A, Help & Troubl

How to properly MOUNT the system so I can change its permission? (USING TERMINAL EMULATOR)
I know the first command for it (mount) (I dont know what command follows)
Because I need to first mount the system before changing permissions.
How to change permissions for a system app (for example SystemUI.apk)? After doing some changes into my SystemUI.apk, I push it into my system and it has different permissions.
I want to change its permission into rw-r--r

In the emulator:
Code:
$ su
# mount -o remount,rw /system
# chmod 0644 /system/app/SystemUI.apk
or:
Code:
$ su
# cd system/app
# mount -o remount,rw /system
# chmod 0644 SystemUI.apk

- What does the "0" in 0644 stands for?
Can you elaborate how that mount works so I can properly use it.
mount -o (what this for) remount (and this) ,rw (this also) /system(its the directory, the one I understand)

klmiciano said:
- What does the "0" in 0644 stands for?
Can you elaborate how that mount works so I can properly use it.
mount -o (what this for) remount (and this) ,rw (this also) /system(its the directory, the one I understand)
Click to expand...
Click to collapse
Permissions for system files go beyond simply rw-r-r. Since Android is essentially Linux, Linux permissions do exist in Android. Alongside the Owner, Group and Other permissions, of which you set rw, r and r respectively, special permissions which are the Sticky bit, GID and UID exist as well. However, since these special permissions are not required for the functioning of Android, the 0 in 0644 is to disable all three of them.
-o in mount is essentially a flag. Flags are options to obtain different outcomes for each command. For example,
Code:
ls -s
not only lists the files in the current directory, but also lists the files' sizes in kB. I am not sure about -o in this case, however.
Remounting is required as your system is already a mounted filesystem, but as read-only (ro). Hence you have to remount it as read-write (rw), in order to change the properties of its files.

This is some good stuff. I need to learn more.
The last time I use the chmod command. I didn't include the '0'. I've only type
chmod 644 (blahblah)
Btw, Thank you for teaching me this stuff.
More power.:laugh:

NightRaven49 said:
Permissions for system files go beyond simply rw-r-r. Since Android is essentially Linux, Linux permissions do exist in Android. Alongside the Owner, Group and Other permissions, of which you set rw, r and r respectively, special permissions which are the Sticky bit, GID and UID exist as well. However, since these special permissions are not required for the functioning of Android, the 0 in 0644 is to disable all three of them.
-o in mount is essentially a flag. Flags are options to obtain different outcomes for each command. For example,
Code:
ls -s
not only lists the files in the current directory, but also lists the files' sizes in kB. I am not sure about -o in this case, however.
Remounting is required as your system is already a mounted filesystem, but as read-only (ro). Hence you have to remount it as read-write (rw), in order to change the properties of its files.
Click to expand...
Click to collapse
This guide probably helped me as well

Related

Adding blur alarm to Fission ROM

For those of you that felt in love with the Blur Alarm and looking for a way to add it back. I have figured out the missing files beside the apk that goes in the system\app. This has been tested with sucess for Fission ROM v2.0.1.
Adding Blur alarm
system\app\BlurAlarmClock.apk
framework\blur-res.apk
framework\com.motorola.blur.library.utilities.jar
Hope it help.
nice,
I prefer the blur alarm over the normal one.
but here is my problem, the dock is DeskClock.apk, which is also the Clock and the alarms,
when I replace it with the Dock.apk, then the dock won't start up,
did you try to do that?
I'm getting the following exception, and have no clue on how to fix that Oo
Code:
11-04 00:39:22.031 2063 2063 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.motorola.dlauncher/com.motorola.dlauncher.DLauncher}: java.lang.SecurityException: Neither user 10048 nor current process has android.permission.DEVICE_POWER.
braway said:
nice,
I prefer the blur alarm over the normal one.
but here is my problem, the dock is DeskClock.apk, which is also the Clock and the alarms,
when I replace it with the Dock.apk, then the dock won't start up,
did you try to do that?
I'm getting the following exception, and have no clue on how to fix that Oo
Code:
11-04 00:39:22.031 2063 2063 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.motorola.dlauncher/com.motorola.dlauncher.DLauncher}: java.lang.SecurityException: Neither user 10048 nor current process has android.permission.DEVICE_POWER.
Click to expand...
Click to collapse
What ROM are you using? I renamed the original DeskClock.apk to DeskClock.bak since I don't have a docking station. May be it has something to do with the dlauncher. I also deleted the original launcher2 and replaced it with launcherpro.apk.
Fission 2.0.2
I basically did the same with the DeskClock.apk
but added the Dock.apk from the clean verizon rom (which is basically the "stock" droid2), I guess I'm simply missing something
btw, com.motorola.dlauncher is Dock.apk
I guess something is still missing which would set the missing permission oO
got it to work...
if someone cares:
I had to manually modify the /data/system/packages.xml
it should contain something like this:
Code:
<package name="com.motorola.dlauncher" codePath="/system/app/Dock.apk" flags="1" ts="1288859615000" version="8" userId="10057">
<sigs count="1">
<cert index="1" />
</sigs>
</package>
userId and ts are probably different
change the cert index to 0 !
reboot (right after it, for example with adb reboot)
after reboot, check that your change is still in this file (should be)
put your phone into the docking station, and the blur dock should start
yay
lol, this default blur alarm app is awesome and best I have seen. I was so surprised at what it wanted me to do when I first woke up to it , lol
I am not using fission and I am using Rubix 1.6.
I can only find the bluralarm.apk file and I can't find
framework\blur-res.apk
framework\com.motorola.blur.library.utilities.jar
Do i have to nandroid back to a blurry room to pick these up or are they available somewhere else?
Thanks
rkrasny said:
I am not using fission and I am using Rubix 1.6.
I can only find the bluralarm.apk file and I can't find
framework\blur-res.apk
framework\com.motorola.blur.library.utilities.jar
Do i have to nandroid back to a blurry room to pick these up or are they available somewhere else?
Thanks
Click to expand...
Click to collapse
get the vzw clean rom (or so) from droid2files.com (http://droid2files.com/roms/VZW_2.4.5_Clean_ROM.zip)
everything should be in it...
braway said:
get the vzw clean rom (or so) from droid2files.com (http://droid2files.com/roms/VZW_2.4.5_Clean_ROM.zip)
everything should be in it...
Click to expand...
Click to collapse
Perfect; thanks much.
Question?
How do I add this to my phone and make it work? Do I need to use ADB and move it to the phone or what? I really liked the blur alarm a lot and would like to get that back if I can. Thanks for any help in advance.
You just need a method to transfer the files to the phone to the correct spot
ADB or root explorer can move the files
I will show the adb method below, you can substitute the adb shell, mount, cp (copy), chmod (change permissions), and rm (delete) steps with Root Explorer
ADB
Open a command prompt
cd to the directory where you have the files on your computer
Code:
adb push BlurAlarmClock.apk /sdcard/BlurAlarmClock.apk
adb push blur-res.apk /sdcard/BlurAlarmClock.apk
adb push com.motorola.blur.library.utilities.jar /sdcard/com.motorola.blur.library.utilities.jar
Then adb shell to the phone, mount system as r/w, copy the files to the system
Code:
adb shell
su
mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
cp /sdcard/BlurAlarmClock.apk /system/app/BlurAlarmClock.apk
cp /sdcard/blur-res.apk /system/framework/blur-res.apk
cp /sdcard/com.motorola.blur.library.utilities.jar /system/framework/com.motorola.blur.library.utilities.jar
Then set the permissions on these files so they will work
Code:
chmod 644 /system/app/BlurAlarmClock.apk
chmod 644 /system/framework/blur-res.apk
chmod 644 /system/framework/com.motorola.blur.library.utilities.jar
You can then remove the files from the sdcard if you wish
Code:
rm /sdcard/BlurAlarmClock.apk
rm /sdcard/blur-res.apk
rm /sdcard/com.motorola.blur.library.utilities.jar
Now mount the system as read-only again
Code:
sync
mount -o ro,remount -t ext3 /dev/block/mmcblk1p21 /system
As for the Blur dock
Use the same steps above to copy the file and move it to the system
Code:
adb push Dock.apk /sdcard/Dock.apk
adb shell
su
mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
cp /sdcard/Dock.apk /system/app/Dock.apk
chmod 644 /system/app/Dock.apk
sync
mount -o ro,remount -t ext3 /dev/block/mmcblk1p21 /system
rm /sdcard/Dock.apk
Next pull the packages.xml file
Code:
adb pull /data/system/packages.xml
Edit packages.xml as shown in the above post
Then push back
Code:
adb push packages.xml /data/system/packages.xml
When you "install" the blur dock, you might want to remove the standard android dock
Code:
adb shell
su
mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
mv /system/app/DeskClock.apk /system/app/DeskClock.bak
sync
mount -o ro,remount -t ext3 /dev/block/mmcblk1p21 /system
Notice I just used mv (rename/move)
This is just in case I want it back later
You may need to reboot the phone when you are finished for this to work.
I never tried without rebooting so I don't know if they will work otherwise.

need write to /system or something EXEC path

I was the first person I know on the internet to compile nmap for android and this guy ( http://wjholden.com/nmap/ ) took it to the next level got a new phone ( CM6 with OC ) nbow it does not work
* can't write to /system even with rw remount
* if I boot recovery I can' write to /systm but its just a temp fs so failsause ...
* can't ADB shell (read below ) to find out where system is really mounted OR mount the real /system my self ..
* remouted / but anything I add gets wipped on reboot ...
* onlything that works is remount / , copy nmap and then add PATH hackery to EXEC nmap ... on EVERY reboot ...
NOTES BELOW:
Code:
http://forum.xda-developers.com/showthread.php?t=701589&page=4
I think its because /system is protected in CM5+ ? even with remount
command... ?
let me know what I need to copy where in recovery mode to /system to
get yours to run properly :/
you could also have your installer check for this and have notes etc ..
# uname -a
Linux localhost 2.6.29.6-cyanogenmod #1 PREEMPT Fri Sep 17 16:05:39
PDT 2010 arm v6l GNU/Linux
# ls
ls
NMAP FOR ANDROID CROSS COMPILE ARM.html
NMAP.zip
nmap
nmap-4.01-1.spec
nmap-mac-prefixes
nmap-os-fingerprints
nmap-protocols
nmap-rpc
nmap-service-probes
nmap-services
# cp * /system/bin
cp * /system/bin
cp: can't create '/system/bin/NMAP FOR ANDROID CROSS COMPILE ARM.html': Out of m
emory
cp: can't create '/system/bin/NMAP.zip': Out of memory
cp: can't create '/system/bin/nmap': Out of memory
cp: can't create '/system/bin/nmap-4.01-1.spec': Out of memory
cp: can't create '/system/bin/nmap-mac-prefixes': Out of memory
cp: can't create '/system/bin/nmap-os-fingerprints': Out of memory
cp: can't create '/system/bin/nmap-protocols': Out of memory
cp: can't create '/system/bin/nmap-rpc': Out of memory
cp: can't create '/system/bin/nmap-service-probes': Out of memory
cp: can't create '/system/bin/nmap-services': Out of memory
# df /system
df /system
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/block/mtdblock3 245760 240824 4936 98% /system
# mount
mount
...
/dev/block/mtdblock3 on /system type yaffs2 (rw)
Code:
mount -o rw,remount -t yaffs2 /
rm -Rf /nmap
mkdir /nmap
echo 'export PATH=$PATH:/nmap' > path
cd /nmap
wget http://rmccurdy.com/stuff/G1/BINS/NMAP/NMAP.zip
unzip NMAP.zip
chmod 777 /nmap/*
export PATH=$PATH:/nmap
echo run /nmap/path before you start nmap
nmap -vvv 127.0.0.1
rmccurdy.com/nmap.sh (tested on CM6 / mytouch slide )
in normal mode ..
Code:
bash
localhost / # mount -o rw,remount -t yaffs2 /system
mount -o rw,remount -t yaffs2 /system
localhost / # cd /system
cd /system
localhost system # for i in `ls` ;do mkdir $i\\nmap ;done
for i in `ls` ;do mkdir $i\\nmap ;done
mkdir: can't create directory 'app\nmap': Out of memory
mkdir: can't create directory 'bin\nmap': Out of memory
mkdir: can't create directory 'build.prop\nmap': Out of memory
mkdir: can't create directory 'etc\nmap': Out of memory
mkdir: can't create directory 'fonts\nmap': Out of memory
mkdir: can't create directory 'framework\nmap': Out of memory
mkdir: can't create directory 'lib\nmap': Out of memory
mkdir: can't create directory 'lost+found\nmap': Out of memory
mkdir: can't create directory 'media\nmap': Out of memory
mkdir: can't create directory 'usr\nmap': Out of memory
mkdir: can't create directory 'xbin\nmap': Out of memory
in "Android system recovery (2e)" :
( note: /system is also a vfs I think .. I adb push to it and reboot and the file is gone ... )
Code:
C:\Documents and Settings\Administrator\nmap>adb shell
- exec '/system/bin/sh' failed: No such file or directory (2) -
C:\Documents and Settings\Administrator\nmap>
You can't write in /system in normal boot mode as security is on (s-on), remounting rw does you no good.
In recovery you will need to mount /system from clockwork before you can do anything.
I do have Clockwork Recovery 2.5.0.1 but I am not sure how to get to a shell and or find /system mount path as I can't adb shell ( read above ) so I can't remount or mount /system
rmccurdy.com/nmap.sh * this is what I am using for nmap as of now ..
Usage:
bash -x /sdcard/nmap.sh localhost
etc ...
There's an option in clockwork under partitions to allow you to mount the system. I'm not sure why but a lot of people have an issue getting into su with adb when they are in recovery, the constant /system/bin/sh error is annoying. Also, if I remember right, yaffs2 is not what you use to mount the system when using that command. It's mtdblock3 or something like that if I'm thinking along the correct lines here.
Maybe you should try putting it in a zip file as a script and running it that way since you use a different command (and much easier) to mount the system and write to it. Then again, I'm not sure what you're trying to so so I could just be talking out of my a$$
I can't do anything usefull in recovery ... reboot and apply update.zip but I dont how how nor do I really want to make a .zip / script to mount system etc .. do you know a zip I can work from as an example
rmccurdy said:
I can't do anything usefull in recovery ... reboot and apply update.zip but I dont how how nor do I really want to make a .zip / script to mount system etc .. do you know a zip I can work from as an example
Click to expand...
Click to collapse
The slide doesn't have S-Off, most HTC phones have them now...So you have to wait for Alpharev 2.0 to be released.
Ace42 said:
The slide doesn't have S-Off, most HTC phones have them now...So you have to wait for Alpharev 2.0 to be released.
Click to expand...
Click to collapse
Yes, but in recovery we can mount the system and write to it. Phones with s-off can do that while booted normally because the NAND is unlocked and the system is no longer protected.
You can do it one of two ways. This one is easiest if you know linux commands but are unfamiliar with update-script format. Make an update script and put this in there:
Code:
show_progress 0.5 0
run_program PACKAGE:example.sh
show_progress 0.5 10
You don't have to use the show_progress line, it's just for aesthetics.
Make a .sh script, name it whatever you want and put the linux commands you want to execute in the script. For example:
Code:
#!/sbin/sh
#
##############################################
mount /system;
rm -rf /nmap
mkdir /nmap
echo 'export PATH=$PATH:/nmap' > path
cd /nmap
wget http://rmccurdy.com/stuff/G1/BINS/NMAP/NMAP.zip
unzip NMAP.zip
chmod 777 /nmap/*
export PATH=$PATH:/nmap
echo run /nmap/path before you start nmap
nmap -vvv 127.0.0.1
exit 0;
Or what ever you're trying to get done. I'll upload an example file of all this since hands on is always better. Looking at this though, you may want to have the files in the zip (in the directories they will be installed to) because wget probably wont work since the radio is off while in recovery.
interesting thanks ! ... do you have to resign it and all or can you just edit and rezip it ?
rmccurdy said:
interesting thanks ! ... do you have to resign it and all or can you just edit and rezip it ?
Click to expand...
Click to collapse
As long as you're using clockwork you just edit and zip. Might be easier to use an archive explorer to open (without uzipping it) then drag and drop, but do what's easiest for you.

[HOWTO] Loop mount

OK, I spent a couple of hours figuring out how loop mounting works. The problem is that the mount command in both toolbox and busybox supports only one loop device. I modified the toolbox version to allow the specification of a new loop device.
Here is how to make a 500mb loop-mounted ext2 system at /mnt/myloop , with the system being stored in /storage/sdcard/myext2system.img
Step 1. Make sure you have root. Download bettermount*.zip to your PC from here. Copy the "bettermount" file from the zip file to /data/local/ (or some other location). One way of doing that is with:
Code:
adb push bettermount /data/local
on the PC. Or you can mount your device to USB, copy bettermount to storage, and then in a root shell copy it to /data/local. Or if you have RW root, you can install bettermount in /bin or some other convenient location.
Start a shell on the device, either via adb or an on-device terminal (not recommended unless you have an external keyboard). Switch to root:
Code:
su
Then make bettermount executable:
Code:
chmod 755 /data/local/bettermount
The following steps assume you're still in your root shell.
Step 2. Create ext2 file system in a file. (Skip this if you already have one.)
Code:
dd if=/dev/zero of=/storage/sdcard/myext2system.img bs=1M count=500
mke2fs /storage/sdcard/myext2system.img
mke2fs will give you a warning that this isn't a block special device, but just press "y" and "enter".
Step 3. Create a loop device node for the ext2 file system. The problem here is that the OS uses loop device nodes for apps moved to external storage and one for the system squashfs, and it only has enough loop device nodes for those purposes--any loop device nodes in /dev/block are already in use. On the assumption that you aren't going to have more than 253 apps moved to storage, we're going to create a loop device node numbered 255. If you like, you can check that there isn't already one with that number with
Code:
ls /dev/block/loop*
So, let's create the loop device node:
Code:
mknod -m640 /dev/block/loop255 b 7 255
Step 4. Create a mount point:
Code:
mkdir /mnt/myloop
Step 5. Mount myext2filesystem.img:
Code:
/data/local/bettermount -t ext2 -orw,exec,noatime,nodiratime,sync,loop=/dev/block/loop255 /storage/sdcard/myext2system.img /mnt/myloop
Enjoy your new file system at /mnt/myloop !
You will have to repeat Steps 3-5 after every boot, or else you can make a script that runs every time you boot. You could simply put the commands for 3-5 into a Script Manager script set to run on boot, or there may be some better, more unixy way (but I haven't had any luck editing startup scripts).
What to do with your shiny new filesystem? Well, you could move not just apps but also their libraries to external storage (you can also do that by remounting your external storage in exec mode).
arpruss said:
OK, I spent a couple of hours figuring out how loop mounting works. The problem is that the mount command in both toolbox and busybox supports only one loop device. I modified the toolbox version to allow the specification of a new loop device.
Here is how to make a 500mb loop-mounted ext2 system at /mnt/myloop , with the system being stored in /storage/sdcard/myext2system.img
Step 1. Make sure you have root. Download bettermount*.zip to your PC from here. Copy the "bettermount" file from the zip file to /data/local/ (or some other location). One way of doing that is with:
Code:
adb push bettermount /data/local
on the PC. Or you can mount your device to USB, copy bettermount to storage, and then in a root shell copy it to /data/local. Or if you have RW root, you can install bettermount in /bin or some other convenient location.
Start a shell on the device, either via adb or an on-device terminal (not recommended unless you have an external keyboard). Switch to root:
Code:
su
Then make bettermount executable:
Code:
chmod 755 /data/local/bettermount
The following steps assume you're still in your root shell.
Step 2. Create ext2 file system in a file. (Skip this if you already have one.)
Code:
dd if=/dev/zero of=/storage/sdcard/myext2system.img bs=1M count=500
mke2fs /storage/sdcard/myext2system.img
mke2fs will give you a warning that this isn't a block special device, but just press "y" and "enter".
Step 3. Create a loop device node for the ext2 file system. The problem here is that the OS uses loop device nodes for apps moved to external storage and one for the system squashfs, and it only has enough loop device nodes for those purposes--any loop device nodes in /dev/block are already in use. On the assumption that you aren't going to have more than 253 apps moved to storage, we're going to create a loop device node numbered 255. If you like, you can check that there isn't already one with that number with
Code:
ls /dev/block/loop*
So, let's create the loop device node:
Code:
mknod -m640 /dev/block/loop255 b 7 255
Step 4. Create a mount point:
Code:
mkdir /mnt/myloop
Step 5. Mount myext2filesystem.img:
Code:
/data/local/bettermount -t ext2 -orw,exec,noatime,nodiratime,sync,loop=/dev/block/loop255 /storage/sdcard/myext2filesystem.img /mnt/myloop
Enjoy your new file system at /mnt/myloop !
You will have to repeat Steps 3-5 after every boot, or else you can make a script that runs every time you boot. You could simply put the commands for 3-5 into a Script Manager script set to run on boot, or there may be some better, more unixy way (but I haven't had any luck editing startup scripts).
What to do with your shiny new filesystem? Well, you could move not just apps but also their libraries to external storage (you can also do that by remounting your external storage in exec mode).
Click to expand...
Click to collapse
Which version of busybox were you testing with? I haven't had a problem with multiple loop devices...
I've been using the stock busybox: 1.7.2.
Do you use -oloop=/dev/block/loopNN to specify the device?
I just tried 1.16.0 from the Titanium Backup website. No luck. I created /dev/block/loop222. Then:
Code:
# /tmp/busybox mount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
mount: can't setup loop device: No such file or directory
# bettermount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
# (works!)
I also tried just plain -oloop, without the =/dev/block/loop222, and it didn't work.
arpruss said:
I've been using the stock busybox: 1.7.2.
Do you use -oloop=/dev/block/loopNN to specify the device?
I just tried 1.16.0 from the Titanium Backup website. No luck. I created /dev/block/loop222. Then:
Code:
# /tmp/busybox mount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
mount: can't setup loop device: No such file or directory
# bettermount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
# (works!)
I also tried just plain -oloop, without the =/dev/block/loop222, and it didn't work.
Click to expand...
Click to collapse
I can't remember if mount was symlinked to busybox at the time, but I just used the standard "mount -o loop disk1.img /mnt/disk". I may have even been on a custom kernel and had a crosscompiled mount, so good work, this is probably going to be a common problem for people.
The problem with busybox seems to be that it thinks /dev/block/loop0 is free, but it's not. Doing losetup -f returns /dev/block/loop0.
If you could mount the loopdevice in init.rc this would be the easiest way to expand the 300MB /data problem with archos.
Also it might be the best way in CM7 until its stable for the persistent Data between revisions.
fzelle said:
If you could mount the loopdevice in init.rc this would be the easiest way to expand the 300MB /data problem with archos.
Also it might be the best way in CM7 until its stable for the persistent Data between revisions.
Click to expand...
Click to collapse
I have had no luck adding anything to init.rc with the rw root.
Moreover, /storage and /storage/sdcard get mounted quite late in the boot process--late enough that I think one can't just move the /data directory there. I suppose one might be able to mount them earlier in the process, but I haven't been able to figure out how to run anything in an init script. If anybody knows how to do it, please speak up!
What one could do, however, is mount the loop from an app's on-boot notification, and then symlink individual app files.
It looks like with a better busybox than the one included with the device, one can also use losetup to specify the loop device--see here.
I built a full 1.18.5 version of Busybox, and it does loop mounting just right. You can replace Step 1 of my HOWTO with fetching my modified busybox and putting it in /data/local, from http://code.google.com/p/busybox-for-android/downloads/list
Then step 3 is not needed.
Step 4 should be replaceable with the very simple:
Code:
/data/local/busybox mount -orw,exec,noatime,nodiratime,sync,loop /storage/sdcard/myext2system.img /mnt/myloop
Or if you're pressed for time, and want to use default mount options:
Code:
/data/local/busybox mount -oloop /storage/sdcard/myext2system.img /mnt/myloop
But if you want to implement this is inside an app, depending on your license needs, you may want to use the longer method, since busybox is GPL while bettermount is Apache 2.

[HOWTO] Add init.d to stock ROM + a few other goodies

I have been resisting the urge to flash a custom ROM for a bit, but I really miss having init.d support. So I read a few threads for other phones and rolled my own.
Warnings
I borrowed bits and pieces from various places. If you don't know what init.d is, you probably don't want to do this. If you aren't willing to take responsibility for bricking your tablet, don't do this. Seriously, the risk of bricking is very low, but if you aren't comfortable booting into an adb shell from recovery, maybe this is not for you. Strongly suggest a nandroid backup before you get started so if you totally bork things you can just hit rewind.
Note: The latest CWM may prompt you on a reboot that the ROM may overwrite the bootloader and offer to fix it for you. Don't do that. The init.d hack takes over the bootloader install script, but does not change your bootloader! If you accidentally do let it fix things for you, just rebuild the install-bootloader.sh file. The other steps should be fine.
Prerequisites
First, you need root, busybox, and some sort of terminal (either adb, or some terminal you like using on the tablet).
I have found that I like Busybox Installer (from the market; https://play.google.com/store/apps/details?id=com.jrummy.busybox.installer) but for some reason it doesn't create new symlinks unless you click advanced install.
Let's get to it!
In the shell (don't type # or anything after #):
Code:
su # get root
mount -o remount,rw /system # get access to /system (4.04 seems to mount ro as is usual; seems like the original mounted rw)
which run-parts # if you don't see /system/xbin/run-parts you need to install/reinstall busybox; if it is somewhere else, note it
mkdir /system/etc/init.d
Create a file called sysinit -- we are going to put it in /system/bin. You can edit it in place with vi, mount your tablet and edit it on your computer, or create it on the computer and push it via adb. Whatever.
Here's the file (you do need the # and the things after it in the file!):
Code:
#!/system/bin/sh
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
/system/bin/logwrapper /system/xbin/run-parts /system/etc/init.d
Note that if your run-parts is not in /system/xbin (from the which command) then fix the above to reflect your reality.
In the shell, make it executable
Code:
chmod 755 /system/bin/sysinit
Now go in the init.d directory and create some things you want to run at start up. For example:
Code:
cd /system/etc/init.d
echo '#!/system/bin/sh' >99test # note: you do need the first # in this line but not the 2nd!
echo 'date >>/data/tmp/init.d-log.txt' >>99test
chmod 755 99test
Here's a more practical one (yes, you need the # signs). Name it something like 10diskperf -- don't forget to chmod it.
Code:
#!/system/bin/sh
# Set disk read aheads to 1024
chmod 777 /sys/block/mmcblk0/queue/read_ahead_kb
echo "1024" > /sys/block/mmcblk0/queue/read_ahead_kb
chmod 777 /sys/block/mmcblk1/queue/read_ahead_kb
echo "1024" > /sys/block/mmcblk1/queue/read_ahead_kb
chmod 777 /sys/devices/virtual/bdi/179:0/read_ahead_kb
echo "1024" > /sys/devices/virtual/bdi/179:0/read_ahead_kb
Or here is one to tweak some TCP parameters (25sysctl):
Code:
#!/system/bin/sh
sysctl -w net.core.rmem_max=524288
sysctl -w net.core.wmem_max=524288
sysctl -w net.ipv4.tcp_rmem=6144 87380 524288
sysctl -w net.ipv4.tcp_wmem=6144 87380 524288
Whatever files you put in, you need to remember to make them executable (chmod 755).
Finally, you need to kick it all off at start up. The hack for that is we are going to create /system/etc/install-recovery.sh which apparently runs on each boot.
Code:
cd /system/etc
echo '#!/system/bin/sh' >install-recovery.sh
echo '/system/bin/sysinit' >>install-recovery.sh
chmod 755 install-recovery.sh
Tips and troubleshooting
If you are too lazy to cut and paste I have the files here (View attachment init.d-support.zip) that you can just move to the right places and change permission. If you are really lazy there is lightly tested install script below.
I like to try running the whole thing before a reboot to see if I get any errors:
Code:
/system/etc/install-recovery.sh
I'd suggest putting the 99test file in first. Verify that you get the expected file in /data/tmp and then reboot and check again. Then you can remove 99test.
Same goes for adding new scripts. Try running them from the shell to see if they throw errors before you reboot!
If you have trouble, see if this looks right:
Code:
ls -ld /system/etc/install-recovery.sh /system/bin/sysinit /system/etc/init.d /system/xbin/run-parts
-rwxr-xr-x root root 39 2012-07-14 10:00 install-recovery.sh
-rwxr-xr-x root root 140 2012-07-14 10:01 sysinit
drwxrwxrwx root root 2012-07-14 10:10 init.d
lrwxrwxrwx root root 2012-07-14 09:55 run-parts -> /system/xbin/busybox
For the brave
The install-init.d zip file (View attachment install-init.d.zip) contains a lightly tested script that SHOULD do the install steps for you.
Send the file to your android to someplace that can execute code (e.g., /system/xbin; I had to use adb to put it on the sdcard and then move it to /systemxbin in the shell since I don't have the adb root kernel installed).
Code:
cd /system/xbin # or wherever you have it
chmod 755 install-init.d
./install-init.d
It performs rude checks to see if init.d exists, and tries to handle moving or missing busybox. It only installs 99test as a script.
Let me know if this works or doesn't work for you.
For the extra brave: There is no reason this should only work on the Samsung. This ought to work on pretty much most stock ROMs as long as they execute install-recovery.sh on start up.
Scripts
What do you put in your init.d? If you post anything cool I'll put it up here in the op.
One that gave me some real gains in I/O performance required a new version of the tune2fs executable. By default, it is part of busybox but the busybox one only has a few simple options. I've included a stand alone version and the script 10disktune here View attachment disktune.zip. Unpack the zip and put the 10disktune in /system/etc/init.d (don't forget to chmod) and put tune2fs in /system/bin (chmod that too). Note that busybox has one in /system/xbin but the script specifically calls out the one in /system/bin.
Here's one that will zipalign your apks on each boot
Code:
#!/system/bin/sh
for apk in /data/app/*.apk ; do
zipalign -c 4 $apk
ZCHECK=$?
if [ $ZCHECK -eq 1 ]; then
zipalign -f 4 $apk /cache/$(basename $apk)
if [ -e /cache/$(basename $apk) ]; then
cp -p -f /cache/$(basename $apk) $apk
rm /cache/$(basename $apk)
fi;
fi;
done;
Fin
Corrections welcome. I considered using exec or . to load some of this into one shell but given that it runs once at startup, I figured it is fine as is.
All files for reference
View attachment init.d-support.zip
View attachment install-init.d.zip
View attachment disktune.zip
Great guide, gonna try it tonight.
Sent from a GNote, hell yeah!
SirRhor said:
Great guide, gonna try it tonight.
Sent from a GNote, hell yeah!
Click to expand...
Click to collapse
I'm curious how it went. If you ran into any issues, let me know so I can update the op. Thanks!
Hmm did anyone get this to work?
wd5gnr said:
Hmm did anyone get this to work?
Click to expand...
Click to collapse
I did it on my Galaxy Nexus.
It works great, I had a bit of problem with the sysinit file, but when I downloaded your zip file and used your sysinit, it worked, so it must be a problem from my side
Thanks for this, I can finally use "Odex Me"
aavan said:
I did it on my Galaxy Nexus.
It works great, I had a bit of problem with the sysinit file, but when I downloaded your zip file and used your sysinit, it worked, so it must be a problem from my side
Thanks for this, I can finally use "Odex Me"
Click to expand...
Click to collapse
Great, just wanted to be sure I hadn't made any typos/errors in the guide.
A lot of init.d files collected here: http://forum.xda-developers.com/showthread.php?t=1227269
Also build.prop things, etc.
Thanks, I use your guide and worksperfect for my RK3066 devices. Very simple to understand all steps and what we are doing to our system, perfect for me. Thanks again dude
Melch1zedeK said:
Thanks, I use your guide and worksperfect for my RK3066 devices. Very simple to understand all steps and what we are doing to our system, perfect for me. Thanks again dude
Click to expand...
Click to collapse
Glad to help!
What is thhe utility of this?
moliverac8 said:
What is thhe utility of this?
Click to expand...
Click to collapse
Init.d is how Linux and many Android (which is kind of Linux, after all) systems manage executing commands on boot up.
The /etc/init.d files run in numerical order as root and you can do things like change system settings, manipulate the file system, etc.
See the init.d section linked below for some ideas.
http://forum.xda-developers.com/showthread.php?t=1227269
Question? what is the difference in this method and running a script?
wd5gnr said:
Init.d is how Linux and many Android (which is kind of Linux, after all) systems manage executing commands on boot up.
The /etc/init.d files run in numerical order as root and you can do things like change system settings, manipulate the file system, etc.
See the init.d section linked below for some ideas.
http://forum.xda-developers.com/showthread.php?t=1227269
Click to expand...
Click to collapse
I use the "swap memory script" and was wondering if it would also work this way with the init.d If so would there be any benefit this way over the current way of running it one way or the other? One drawback I see running the script as is is that I have to wait once the system has fully booted until the script has run and I see the Smanager screen to let me know that my memory has been remounted.
Thanks for the info and the learning process.
Here is the script and the link.
http://forum.xda-developers.com/showthread.php?t=1961097
Code:
sleep 5
mount -o remount,rw /
mount -t vfat -o umask=0000 /dev/block/vold/179:25 /mnt/sdcard
sleep 5
mount -o bind /data/media /mnt/extSdCard
As long as the device is ready to mount at boot time and doesn't get remounted, ought to work. Backup and try it
External memory wasn't ready
wd5gnr said:
As long as the device is ready to mount at boot time and doesn't get remounted, ought to work. Backup and try it
Click to expand...
Click to collapse
Thanks for the guide, but I think that the external memory was not ready to be mounted at that time. it didn't see the card till after boot. It was worth a shot, Reverted back to the script in /data and all worked again,
Note: I didn't find /system/xbin/run-parts however, I did find /system/bin/run-parts and changed the path to reflect that, I don't think this was an issue but I'm not 100% sure.

Unable to mount System as rw in 7.1.1 DP

I am trying to create an overlay folder under /system/vendor so that I can throw a layers apk there to hide the nav bar. I am currently using the build.prop method which doesn't work nicely with the Now on Tap action of Swipe Navigation which is what I am ultimately trying to fix.
I tried using Solid Explorer to simply create the new directory like I did previously in 7.0 and 6.x but was unable to do so (action failed). I decided to try using the terminal and create the folder and move files from there but got the message that the system was read-only. I then attempted to mount system a few different ways all of which failed. I did use su before entering these commands.
Code:
angler:/system/vendor $ mkdir overlay
mkdir: 'overlay': Read-only file system
angler:/system/vendor $ mount -o rw,remount,rw /system
mount: '/dev/block/platform/soc.0/f9824900.sdhci/by-name/system' not user mountable in fstab
angler:/system/vendor $ /system/bin/mount -o rw,remount,rw /system /system
mount: '/system' not in /proc/mounts
angler:/system/vendor $ /system/bin/mount /system
mount: bad /etc/fstab: No such file or directory
Googling around didn't yield much in the way of solutions other than these different methods of mounting system. Am I just unable to mount system as rw in 7.1.1 currently, and if so, is there another way to accomplish what I want?
I'm trying to find thread I read this from, so if I find it I'll post link to it. When I was on early 7 previews that was set up with systemless root I went into twrp and then went to terminal and typed the following, touch su. When your in terminal cd to both bin and xbin and type command "touch su" without quotes. Then reboot and you should be able to use something like es file explorer to get into and write in /system. Hope that helps.
Found it, look to post = 15
http://forum.xda-developers.com/nexus-6p/help/es-file-explorer-doesnt-understand-t3242775
Unfortunately that did not end up working for me, thanks for looking up the link for me though!
On Nougat the rw mount command should be typed like this:
mount -o rw,remount /system
then for touch:
touch sbin/su
Thank you blitz for clarifying.
Hmm... it seems like the mount worked but the touch did not. I ended up using just "touch su" but ran into a different error with mkdir. I think I may just be out of luck for now. Thank you both for your help!
Code:
~ # mount -o rw,remount /system
~ # cd /system/bin
/system/bin # touch sbin/su
touch: sbin/su: No such file or directory
/system/bin # touch su
/system/bin # cd /system/xbin
/system/xbin # touch su
/system/xbin # cd /system/vendor
/vendor # mkdir overlay
mkdir: cannot create directory 'overlay': No space left on device
AbuShabanov said:
Hmm... it seems like the mount worked but the touch did not. I ended up using just "touch su" but ran into a different error with mkdir. I think I may just be out of luck for now. Thank you both for your help!
Code:
~ # mount -o rw,remount /system
~ # cd /system/bin
/system/bin # touch sbin/su
touch: sbin/su: No such file or directory
/system/bin # touch su
/system/bin # cd /system/xbin
/system/xbin # touch su
/system/xbin # cd /system/vendor
/vendor # mkdir overlay
mkdir: cannot create directory 'overlay': No space left on device
Click to expand...
Click to collapse
I'm not sure what you're trying to accomplish but still:
The touch sbin/su means creating an empty file called su in the sbin subdirectory under the current directory. So if there is no subdir named sbin under /system/bin, then it's not going to work
Secondly, you should know about the ls command: ls -la lists the files in the current directory, and remember than in unix and linux terminology, a directory is also a file so you'll also see directories (including current "." and parent "..")
Third, you should know about the df command which shows filesystem disk space usage. df -h will show you how much free space you have an all of your filesystems, including system.
Last, with great power comes great responsibilities. Running the wrong command as root will easily make your system unusable.
I have substratum installed and inside /system/vendor there is a link (again a file) called overlay which links to directory /system/overlay where apks are.
rchtk said:
I'm not sure what you're trying to accomplish
Click to expand...
Click to collapse
I am trying to create an overlay folder under /system/vendor so that I can throw a layers apk there to hide the nav bar.
rchtk said:
I have substratum installed and inside /system/vendor there is a link (again a file) called overlay which links to directory /system/overlay where apks are.
Click to expand...
Click to collapse
Are you on the 7.1.1 (NPF10C)? If so it sounds like you have accomplished what I am trying to do. I'm only familiar with the basic unix commands as I haven't actively used it in about 5 years. Would you mind sharing how to create the link to /system/overlay from /system/vendor, or does Substratum take care of that? Offhand it sounds like a symbolic link but my terminology is pretty rusty.
AbuShabanov said:
I am trying to create an overlay folder under /system/vendor so that I can throw a layers apk there to hide the nav bar.
Are you on the 7.1.1 (NPF10C)? If so it sounds like you have accomplished what I am trying to do. I'm only familiar with the basic unix commands as I haven't actively used it in about 5 years. Would you mind sharing how to create the link to /system/overlay from /system/vendor, or does Substratum take care of that? Offhand it sounds like a symbolic link but my terminology is pretty rusty.
Click to expand...
Click to collapse
Yes 7.1.1.
Substratum created the overlay directory and the link to it.
Manually that would be:
mount -o rw,remount -t auto /vendor
mount -o rw,remount -t auto /system
mkdir /system/overlay
cd /system/vendor
ln -s /system/overlay
mount -o ro,remount -t auto /vendor
mount -o ro,remount -t auto /system
But links do take a very small amount of bytes (roughly name and target) so for that, you'll need some space in your vendor partition (no space left on /vendor). check with "df".
I have 3.8MB free (that's an original vendor + overlay link)
rchtk said:
mount -o rw,remount -t auto /vendor
mount -o rw,remount -t auto /system
mkdir /system/overlay
cd /system/vendor
ln -s /system/overlay
mount -o ro,remount -t auto /vendor
mount -o ro,remount -t auto /system
Click to expand...
Click to collapse
Well, this works and I was able to mount system and vendor, create the link, move the apk file, etc but it appears that the apk itself is not working on NPF10C. Thank you for your help and the refresher on the unix commands!

Categories

Resources