Change hosts file without root? - Nexus 6P Q&A, Help & Troubleshooting

I am thinking of keeping my phone stock given (Android Pay, Security Updates, Work requirements for email/messages). Is there any way to update the hosts file without unlocking the bootloader and installing TWRP? I just want to get rid of the ads as they are soo annoying for non-donate/IAP/Pro-version apps.
Thanks! :fingers-crossed:

Don't Think it is Possible
Unfortunately I do not think that it is possible to adjust the host file without root access. It is in a protected area of the system storage.

Zlatty said:
I am thinking of keeping my phone stock given (Android Pay, Security Updates, Work requirements for email/messages). Is there any way to update the hosts file without unlocking the bootloader and installing TWRP? I just want to get rid of the ads as they are soo annoying for non-donate/IAP/Pro-version apps.
Thanks! :fingers-crossed:
Click to expand...
Click to collapse
There's no way to do this without root access, it's within the /system partition so that says it all really. You don't have to install TWRP, you can live-boot it instead. There's no way around unlocking your bootloader though, plus I'd strongly recommend unlocked it anyway, if something goes wrong with your phone one day and you can't unlock it you're gonna wish you did.

Dang it. I gave non-root a day. It's not for me. Thanks y'all!

can the system.img be modified so that the hosts file is overwritten? when i go in through TWRP and copy an edited hosts file over the one in /system/etc, i can copy it back out and confirm that the file has had its contents changed. but once the device boots up, it acts as if nothing is different.
is it a matter of when the system folder is mounted/read-only?

640k said:
can the system.img be modified so that the hosts file is overwritten? when i go in through TWRP and copy an edited hosts file over the one in /system/etc, i can copy it back out and confirm that the file has had its contents changed. but once the device boots up, it acts as if nothing is different.
is it a matter of when the system folder is mounted/read-only?
Click to expand...
Click to collapse
https://source.android.com/security/verifiedboot/
As far as I understand it, dm-verity will overwrite those changes on boot. Many ROM / Kernels disable it for that reason. Maybe @Heisenberg or someone else can give you a better explanation, though.

Related

Cannot for the life of me get system r/w permissions

I've been running cm7 nightlies and now stable 7.0 for some time now. I have the new radio, ladios' kernel, and the sdcard read fix flashed.
I installed super manager and successfully deleted some of the stock cm7 media off my phone last week. Today, I came across the new GPS.conf files and wanted to try them.
Super manager couldn't switch the system to r/w despite saying "ok"
When I try to delete or write in the system with EStrongs file explorer, ghost commander, or android mate, they all give strange errors. The deleted files disappear but reappear after reboot. If I try to paste a file in system/etc I only get an error.
Superuser is successfully allowing permissions. I have the latest busybox. I have r/w enabled in each file manager.
I even tried an adb push test which first said "system is r/o only". The next try was "successful" but didn't do anything.
I'm still new with adb so I probably did something wrong. I typed in that r/w command, mount now shows: /dev/block/mtdblock3 on /system type yaffs2 (rw,relatime)
I can't figure out what changed and what I need to do to get r/w permissions. My only theory is that i had uninstalled and reinstalled super manager earlier and that somehow messed with my permissions.
You cannot permanently modify the system partition while the phone is booted into Android. The only way is to use adb while the phone is in recovery mode. Any changes you make while the phone is booted will be lost after a reboot.
Go check on those media files you thought you deleted. I bet you'll find they are still there.
Yes that worked. Thank you.
I thought I had read somewhere that you had to be booted to adb push.
I also thought that root managers advertising r/w capability would make permanent changes.
Next question:
Can I add and remove files from the cm7 zip before flashing it? Do I have to rezip it in any special or can windows 7 manage it fine?
EDIT: Ok I guess i need to sign it... lets see...
jamus28 said:
Yes that worked. Thank you.
I thought I had read somewhere that you had to be booted to adb push.
I also thought that root managers advertising r/w capability would make permanent changes.
Next question:
Can I add and remove files from the cm7 zip before flashing it? Do I have to rezip it in any special or can windows 7 manage it fine?
EDIT: Ok I guess i need to sign it... lets see...
Click to expand...
Click to collapse
You don't need to sign them on the aria
Sent from my Liberty using XDA App
jamus28 said:
Yes that worked. Thank you.
I thought I had read somewhere that you had to be booted to adb push.
I also thought that root managers advertising r/w capability would make permanent changes.
Click to expand...
Click to collapse
Those programs will work on some phones but not the Aria.
Next question:
Can I add and remove files from the cm7 zip before flashing it? Do I have to rezip it in any special or can windows 7 manage it fine?
EDIT: Ok I guess i need to sign it... lets see...
Click to expand...
Click to collapse
It really is as simple as adding or removing a few files from the zip file if you want to modify it.

