zRAM Swap Manager for Android and GNU/Linux Systems - Magisk

Upstream Repository
Official Kernel Documentation (zRAM)
Swap Performance (ArchWIki)
This project targets mainly gamers, heavy multitaskers and those with low RAM systems.

VR25 said:
Upstream Repository
Official Kernel Documentation (zRAM)
Swap Performance (ArchWIki)
This project targets mainly gamers, heavy multitaskers and those with low RAM systems.
Click to expand...
Click to collapse
i dont understand what memory limit does

VR25 said:
Upstream Repository
Official Kernel Documentation (zRAM)
Swap Performance (ArchWIki)
This project targets mainly gamers, heavy multitaskers and those with low RAM systems.
Click to expand...
Click to collapse
and how do i change setting , i typed zsm but i dont understand

Guan Yu said:
i dont understand what memory limit does
Click to expand...
Click to collapse
Memory limit caps the amount of memory zRAM can use. This is not something users must deeply understand to use this software. There's a config file: /data/adb/vr25/zram-swap-manager/config.txt (Android) or /etc/zram-swap-manager.conf (GNU/Linux). While the config can be edited with one of many programs, the usual way is with zsm -c [editor], editor being optional (falling back to vim | vi | nano).

sm -v
v2022.1.9 (202201090)
sm -e
Memory Estimates
Without zRAM: 2734 MB
With zRAM: 3727 MB
Net Gain: 993 MB (36%)
sm -f
sm -n
Loops into this.....
cat: can't open '/sys/block/zram0/comp_algorithm': No such file or directory
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /system/bin/mkswap...
mkswap: can't open '/dev/block/zram0': No such file or directory
(i) Trying alternative: /system/xbin/mkswap...
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /vendor/bin/mkswap...
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /system/bin/mkswap...
mkswap: can't open '/dev/block/zram0': No such file or directory

sieger007 said:
sm -v
v2022.1.9 (202201090)
sm -e
Memory Estimates
Without zRAM: 2734 MB
With zRAM: 3727 MB
Net Gain: 993 MB (36%)
sm -f
sm -n
Loops into this.....
cat: can't open '/sys/block/zram0/comp_algorithm': No such file or directory
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /system/bin/mkswap...
mkswap: can't open '/dev/block/zram0': No such file or directory
(i) Trying alternative: /system/xbin/mkswap...
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /vendor/bin/mkswap...
mkswap: /dev/block/zram0: No such file or directory
(i) Trying alternative: /system/bin/mkswap...
mkswap: can't open '/dev/block/zram0': No such file or directory
Click to expand...
Click to collapse
What's the output of ls /dev/zram*?

Bash:
ls /dev/zram*
ls: /dev/zram*: No such file or directory
and here is the mod
Bash:
ls -al /data/adb/modules/zram-swap-manager
total 19
drwxr-xr-x 3 root root 3488 2022-03-28 06:04 .
drwxr-xr-x 14 root root 3488 2022-04-01 18:39 ..
-rwxr-xr-x 1 root root 767 2022-03-28 06:04 busybox.sh
-rw-r--r-- 1 root root 103 2022-03-28 06:04 module.prop
-rwxr-xr-x 1 root root 161 2022-03-28 06:04 service.sh
drwxr-xr-x 3 root root 3488 2022-03-28 06:04 system
-rwxrwxrwx 1 root root 697 2022-03-28 06:04 uninstall.sh
-rwxrwxrwx 1 root root 5803 2022-03-28 06:04 zram-swap-manager.sh
Also while you are at it - if its ok with you wanted to ask you about fbind - is there anyway you figured out to modify selinux policy so it can run successfully on enforced mobs. I asked that in relevant thread. wondered if it updated. thx!

sieger007 said:
Bash:
ls /dev/zram*
ls: /dev/zram*: No such file or directory
and here is the mod
Bash:
ls -al /data/adb/modules/zram-swap-manager
total 19
drwxr-xr-x 3 root root 3488 2022-03-28 06:04 .
drwxr-xr-x 14 root root 3488 2022-04-01 18:39 ..
-rwxr-xr-x 1 root root 767 2022-03-28 06:04 busybox.sh
-rw-r--r-- 1 root root 103 2022-03-28 06:04 module.prop
-rwxr-xr-x 1 root root 161 2022-03-28 06:04 service.sh
drwxr-xr-x 3 root root 3488 2022-03-28 06:04 system
-rwxrwxrwx 1 root root 697 2022-03-28 06:04 uninstall.sh
-rwxrwxrwx 1 root root 5803 2022-03-28 06:04 zram-swap-manager.sh
Click to expand...
Click to collapse
It almost seems like your kernel lacks [proper] zRAM support.
Share /dev/.vr25/zram-swap-manager/service.log (recreated on reboot).
Also while you are at it - if its ok with you wanted to ask you about fbind - is there anyway you figured out to modify selinux policy so it can run successfully on enforced mobs. I asked that in relevant thread. wondered if it updated. thx!
Answered in the dedicated thread.

