yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] defiant07:
Sorry...headache, lol

Quick fix would be to delete lines 56-59:

if [ "$(busybox id)" = "uid=0(root) gid=0(root)" ]; then echo " Gnarly, running as root."; echo; sleep 3
else echo " Not Running as Root - No Swap for You!"
echo " Bye :p."; exit 69
fi

what output do you get from: su -c busybox id???
[Android Software/Hacking General [Developers Only]] famewolf:
I'll try it in a bit. I backed off the nightly to the CM10.1 SR1.1 to see if it made a difference. Gotta get mount2sd working first before I can get to the swapfile. ;)
[Android Software/Hacking General [Developers Only]] famewolf:
Well the good news is I got the latest stable release of cm10.1 installed and mount2sd working....moving on to trying for swapfile.....and here's a new one on me....root is enabled for adb and apps in settings.

shell@android:/ $ su

Permission denied

Any thoughts? Run fix permissions from recovery?

---------- Post added at 10:34 PM ---------- Previous post was at 10:11 PM ----------

Fix permissions resolved the su issue....

Okay, first gunna make sure busybox has the

required applets, that you are running as

root, that /etc/init.d exists, and that your

kernel supports swap.

Boss, busybox is complete.

Not Running as Root - No Swap for You!

Bye :p.

69|shell@android:/ # whoami

root

shell@android:/ # busybox id

uid=0(root) gid=0(root) groups=1003(graphics),1004(input),1007(log),1009(mount),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats)

The script ran fine after I commented out your root check. ;) Maybe you should just use "whoami" = root

---------- Post added at 11:15 PM ---------- Previous post was at 10:34 PM ----------

If the swapfile is missing your script does "dd if=/dev/zero of=/sd-ext/swapfile bs=1048576 count="

Is the count= supposed to be blank? It doesn't look right.
[Android Software/Hacking General [Developers Only]] defiant07:
thanks...guess some versions of id print all the supplementary stuff too. I think what I will do is use the -u switch, so it should just return a zero.

umm....no...if a swapfile is not detected it does:

dd if=/dev/zero of=$storage/swapfile bs=1048576 count=$desiredsize [B]2>&1 | sed 's/^/ /'[/B]

which it what it has always done with the exception of the stuff at the end in bold that just redirects stuff to standard out and indents the standard out one space.

post a screen shot or something if count is blank you should get some error.
[Android Software/Hacking General [Developers Only]] famewolf:
shell@android:/etc/init.d $ cat Z99SwapOn
#!/system/bin/sh

# This script was authored by Defiant07 @ XDA. If you use/redistribute it, even in an altered form, please give proper credit.
# Thanks to zeppelinrox most of all, but also many thanks to dk_zero-cool & gu5t3r @ XDA for the super-mega-ultra-refined functional while loop & if statement, which helps avoid bootloops.
# Read Karl Marx!