pre-rooted stock 6.2.1 update

See: http://forum.xda-developers.com/showthread.php?t=1402440
Sorry - don't have enough posts to reply directly in the dev tree, but it would seem to me that if all the updates are just zip files, couldn't they be modified to include root? Then the normal update system would handle the installation? You wouldn't need root then.. Just dump it into the "kindleupdates" folder and let it do its thing. It would just install it.
It looks like the install is just running a script.. one of the first things it does is wipe the system folder.. doesn't mean you can't include additional files and copy them in afterwards with the script does it?
AndrewTL said:
See: http://forum.xda-developers.com/showthread.php?t=1402440
Sorry - don't have enough posts to reply directly in the dev tree, but it would seem to me that if all the updates are just zip files, couldn't they be modified to include root? Then the normal update system would handle the installation? You wouldn't need root then.. Just dump it into the "kindleupdates" folder and let it do its thing. It would just install it.
It looks like the install is just running a script.. one of the first things it does is wipe the system folder.. doesn't mean you can't include additional files and copy them in afterwards with the script does it?
Click to expand...
Click to collapse
You need to go through all the lines of code for that and I believe some of them are binary files as well. Possible but will take much time. For now we must wait until someone finds a better solution.
Sent from my Kindle Fire using Tapatalk
signature issues.
6.2.1 experiment?
transfuntioner said:
signature issues.
Click to expand...
Click to collapse
Maybe I don't follow the process.. but I'm guessing no signatures..
not a signed bootloader.. no signatures required...
Get beyond compare and look at the differences between the OTA updates and the zip that Eldarerathis put together.
The ".bin" files are just ".zip" files renamed.
Look at
META-INF/com/google/android/updater-script in the bin files they release.
It is just a script.
And to do the things that it is doing, it has to be getting root permissions while it is running.
I don't know how to recover if it doesn't work, but I half wonder if you were to take the zip that fellow created, change the extension to ".bin" and just dump it into the update folder if the fire would install it for you?
He took out the image files from the script. He's just updating the system tree directly. He doesn't update the bootloader, recovery or backup trees.
For that matter if those contained something nasty, they could probably be pulled from an earlier update.
== cut ===
package_extract_file("recovery.img", "/dev/block/platform/mmci-omap-hs.1/by-name/recovery");
show_progress(0.100000, 10);
package_extract_file("u-boot.bin", "/dev/block/platform/mmci-omap-hs.1/by-name/bootloader");
format("ext4", "EMMC", "/dev/block/platform/mmci-omap-hs.1/by-name/backup");
mount("ext4", "EMMC", "/dev/block/platform/mmci-omap-hs.1/by-name/backup", "/backup");
package_extract_file("backup_userdata.zip", "/backup/backup_userdata.zip");
== cut ===
Please nobody try this idea that doesn't know enough to recover if it doesn't work, because I've not a clue how.
But could someone explain why wouldn't it work?
Worst case the rev might need to be manually edited to bump it one for the script.
Seems like it might be an easy way to get around headaches with OTA updates.
Andrew,
Are you having issues with getting into recovery so that you can test this? The Devolopers have a copy of TWRP 2 working perfectly on the device so you can get a clean backup of the OS before you test.
You sound like you may know what to do to fix the issue and I just want to help you get a good recovery in case it doesn't pan out or for testing.
~enjoy.
Actually I'm just afraid of messing up what I have working now.
I've got TWRP 2 running with the 6.2.1 image.
I'm setting these up as gifts. I spent a good 12 hours yesterday fighting the darn things. Guess I'm getting gun shy. Had a lot of issues with adb. Kudos to the new utility and setting the second ports up. I'm learning.
The OTA install wipes the system directory. It's in the script.
I was tempted to just comment that line out and see if it would leave the rest alone.
If I brick the thing its going to be painful for me to sort out.
I also didn't want to risk losing root. I also haven't tried loading an older OTA version.
At the time, I couldn't ask the fellow that developed the rooted 6.2.1 zip the question in his thread as I didn't have enough posts.
I'm going to be out of pocket for quite some time. I'm not going to have time to spend like this again for at least a few days.
But I was checking the zip he made versus the .bin/.zip files that the OTA releases using beyond compare. I wanted to see what files had actually changed.
That's when I found that script. It is manipulating permissions directly. It has to be running at a root level. I don't see anything like a signature on it, so why couldn't their own update system be used to tweak their own updates to allow for root?

