[mod][6T] init.d / services.d framework using Magisk [linux] - OnePlus 6T ROMs, Kernels, Recoveries, & Other Dev

This thread will allow you to set up init.d (and services.d) scripts on your phone so they can run at boot time.
Prerequisites
- understanding of what "init.d" scripts mean ...
- your phone must be rooted (see https://www.xda-developers.com/oneplus-6t-unlock-bootloader-root/)
- you must have a working Magisk (see https://forum.xda-developers.com/apps/magisk)
- linux knowledge (I am not a Windows guy but instructions below should easily apply to Windows / PowerShell)
- adb knowledge
If this scares you, stop reading and go play with something else.
Attached zip file contains
- a magisk.img file
- a directory with init.d scripts
- a directory with services.d scripts
You can use the scripts provided or not use (some) of them, or write your own.
What's the difference between init.d and services.d scripts?
The idea is to have 2 directories on your phone with scripts:
Code:
/system/etc/init.d/
/system/etc/services.d/
The init.d scripts are run early in the boot (when Magisk initializes). The scripts in /system/etc/services.d/ will run a bit "later", to be precise: when sys.boot_completed = true.
Important warrning: even when sys.boot_completed = true, this does NOT guarantee that /sdcard is mounted. Your script can "sleep" until /sdcard is mounted if it relies on things on /sdcard. See for example the code in /system/etc/services.d/LS99maxvolumewarning which will show how you can do that.
Scripts in init.d should NOT rely on any of the file systems being mounted !
The framework will run all scripts in parallel. So be careful that you do not write scripts which depend on eachother!
The framework will run all scripts as background processes so that they do not hinder the normal boot of your phone.
Prepare the basic setup
To use the scripts (or your own), you must first create the directories init.d and services.d; to do that open a linux shell and do:
Code:
> adb shell
$ su
# mount -o rw,remount /system
# mkdir /system/etc/init.d/
# mkdir /system/etc/services.d/
# chown 0.0 /system/etc/init.d
# chown 0.0 /system/etc/services.d
# chmod 755 /system/etc/init.d
# chmod 755 /system/etc/services.d
# sync; exit
Putting the scripts on your phone
Download the attached zip file (initd.zip); create a directory in your linux file system and unzip, e.g.
Code:
> mkdir mydir
> cd mydir
> unzip ~/initd.zip
> adb push init.d/ /sdcard/
> adb push services.d/ /sdcard/
> adb shell
$ su
# mount -o rw,remount /system
# mv /sdcard/LS00* /system/etc/init.d/
# mv /sdcard/LS99* /system/etc/services.d/
# chown 0.0 /system/etc/init.d/*
# chown 0.0 /system/etc/services.d/*
# chmod 755 /system/etc/init.d/*
# chmod 755 /system/etc/services.d/*
# sync
# exit
$ exit
Installing the magisk image on your phone
First important remark: I need to turn this really into a proper magisk "module" but I need to study that first. Open a linux shell and do:
Code:
> cd mydir
> gunzip magisk.img.gz
> adb push magisk.img /sdcard/
> adb shell
$ su
# cd /data/adb
# mv magisk.img magisk.img.orig
# cp /sdcard/magisk.img .
# chown 0.0 magisk.img
# chmod 644 magisk.img
# sync
# exit
$ exit
That's all !!! If you now reboot your phone your init.d and services.d scripts will run.
How can I tell this is working?
Each script has a log file in /data/; whose name is LS00 (for init.d) or LS99 (for services.d) appended with the name of the script. That log file is passed as "$1" into the script and the script code can write to this log file using:
Code:
LOGFILE=$1
echo "Hi I am writing to the log" | tee -a $LOGFILE
To check that the log files are there, open a linux shell and do:
Code:
> adb shell
$ su
# ls /data/LS*
And you should see something like:
Code:
16 /data/LS00blockdev 4 /data/LS99bootclean 4 /data/LS99maxvolumewarning 4 /data/LS99sysctl
4 /data/LS00governors 4 /data/LS99callrecording 4 /data/LS99network 4 /data/LS99trimcaches
4 /data/LS00kerneltweaks 4 /data/LS99cputweaks 4 /data/LS99overlays 4 /data/LS99turnoffnightmode
4 /data/LS00procgate 4 /data/LS99enablecallrecording 4 /data/LS99remounts 4 /data/LS99workqueue
4 /data/LS00readahead 4 /data/LS99hdparm 4 /data/LS99resetprop
4 /data/LS00resetprop 4 /data/LS99magiskhide 4 /data/LS99sqlite
To check the contents of the log files, do:
Code:
> adb shell
$ su
# cat /data/LS*
And you will see logging info:
Code:
>> Starting /system/etc/init.d/LS00procgate at 19700110-17:21:12
-- remounting: mount -o remount,hidepid=2,gid=3009 /proc
<< Ending /system/etc/init.d/LS00procgate at 19700110-17:21:12
>> Starting /system/etc/services.d/LS99maxvolumewarning at 20181201-07:34:00
-- slept for 4 seconds waiting for /sdcard/Android
-- disabling max volume warning
<< Ending /system/etc/services.d/LS99maxvolumewarning at 20181201-07:33:58
What's next
Write your own scripts (and share them). Note that scripts must be owned by root (chown 0.0) and have 755 linux permissions (chmod) to run.
How does it really work?
No secrets ... magisk.img is actually a magisk module which runs the scripts. To see the inner details, do the following after you have installed the magisk image and rebooted your phone:
Code:
> adb shell
$ su
# ls -l /sbin/.core/img/template/
total 12
0 -rw-r--r-- 1 root root 0 2018-03-12 21:19 auto_mount
4 -rw-r--r-- 1 root root 935 2018-08-06 17:59 post-fs-data.sh
4 -rwxr-xr-x 1 root root 498 2018-08-05 10:11 scriptwrapper*
4 -rw-r--r-- 1 root root 2750 2018-08-11 12:07 service.sh
Magisk will run the post-fs-data.sh first and service.sh later. Check the code of both of these files to understand how init.d and services.d are ran (using run-parts). If you want more details please read: https://topjohnwu.github.io/Magisk/guides.html#scripts.
Disable ALL scripts from running
If you want to disable any script from running do:
Code:
> adb shell
$ su
# touch /data/noinitrd
To undo this and get your scripts running again, do:
Code:
> adb shell
$ su
# rm /data/noinitrd
What do my init.d scripts do?
Code:
LS00blockdev: change properties of block devices (non rotational, no kernel io stats, ...)
LS00governors: set all CPU governers (to schedutil; which is actually the 6T default)
LS00kerneltweaks: a few basic kernel tweaks + stop debug of kernel modules
LS00procgate: protections against the procgate security vulnerability (thanks to @topjohnwu)
LS00readahead: change the readahead amount on logical disk devicesw
LS00resetprop: reset model, brand, manufacturer (only useful if you would want to get your phone appear externally as a Pixel; check the code)
What do my services.d scripts do?
Code:
LS99bootclean: clean junk and log files
LS99cputweaks: improve scaling governor
LS99enablecallrecording: enable call recording (must be done at every device boot)
LS99execonce: a whole series of settings; this is only executed ONCE
LS99hdparm: increase readahead on /system and /data
LS99magiskhide: hide some packages from seeing root
LS99maxvolumewarning: remove the high volume warning (I am not sure this will always work !!!)
LS99network: TCP transmit queue and congestion control
LS99overlays: enable all overlays automatically (if you use substratum then no need to enable them manually)
LS99remounts: improve file system performance of multiple partitions
LS99resetprop: increase memory used by dalvik
LS99sqlite: REINDEX and VACCUM sqlite database files (the script only runs every 3rd day)
LS99sysctl: optimize linux kernel settings and TCP/IP performance
LS99trimcaches: trim android cache files
LS99turnoffnightmode: reset the night mode to OFF (night mode conflicts with dark mode in newer Google apps)
LS99workqueue: tune kernel work queue

Thanks man I have been trying to get boot scripts to run.

jacksummers said:
Thanks man I have been trying to get boot scripts to run.
Click to expand...
Click to collapse

excuse me for the ignorance, but what is the use of this mod?
Sent from my [device_name] using XDA-Developers Legacy app

isoladisegnata said:
excuse me for the ignorance, but what is the use of this mod?
Sent from my [device_name] using XDA-Developers Legacy app
Click to expand...
Click to collapse
At the end of OP he's got a summary of what the different scripts do.

I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?

kirschdog1 said:
I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?
Click to expand...
Click to collapse
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).

Still not working
Base2 said:
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).
Click to expand...
Click to collapse
1|OnePlus6T:/ # cd mydir
OnePlus6T:/mydir # unzip ~/initd.zip
unzip: can't open //initd.zip[.zip]
1|OnePlus6T:/mydir # unzip /mydir/initd.zip
unzip: can't open /mydir/initd.zip[.zip]
Any ideas? How to get this working? I tried both commands to no avail.