swappin_time(){
while [ ! "`ps | grep -m 1 [a]ndroid`" ]; do sleep 10; done
if [ ! -f "/sd-ext/swapfile" ]; then
dd if=/dev/zero of=/sd-ext/swapfile bs=1048576 count=
sleep 30
mkswap /sd-ext/swapfile
fi
LOG=/data/Ran_SwapOn.log
echo " Time To Get Our SwapOn!!!" > $LOG
echo "" >> $LOG
swapon /sd-ext/swapfile
echo "$(cat /sd-ext/swappinessvalue.txt)" > /proc/sys/vm/swappiness
accramkb=`awk '/MemTotal/{print $2}' /proc/meminfo`
if [ "$accramkb" -lt "524288" ]; then
busybox sysctl -e -w vm.dirty_background_ratio=20
busybox sysctl -e -w vm.dirty_ratio=40
elif [ "$accramkb" -lt "1049776" ];then
busybox sysctl -e -w vm.dirty_background_ratio=25
busybox sysctl -e -w vm.dirty_ratio=50
else
busybox sysctl -e -w vm.dirty_background_ratio=30
busybox sysctl -e -w vm.dirty_ratio=60
fi
busybox sysctl -e -w vm.vfs_cache_pressure=10
busybox sysctl -e -w vm.dirty_writeback_centisecs=3000
busybox sysctl -e -w vm.dirty_expire_centisecs=1500
echo " ##########################################################################" >> $LOG
echo " #>>>>>>>°•°•°•[{[{Defiant07's SwapOn Verification!?!?!?!}]}]•°•°•°<<<<<<<#" >> $LOG
echo " ##########################################################################" >> $LOG
echo "" >> $LOG
echo " Swappy Swap Swappin' Swappiness: $(cat /proc/sys/vm/swappiness)" >> $LOG
echo " SwapOn@: $(date +"%r %Y.%m.%d")" >> $LOG
echo "" >> $LOG
echo " Dirty Background Ratio: $(cat /proc/sys/vm/dirty_background_ratio)" >> $LOG
echo " Dirty Ratio: $(cat /proc/sys/vm/dirty_ratio)" >> $LOG
echo " VFS Cache Pressure: $(cat /proc/sys/vm/vfs_cache_pressure)" >> $LOG
echo " Dirty Writeback Centisecs: $(cat /proc/sys/vm/dirty_writeback_centisecs)" >> $LOG
echo " Dirty Expire Centisecs: $(cat /proc/sys/vm/dirty_expire_centisecs)" >> $LOG
echo "" >> $LOG
free | sed 's/^/ /' >> $LOG
echo "" >> $LOG
echo " ##########################################################################" >> $LOG
exit 0
}
if [ "`ps | grep -m 1 [a]ndroid`" ]; then swappin_time
else exec > /data/BootLog_SwapOn.log 2>&1
swappin_time &
fi
exit 0

To recreate scenario just pick /sd-ext as a custom location and have a swapfile already exist (512mb). Looks like you only check for 512mb memory or 1GB memory....you should probably have 768mb(my desire has this)...not to mention 256 and 128 are the one's that would need your script the most. Also memtotal doesn't always give the results you expect...for example on my desire:

shell@android:/ $ cat /proc/meminfo
MemTotal: 605968 kB
[Android Software/Hacking General [Developers Only]] defiant07:
Ahh you were talking about the init.d script...thanks for noticing that minor bug (it is not a big deal and should not cause any issues as it is just a precaution should the user accidentally delete the swapfile). Actually to recreate the bug you just have to skip the creation of the swapfile and since desiredsize is never inputted it ends up as a blank in the init.d script...if ya wanna play along and fix the issue before the next update, make a new line 286 and add this:

desiredsize=`busybox du -m $storage/swapfile | awk '{ print $1 }'`

and if ya wanna fix the root check replace the old one you commented out with this:

if [ "`busybox id | awk '/\<0\>/&&/\<root\>/'`" ]; then echo " Gnarly, running as root."; echo; sleep 3
else echo " Not Running as Root - No Swap for You!"
echo " Bye :p."; exit 69
fi

Regarding the ram stuff: I gave up trying to find the real total ram since the grepping of dmesg test you helped me with failed...did more research and found there are quite a few kernels that never print that information, thus it became pointless to search for a universal method of getting the real total ram. Since there is no universal means of getting real ram I ended up using the accessible ram, which is a reasonable proxy being that less than is used.

Since the desire is 768mb that kind of figure (about 600mb) would be expected.

I could add further gradations for 256 and 128 mb devices to my middle-ground values, but I doubt adding settings specific for 768mb devices would be worthwhile being that 512 mb gets 20/40 and 1 gb gets 25/50...doubt adding 23/45 for 768 mb would make much of a difference.
[Android Software/Hacking General [Developers Only]] famewolf:
I might be willing to test further in future but currently talking in the obackup thread to find out why all 3 of my backups of "data" partition were "bad" and failed on restore.....so not wanting to monkey with the system more than I have to.
[Android Software/Hacking General [Developers Only]] defiant07:
understandable...sorry to hear it...gl and have fun with that :p