VR25 said:
It almost seems like your kernel lacks [proper] zRAM support.
Share /dev/.vr25/zram-swap-manager/service.log (recreated on reboot).
Also while you are at it - if its ok with you wanted to ask you about fbind - is there anyway you figured out to modify selinux policy so it can run successfully on enforced mobs. I asked that in relevant thread. wondered if it updated. thx!
Answered in the dedicated thread.
Click to expand...
Click to collapse

@sieger007, your kernel does not seem to support zRAM.
Which device is this?
Does /sys/class/zram-control/ exist?

Hi, can you please release a guide for how to do this? My goal is to keep (certain) apps running in the background. If I can't choose specific apps, I'd like to keep ALL apps running in the background unless I actively close them. It's pretty ridiculous not being able to use more than 1-2 apps at a time. I run adguard, accubattery, JamesDSP constantly. I also listen to music sometimes while also browsing or playing a light game. Browsing even requires the keyboard open sometimes to type. And don't even think about summoning the Google assistant or any voice typing because instead of opening as an overlay, it closes the background app and switches to GA as an active foreground app.
I'm using a Pixel 3 with PixelDust12 and sure, it only has 4 gigs of ram. But even stock behavior isn't this bad. And I have the highest amount of zram I can set through EX kernel manager. (yes my kernel supports it. I have the directory mentioned above with two files inside it)
But the more I mess with zram settings the worse it seems to get. At one point yesterday it got so bad I wasn't able to use even 1 foreground app without it crashing on me. Sometimes even pulling up multi-tasking is enough to make it all crash. I even switched to Pure browser because it has far lower foreground ram usage than Brave (more than half) and it was still not enough. I'm now in Via browser and it seems to be ok. But without anything running in the background. Even system keeps crashing on me. Dev ops shows 0 background processes and around 10% average ram usage. It's crazy. EX shows that zram keeps getting disabled.

Hasn't been updated in a year... Does this still work ?

Related

DDMS: Unable to open log device

I am currently on PA2.57, some kind of CM10.1 version. I try to connect with Eclipse DDMS to check something in the logcat, but there it mentions:
Unable to open log device '/dev/log/main': No such file or directory.
[email protected]:/dev # pwd
pwd
/dev
[email protected]:/dev # ls l*
ls l*
light link_pm
[email protected]d:/dev # cd /system/bin
cd /system/bin
[email protected]:/system/bin # ls -l log*
ls -l log*
lrwxrwxrwx 1 root root 7 Jan 23 15:43 log -> toolbox
-rwxr-xr-x 1 root shell 13672 Aug 1 2008 logcat
-rwxr-xr-x 1 root shell 9592 Aug 1 2008 logwrapper
[email protected]:/system/bin #
Click to expand...
Click to collapse
I am confused, cause the logcat is there, but why is there no proper dir? Can anybody help how to set up the dirs properly? Is this related with CM? or..
Roland_SGN said:
I am currently on PA2.57, some kind of CM10.1 version. I try to connect with Eclipse DDMS to check something in the logcat, but there it mentions:
Unable to open log device '/dev/log/main': No such file or directory.
I am confused, cause the logcat is there, but why is there no proper dir? Can anybody help how to set up the dirs properly? Is this related with CM? or..
Click to expand...
Click to collapse
Your kernel or an app that controls the kernel has the logging disabled. You need to enable logging in order for /dev/log/main to be created and be viewed with Eclipse or a log app. Look for the disable/enable log in the kernel app. If there isn't one then you need to consult the dev responsible for the custom ROM with his/her preferred kernel or consult the creator of that specific kernel.

[Q] Custom kernal/ROM - root "disappeared" after some time