kirschdog1 said:
I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?
Click to expand...
Click to collapse
You have to create the directory mydir on your linux machine, not on your phone.

Base2 said:
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).
Click to expand...
Click to collapse
No, not a typo. mydir is on your PC, not on the phone !

foobar66 said:
No, not a typo. mydir is on your PC, not on the phone !
Click to expand...
Click to collapse
How do I create the directory? I'm using a windows device using adb command prompts?

kirschdog1 said:
How do I create the directory? I'm using a windows device using adb command prompts?
Click to expand...
Click to collapse
Search how to create directories in PowerShell ... I am not a Windows guru :crying:

foobar66 said:
Search how to create directories in PowerShell ... I am not a Windows guru :crying:
Click to expand...
Click to collapse
Ok thank you.ill hold off as it appears to be above my pay grade.

foobar66 said:
You have to create the directory mydir on your linux machine, not on your phone.
Click to expand...
Click to collapse
This won't work anymore as magisk doesn't use magisk.img anymore

Related

[MOD] v0.3.1 Working Full Ubuntu for 1.5.7 and 1.8.3 based on Sogarth's script

Sogarth's webtop2sd will be released soon, you really should wait and install that instead of this! Thanks -The Management
No longer breaks on 1.83, thanks to Romracer
Update: This script worked on my phone. Mind you I was installing it from a fresh SBF flash, but it should work on your phone too. Absolutely no guarantees as usual.
Update 11th April 2011, 06:59 PM: Won't be getting CWM package because it'd be huuuuuuuuuge.
Update 28th April 2011. 16:38 PM: Removing BETA tag since there have been no issues with the script for quite some time.
First off I would like to thank Sogarth for making this script in the first place as well as Romracer for fixing it for 1.83. Since he is busy doing more important work I decided to do this little hack for those of us that updated to 1.5.7 and dont feel like flashing back to earlier versions to get full Ubuntu working.
Again, this is only necessary if you're already running 1.5.7 or 1.8.3.
Secondly, I am still working on this script so it may not work for you. If you have a problem you may post in the thread or PM me showing exactly the error message, word for word, that you receive.
Updates will be included in the OP from time to time as I fix errors.
Instructions:
1) install.bat (from your computer)
2) adb shell (get a shell on your phone)
3) su (get root on your phone in that shell)
4) . /data/local/tmp/install.sh (run the install script *on your phone* don't forget the "." and the space after the dot, or you will have to chmod 755 the shell script manually)
5) ?????
6) profit\
Noob instructions, written by Viamonte (I take no credit or responsibility):
Thanks again for all your help. Now the noob instructions:
"1-Download "Terminal Emulator" from the market, on your phone (or any other terminal), and the file anexed in this thread to your computer.
2-Connect the Atrix to the computer via USB, configuring the connection mode to "None" and enabling USB Debugging mode (Settings>Applications>Development>USB debugging)
3-Unzip the file you downloaded on your pc, and run Install.bat. This will push the script to your phone.
4-Go back to your phone and open the emulator you downloaded. Then type "su" (without quotes) and press enter. Then type ". /data/local/tmp/install.sh" (without quotes) and press enter again.
The script should begin running now. It will stop in two moments where you'll be instructed to get a cup of coffee, and may take several minutes to continue form this point. When finished, the Atrix will reboot.
To check if this worked, use the Webtop either on your multimidia dock or your lapdock and verify if new itens appeared on your task bar and on the right upper side of the screen"
0.3.1 release
0.2 release
0.1 first release
Changelog
0.3.1 fix to gconf file's mdate so it does what its supposed to do =)
0.3 Small typo fixes and cpp package install fix by romracer, now works on 1.83 =)
0.2 Fixed some typos in uninstall.sh and make sure the %gconf file wound up in the right spot.
0.1 - first version. NOT CWM install but ready to be packaged for that more or less
Nice, I'll give this a shot later.
Ill give it a shot when I get home!
Sent from Motorola Atrix on TELUS.
My phone is working perfectly, so why not ruin it?
I'm giving this a try right now!
1.4.57 - Rooted and gingerblurred with HDMI Mirroring and Webtop hack.
I'll update as progress goes along:
Edit 1:
Initial try gave me this
Checking device state...
Obtaining temporary root access...pushing shell scripts
A filesystem file already exists. Reset it? [n] y
Mounting the filesystem...
07.sh
--------------------------------------------
EXECUTION FAILED
Unable to mount the filesystem file. ERR 07
--------------------------------------------
Press any key to continue . . .
Edit 2:
Ok, it doesnt work with resetting it. How about removing?
Checking device state...
Obtaining temporary root access...pushing shell scripts
A filesystem file already exists. Reset it? [n] n
A filesystem file already exists. Delete it? [n] y
Deleting the filesystem file...
--------------------------------------
EXECUTION FAILED
Unable to delete the filesystem file.
--------------------------------------
Press any key to continue . . .
Edit 3:
Ok, only one option left then.
Checking device state...
Obtaining temporary root access...pushing shell scripts
A filesystem file already exists. Reset it? [n] n
A filesystem file already exists. Delete it? [n] n
--------------------------------------------------------------------------
EXECUTION FAILED
The filesystem file already exists, but no operations have been selected.
--------------------------------------------------------------------------
Press any key to continue . . .
=====================================================================
Edit 4:
Since execution is failing I'm trying to find the problem. Using ADB Shell i tried to manually run the shell scripts and stumbled here:
(I tried chmod 777 @ 02.sh to see if that was the problem, no change is results)
# ls -l
...
...
-rwsr-sr-x shell shell 87 2011-04-06 12:13 03.sh
-rwxrwxrwx shell shell 82 2011-04-06 12:11 02.sh
-rwsr-sr-x shell shell 251 2011-04-06 12:04 01.sh
# pwd
pwd
/data/tmp/shell
# /data/tmp/shell/02.sh
/data/tmp/shell/02.sh
/data/tmp/shell/02.sh: not found
I had the same issue as flybob when I tried to run the script.
Sent from my MB860 using XDA Premium App
Good effort, but 1.57 changes how we have to run commands as root. On a normal linux box, I'm sure your methods would work fine, but we're not dealing with a normal su binary. You should look into doing this as CWM as opposed to .bat files. I had a hell of a time getting around the restrictions since the psneuter exploit was closed.
Ah, I did not think about that Ririal, thanks for the info. I am not familiar with CWM though.
Why is the /tmp directory in /data ? That would certainly cause every script to fail.
I'll look at this some more tonight.
Ririal said:
Good effort, but 1.57 changes how we have to run commands as root. On a normal linux box, I'm sure your methods would work fine, but we're not dealing with a normal su binary. You should look into doing this as CWM as opposed to .bat files. I had a hell of a time getting around the restrictions since the psneuter exploit was closed.
Click to expand...
Click to collapse
How about a shell script that we can run in terminal emulator ? and the output goes to screen and a log file for debug !
molotof said:
How about a shell script that we can run in terminal emulator ? and the output goes to screen and a log file for debug !
Click to expand...
Click to collapse
most of the script is now run by shell scripts, no reason you couldn't run them in the terminal emulator, just get the order right. There are also a few lines I didn't translate to shell so you'd have to enter them by hand.
In any case I'll keep working on this until Sogarth releases his version with union mounts =D
You might be interested to know this;
# cd /tmp
cd /tmp
# pwd
pwd
/data/tmp
# ls -l /tmp
lrwxrwxrwx root root 2011-04-09 14:47 tmp -> /data/tmp
I'll happily help with the script, i know tons of linux and got my Atrix ready to be bricked
flybob said:
You might be interested to know this;
# cd /tmp
cd /tmp
# pwd
pwd
/data/tmp
# ls -l /tmp
lrwxrwxrwx root root 2011-04-09 14:47 tmp -> /data/tmp
I'll happily help with the script, i know tons of linux and got my Atrix ready to be bricked
Click to expand...
Click to collapse
That's just a symlinked directory. I won't make a difference if you call either.
Yes, just replied to the previous question
Why is the /tmp directory in /data ? That would certainly cause every script to fail.
I'll look at this some more tonight.
Click to expand...
Click to collapse
However, why doesn't the scripts run as wanted...?
# cat /tmp/shell/02.sh
cat /tmp/shell/02.sh
#!/bin/sh
/system/bin/su
/bin/rm /data/ubuntu.disk > /dev/null 2>&1 && echo PASS#
# ls -l /tmp/shell/02.sh
ls -l /tmp/shell/02.sh
-rwxrwxrwx shell shell 82 2011-04-06 12:11 02.sh
# /tmp/shell/02.sh
/tmp/shell/02.sh
/tmp/shell/02.sh: not found
flybob said:
Yes, just replied to the previous question
However, why doesn't the scripts run as wanted...?
# cat /tmp/shell/02.sh
cat /tmp/shell/02.sh
#!/bin/sh
/system/bin/su
/bin/rm /data/ubuntu.disk > /dev/null 2>&1 && echo PASS#
# ls -l /tmp/shell/02.sh
ls -l /tmp/shell/02.sh
-rwxrwxrwx shell shell 82 2011-04-06 12:11 02.sh
# /tmp/shell/02.sh
/tmp/shell/02.sh
/tmp/shell/02.sh: not found
Click to expand...
Click to collapse
Ah ok my mistake, you didn't quote anything I didn't realize that's what you were responding too
Likely noexec flag causing that issue.
Also, you can't invoke su from inside a shell script. It just doesn't work with this su binary.
yeah, I guess not. I hadn't realized that it wasn't a real 'su' before making this... too bad.
If anyone figures out how to get around that we'll be in business Unfortunately that's way beyond my expertise.
Okay, after fiddling a little bit and talking to a friend I may have solved some of the problems, mainly with the scripts executing and su working.
I will have to rewrite a bunch of things but should report back tonight.
the2dcour said:
Okay, after fiddling a little bit and talking to a friend I may have solved some of the problems, mainly with the scripts executing and su working.
I will have to rewrite a bunch of things but should report back tonight.
Click to expand...
Click to collapse
su -c "command"
You'll have to allow superuser on the phone for every single command.
PM'd you my error. I tried manually editing the permissions, but that didn't work.
Running on GladAtrix2 v3
USB debugging on; USB set to none
Checking device state...
Obtaining temporary root access...pushing shell scripts
-------------------------
EXECUTION FAILED
Unable to chmod scripts.
-------------------------
Press any key to continue . . .
Changed /sdcard-ext to /sdcard in script. Got this error
Checking device state...
Obtaining temporary root access...pushing shell scripts
-------------------------
EXECUTION FAILED
Unable to chmod scripts.
-------------------------
* server not running *
Press any key to continue . . .
Running BETA_ubuntu-1.0.6.4.zip. File extracts to BETA_ubuntu-1.0.6.2 directory. Ran ubuntu-1.5.7.bat
Moved BETA_ubuntu-1.0.6.2 to C:\ Same error
The only easy workaround to that I can see at the moment is to
Code:
adb shell
su
chmod 777 /path-to-scripts/*
ls -l /path-to-scripts/*
make sure all the files are executable (should say rwxrwxrwx)
then remove the bit of code from 1.5.7.bat
Code:
set retval=
for /f "tokens=*" %%l in ('%~dps0adb.exe shell "/bin/chmod 6755 /mnt/sdcard-ext/shell/* > /dev/null 2>&1 && echo PASS"') do set retval=%%l
if "%retval%" neq "PASS" set message=Unable to chmod scripts. && goto abort
If anyone can help me fix this problem I should be able to automate the chmod process using ririal's suggestion of su -c. The problem is that there are too many nested quotation marks in this section of the batch file, and I can't for the life of me figure out how to escape quotes so they pass through to adb:
Code:
set retval=
for /f "tokens=*" %%l in ('%~dps0adb.exe shell "/system/bin/su -c [U]'/bin/chmod 6755 /mnt/sdcard-ext/shell/*'[/U] > /dev/null 2>&1 && echo PASS"') do set retval=%%l
if "%retval%" neq "PASS" set message=Unable to chmod scripts. && goto abort
The underlined bit is where I need to escape either single or double quotes.
the2dcour said:
The only easy workaround to that I can see at the moment is to
Code:
adb shell
su
chmod 777 /path-to-scripts/*
ls -l /path-to-scripts/*
make sure all the files are executable (should say rwxrwxrwx)
then remove the bit of code from 1.5.7.bat
Code:
set retval=
for /f "tokens=*" %%l in ('%~dps0adb.exe shell "/bin/chmod 6755 /mnt/sdcard-ext/shell/* > /dev/null 2>&1 && echo PASS"') do set retval=%%l
if "%retval%" neq "PASS" set message=Unable to chmod scripts. && goto abort
If anyone can help me fix this problem I should be able to automate the chmod process using ririal's suggestion of su -c. The problem is that there are too many nested quotation marks in this section of the batch file, and I can't for the life of me figure out how to escape quotes so they pass through to adb:
Code:
set retval=
for /f "tokens=*" %%l in ('%~dps0adb.exe shell "/system/bin/su -c [U]'/bin/chmod 6755 /mnt/sdcard-ext/shell/*'[/U] > /dev/null 2>&1 && echo PASS"') do set retval=%%l
if "%retval%" neq "PASS" set message=Unable to chmod scripts. && goto abort
The underlined bit is where I need to escape either single or double quotes.
Click to expand...
Click to collapse
^ escapes batch, \ escapes shell. Hope this helps. If you zip up and send me the whole process in a single .sh file I can wrap it up in CWM for you.

How to install ubuntu on the Droid 4

How to install ubuntu on the Droid 4
Note to mods: this thread is a branch off of this thread
Huge thanks to zacthespack for creating the ubuntu installer app and original boot script and to zeroktal for modifying the script to work on the D4 and helping me get it working on my device.
I decided to take my experience in setting this up and put it into a how-to so that others could enjoy the experience of having ubuntu on the Droid 4. If zackthespac or zeroktal have any problems with me making and putting this guide up, please let me know and I will remove it.
Knowledge Required:
working knowledge of command line
working knowledge of vi
OR the ability to learn how to use both
Tools Required:
A rooted Motorola Droid 4
BusyBox (Android Market)
Terminal Emulator (Android Market)
Android VNC Viewer (Android Market)
Ubuntu Installer App (Android Market)
zeroktal's ubuntud4.zip file (attached to this post and mediafire)
Vi Cheat Sheet (lagmonster.org)
Step by Step:
Install BusyBox, Terminal, and Android VNC Viewer
Install and run Ubunutu Installer App
Follow the on-screen instructions and click next
Download either the Small or Large image to your phone, (use zeroktal's ubuntud4.zip file instead of the boot script provided in the guide) after the image downloads (will take a while because the file is HUGE) click next
For this screen, the instructions differ from the app.
1. With your D4 plugged into your PC in USB Mass Storage, create a directory (folder) called ubuntu in the EXTERNAL sdcard's root*
2. Extract the image you downloaded to that directory
3. Download and extract the attached .sh (ununtud4.zip) to that directory
4. Disconnect your phone from your PC
5. Open terminal and run the following commands:
su [ENTER]
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext [ENTER]
cd /mnt/sdcard-ext/ubuntu [ENTER]
sh ubuntud4.sh [ENTER]
960x540 [ENTER]**​If you get an error message: ubuntud4.sh: 45: syntax error: end of file unexpected (expecting "then") see troubleshooting section below.​killall -TERM Xtightvnc [ENTER]
vncserver :1 -geometry 960x540 [ENTER]**​6. Open androidVNC app and enter the following settings:
Nickname: Anything you want
Password: ubuntu
Address: localhost
Port: 5901
Color Format: 24-bit color (4 bpp)
7. Hit connect
8. Hit your menu soft button and then set input mode to touchpad
9. You have ubuntu on your Droid 4!
To "shut down" ubuntu:
press the menu button, select disconnect in VNC
In terminal type this command 3 times (terminal will close itself when you are done):
exit [ENTER]
To "start up" ubuntu again:
Follow steps 5-8 above
Troubleshooting:
If you get the error message: ubuntud4.sh: 45: syntax error: end of file unexpected (expecting "then") you are about to have fun with vi at the command line.
Do the following from inside terminal:
su [ENTER]
cd /mnt/sdcard-ext/ubuntu [ENTER]
vi ubuntud4.sh [ENTER]​If you see ^M or ^ at the end of any line (remember to scroll all the way to the right to see the end of long lines) remove it. once you do that, everything should work just fine. (See the Vi Cheat Sheet above for help with Vi)
Note: Vol Up + E is [ESC] by default in this terminal emulator
Notes:
* It does not have to be on the external SD, but if you put it on the internal SD you will have to modify things as needed-- if you dont know what needs to be changed, just put it on the external SD.
** Screen size can be whatever you want it to be, but 960x540 is the size of the D4 screen.
*** This is a fairly involved process... especially when it comes to editing the .sh file in vi things can get very frustrating and hard, but just take your time and you will get it. As always, doing anything with root access on your phone, especially on the command line has risks. I am not responsible if anything goes wrong with your phone... proceed at your own risk!
greekchampion04 said:
Notes:
* It does not have to be on the external SD, but if you put it on the internal SD you will have to modify things as needed-- if you dont know what needs to be changed, just put it on the external SD.
** Screen size can be whatever you want it to be, but 960x540 is the size of the D4 screen.
*** This is a fairly involved process... especially when it comes to editing the .sh file in vi things can get very frustrating and hard, but just take your time and you will get it. As always, doing anything with root access on your phone, especially on the command line has risks. I am not responsible if anything goes wrong with your phone... proceed at your own risk!
Click to expand...
Click to collapse
I actually got it up and running on my internal sdcard partition. Pretty much just have to modify the Mount remount command, and a few lines in the script.
Here's the original command
Code:
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext
And the modified one
Code:
mount -o remount,rw,exec,suid /dev/block/vold/179:57 /mnt/sdcard
Only things you have to change are the device location(179:57) and mount location(drop the -ext after sdcard)
Now, after that you also have to modify the script a bit. Just go through it, and anywhere that you see sdcard-ext, drop the -ext off the end.
thanks for putting that up for everybody! like i said, if you know what you are doing its not a hard swap to make.
Is anyone else getting just a gray screen when they remote in? What could be causing this?
i had that same problem at first... did you use zeroktal's ubuntud4.zip file? or did you use the ubuntu.sh file included in the app?
I used the sh file included. I did however fix the problem, when mounting at the start i confused vold with void. I did not get the file system mounted properly. This method does work!! however I am currently trying to get bash on my droid to replace sh as the shell. I've checked the forums but have not found anything yet about someone installing bash on the droid 4. With no way for nandroids I feel i should wait before I kill sh.
Sent from my DROID4 using XDA App
If you mod your init.sh in your root directory to the following, your vnc will work on startup without issue. It will also shutdown vnc on exit.
#!/bin/bash
#############################################
# Asks User to screen size and saves as REZ #
#############################################
#echo "Now enter the screen size you want in pixels (e.g. 800x480), followed by [ENTER]:"
#read REZ
##############################################
# Pick which desktop environment to use, this#
# is done by having a xstartup file for each #
# desktop, then renaming the one you want to #
# use to 'xstartup' before boot #
##############################################
echo "Please select which Desktop environment you want to use, type the number to select it then press [ENTER]"
echo "1 - LXDE"
echo "2 - Gnome"
echo "Make your Selection:"
read DESKTOP
if [ $DESKTOP == 1 ]
then
mv /root/.vnc/lxstartup /root/.vnc/xstartup
fi
if [ $DESKTOP == 2 ]
then
mv /root/.vnc/gxstartup /root/.vnc/xstartup
fi
###########################################
# Tidy up previous LXDE and DBUS sessions #
###########################################
rm /tmp/.X* > /dev/null 2>&1
rm /tmp/.X11-unix/X* > /dev/null 2>&1
rm /root/.vnc/localhost* > /dev/null 2>&1
rm /var/run/dbus/pid > /dev/null 2>&1
############################################################
# enable workaround for upstart dependent installs #
# in chroot'd environment. this allows certain packages #
# that use upstart start/stop to not fail on install. #
# this means they will have to be launched manually though #
############################################################
dpkg-divert --local --rename --add /sbin/initctl > /dev/null 2>&1
ln -s /bin/true /sbin/initctl > /dev/null 2>&1
###############################################
# start vnc server with given resolution and #
# DBUS server, (and optionally an SSH server) #
###############################################
dbus-daemon --system --fork > /dev/null 2>&1
/etc/init.d/ssh start
vncserver :1 -geometry 960x540
echo
echo "If you see the message 'New 'X' Desktop is localhost:1' then you are ready to VNC into your ubuntu OS.."
echo
echo "If VNC'ing from a different machine on the same network as the android device use the 1st address below:"
##########################################
# Output IP address of android device #
##########################################
ifconfig | grep "inet addr"
echo
echo "If using androidVNC, change the 'Color Format' setting to 24-bit colour, and once you've VNC'd in, change the 'input mode' to touchpad (in settings)"
echo
echo "To shut down the VNC server and exit the ubuntu environment, just enter 'exit' at this terminal - and WAIT for all shutdown routines to finish!"
echo
###############################################################
# Spawn and interactive shell - this effectively halts script #
# execution until the spawning shell is exited (i.e. you want #
# to shut down vncserver and exit the ubuntu environment) #
###############################################################
/bin/bash -i
#########################################
# Disable upstart workaround and #
# kill VNC server (and optionally SSH) #
# Rename used xstartup to its first file#
#########################################
killall -TERM Xtightvnc
/etc/init.d/ssh stop
Also save the follow lines between ### as remount.sh on your system partition. Then chmod 755 /system/remount.sh. Now you can just run run from a terminal /system/remount.sh and voila it remounts correctly and starts ubuntu(with the above fixes). Im still working on the unmounts.
####### for the internal sd card
mount -o remount,rw,exec,suid /dev/block/vold/179:57 /mnt/sdcard
/mnt/sdcard/ubuntu/ubuntu.sh
######
OR
####### for the external sd card
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext
/mnt/sdcard-ext/ubuntu/ubuntu.sh
#######
great stuff!
feel free
Feel free and take, modify, repost or edit anything I touch.
QUESTION:
After I delete all the ^M and ^ what do i do next? I try to hit the command ":x" to exit and save changes but it just creates another line. Also when I press VOL UP + E to escape nothing happens.
PhanTuhC said:
QUESTION:
After I delete all the ^M and ^ what do i do next? I try to hit the command ":x" to exit and save changes but it just creates another line. Also when I press VOL UP + E to escape nothing happens.
Click to expand...
Click to collapse
In vi, the command to save and exit is :wq (probably short for write and quit).
remember, read up on the vi quick-reference guide: http://www.lagmonster.org/docs/vi.html
OK I fixed it but now its not letting me connect with androidVNC. All the settings entered is correct but when I try to connect it says:
"VNC connection failed!" localhost/127.0.0.1:5901 - Connection refused"
ok, i've gone thru this a few times (slowly and deliberately) and must be missing something...the directions seem pretty straightforward! here's what i know...
busy/terminal/vnc are all installed
small 2.5gb image is unzipped in /sdcard-ext/ubuntu directory
the attached .sh file from page 1 is in the same directory
i removed all ^M using vi
but when I try sh ubuntud4.sh i get an error...
"mkdir failed for /data/local/mnt/ubun, No such file or directory"
(plus a few other errors)
should the directory be "ubun" or "ubuntu"? am I typing something incorrectly?
copy and paste new script
Copy and paste the new scripts I posted. They will fix your problem. Remember to use the remount script from /system/ the rest will work perfectly if you are root. I'll check back later on your progress.
Ok, well I started from scratch (deleted both .img and .sh files) and it's still not working.
I have all the apps installed (and yes rooted, SU works just fine)
I used Ubuntu Installer app to download the image zip (tried both the large and small img)
I downloaded the .sh file from the first post
The /sdcard-ext/ubuntu/ folder now has two files: "ubuntu.img" and "ubuntud4.sh"
All ^M characters have been removed from .sh file
Still no joy...
Ideas? What am I missing?
In terminal, I can set SU permissions and the mount/cd commands work just fine...it's the last sh command that spits out a bunch of errors about not being able to create/find the directories.
I'm going to format the sdcard and try again...any help is appreciated.
Update: Even after re-formatting the SD and following the steps exactly, no luck!
Did you remember to remount the sdcard with exec and suid permissions?
Andbuntu will work much better than this method. It works on every single phone with modification to the "environmental variables".
http://code.google.com/p/andbuntu/
Follow the directions in the script to make the process much easier than the first post.
instructions:
generate an image with rootstock on an ubuntu computer.
put it on /sdcard/ubuntu/ubuntu.img
run the script on your phone with "sh /path/to/script"
Here is the script. http://andbuntu.googlecode.com/svn/trunk/uboot
Also, run "firstRun" to make things like terminals work properly.
Adamoutler: That didnt work for me. The permissions were incorrect on the mounted partitions.
Sent from my DROID4 using XDA App

[GT-P3XXX] busybox + install-script [+cyanogen edition][2012-08-15]

Hi folks,
here's an easy-to-install busybox for your Galaxy Tab 2. NOW with Cyanogen Mod support.
ChangeLog:
BusyBox 1.21.0-git Nano1 (2012-07-28): initial release
BusyBox 1.21.0-git Nano2 (2012-07-29): applied various patches:
BUGFIX: flush all open files after listing them (ls)
BUGFIX: when setting hostname from file p**** whole name
COMPAT: ps now accepts (= ignores) all options a POSIX ps should
allow passing -mthumb to make
ash applet now exports HOME
silently ignore processes from inittab with terminal names without matching device file
default behaviour of 'showkey' applet changed from displaying interpreted keycode to decimals
do not show a message when testing an uninitialized variable
changed some terms in top applet output (rss vs. vsz)
BusyBox 1.21.0-git Nano3 (2012-08-05): major fix
NEW: rfkill applet¹
several minor modifications to applet
BUGFIX fixed a bug in busyinstall that left system without 'sh' upon uninstall²
provide busybox-patches to the world
BusyBox 1.21.0-git Nano4 (2012-08-15): minor fix / cm 10 edition
updated to latest git (some bugfixes)
BUGFIX: reading profile now works
BUGFIX: adjusted shell paths
BUGFIX: history now works
BUGFIX: no longer replace reboot on stock rom³
NEW: Cyanogen Mod edition (tested on cm10)
¹ Either redo 'busyinstall install', or do 'ln -sf /system/bin/busybox /system/bin/rfkill'
² You can find the original sh in you CWM backup, or here: http://www.nanolx.org/downloads/P3110/original-sh
If you didn't get /system/bin/sh.orig after 'busyinstall install', use this file as /system/bin/sh.orig
³ push new busyinstall into tablet to ensure future install/uninstall is fine. then do 'mv /system/bin/reboot.orig /system/bin/reboot'
from within 'adb shell' as root to get original reboot back.
Prerequisites:
* root access on your Tablet
Download:
busybox (normal): http://www.nanolx.org/downloads/P3110/busybox-nano4
busybox (debug): http://www.nanolx.org/downloads/P3110/busybox_unstripped-nano4
busyinstall (installer/stock): http://www.nanolx.org/downloads/P3110/busyinstall
busyinstall (installer/cm10): http://www.nanolx.org/downloads/P3110/busyinstall-cm
profile (optional): http://www.nanolx.org/downloads/P3110/profile¹
busybox (patches): http://www.nanolx.org/downloads/index.php?dir=P3110/busybox-patches/
¹ profile is a generic file, read on each startup of busybox. Mine sets HOME to /,
and puts /system/xbin/ in front of /system/bin/ in PATH. You can also adjust the
prompt (PS1) or whatever here, it's valid for all users. You could check for
'$(id -u) == 0' to adjust prompt for root, if not 0, for ordinary user.
Ordinary user should get 'busybox (normal)', rather than 'busybox (debug)'.
NEW INSTALLATION (STOCK ROM):
Putting busybox on internal sd-storage:
Code:
adb push busybox /mnt/extSdCard/
adb push busyinstall /mnt/extSdCard/
replace "extSdCard" if you saved busybox somewhere else
Code:
adb shell
su
chmod 0777 /mnt/extSdCard/busybox
chmod 0777 /mnt/extSdCard/busyinstall
/mnt/extSdCard/busybox remount -o rw,remount /system
/mnt/extSdCard/busybox mv -f /mnt/extSdCard/busybox /system/bin/
/system/bin/busybox mv -f /mnt/extSdCard/busyinstall /system/bin
busyinstall install
NEW INSTALLATION (CYANOGEN ROM):
Putting busybox on device:
in Settings > Development > set 'root access' to 'apps + adb'
Code:
adb root
adb shell
busybox mount -o rw,remount /system
exit
adb push busybox /system/xbin/busybox.nano
adb push busyinstall /system/bin/busyinstall
adb push profile /system/etc/profile # optional, if downloaded profile
adb shell
chmod 0777 /system/bin/busyinstall
busyinstall install
UPDATE:
Just download busybox, busyinstall and replace the ones in /system/bin/ - it will instantly work:
Code:
adb push busybox /system/bin/
adb push busyinstall /system/bin/
adb shell
su
toolbox chmod 0777 /system/bin/busybox # if you use windows, the executable bit might be missing in the uploaded file
chmod 0777 /system/bin/busyinstall
UNINSTALLATION:
Code:
ab shell
su
busyinstall --
That's it!
I tested everything and it does work perfect, either way a backup (CWM) is always recommened, when working around with stuff down the stack.
Suggestions welcome.
Out of curiosity, what is the difference between what this does and what BusyBox (by Stericson) from the Play Store does?
Sent from my MB855 using Tapatalk 2
Jleeblanch said:
Out of curiosity, what is the difference between what this does and what BusyBox (by Stericson) from the Play Store does?
Sent from my MB855 using Tapatalk 2
Click to expand...
Click to collapse
mine is a newer version
has all features of busybox (stericsons free version does not have all applets in busybox enabled, eg. 'sh' applet is missing)
installation 100% GT-P3XXX optimized
As of now, mostly personal preference I'd say.
Edit: But I'm currently applying stuff from busybox-power (maemo) which adds serveral bugfixes and stuff to busybox.
OK, improved version of busybox available in post 1 (+ changelog)
OK, thanks for letting me know!
I actually haven't done much with my Tablet lately as I've been busy with my phone as that now has CM10 too
But once I get my phone all set I'll use your BusyBox and give it a go!
Also, you said your busybox version is newer...but busybox via my phone is version 1.20.2. Just letting you know!
Thanks for this btw, I'd rather have a modified version optimized for my tablet versus a more universal version so to speak. Plus, with your updated applets! Thanks!
Sent from my MB855 using Tapatalk 2
Jleeblanch said:
Also, you said your busybox version is newer...but busybox via my phone is version 1.20.2. Just letting you know!
Sent from my MB855 using Tapatalk 2
Click to expand...
Click to collapse
Oh, ... mine is 1.21.0-git - fixed the typo
First,thank you for your work,second I've a question: I've an p3100 (wifi+gsm) ,it rooted on stock 4.0.4 ,and no busybox installed.It has 16gb onboard ,and I don't have at the moment any external microsd in slot,I've ordered an 32gb,but it hasn't come yet.Can you please tell me if it's safe puting your files in /sdcad (not ExtSdCard like you wrote) and give the commands using ''sdcard'' word ?
For e.g:
db shell
su
/mnt/sdcard/busybox remount -o rw,remount /system
I need busybox to backup my /efs folder ,but I don't want to screw something,so please tell me if it is safe to use internal memory (sdcard) for busybox install?Also ,when I'll receive the microsd ,I will need to install again busybox with your original commands from this topic ?
Thanks a lot!!
Best Regards!
viasat said:
First,thank you for your work,second I've a question: I've an p3100 (wifi+gsm) ,it rooted on stock 4.0.4 ,and no busybox installed.It has 16gb onboard ,and I don't have at the moment any external microsd in slot,I've ordered an 32gb,but it hasn't come yet.Can you please tell me if it's safe puting your files in /sdcad (not ExtSdCard like you wrote) and give the commands using ''sdcard'' word ?
For e.g:
db shell
su
/mnt/sdcard/busybox remount -o rw,remount /system
I need busybox to backup my /efs folder ,but I don't want to screw something,so please tell me if it is safe to use internal memory (sdcard) for busybox install?Also ,when I'll receive the microsd ,I will need to install again busybox with your original commands from this topic ?
Thanks a lot!!
Best Regards!
Click to expand...
Click to collapse
Of course you can. It does not matter where you put busybox. All that matters is, that you adjust the commands to your path.
In your you would push the files using ADB, like
Code:
adb push busybox /mnt/sdcard
adb push busyinstall /mnt/sdcard
also you don't need to re-do this when you got your sd-card, because during the steps you move busybox/busyinstall into /system/bin/.
Edit: updated instructions to clarify this.
Ok,thank you for your time,everything it's clear now.I'll try later,when I'm going home.
Cheers!
---------- Post added at 07:04 PM ---------- Previous post was at 06:11 PM ----------
OK,first problem:when I try to execute the first comand,it gives me ''permission denied'',so after a little reading,because my kernel it's stock,I've installed Chainfire's ''adbd Insecure v1.0 '' http://forum.xda-developers.com/showthread.php?t=1687590 to give me rights.After that I've no more errors,but,when I execute first command in adb,it says nothing,just hanging,and adb doesn't come back to # symbol ,and because of that I can't execute the next command.Any ideea what I'm doing wrong?Thanks!
What command failed?
Gesendet von meinem GT-P3110 mit Tapatalk 2
I don't know how to explain,it not really failed, but when I type
/mnt/sdcard/busybox remount -o rw,remount /system the adb doesn't return anything back,and doesn't come back to # symbol ,it just staying,nothing more,no response.I was waiting 2 minutes,and nothing ,doesn't return to # .I can type the next command
/mnt/sdcard/busybox mv /mnt/sdcard/busybox /mnt/sdcard/busyinstall /system/bin/
it's the same,no output,nothing.
Can you please tell me what I'm doing wrong?
Thanks again!
Now I'm stuck,even with adbd insecure activate I cannot execute commands:
C:\Documents and Settings\X\Desktop\ADB>adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
[email protected]:/ # /mnt/sdcard/busybox remount -o rw,remount /system
/mnt/sdcard/busybox remount -o rw,remount /system
/system/bin/sh: /mnt/sdcard/busybox: cannot execute - Permission denied
126|[email protected]:/ # /mnt/sdcard/busybox mv /mnt/sdcard/busybox /mnt/sdcard/busy
install /system/bin/
dcard/busybox /mnt/sdcard/busyinstall /system/bin/ <
/system/bin/sh: /mnt/sdcard/busybox: cannot execute - Permission denied
126|[email protected]:/ #
Maybe I need first to install Stericsson's busybox from Market?At the moment,as I said before I don't have busybox installed at all,only su.
One more thing,every time when I save from your link busyinstall,no matter what browser,the file is saved as busyinstall.txt
It is normal ,or I need to rename it?
Thanks a lot!
Hmm... seems I forgot a little thing.
do this after you put busybox on tablet, before anything else:
Code:
adb shell
su
chmod 0777 /mnt/sdcard/busybox
then follow the rest of the instructions.
/goingtofixfirstpost
Same story,take a look:
[email protected]:/ # chmod 0777 /mnt/sdcard/busybox
chmod 0777 /mnt/sdcard/busybox
[email protected]:/ # chmod 0777 /mnt/sdcard/busyinstall
chmod 0777 /mnt/sdcard/busyinstall
[email protected]:/ # /mnt/sdcard/busybox remount -o rw,remount /system
/mnt/sdcard/busybox remount -o rw,remount /system
/system/bin/sh: /mnt/sdcard/busybox: cannot execute - Permission denied
126|[email protected]:/ #
Hmmm... > could you provide me the details of 'adb logcat'? Ensure to run those commands while logging.
Gesendet von meinem GT-P3110 mit Tapatalk 2
I don't know if this is what you want,but here we go:
I'm going to check your logs soon and report back.
Meanwhile I updated to Nano3 - see first post.
I got no clue why it does not work for you, but me.
What boot image and ROM are you using? Default boot/ROM, rooted boot/ROM, cyanogen?
I only tested default ROM with my boot. Currently testing cyanogenmod 10, but except some adjustments to busyinstall it will work there, too.
Sorry for the late reply,I'm on vacation until Sunday,and my acces to internet it's very limited here.Now,regarding my problem,first when I got the tablet it was on stock 4.0.3 ,wich I rooted manually to keep the counter to 0 (for warranity) ,and after that I updated to stock 4.0.4 using Mobile Odin Pro,with Everoot option ( it's rooting the rom on the fly) .So now I'm rooted on stock 4.0.4 ,stock recovery, and no busybox installed.I fell more secure and want to install your busybox version,because it's specialy designed for tab2,and it's has features from Maemo (I'm a big fan,I owned an N800,and I've also an N900 ).Maybe,if you have the time and the skills,you can pack it on an .apk version,if it's possible,of course.I will try more Sunday,when I'll be back home.Thanks again for your patience and help.Best Regards!
It will be great if we have a kernel (even stock) with CWM and this busybox...
I am also rooted with flash counter 0 and stock recovery.
Sent from my GT-P3110 using Tapatalk 2
Maybe some contributor creates a flashable zip (for CWM).
So... uploaded 1.20.1-Nano4. See first post for changes.
This time an addtional install-script for cyanogen mod was added, along some fixes.
ah... and: 100th post

How To Guide How to change the home directory for the user root on an Android phone

How to change the home directory for the user root on an Android phone
When working a lot in a shell via adb on an Android phone it's usefull to be able to store some user dependent config files in the home directory of the user. So let's see how that can be implemented on a phone running Android.
Note: The config was done and tested on a phone running OmniROM (based on Android 12)
The home directory for all user used in an (adb) shell on Android is the root directory "/".
Using a home directory for more then one user is not really usefull and in addition on Android "/" is mounted read-only so more or less useless as home directory.
Therefor this should be changed . Unfortunately there is no /etc/passwd file in Android to configure the home directory for a user.
Well, there is an /etc/passwd file (probably for compatibily reasons) but it's empty:
Code:
[email protected]_I006D:/ $ ls -l /etc/passwd
-rw-r--r-- 1 root root 0 2009-01-01 01:00 /etc/passwd
[email protected]_I006D:/ $
And as far as I know there is no other config file to configure the home directory of the user in the Android OS.
So we must implement some work around to get this working.
The shell on Android behaves like normal shells on Linux and executes the file /etc/profile when starting a new session.
In Android /etc is a symbolic link to /system/etc:
Code:
[email protected]_I006D:/ # ls -ld /etc
lrw-r--r-- 1 root root 11 2009-01-01 01:00 /etc -> /system/etc
[email protected]_I006D:/ #
And in the default config there is no file called profile in that directory:
Code:
[email protected]_I006D:/ $ ls -l /etc/system/profile
ls: /etc/system/profile: No such file or directory
[email protected]_I006D:/ $
Because /system is also mounted read-only we need the magic tool Magisk again to create the file /system/etc/profile.
To create the file /system/etc/profile create these directories and files on the phone as user root (assuming Magisk is already installed on the phone):
Code:
[email protected]_I006D:/ # find /data/adb/modules/initshell/
/data/adb/modules/initshell/
/data/adb/modules/initshell/system
/data/adb/modules/initshell/system/etc
/data/adb/modules/initshell/system/etc/profile
[email protected]_I006D:/ #
and reboot the phone. After the reboot there should be the writable file /etc/profile:
Code:
[email protected]_I006D:/ # ls -l /etc/profile
-rw-rw-rw- 1 root root 1100 2022-07-14 14:51 /etc/profile
[email protected]_I006D:/ #
which is in reality the file
Code:
/data/adb/modules/initshell/system/etc/profile
Now you can edit the file /etc/profile as user root until it fullfills your requirements (be aware that all changes in that file are now persistent).
To test the changes open a new adb session (you should not close the current adb session to be able to fix an error in the profile if opening a new adb session fails).
This file can now be used to define the home directory for the user. The home directory should be on one of the writable filesystem, e.g. in /data:
Code:
# add in /etc/profile
HOME="/data/home/root"
export HOME
and the result is:
Code:
[email protected]_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:su:s0
[email protected]_I006D:/ # echo $HOME
/data/home/root
[email protected]_I006D:/ #
Note that there is not really a writable filesystem for the user shell so this approach to change the home directory is mainly usable for the user root.
The file /etc/profile can also be used to init some other settings for (adb) sessions (e..g. change the PATH, etc) . This feature can be used for sessions for non-root users also.
For additional user dependent configs you can also create the file .profile in the home directory of the user; the file ${HOME}/.profile will be executed after the execution of the file /etc/profile.
Notes:
Be aware that creating a profile for the user root and changing the home directory for the user root might have some side effects on other processes using the shell!
Therefor it's recommended to use the command "tty -s" to test if the profile is executed in an interactive session:
Code:
#
# check if we're running in an interactive session
#
if ! tty -s; then
#
# this is not an interactive session - so we're just doing nothing at all
#
:
else
#
# running in an interactive session
#
...
fi
You can also check if the parent process is the adb daemon to not do anything in non-adb sessions.
Code:
ps -fp $PPID| grep adbd >/dev/null
if [ $? -ne 0 ] ; then
#
# not running in an adb session
:
else
#
# running in an adb session
...
fi
For testing purpose I suggest to open at least two shells via adb to be able to fix an error in case opening a new shell fails due to a bug in the profile.
If opening a shell session fails due to an error in the /etc/profile and you do not have another open shell either delete the file /data/adb/modules/initshell/system/etc/profile with a filemanager with root access on the phone or boot the phone from a recovery image (like TWRP) and delete or edit the file /data/adb/modules/initshell/system/etc/profile.
I initially looked at this feature to enable a persistent command history for the shell on the Android phone. But after some google searches I found out that persistent history shells are disabled for the shell binary on Android. So this will not work without recompiling the shell binary.
The attached example for the profile (rename the attached file profile.txt to profile) will use the directory /data/home/root as home directory for the user root and will not change the home directory for other users. The profile will do nothing if not running in an interactive session.
The directory /data/home/root will be created by the profile if it does not yet exist.
As always, if the config is working you should create a real Magisk Module for the profile.
The Magisk Module attached, initshell.zip, can be used to create a Magisk Module with your own profile:
To create a new Magisk Module with your own /etc/profile do:
Code:
# create an empty working directory
#
TEMPDIR="/tmp/newdir"
mkdir "${TEMPDIR}"
cd "${TEMPDIR}"
# unpack the zip file in the new directory
#
unzip ../initshell.zip
# now edit the file ${TEMPDIR}/system/etc/profile
# also (optional) edit the files config.sh and module.prop in the new directory to document your changes
# the script customize.sh from the module will be executed once when the module is installed. You might add the code
# create the home directories or any other code here
#
# and recreate the zip file
#
zip -r ../initshell.zip .
Note:
Both attached files are also available from my web site: http://bnsmb.de/My_HowTos_for_Android.html

How To Guide How to make files in /system writable

How to make files in /system writable
In Android 12 and newer /system is mounted read-only can not be remounted read-write anymore.
Sometimes it's useful that one or more files in /system are writable (for example for develop tasks or for testing)
This can be implemented using Magisk (see How to change files in the directory /system for more details)
Example :
Make the file /system/etc/vimrc writable
Note:
In Android 12 /etc is a symbolic link to /system/etc.
Open a (adb) shell as user root and do
Bash:
# create a dummy Magisk module
#
mkdir -p /data/adb/modules/writable_system/system/etc
# copy the file that should be writable to the Magisk module directory
#
cp /system/etc/vimrc /data/adb/modules/writable_system/system/etc/
# make the file in the Magisk module directory writable
#
chmod +w /data/adb/modules/writable_system/system/etc/vimrc
Now reboot the phone.
After the reboot the file /system/etc/vimrc is writable by the user root, Example:
Code:
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # ls -l /system/etc/vimrc
-rw-r--r-- 0 root root 3350 2022-11-04 11:36 /system/etc/vimrc
ASUS_I006D:/ # tail -2 /system/etc/vimrc
\ | wincmd p | diffthis
endif
ASUS_I006D:/ #
ASUS_I006D:/ # echo '" Test Comment' >>/system/etc/vimrc
ASUS_I006D:/ #
ASUS_I006D:/ # tail -2 /system/etc/vimrc
endif
" Test Comment
ASUS_I006D:/ #
Only the user root can access the directory /data/adb. Therefor the files configured using this approach are only writable by the user root.
To make a file in /system writable for non-root users use this method:
Open a (adb) shell and execute as user shell:
Bash:
#
# create a directory that is writable for the user shell
#
mkdir /data/local/tmp/writable_system
mkdir /data/local/tmp/writable_system/etc
#
# copy the file that should be writable to that directory
#
cp /system/etc/vimrc /data/local/tmp/writable_system/etc
The next commands must be executed as user root:
Bash:
# create dummy Magisk module
#
mkdir -p /data/adb/modules/writable_system/system/etc
#
# create a symbolic link to the file in the writable directory in the directory with the dummy Magisk module
#
ln -s /data/local/tmp/writable_system/etc/vimrc /data/adb/modules/writable_system/system/etc
Now reboot the phone.
After the reboot the file /system/etc/vimrc is writable by the user shell, Example:
Code:
ASUS_I006D:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012(readtracefs) context=u:r:shell:s0
ASUS_I006D:/ $
ASUS_I006D:/ $ tail -2 /system/etc/vimrc
\ | wincmd p | diffthis
endif
ASUS_I006D:/ $
ASUS_I006D:/ $ echo '" Test Comment' >>/system/etc/vimrc
ASUS_I006D:/ $
ASUS_I006D:/ $ tail -2 /system/etc/vimrc
endif
" Test Comment
ASUS_I006D:/ $
Important:
The writable directory can also be in a sub directory in /sdcard. But be aware that /sdcard is mounted late in the boot process so it might be that the overwritten file in /system will be used by the OS when the bind mount points to a non-existent file if using a sub directory in /sdcard.
The changes to the file done using these methods are "persistent" as long as Magisk is installed in the boot partition.
To restore the file with the original contents after each new reboot of the phone without removing the writable config open a (adb) shell as user root and execute:
Bash:
#
# restore the file /data/adb/modules/writable_system/system/etc/vimrc from the original file /system/etc/vimrc
#
# this must be done before Magisk creates the bind mounts
#
echo "cp /system/etc/vimrc /data/adb/modules/writable_system/system/etc/vimrc">/data/adb/post-fs-data.d/restore_vimrc.sh
chmod 755 /data/adb/post-fs-data.d/restore_vimrc.sh
Now the file in the dummy Magisk module will be restored with the contents of the original file from /system after each reboot
To temporary access the original file from /system just stop the Magisk daemon, Example:
Code:
ASUS_I006D:/ # echo '"Test Test' >>/etc/vimrc
ASUS_I006D:/ #
ASUS_I006D:/ # tail -1 /etc/vimrc
"Test Test
ASUS_I006D:/ #
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # magisk --stop
ASUS_I006D:/ #
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # tail -1 /etc/vimrc
endif
ASUS_I006D:/ #
Note
Stopping the Magisk daemon will disable all bind mounts done by Magisk.
Restarting the Magisk daemon will not re-create the bind mount - to re-activate the bind mount for the writable file after stopping the Magisk daemon the phone must be rebooted.
To make more then one file writable in a sub directory in /system you can also replace the complete folder using these commands as user root:
Bash:
#
# make all files in /system/etc writable by the user root
#
mkdir -p /data/adb/modules/writable_system/system/etc/
cd /system/etc
find . | cpio -pdum /data/adb/modules/writable_system/system/etc/
touch /data/adb/modules/writable_system/system/etc/.replace
Now Magisk will replace the directory /system/etc with the directory /data/adb/modules/writable_system/system/etc after the next reboot
Notes
You should test these commands with a not important file like /system/etc/vimrc before changing important files.
It is NOT recommended to use this approach on productive phones.
See How to change any file or directory using Magisk for another approach to change files on read-only mounted filesystems.
Trouble Shooting
As always: If something does not work like expected check the Magisk log file /cache/magisk.log and also check the infos in this post.
Does this method require root on device?
FormulaSea said:
Does this method require root on device?
Click to expand...
Click to collapse
yes
Is there any method don't require root?
This looks interesting. Are you using OverlayFS for this? Looks like you did quite the research on this
Read-only is boring even as root. It's time for some RW baby
FormulaSea said:
Does this method require root on device?
Click to expand...
Click to collapse
I don't know a method to do this without root access.
But you can disable the root access in Magisk after implementing the changes . You could even uninstall tne Magisk app afterwards (but not the Magisk part from the boot partition)
regards
Bernd
lebigmac said:
This looks interesting. Are you using OverlayFS for this? Looks like you did quite the research on this
Read-only is boring even as root. It's time for some RW baby
Click to expand...
Click to collapse
I don't know what exactly you mean by "OverlayFS" - I use MagiskModules to modify files in /system and as far as I know Magisk used bind mounts to implement it.
>>Read-only is boring even as root.
Correct, but if you made the changes directly in /system, they would not survive the next OS upgrade.
One of the great advantages of this feature of Magisk is that it survives an OS upgrade - so as long as the change is compatible with the installed OS version, it only needs to be done once.
regards
Bernd
Thanks it worked on the audio folders on my 7t pro but didn't work on the boot animation folder. Both folders appear in the adb though with there files. Let me know op if you figure out how to do the boot animation folder it's moved to /my_product/ instead of /system/ I see that the my product folder and boot animation appear in the adb modules like the audio folder does and I swapped files the same way as with my audio modding but the changes for boot didn't take effect.
cbomb1337 said:
Thanks it worked on the audio folders on my 7t pro but didn't work on the boot animation folder. Both folders appear in the adb though with there files. Let me know op if you figure out how to do the boot animation folder it's moved to /my_product/ instead of /system/ I see that the my product folder and boot animation appear in the adb modules like the audio folder does and I swapped files the same way as with my audio modding but the changes for boot didn't take effect.
Click to expand...
Click to collapse
/my_product is not in the list of folders supported by Magisk so that may not work
Please post the output of these commands (executed as root user):
df -h
mount
ls -ald /*
ls -lZd /my_product
and a
ls -ldZ $( find /data/adb/modules/ )
and
cat /cache/magisk.log
(or attach the log file to the post if too big)
regards
Bernd
Here is this the correct log file. Thank you for responding to me.
cbomb1337 said:
Here is this the correct log file. Thank you for responding to me.
Click to expand...
Click to collapse
can you also post the output of the OS commands listed?
I Don't know how.
It didn't let me add the log here. Sorry that's it's cut and paste I tried a few termux commands to save a log but the were blank. I don't understand how to do it right.
Edit here I managed to upload the log to drive
https://drive.google.com/uc?id=1uWurf_462b5uLC_D21SFcgLcBWiXQZOn&export=download
bnsmb said:
can you also post the output of the OS commands listed?
Click to expand...
Click to collapse
Linefeeds are missing in that file so it's very hard to interpret the file contents correct
Can you do in a adb shell on the phone:
Bash:
(
set -x
set -v
su -
echo
df -h
echo
mount
echo
ls -ald /*
echo
ls -lZd /my_product
echo
ls -ldZ $( find /data/adb/modules/ )
echo
) > /sdcard/Download/oscmds.log 2>&1
then
Bash:
gzip /sdcard/Download/oscmds.log
and post / upload the file
/sdcard/Download/oscmds.log.gz
regards
Bernd
and
Here is the gzip I wasn't sure what was going on after entering that first command the termux was frozen for a few minutes. Also With the folders in the module folder and them being a copy of the original folder is it ok to delete them as a whole folder to remove the rw and revert it of needed. I tried it and didn't see any issues doing it but wanted to know if it reverted it properly and does deleting the module folders make me lose anything original that was in it or is my stock stuff safe because it's through magisk.
cbomb1337 said:
Here is the gzip I wasn't sure what was going on after entering that first command the termux was frozen for a few minutes. Also With the folders in the module folder and them being a copy of the original folder is it ok to delete them as a whole folder to remove the rw and revert it of needed. I tried it and didn't see any issues doing it but wanted to know if it reverted it properly and does deleting the module folders make me lose anything original that was in it or is my stock stuff safe because it's through magisk.
Click to expand...
Click to collapse
Looks like /my_product is a directory in the root filesystem but on the other hand there is a mount point called /mnt/vendor/my_product so I'm not sure about that.
If /my_product is really only a separate directory in the root filesystem the only method to change it is to manipulate the ramdisk used for booting the phone (only if the phone is using a ramdisk, of course).
Can you check if there are other directories called my_product:
find / -type d -name my_product 2>/dev/null
And, if there are any, compare the files in that directory with the files in the directory /my_product?
regards
Bernd
The only folder that has the same boot animation files is the /dev/ ones and the mnt one like you said.
It's all good if it can't be done i just found a magisk module before which works for flashing my boot animation
cbomb1337 said:
The only folder that has the same boot animation files is the /dev/ ones and the mnt one like you said.
Click to expand...
Click to collapse
Then it can't be done using the standard Magisk feature for making r/o mounted filesystems read-write.
cbomb1337 said:
It's all good if it can't be done i just found a magisk module before which works for flashing my boot animation
Click to expand...
Click to collapse
OK, do you have the URL?
And you could just check the contents of the zip file with the Magisk Module on how it's implemented
regards
Bernd
bnsmb said:
Then it can't be done using the standard Magisk feature for making r/o mounted filesystems read-write.
OK, do you have the URL?
And you could just check the contents of the zip file with the Magisk Module on how it's implemented
regards
Bernd
Click to expand...
Click to collapse
I read the module it mentions binding. I don't understand none of it :/ I upload the module here and removed the boot animation to make it small.
cbomb1337 said:
I read the module it mentions binding. I don't understand none of it :/ I upload the module here and removed the boot animation to make it small.
Click to expand...
Click to collapse
Cool -- that's the solution I also found in the meantime (and successfully tested it on my Zenfone 8)
In principle the module does for the bootanimation file what Magisk does if you replace some directories or files in /system
I will write a general HowTo how that works today or in the next days
regards
Bernd

Categories

Resources