[Q] Ads reapearing after Rooting->Building hosts file>Uninstalling Magisk

Hey, I'm having an interesting issue that I haven't seen before on my previous phones. Normally, I'll occasionally flash magisk to root and update my hosts file with Adaway (and several lists that I've added to it which seem to block most/all ads), then unroot my phone. I noticed with the 6T that after I unroot (restore images, then uninstall through Magisk Manager) that the hosts file seems to be restored back to the stock file without any of my blocks. Am I doing something wrong? Thanks!
the00guy said:
Hey, I'm having an interesting issue that I haven't seen before on my previous phones. Normally, I'll occasionally flash magisk to root and update my hosts file with Adaway (and several lists that I've added to it which seem to block most/all ads), then unroot my phone. I noticed with the 6T that after I unroot (restore images, then uninstall through Magisk Manager) that the hosts file seems to be restored back to the stock file without any of my blocks. Am I doing something wrong? Thanks!
Click to expand...
Click to collapse
Without having some type of ramdisk patch in place, like Magisk or custom kernel, the system will default to the stored system image and effectively undo any changes to the /system partition. Any changes to the system partition that you have made will not be there until you install Magisk or a custom kernel again.
So basically with the stock boot image unmodified you cannot make persistent edits on the /system partition from my experience.
Wow, I was not aware that the system started keeping a clean system image like that. Historically I've always been able to modify /system with root and then unroot and the changes would remaim. Since TWRP is part of /boot now, perhaps that would be sufficient to prevent the stock boot from rewriting my /system changes...? Are there any other ways to prevent the system from being restored to stock after unrooting?
the00guy said:
Wow, I was not aware that the system started keeping a clean system image like that. Historically I've always been able to modify /system with root and then unroot and the changes would remaim. Since TWRP is part of /boot now, perhaps that would be sufficient to prevent the stock boot from rewriting my /system changes...? Are there any other ways to prevent the system from being restored to stock after unrooting?
Click to expand...
Click to collapse
As far as I know the phone wont boot with just TWRP installed, you need Magisk as well. So if you don't want to keep Magisk installed I suggest installing only a custom kernel. I personally love Smurf Kernel here (https://forum.xda-developers.com/oneplus-6t/development/kernel-smurfkernel-2-0-49-t3868360). Although I have not tested to see if /system modifications stick with only custom kernel but I feel like they should since it is modifying the ramdisk to allow the phone to boot modified. I know that Smurf Kernel will detect if you have Magisk or not and patch the boot image accordingly. So you will be able to run just a custom kernel without root if this is what you want.
Also if you are not aware you can disable all root access from the Magisk app without having to uninstall anything, maybe that could work for you as well.
Make sure to hit the thanks button if I was able to help you out here!
the00guy said:
Wow, I was not aware that the system started keeping a clean system image like that. Historically I've always been able to modify /system with root and then unroot and the changes would remaim. Since TWRP is part of /boot now, perhaps that would be sufficient to prevent the stock boot from rewriting my /system changes...? Are there any other ways to prevent the system from being restored to stock after unrooting?
Click to expand...
Click to collapse
You could always, edit the partition directly in TWRP and install an alternative host file.
tech_head said:
You could always, edit the partition directly in TWRP and install an alternative host file.
Click to expand...
Click to collapse
The issue is that Android will replace the /system partition with the stored stock system image if you do not have a modified ramdisk. So if you remove Magisk and don't use custom kernel you effectively cannot modify anything on /system as it will not persist.
yerger said:
The issue is that Android will replace the /system partition with the stored stock system image if you do not have a modified ramdisk. So if you remove Magisk and don't use custom kernel you effectively cannot modify anything on /system as it will not persist.
Click to expand...
Click to collapse
Hopefully the community can find a workaround eventually for this that won't replace the /system with a clean image, or find a way to patch the clean image when performing root operations. Some apps can still detect/are broken by magisk, as good as it is, and I hate running any of my phone without ad blocking. I tried going the DNS route, but have yet to find a good private dns provider that oxygen os plays nicely with that also doesn't log.
the00guy said:
Hopefully the community can find a workaround eventually for this that won't replace the /system with a clean image, or find a way to patch the clean image when performing root operations. Some apps can still detect/are broken by magisk, as good as it is, and I hate running any of my phone without ad blocking. I tried going the DNS route, but have yet to find a good private dns provider that oxygen os plays nicely with that also doesn't log.
Click to expand...
Click to collapse
Try using just a custom kernel. You can do that without root and it should prevent /system from being overwritten with the stored system image. The issue is that you need a patched ramdisk in order for the /system partition to boot modified. No way around that unfortunately.
I personally use Smurf Kernel (https://forum.xda-developers.com/one...-0-49-t3868360) and get much better battery life than the stock kernel. The phone is much smoother and snappier as well.
yerger said:
Try using just a custom kernel. You can do that without root and it should prevent /system from being overwritten with the stored system image. The issue is that you need a patched ramdisk in order for the /system partition to boot modified. No way around that unfortunately.
I personally use Smurf Kernel (https://forum.xda-developers.com/one...-0-49-t3868360) and get much better battery life than the stock kernel. The phone is much smoother and snappier as well.
Click to expand...
Click to collapse
Thank you all for the information. It seems I need to read up more on how android pie works behind the scenes particularly with the ramdisk and how the system position is managed.
https://blokada.org/
Non root adblocker, many lists available, DNS change
Or just use Adguard DNS. Works great.

persistant changes to hosts file following reboot?

Hi everyone. I'm scratching my head here and struggling to find a solution that doesn't require root.
I've got a hosts file that I love as it blocks nearly all advert servers on my phone.
I know there are several adblocking apps but they all require root.
I have had to remove root as I have some critical apps that still don;t work, even after hiding magisk from the apps within the Magisk Manager.
I've got a magisk patched image that I can "fastboot boot" with and can edit the hosts file (after remounting /system as rw) but when I then reboot afterwards, the hosts file has been overwritten.
Can anyone help me please or give me a pointer of how to make the hosts edits remain following a reboot?
edit2add
I am using stock ROM with latest August patches on my Mi A1
You can't without root even if you do it your system partition will be modified and it will result in phone not booting or just safetynet won't pass.
Use a vpn or I'm pretty sure there's app that can fake a vpn with a ad ban list
Dead-neM said:
You can't without root even if you do it your system partition will be modified and it will result in phone not booting or just safetynet won't pass.
Use a vpn or I'm pretty sure there's app that can fake a vpn with a ad ban list
Click to expand...
Click to collapse
Interesting idea regarding spoof VPN.
Do you know how the hosts file is generated? If it's copied over from somewhere during boot then could I edit the source file it's copied from?
If it's generated procedurally, might I be able to script it to add my edits during creation?
wodgey said:
Interesting idea regarding spoof VPN.
Do you know how the hosts file is generated? If it's copied over from somewhere during boot then could I edit the source file it's copied from?
If it's generated procedurally, might I be able to script it to add my edits during creation?
Click to expand...
Click to collapse
System partition ? so that's a good idea but you'll have to compile a rom to change this file. On Linux distro the host file is a thing you can modify easily. On android it's just deprecated by google as it's use mostly used as an adfilter. And google is an ad company. That's my guess.
Anyway host file will always need root even on Linux.
Simply because it can be used against you.
The problem is more on apps that blocks you because you're rooted than being rooted for changing this file.
If any app could modify host then bang you go to YouTube and it redirect you to something else.
Maybe for you it's just an adblock file but it's a little more than that.
So sorry but it's root or vpn.
Dead-neM said:
System partition ? so that's a good idea but you'll have to compile a rom to change this file. On Linux distro the host file is a thing you can modify easily. On android it's just deprecated by google as it's use mostly used as an adfilter. And google is an ad company. That's my guess.
Anyway host file will always need root even on Linux.
Simply because it can be used against you.
The problem is more on apps that blocks you because you're rooted than being rooted for changing this file.
If any app could modify host then bang you go to YouTube and it redirect you to something else.
Maybe for you it's just an adblock file but it's a little more than that.
So sorry but it's root or vpn.
Click to expand...
Click to collapse
So? Could I possibly extract the system.img from the stock ROM, make the edits there and then recompile?
(I've got a copy of payload.bin that I extracted a few weeks ago, when trying to flash the August security patches (this was before I did a compete flash of stock ROM using fastboot)
That actually seems like it wouldn't take too much effort
wodgey said:
So? Could I possibly extract the system.img from the stock ROM, make the edits there and then recompile?
(I've got a copy of payload.bin that I extracted a few weeks ago, when trying to flash the August security patches (this was before I did a compete flash of stock ROM using fastboot)
That actually seems like it wouldn't take too much effort
Click to expand...
Click to collapse
This will lead to a corrupt system partition modified. As i said the worse thing is you could not boot and the good just won't pass safetynet.
Dead-neM said:
This will lead to a corrupt system partition modified. As i said the worse thing is you could not boot and the good just won't pass safetynet.
Click to expand...
Click to collapse
Ok I understand.
How does the device 'know' that the system partition is corrupt? Does it perform a hash check perhaps?
How would compiling my own custom ROM avoid this same problem?
wodgey said:
Ok I understand.
How does the device 'know' that the system partition is corrupt? Does it perform a hash check perhaps?
How would compiling my own custom ROM avoid this same problem?
Click to expand...
Click to collapse
It does many thing to know that its have been touched. You'll have to modify some stuff and it will work. You'll loose certification but you'll have you own rom.
Dead-neM said:
It does many thing to know that its have been touched. You'll have to modify some stuff and it will work. You'll loose certification but you'll have you own rom.
Click to expand...
Click to collapse
Any chance you can outline the other stuff I'd need to change?
If it's really in-depth then don't worry but if it's just a few bullet-points that I can Google more info on, I'd appreciate it.
wodgey said:
Any chance you can outline the other stuff I'd need to change?
If it's really in-depth then don't worry but if it's just a few bullet-points that I can Google more info on, I'd appreciate it.
Click to expand...
Click to collapse
Search "dm-verity" and "safetynet". The first one is what will look at any r/o partition like system and kernel. It's been a long time since i dig into this. I'm not into this anymore.
But You can disable it but you'll loose safetynet, encrypted partition etc... (i may be wrong but you got the idea). And safetynet look if partition have been modified and you are a certified device if it won't pass the banking app and apps like Pokemon go etc won't work.
Magisk hide the fact that the kernel img have been touch and most app that detect it detect just the app itself. That means magisk capability (su, hide and module)
So you could maybe compile stock rom with a custom host file. Never touch vendor partition! Make a backup before! By booting and not flashing twrp. Do not flash twrp just use the "fastboot boot command"
You'll need to make a custom kernel and system img to flash in order to do it.
I'll try to do a rom without anything modded except kernel without dm verity and system with your host and i guess it needs change too.
I dunno if it will pass safetynet after.
Just don't brick your phone ?
Keep in mind that you'll loose ota. There's a chance that the rom work with just some changes but i can be a mess to do.
Why not trying a custom rom like lineage os?
Using their supersu zip won't you be able to replace the host file then remove root?
Once you make a backup a move it to a pc as a savestate. You are free to try different solution
Dead-neM said:
Search "dm-verity" and "safetynet". The first one is what will look at any r/o partition like system and kernel. It's been a long time since i dig into this. I'm not into this anymore.
But You can disable it but you'll loose safetynet, encrypted partition etc... (i may be wrong but you got the idea). And safetynet look if partition have been modified and you are a certified device if it won't pass the banking app and apps like Pokemon go etc won't work.
Magisk hide the fact that the kernel img have been touch and most app that detect it detect just the app itself. That means magisk capability (su, hide and module)
So you could maybe compile stock rom with a custom host file. Never touch vendor partition! Make a backup before! By booting and not flashing twrp. Do not flash twrp just use the "fastboot boot command"
You'll need to make a custom kernel and system img to flash in order to do it.
I'll try to do a rom without anything modded except kernel without dm verity and system with your host and i guess it needs change too.
I dunno if it will pass safetynet after.
Just don't brick your phone ?
Keep in mind that you'll loose ota. There's a chance that the rom work with just some changes but i can be a mess to do.
Why not trying a custom rom like lineage os?
Using their supersu zip won't you be able to replace the host file then remove root?
Once you make a backup a move it to a pc as a savestate. You are free to try different solution
Click to expand...
Click to collapse
Thanks for info I'll investigate later in the week when I have more time. Monday has arrived too quickly!
Appreciated though

OP5 upgraded to Android 10 and rooted with Magisk, system changes don't stick

Hi,
Just upgraded my OP5 to Android 10 official stable version. Rooted successfully with Magisk 20.4
Now I'm trying to do some changes to the system folder but they revert back when I reboot.
1- Trying to replace the emoji with another ttf file, as I always did in Pie but the file gets reverted upon restart.
2- Trying to apply hosts file for ad blocking, same issue the file gets reverted as soon as I restart.
it looks like my system partition is reverting itself for some reason, does anyone know why this happens and how to make the changes stick?
PS: I don't want to enable (Systemless hosts in Magisk) because I'm planning to unroot after doing these changes.
thanks..
medo159 said:
Hi,
Just upgraded my OP5 to Android 10 official stable version. Rooted successfully with Magisk 20.4
Now I'm trying to do some changes to the system folder but they revert back when I reboot.
1- Trying to replace the emoji with another ttf file, as I always did in Pie but the file gets reverted upon restart.
2- Trying to apply hosts file for ad blocking, same issue the file gets reverted as soon as I restart.
it looks like my system partition is reverting itself for some reason, does anyone know why this happens and how to make the changes stick?
PS: I don't want to enable (Systemless hosts in Magisk) because I'm planning to unroot after doing these changes.
thanks..
Click to expand...
Click to collapse
Just forget to change hosts file manualy, use the better Adbloacker Rootless, Blokada
medo159 said:
QUOTE
Click to expand...
Click to collapse
Hi Mate,
Ensure to give proper permissions as follows: rw-r--r-- (0644) to the file. If it is a folder, the permissions are: rwxr-xr-x (0755)
medo159 said:
Hi,
Just upgraded my OP5 to Android 10 official stable version. Rooted successfully with Magisk 20.4
Now I'm trying to do some changes to the system folder but they revert back when I reboot.
1- Trying to replace the emoji with another ttf file, as I always did in Pie but the file gets reverted upon restart.
2- Trying to apply hosts file for ad blocking, same issue the file gets reverted as soon as I restart.
it looks like my system partition is reverting itself for some reason, does anyone know why this happens and how to make the changes stick?
PS: I don't want to enable (Systemless hosts in Magisk) because I'm planning to unroot after doing these changes.
thanks..
Click to expand...
Click to collapse
You can't mount the system partition as rw directly in Android 10. Here's a thread by topjohnwu (slightly technical, but give it a read) on why: https://twitter.com/topjohnwu/status/1259039809361739776

Categories

Resources