no real need to test...I am confident that both the fixes will work...the only reason the root check could be flawed now is if the output of some versions of "busybox id" do not return '0' and 'root' on the same line when running as su...the reason I did not upload a new fix version is I have been toying with the busybox test...been trying to find an awk or grep exact match syntax that uses the variable from a for loop as a regex pattern...beginning to think it is futile effort like the real total ram thing :crying:.
[Android Software/Hacking General [Developers Only]] zeppelinrox:
Like this?

for i in awk cat chmod clear dd df echo free grep id mkdir mkswap mount ps rm sed sleep swapoff swapon sysctl poo; do
if [ ! "`busybox | awk '/\t'$i',| '$i',/'`" ]; then echo " Bad Busybox - No Swap for You!"; echo " You are missing $i...Bye :p."; exit 69; fi
done

It searches $i followed by a comma (,) and preceded by either a tab or a space

My output...

Bad Busybox - No Swap for You!
You are missing poo...Bye :p.

edit.... ooo... even better...

for i in awk cat chmod clear dd df echo free grep id mkdir mkswap mount ount ps rm sed sleep swapoff swapon sysctl; do
if [ ! "`busybox | awk '/[^a-zA-Z]'$i',/'`" ]; then echo " Bad Busybox - No Swap for You!"; echo " You are missing $i...Bye :p."; exit 69; fi
done

This one searches for $i then a comma and excludes any preceding letter ;)

Output...

Bad Busybox - No Swap for You!
You are missing ount...Bye :p.

There is mount of course but erred on "ount" :D

argh... edit 3!

for i in awk cat chmod clear dd df echo free grep id mkdir mkswap mount ount ps rm sed sleep swapoff swapon sysctl; do
if [ ! "`busybox | grep "[^a-zA-Z]$i,"`" ]; then echo " Bad Busybox - No Swap for You!"; echo " You are missing $i...Bye :p."; exit 69; fi
done

Same logic but cleaner and better than edit 2 because it works with toolbox's grep whereas rom's often don't have awk.

Output is the same... it don't like "ount"

Bad Busybox - No Swap for You!
You are missing ount...Bye :p.
[Android Software/Hacking General [Developers Only]] hoholee12:
Umm.. I never have seen any applets that has a capital letter for a name:confused:

Why A-Z?
[Android Software/Hacking General [Developers Only]] zeppelinrox:
That's just standard regex form for finding any letters.

Not likely that there would be any capitals of course but it would eliminate the likelihood of any hits in the BB description in the future.

Stranger things have happened :p
[Android Software/Hacking General [Developers Only]] defiant07:
after hours of playing with grep, awk, and sed I found a solution to using and exact matching a variable from a for loop in an if statement - it is find (I found the find solution :p)...it is heavily based off [MENTION=4629194]LENAROX[/MENTION]'s code from THIS...it is basically a trimmed down and imo better test because it is more precise...at any rate here is is:

cmdls="awk cat chmod clear dd df du echo find free grep id mkdir mkswap mount ps rm sed sleep swapoff swapon sysctl"
if [ "`busybox`" ]; then
for i in $cmdls; do
bbloc=$(dirname $(which busybox))
if [ "`busybox find $bbloc -name $i`" ]; then
alias $i="busybox $i"
echo " Righteous, found $(find $bbloc -name $i)."
else
echo " Bad Busybox - No Swap for You!"; echo " You are missing $i...Bye :p."; exit 69
fi
done
echo " Boss, busybox is complete."
else
echo " No Busybox - No Swap for You!"; echo " Install busybox and try again...Bye :p."; exit 69
fi

it works like a champ...feel free to update your github code if ya wanna use any of my solutions...no credits needed, although it would be appreciated :D.

=====EDIT=====