Hello all,
Bit of background, I've been rooting phones since my old HTC Hero so I'm not a complete newb... but your help on this would be appreciated.
Got a Samsung Galaxy Note GT-N7000 some years ago, of course immediately rooted it and put on a ROM (non-stock, not CM). Anyhoo all things go well for several years. Late last year I put a new kernel and Asylum 4.4 ROM on it. Again all is pretty well, works as intended.
BUT
I tried to do something which required root the other day and things were not successful. Tried a few bits and pieces, fired up SuperSU app, informed me that root was out of date, flash a new one... tried that, but it failed.
Long story short, I've flashed new kernel/recovery (raw_kernel_r4_j43) and new ROM (4.4.2 SlimSaber), tried flashing SuperSU from recovery, tried FramaRoot... Flashing in recovery indicates success, but RootChecker still indicates that there is no root access. FramaRoot comes up with an error advising me to use the "build.prop" (maybe "local.prop"?) trick. Whatever I've tried is all to no avail. To be clear, the device works perfectly otherwise - boots up normally, runs apps without problem, etc. Developer menus and so on all available. Root access just doesn't stick, and whenever I try to do something that requires root access - change DPI for instance - the app just hangs.
Here's the log from RootChecker Pro:
Super User Application Status:
SuperSU application - version 1.93 - is installed!
System File Properties for Root Access:
Standard Location
Check Command: ls -l /system/bin/su:
Result: lrwxrwxrwx root root 2014-03-12 13:18 su -> /system/xbin/su
Analysis: File: su is a symbolic link pointing to another file: /system/xbin/su
Standard Location
Check Command: ls -l /system/xbin/su:
Result: -rwsr-sr-x root root 91980 2008-08-01 13:00 su
Analysis: Setuid attribute is present and root user ownership is present. Root access is correctly configured for this file! Executing this file can grant root access!
Alternative Location
Check Command: ls -l /sbin/su:
Result: /sbin/su: Permission denied
Analysis: File system permissions restricted and denied access.
Alternative Location
Check Command: ls -l /system/xbin/sudo:
Result: /system/xbin/sudo: No such file or directory
Analysis: File /system/xbin/sudo does not exist.
Root User ID and Group ID Status:
SU binary not found or not operating properly
System Environment PATH: /sbin /vendor/bin /system/sbin /system/bin /system/xbin
ADB Shell Default User:
ADB shell setting for standard access, stored in default.prop, is configured as: shell (non root) user - ro.secure=1
Results provided on your GT-N7000 device by Root Checker Pro version 1.3.6 from joeykrim in the Android Market
Click to expand...
Click to collapse
And regarding Busybox:
BusyBox has been installed correctly!
System Environment PATH: /sbin /vendor/bin /system/sbin /system/bin /system/xbin
BusyBox binary location:
/system/xbin/busybox
BusyBox binary file information:
-rwsr-xr-x root root 1165484 2008-08-01 13:00 busybox
Installed BusyBox Version:
1.20.2-linusyang
BusyBox supports the following applets:
[, [[, acpid, adjtimex, ar, arp, arping, ash, awk, base64, basename, bbconfig, beep, blkid, blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cttyhack, cut, date, dc, dd, deallocvt, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dumpleases, echo, ed, egrep, env, envdir, envuidgid, ether-wake, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flash_lock, flash_unlock, flashcp, flock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, grep, groups, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifup, inetd, init, inotifyd, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, less, linuxrc, ln, loadkmap, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.reiser, mkfs.vfat, mknod, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mv, nameif, nanddump, nandwrite, nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, od, openvt, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pstree, pwd, pwdx, raidautorun, rdate, rdev, readlink, readprofile, realpath, reboot, reformime, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setconsole, setkeycodes, setlogcons, setserial, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, tune2fs, ubiattach, ubidetach, ubimkvol, ubirmvol, ubirsvol, ubiupdatevol, udhcpc, udhcpd, udpsvd, umount, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, volname, watch, watchdog, wc, wget, which, whoami, whois, xargs, xz, xzcat, yes, zcat, zcip
Results provided on your GT-N7000 device by Root Checker Pro version 1.3.6 from joeykrim in the Android Market -
Click to expand...
Click to collapse
Any help or ideas would be much appreciated, and thanks in advance!

[Q] Problem starting own script from init.rc

Hello,
I am having some trouble running a script at boot started with init.rc:
I have added the following to the init.rc
Code:
service custom-init /system/bin/init.custom
class main
user root
group root
oneshot
The file exists and has executable rights:
Code:
ll /system/bin/init.custom
-rwxr-xr-x root root 645 2008-08-01 14:00 init.custom
If I execute the file from the shell everything works fine. What am I doing wrong? Needs the started script to be a binary?

Cannot delete files/folders from internal memory

Hey everyone!
I recently installed the Google Pixel Launcher as a system app using Solid Explorer by installing it normally, then moving the app's folder from /data/app to /system/app and setting the folder's permissions to: Owner - Read/Write/Execute Group - Read/Execute Global - Read/Execute (755 - drwxr-xr-x) and the base.apk file to: Owner - Read/Write Group - Read Global - Read (644 -rw-r--r--) Now I can't seem to delete any files in the user internal storage space. I can however delete them if I browse there directly from /data/media/0. I imagine this is because I'm using root privileges when I navigate there directly. I'm pretty sure this is a simple permissions issue, but I honestly know little about permissions, and was only following the guide here. Can anyone give me a hand in sorting this mess out? Thanks in advance!
Let's see if I can make any sense here
First, Android is a flavor of Linux. So I'm going to talk about Linux permissions, but it applies equally to Android.
The groups (Linux term) that have access are dependant on which mount point you are accessing the internal storage from. Each directory/file has an owner and a group. Linux permissions address privileges for: owner, group, all users. The permissions for each look like: rwx. So when you look at a complete permission string it might look like:
rwxrwxrw
That's three sets of read, write, execute. If only the owner has full permissions, and the group has partial permissions, and all users have no permissions it might look like:
-rw-rw----
The very first character in that example is a "-" so I know it's not a directory. If it was a directory, the first character would be a "d". With the same permissions it would look like:
drw-rw----
Here are some examples of the same directory and file in the internal storage, but reached via different mount points. Inside a terminal app on your device, if you type "ls -al" in each of these directories, you should see something similar.
The owner and group are also indicated in a directory listing. In the first example, the owner is root and the group is sdcard_rw.
A final thing, in each example, the first line ends in a single dot "." and the second line in a double "..". The single represents the current directory you are in and the double the current directory's parent.
/storage/emulated
drwxrwx--x 50 root sdcard_rw 4096 2017-06-12 19:06 .
drwx--x--x 4 root sdcard_rw 4096 2016-06-13 19:22 ..
drwxrwx--x 6 root sdcard_rw 4096 2016-09-20 10:45 Android
-rw-rw---- 1 root sdcard_rw 629591 2017-05-27 13:17 image.jpg
Click to expand...
Click to collapse
/data/media/0
drwxrwx--- 50 media_rw media_rw 4096 2017-06-12 19:06 .
drwxrwx--- 4 media_rw media_rw 4096 2016-06-13 19:22 ..
drwxrwxr-x 6 media_rw media_rw 4096 2016-09-20 10:45 Android
-rw-rw-r-- 1 media_rw media_rw 629591 2017-05-27 13:17 image.jpg
Click to expand...
Click to collapse
/sdcard
drwxrwx--x 50 root sdcard_rw 4096 2017-06-12 19:06 .
drwx--x--x 4 root sdcard_rw 4096 2016-06-13 19:22 ..
drwxrwx--x 6 root sdcard_rw 4096 2016-09-20 10:45 Android
-rw-rw---- 1 root sdcard_rw 629591 2017-05-27 13:17 image.jpg
Click to expand...
Click to collapse
So now my question in your case is, what does a directory listing (ls -al) of /sdcard look like in your device? If it's different than my - very abbreviated - example, then you have a permissions problem.
ktmom said:
Let's see if I can make any sense here
First, Android is a flavor of Linux. So I'm going to talk about Linux permissions, but it applies equally to Android.
The groups (Linux term) that have access are dependant on which mount point you are accessing the internal storage from. Each directory/file has an owner and a group. Linux permissions address privileges for: owner, group, all users. The permissions for each look like: rwx. So when you look at a complete permission string it might look like:
rwxrwxrw
That's three sets of read, write, execute. If only the owner has full permissions, and the group has partial permissions, and all users have no permissions it might look like:
-rw-rw----
The very first character in that example is a "-" so I know it's not a directory. If it was a directory, the first character would be a "d". With the same permissions it would look like:
drw-rw----
Here are some examples of the same directory and file in the internal storage, but reached via different mount points. Inside a terminal app on your device, if you type "ls -al" in each of these directories, you should see something similar.
The owner and group are also indicated in a directory listing. In the first example, the owner is root and the group is sdcard_rw.
A final thing, in each example, the first line ends in a single dot "." and the second line in a double "..". The single represents the current directory you are in and the double the current directory's parent.
/storage/emulated
/data/media/0
/sdcard
So now my question in your case is, what does a directory listing (ls -al) of /sdcard look like in your device? If it's different than my - very abbreviated - example, then you have a permissions problem.
Click to expand...
Click to collapse
Screenshot attached.
cfhsncb said:
Screenshot attached.
Click to expand...
Click to collapse
There doesn't seem to be anything wrong there. If you can reproduce the problem, try capturing a logcat and see if it gives a clue.
ktmom said:
There doesn't seem to be anything wrong there. If you can reproduce the problem, try capturing a logcat and see if it gives a clue.
Click to expand...
Click to collapse
Yeah, I had been messing around with the permissions based on the information in your post before I took that screenshot. I think I have everything working now, and if it looks good to you, I'm just going to roll with it.

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

Categories

Resources