I am curious why search for mount and ount??? nvm...it was a test..duh
[Android Software/Hacking General [Developers Only]] zeppelinrox:
I did time it (created 2 functions and did "time function") and the regex grep is much faster - after all, it only has to search an output screen for text instead of physically searching for files with find.

It can be sped up tho - you don't really need to do "bbloc=$(dirname $(which busybox))" 20+ times, do you?

I don't think bbloc is gonna change :p

That was to show, for example, that lzcat won't be a match if searching for cat.
[Android Software/Hacking General [Developers Only]] defiant07:
Nice...I did not do as technical of a test, but the speed difference is definitely noticeable...I will integrate your solution :).

lol, it did not occur to me to move it out of the if statement, but yeah that was pretty dumb :eek:.

Yeah, I figured it out and edited my post as you were posting...as usual I spoke before I thought and I am a dollar short and two steps behind, lol :rolleyes:.
[Android Software/Hacking General [Developers Only]] defiant07:
Uploaded v9_fix2...fully fixed...hopefully :fingers-crossed:.
[Android Software/Hacking General [Developers Only]] psyntific:
Still does not detect root mate... Wat can I do... use 9.0 cuz that worked
[Android Software/Hacking General [Developers Only]] famewolf:
Why don't you try providing the same info I did....a cut and paste of it failing followed by the "whoami" command followed by "busybox id" command.
[Android Software/Hacking General [Developers Only]] zeppelinrox:
Some output will only have a 0 without ”root” in the output
[Android Software/Hacking General [Developers Only]] famewolf:
OT

zeppelinrox,

Any chance in future of either updating the web patcher to current or providing a patch method for linux? adb access is available so the usual pull/push commands are available. Feel free to PM me if you need a tester.....the constant need to access a windows laptop to patch rom's as I update them is the only thing holding me back from running V6 on all my devices.

OT

psyntific, you can also do what I did which is put a # sign in front of lines 56-59 (beginning with the if and ending with the "fi") to comment out the check.
[Android Software/Hacking General [Developers Only]] defiant07:
Sorry man...but this is quite odd being that if v9 worked v9_fix2 should work because v9_fix2 is actually more general it just searches for 0 and root on the same line...v9 demanded "uid=0(root) gid=0(root)".

Do you get any error messages? If no, post the output of su -c busybox id

If you are comfortable editing the script you could delete or comment out lines 49-52:

if [ "`id | awk '/\<0\>/&&/\<root\>/'`" ]; then echo " Gnarly, running as root."; echo; sleep 3
else echo " Not Running as Root - No Swap for You!"
echo " Bye :p."; exit 69
fi

If you want to try to fix it change the && in first line to ||

lines changed being that I changed the busybox test...it is now lines 49-52.

Should have known ya used a logical or in V6 for good reason...I am surprised I didn't see any bad root check posts in other scripts that used logical and.
[Android Software/Hacking General [Developers Only]] psyntific:
su -c busybox id

Gives uid=0 gid=0

Edit; tried changing && to ||

Result:

==============================================

Hi. Thanks for using...

//----------------------------------------//

// Defiant07's SwapItOn //

//----------------------------------------//

Hope you like it!

==============================================

Okay, first gunna make sure busybox has the

required applets, that you are running as

root, that /etc/init.d exists, and that your

kernel supports swap.

Boss, busybox is complete.

Not Running as Root - No Swap for You!

Bye :p.
[Android Software/Hacking General [Developers Only]] defiant07:
Very odd...given your output from the id command changing the and (&&) to an or (||) should have fixed the problem...what is even odder is that v9 should NOT have worked for you either. Have you changed your busybox version recently? Also, although I doubt this is the case, but just to make sure, you are running the script with superuser permission right?

I am thinking your awk might be messed up in that it does not like the exact match syntax.

Please try these commands:

su -c busybox id | awk /0/

and

su -c busybox id | awk '/\<0\>/'

Although I doubt this will happen, if the first one returns nothing the problem is your awk is totally messed up; in which case the solution would be to install another busybox that properly implements awk. If the first one returns output and the second one does not, your version of awk does not like the exact match syntax I used and I will work to find a more universal root check method.

sorry again and thanks
[Android Software/Hacking General [Developers Only]] psyntific:
The first command gives the same result uid=0 gid=0
[Android Software/Hacking General [Developers Only]] zeppelinrox:
Actually, I test without need for busybox...

id=$(id); id=${id#*=}; id=${id%%[\( ]*}
if [ "$id" = "0" ] || [ "$id" = "root" ]; then echo " Nice! You're Running as Root/SuperUser!"; fi

id is likely everytime equal to 0 and the "|| root" part is probably not even needed but I put it just in case "uid=root"

The magic of id=${id#*=} - removes everything up to and including the first = sign

"uid=0 gid=0" becomes "0 gid=0"

"uid=0(root) gid=0(root)" becomes "0(root) gid=0(root)"

The magic of id=${id%%[\( ]*} - removes first space or ( and everything after them (technically, the %% removes everything up to and including either instance starting from the end of the string.)

"0 gid=0" becomes 0

"0(root) gid=0(root)" becomes 0

If id is "uid=root gid=root" or even "uid=root(0) gid=root(0)" it would still work since I did add the || root to the condition lol
[Android Software/Hacking General [Developers Only]] defiant07:
I assume the second command returned nothing...I will switch to Zep's root check method from V6 and upload a fix in the near future...thanks and apologies for any inconveniences

I was hoping calling bb would standardize the output; obviously I was wrong. I find it astounding that it is such a pita to get precise matches...you would think those ever so logical brainiacs that designed this stuff would have some sort of simpler method for doing what seems to me to be such a basic and critical function.

Thanks for the explanation...I actually ran V6 in debug last night to try and get an idea of how the root check worked...despite all this I must still admit the usage of special characters/operators (<< not sure those are the correct technical terms, but you get my meaning I think) in pattern matching and text manipulation is still a fairly mysterious subject to me :confused:.

I will switch to your method :good:...if ya can't beat 'em, copy 'em, lol :p.
[Android Software/Hacking General [Developers Only]] zeppelinrox:
Ya I was surprised that there was no easy way.

You'd be surprised at how long it took for me to figure out a fool proof way lol

BTW you won't be the first to borrow it but at least you apply credit liberally :p
[Android Software/Hacking General [Developers Only]] defiant07:
They say the third time is a charm...Uploaded v9_fix3...busybox and running as root check methods should be universal.

ahh a bit of irony (reposting a meme about reposts)...also does using the same image with different text for a second time make it any funnier?...probably not, lol :p​
[Android Software/Hacking General [Developers Only]] psyntific:
Works perfectly now... thanks mate
[Android Software/Hacking General [Developers Only]] defiant07:
Nice...finally, lol :laugh:.

Thanks for the reports and feedback.
[Android Software/Hacking General [Developers Only]] inunxelex:
how to enable ram swap (swapit) with modified vold.fstab ?

dev_mount sdcard /storage/sdcard1 14 /devices/sdi4/mmc_host/mmc1/mmc1

dev_mount ext_card /storage/sdcard0 auto /devices/sdi3/mmc_host/mmc3/mmc3

dev_mount usbdisk /storage/usbdisk auto /devices/platform/musb-ux500.0/musb-hdrc

in file manager real sdcard(external) is /storage/sdcard0 and internal card is /storage/sdcard1, but in cwm 5 real sdcard(external) as ext_sd and internal card as sdcard, i got boot loop using custom path /sdcard or /storage/sdcard0
[Android Software/Hacking General [Developers Only]] defiant07:
Hmmm...I too use the vold.fstab switch trick, but obviously without issue. Not really sure why your device does not like it. And I am really not sure why you get boot loops either being that the init.d script waits until android is loaded before it runs, thereby avoiding boot loops.

When you use /sdcard or /storage/sdcard0 do you get any swapon or swapoff errors when running swapit to set things up?

Its a long shot, but was /data/BootLog_SwapOn.log ever created? If so it should contain any error messages.

Are you running jelly bean? It maybe an issue with the way jb mirrors data in multiple locations...maybe try /data?
[Android Software/Hacking General [Developers Only]] inunxelex:
yes.... its working using data, but harmfull when i do full wipe/reset data, xperia sola running unofficially jelly bean 4.1.2 :D

after using this my dumb scripts in init.d :

#!/system/bin/sh

sleep 60

echo "1 where is my sdcard ?" >> /mnt/sdcard/sdtest.log

echo "2 where is my sdcard ?" >> /ext_card/sdtest.log

echo "3 where is my sdcard ?" >> /sdcard/sdtest.log

echo "4 where is my sdcard ?" >> /storage/sdcard0/sdtest.log

echo "5 where is my sdcard ?" >> /storage/sdcard1/sdtest.log

my dumb scripts its working on real sdcard, here is the result :

1 where is my sdcard ?

3 where is my sdcard ?

4 where is my sdcard ?

the main problem is waiting sdcard to be mounted after 60sec sleep :D
[Android Software/Hacking General [Developers Only]] defiant07:
Was /data/BootLog_SwapOn.log ever created??? In addition to showing error messages it would also show if the init.d script tried to make the swapfile due to it not being detected.

Ummm...this give me an idea...I think what maybe causing the problem is that the swapfile is not being detected because your "real sdcard" is not getting mounted soon enough. If ya feel like experimenting and assuming you got no errors when setting things up on /sdcard, try again with /sdcard and after creating everything, in Z99SwapOn added the line in bold:

swappin_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
[B]sleep 60[/B]
if [ ! -f "$storage/swapfile" ]; then
dd if=/dev/zero of=$storage/swapfile bs=1048576 count=$desiredsize
sleep 30
mkswap $storage/swapfile
fi

it's kinda a shot in the dark, but if your test script works with the delay, maybe swapit will too :fingers-crossed:.

===edit===

Maybe also delete that entire if statement (i.e. the five lines that follow the added sleep 60 command)...that way it won't attempt to make the swapfile just in case this is the problem and that sleep 60 is not long enough.
[Android Software/Hacking General [Developers Only]] inunxelex:
its worked on /data partition, but on sdcard im never saw it, coz my sola got boot loop, this metode from other forum is working fine :D

http://androidforums.com/boost-mobile-warp-all-things-root/610449-ram-swapping-without-swapper2.html
[Android Software/Hacking General [Developers Only]] defiant07:
If that method works on /sdcard for you, then the problem is almost definitely that your real sdcard it not getting mounted soon enough. Making the edit I suggested in my previous post (adding the sleep 60 command to Z99SwapOn) should (I am 99.99% confident) resolve your issues.

===EDIT===

Another solution would be to use swapit to set things up on /sdcard and then make a new init.d script:

#!/system/bin/sh

while [ 1 ]; do
if [ -f "/mnt/sdcard/swapfile" ]; then
exit 0
else
sleep 10
fi
done

run this script at lower priority and it should build in enough delay before Z99SwapOn gets run for it to detect the swapfile.
[Android Software/Hacking General [Developers Only]] inunxelex:
damn... quartet same lines :((

swappin_time(){

while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done

sleep 60

...

thanks, its worked now, please add some sleep user configuration for next release :D
[Android Software/Hacking General [Developers Only]] defiant07:
quartet same lines??? not sure what that means...

Nice...you just add the sleep 60 command, right?

Good idea...I will add some sort of sleep configuration option for users who use the vold.fstab switch. thanks for the suggestion.
[Android Software/Hacking General [Developers Only]] inunxelex:
yeah, i must add 4 "sleep 60" text on your script :D