[Magisk][Module][Deprecated] Unified Hosts Adblocker - Magisk

This mod has since been discontinued in favor of Adaway. Read on for information on how to use Unified Hosts with Adaway
What are Unified Host Files?
Unified host files combine many reputable sources into a single hosts file (with duplicates removed). Some examples include adaway, mvps, yoyo.org, and malware domain list (see Steven Black's page here for a complete list).
Adaway Installation for Magisk:
Adaway version 4.x now works properly with magisk systemless hosts. To enable it, just install the latest version from here (the main xda thread for it hasn't been updated for it yet). Then go to Preferences -> Enable systemless mode. This automatically enables the Systemless hosts option in magisk manager so no need to bother with that. Then use the app as normal.
How to Add Unified Hosts to Adaway:
In the adaway app, go to Preferences -> Redirection IP (NOT Allow Redirects). Change the value to 0.0.0.0. Read the readme on Steven Black's GitHub linked above for why.
Then go to Hosts Sources. Then add the url of the unified hosts you want (ONLY CHOOSE 1):
Master: https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
Master+FakeNews: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts
Master+Gambling: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling/hosts
Master+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts
Master+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts
Master+FakeNews+Gambling: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts
Master+FakeNews+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn/hosts
Master+FakeNews+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-social/hosts
Master+Gambling+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn/hosts
Master+Gambling+Social https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social/hosts
Master+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-social/hosts
Master+Fakenews+Gambling+Porn (This is the one I use): https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts
Master+Fakenews+Gambling+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social/hosts
Master+Fakenews+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn-social/hosts
Master+Gambling+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-social/hosts
Master+Fakenews+Gambling+Porn+social: https://raw.githubusercontent.com/S...lternates/fakenews-gambling-porn-social/hosts
You can then uncheck the host sources already added by default to adaway since they're included in unified hosts sources already
**Note that the 'Social' filter does exactly what you think: blocks social networks. So if you use any kind of social networking, DO NOT CHOOSE THIS ANY SOURCE WITH THIS IN IT**
Using a APN that uses a proxy server or a subsidiary provider and unable to get adblocking working? See here for a fix
Original Mod Information:
Description
Blocks ads by using Steven Black's Unified Hosts
Comes with a small utility based off of LarappsOfDongle's RP modular host module that allows you to choose which kind of host file you want (adware/malware, fakenews, gambling, porn, social, or any combination)
Installation
Go to Settings in Magisk Manager and enable 'Systemless Hosts'
Flash module
Open terminal and type:
Code:
su
hosts
Then follow the prompts to install the host file of your choice.
OR
- Open terminal and type:
Code:
su -c hosts arg1 arg2 arg3
- The script will apply your arguments all at once and close. Useful for automation purposes
- For example: `su -c hosts m wr b`
- Script will apply the master filter, then your regex whitelist, then your blacklist
Updating Hosts:
Just run the hosts file again in terminal and it'll overwrite the old one
Note: The script will now notify you to say if you need to update or not at the top of it
Disabling Host Mod:
Just toggle the enable systemless hosts option in magisk manager
Whitelist Instructions:
Create an empty file on sdcard card called "whitelist"
Either add exact lines you want remove to it -> Run hosts script and choose whitelist option
For example:
Code:
0.0.0.0 facebook.com
Will unblock facebook.com
Or add regex for lines you want removed -> Run hosts script and choose whitelist regex option
For example:
Code:
.*facebook.*
Will unblock all domains with "facebook" in them
Blacklist Instructions:
Create an empty file on sdcard card called "blacklist"
Add exact lines you want to remove it (do not include the 0.0.0.0 -> so for example: "facebook.com")
Run hosts script and choose blacklist option
For example:
Code:
google-analytics.com
Will block the google-analytics.com domain (it will add the entry "0.0.0.0 google-analytics.com" to the hosts file - note the lack of the 0's here. The script takes care of it automatically for the blacklist feature)
To Remove Whitelist:
Just run hosts script and reinstall host file of choice
Latest Magisk Version Compatibility:
15.x
Source
Can't Boot?
Try rebooting into the bootloader, then boot into system. Thanks @rignfool for the tip
Bonus!
I made a quick automate flow to update the hosts file. Just import it, add a shortcut to your home screen, and you can update it in one click
Just change the 2nd block to whatever options you want
@Didgeridoohan made a tasker profile here for any who use tasker: https://forum.xda-developers.com/showpost.php?p=73369050&postcount=451
Download

How does this differ from AdAway?

serubin323 said:
How does this differ from AdAway?
Click to expand...
Click to collapse
The unified hosts file combine many sources including AdAway, mvps, malware domains, and more. Check out steve black's page in the op for a full list.
Also, for some reason, adaway wouldn't detect the systemless hosts file for me so i had to set a custom path and symlink it

Updated module for latest magisk manager update (required changes to the readme). Doesn't change the functionality of the module at all so if you're in 1.1, there's no need to upgrade since these readme changes will only be reflected in magisk manager once this module is approved into the repo.

Damnit... Wrong thread...
OK...
Syntax...
su -c hosts ______
Please fill in the blank...

rignfool said:
Damnit... Wrong thread...
OK...
Syntax...
su -c hosts ______
Please fill in the blank...
Click to expand...
Click to collapse
Code:
su
Give root permissions
Code:
hosts
Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
Code:
fg
The reason for not including the master (adware/malware) in the arguments is that it's already included by default in each host file. So the fakenews host file is actually master + fakenews. It's how steven set it up so I have no control over it (and who wouldn't want the malware block anyways)

Found a typo in the directions for the host file. Once again doesn't effect functionality at all but does eliminate confusion so uploaded fixed version (sorry)

Zackptg5 said:
Give root permissions
Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
Click to expand...
Click to collapse
I'm looking to execute as a one line shell command with tasker...
So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...
Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...

rignfool said:
I'm looking to execute as a one line shell command with tasker...
So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...
Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...
Click to expand...
Click to collapse
I've never used tasker (use automate instead). Perhaps
su -c; hosts; sleep 1; fgps; sleep 2; q
Not sure if the sleep command works for tasker (linux thing) but if there's a way to have it wait a half a second or so before inputting the next command, and then waiting 2 seconds or so to quit after the hosts is applied (not sure on the time, just guessing).
Edit, just saw you didn't want to deal with the script. The 'hosts' command is the script. If you look my source for the hosts script, it lists each url for the file and what it does. So all of the terminal code for fgps would be:
Code:
su -c
cd /magisk/.core
wget -O hosts --no-check-certificate https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
This will replace the systemless hosts file with the one you want. Note you will at least need the wget portion of the module (system/bin) since it's not included in most roms

v1.3 update: Noticed that the disable option was broken so I removed it since it's not needed (see OP for disable instructions)

Using ze551ml, after rebooting, module disappeared. I can't find hosts command anywhere.

danzel said:
Using ze551ml, after rebooting, module disappeared. I can't find hosts command anywhere.
Click to expand...
Click to collapse
Does magisk manager say root is enabled? There's been an ongoing issue where root will disappear and so all modules will disappear as well. This isn't a module issue but a magisk issue

Automating hosts update?
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!

Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
The menu is part of the command line. I don't have tasker however, maybe this post will help: https://forum.xda-developers.com/showpost.php?p=71117156&postcount=9
You can circumvent running the script completely and just wget your host of choice. In that post, I have a link to the source for the hosts file with all of the urls. For fg for example, it would be: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts

Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
As @Zackptg5 says, to automate with Tasker it's easier to just circumvent the script altogether...
I have a Tasker profile set up to fetch the hosts file directly from Steven Blacks GitHub and save it to /magisk/.core/hosts. I couldn't get wget to work properly with Taskers Run Shell, so I used the HTTP Get instead to fetch it to /sdcard and then Run Shell to move it to /magisk/.core/hosts (and to remove it from /sdcard afterwards).

Is there a possibility of whitelists?

ChronoReverse said:
Is there a possibility of whitelists?
Click to expand...
Click to collapse
In theory, you shouldn't need a white list with these hosts files. I chose them because they are gone over with a fine tooth comb so you shouldn't have any issues. However, when I get on spring break, I could attempt to add a whitelist option to the script. I was thinking the easiest way to do this would be to read a text file (would be a blank one in the module folder by default but is editable the uses to add whatever) and remove any matches from the host file. Have any better ideas to implement this? I have no experience with GUI development and that would add unnecessary overhead anyways

Does this module work currently? I disabled adaway and enabled this but it's not blocking ads that adaway blocks.
Testcase: root check by Jrummy
Adaway blocks the in app ads. This module does not
EDIT: apparently I can't read... Lol. Followed the Op and now it works great!

Neat module. It's working great! Thanks for sharing it!

Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
I have a profile set up to do this every 12 hours. If you still need it, I updated it to use your preferred settings and exported it. All you need to do is import it in Tasker (long-press Profiles header) and turn it on.

Related

Adblock Plus on Nook ST: link to last working version & proxy settings guide

The latest versions of Adblock Plus don't work with the Nook. Although they can be installed, they will force-close upon initial start-up (silently if looking just at the UI but with a lot of stuff going on behind the curtains if you read the logcat). I've just reported it as a bug, and it got assigned the nice number #2000 but I expect it will be resolved by marking the APK as unsuitable for the Eclair API level.
So, if you want to use Adblock Plus, the last working version seems to be Adblock Plus 1.1.4.287. It's a development build, as I couldn't find an archive of old stable releases. Download it and install with:
Code:
adb install adblockplusandroid-1.1.4.287.apk
To make Adblock Plus work with the Nook, you need to set a HTTP proxy to address 127.0.0.1 (localhost) port 2020. There are two ways to do it:
This will open a dialog where you can input the above data:
Code:
adb shell am start -n com.android.settings/com.android.settings.ProxySelector
This is totally automatic but a reboot might be required:
Code:
adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) VALUES('http_proxy', '127.0.0.1:2020');"
Adblock Plus does an even better job in conjuction with AdAway, available here. In this case, the last version appears to work just fine.
Please note that you don't have to use ADB, you can also do all this directly from your Nook if you have Terminal Emulator installed.
Steps for installing directly from your Nook:
1. Install Adblock Plus by tapping on it in a file explorer, tapping "Install" and tapping "Done".
2. Set an HTTP proxy to localhost 127.0.0.1 and port 2020 by opening up Terminal Emulator and executing this:
Code:
su
am start -n com.android.settings/.ProxySelector
Then, in the "Hostname" text box, enter 127.0.0.1, and in the "Port" text box, enter "2020". Then tap "Save".
Done! ABP will now work properly.
Is it possible to hide notification message or icon?
kazikas said:
Is it possible to hide notification message or icon?
Click to expand...
Click to collapse
Somewhat OT, but yes, you can do that by making the notifications .png files in framework-res.apk plain black.
PM me for detailed instructions.

Q: /RQ:

Whats the best adblocking host file you've ever used for Mi5 (or any device)
You can share a magisk module if that worked for you, tried a bunch but none worked thanks.
pi4a7a said:
Whats the best adblocking host file you've ever used for Mi5 (or any device)
You can share a magisk module if that worked for you, tried a bunch but none worked thanks.
Click to expand...
Click to collapse
I used adaway... It work with magisk systemless hosts.
Just enable systemless host in magisk setting.
In adaway, don't applying adblock first....
But you need to set target hosts file to "custom target"
and
Set custom target path like attached image.
Some important to used it as systemless is :
- After applying, when it ask to create symlink # select "NO".
- It will show red disabled after applying (because you select to not create symlink) # just relauch adaway or restart your phone better.
- Next time you open adaway it will show green enabled.
- Make sure you do the same (select NO) when update adsblock available and you want to apply update.
UCHIHA said:
I used adaway... It work with magisk systemless hosts.
Just enable systemless host in magisk setting.
In adaway, don't applying adblock first....
But you need to set target hosts file to "custom target"
and
Set custom target path like attached image.
Some important to used it as systemless is :
- After applying, when it ask to create symlink # select "NO".
- It will show red disabled after applying (because you select to not create symlink) # just relauch adaway or restart your phone better.
- Next time you open adaway it will show green enabled.
- Make sure you do the same (select NO) when update adsblock available and you want to apply update.
Click to expand...
Click to collapse
Can you share a link for Adaway or module ?

[MODULE] Aria2 wrapper for android (arm)

# Aria2 wrapper for android
### rms112 @ xda-developers, scripts provided @ GNU GPL 3+ or later. Aria2c binaries are GNU GPL 2+
*A simple download manager shell script using aria2*
### Description
I hated the download managers in android because every one of them is closed source, ads and analytics infested. Aria2 is my favorite tool in GNU/Linux which is available in Android too.
The binary was taken from:
https://github.com/aria2/aria2/releases
This wrapper was written to avoid the hassle of writing commands every time while using aria2. Simply flash from magisk and reboot. Then enter
Code:
download
in a terminal emulator and you're done. I recommend making a profile in connectbot (local) with download + enter key in automation post login command and save that profile as a widget for easy access. See screenshots.
This is very basic script. Since nobody was doing it, I did it myself and I'm not even an android dev. It was for my own use but i hope it will be useful to someone else too. Anyone willing to improve this tool are more than welcome to do so. More features for easy customisation to come later...
Oh and yeah the installer script is based off osm0sis's modules.
--reserved post--
I've never used linux before .. So don't know how to operate it but can you specify steps how to start downloading and specify downloading path and it only support direct link downloading.. Right?
I've termux installed on my Android phone.. And if support would be provided then it'll be best download manager out there.. Your thread looks promising about it..
aria2 is my favorite downloader manager too.
we can use multiple source to accelerate download and you can resume downloading. the advantage using it in terminal it's stable no crash.
big thanks to the developper of this module i'm installing it
adikri said:
can you specify steps how to start downloading and specify downloading path and it only support direct link downloading.. Right?
Click to expand...
Click to collapse
Just enter "download" in any terminal emulator. The location is set to /Download folder on your internal memory. And a bunch of other parameters are set by default for eg : download is resumed by default and you can have up to max 10 connections if supported by server. You can open download from /system/bin and check/edit/add other parameters.
I've termux installed on my Android phone.. And if support would be provided then it'll be best download manager out there.. Your thread looks promising about it..
Click to expand...
Click to collapse
Termux might have aria2 on repository idk but I prefer to use connectbot because of low storage on my phone. Termux takes ~100mb and I don't use anything except ssh which is done easily by connectbot 2mb package. I automate the script by setting 'download + enter' in local connection's post login automation and set that as a widget. Might look confusing but really isn't. Here's a video demonstration. (16 sec) https://my.mixtape.moe/tzpyzw.mkv
Some screenshots for connectbot settings.

[MODULE HELP] How to execute a script only once when module is installed/uninstalled?

The question title can't be much longer but I basically need to execute a script only once when each of the following events happen:
Module is installed.
Module is uninstalled.
Module is enabled.
Module is disabled.
In other words:
When the user first installs my module, I need to execute a script just once.
If the user eventually disables the module, I need to execute the same script again just once.
If the user eventually re-enables the module, I need to execute the same script again just once.
When the user decides to uninstall my module, I need to execute a script just once.
That script is basically removing a particular app's dalvik cache (rm -rf /data/dalvik-cache/<(arm|arm64)>/<app_specific_folder>), and user data (rm -rf /data/data/<package_name>).
I need some pointers on how to do this properly for those 4 events mentioned above and in a way compatible with most devices (for the record, I'm only supporting Nougat and above, if that's relevant).
Installation is easy. Make a function with your script in config.sh and call that from update-binary. Also make sure to let the module install a boot script (post-fs-data.d or service.d, depends on what you want to do) that takes care of the rest for you.
Whenever a module is disabled, there'll be a file named disable in the module folder, so you can let the boot script check for that and then run whatever code you need for the "module disabled" scenario. If you also let that code add a check file to the module folder you can let the code only run once. If both the disable and check files are present, don't run the code...
If the module then is enabled again, the disable file will be deleted. In that case you'll only have the check file, which will mean you should then run the "module enabled" code (which should also delete the check file, of course).
Also let the boot script check for the module folder. If it isn't found it means the module has been uninstalled and you can safely run your "module uninstalled" scenario, do some cleanup, and then let the boot script uninstall itself.
That should work...
There are several modules that do something similar, my MagiskHide Props Config is one of them. Look around for more examples.
I see what you mean but I need to test my code with logging to make sure I'm doing things correctly. What's the best way for me to print to logcat from my Magisk module?
Use exec with xtrace.
Code:
exec 2>/path/to/log/file;
set -x;
It will redirect the command (execution) tree and their errors to the log_file.
Regards.
@JayminSuthar Sorry, I don't understand. Where should I place that code? And are you saying that all the commands (outputs and errors) on my module will be redirected to that file, no exceptions?
You should place this code in your script from where you want logging to start (mostly the beginning). This will print the command (execution) tree in the log file, and all errors (if any), It will not print the output, but the command executed itself.
The format of the logs should be like
Code:
+ >&2
+ echo 'Here logging starts, I'm stderr'
Here logging starts, I'm stderr
+ rm -f /some/non/existent/file
rm: Can't remove file: No such file or directory

Magisk 24.3 "su" Permission denied

Greetings, I've been attempting for several days to execute "su" from adb shell. Essentially, Magisk 24.3 is properly installed within Android 12 on a Google Pixel 6. My primary purpose for rooting is to add my LAN entries to /system/etc/hosts.
An androidforums.com thread details the steps taken several times.
I would very much appreciate your help in getting "su" to work in Android 12 on a Pixel 6. No such problem occurred in Android 8.2 on a Nexus 6P.
Magisk is now uninstalled from the phone, and doesn't appear in the list of apps on the Pixel 6.
On the laptop:
$ adb install Magisk-v24.3.apk
Performing Streamed Install
Success
Invoking Magisk on the phone indicates that the App 24.3 (24300)(27) is installed, Magisk "Installed: NA"
From the factory image, unzipping image-oriole-sp2a.220305.013.a3.zip into a tmp directory:
$ adb push boot.img /storage/emulated/0/Download/boot.img
boot.img: 1 file pushed, 0 skipped. 51.4 MB/s (67108864 bytes in 1.246s)
In Magisk Install "Select and Patch a file", the boot.img is selected. "LET'S GO" results in a sequence ending with the name of the patched file and "All done!"
On the laptop:
adb pull /storage/emulated/0/Download/magisk_patched-24300_jdnPc.img magisk_patched.img
/storage/emulated/0/Download/magisk_patched-24300_jdnP...ulled, 0 skipped. 35.6 MB/s (67108864 bytes in 1.796s)
$ adb reboot bootloader
$ fastboot flash boot magisk_patched.img
Sending 'boot_a' (65536 KB) OKAY [ 1.683s]
Writing 'boot_a' OKAY [ 0.100s]
Finished. Total time: 1.785s
Android reboots normally. The Magisk app reports "Installed: 24.3 (24300)
On the laptop:
$ adb shell
oriole:/ $ su
Permission denied
13|oriole:/ $ exit
$
Please tell me where was my rooting error.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I assure you that the correct factory boot.img was transferred to Magisk, and the correct patched *.img file was uploaded and flashed to the phone.
hstroph said:
Greetings, I've been attempting for several days to execute "su" from adb shell. Essentially, Magisk 24.3 is properly installed within Android 12 on a Google Pixel 6. My primary purpose for rooting is to add my LAN entries to /system/etc/hosts.
I would very much appreciate your help in getting "su" to work in Android 12 on a Pixel 6. No such problem occurred in Android 8.2 on a Nexus 6P.
Click to expand...
Click to collapse
I think what you are facing is less about su rights and privileges and more about modern versus legacy partitioning and file systems. See this StackExchange Q&A, in particular the second answer about a hosts file solution.
But instead of mounting /system in Android 12, which is more hardened than 10 and 11, a safer method would involve systemless hosts courtesy of Magisk. One issue with that, though, is that most people use systemless hosts for block lists that redirect in bulk to 127.0.0.0 or 0.0.0.0. Adding friendly host names and IPs gets tricky because ad blocking apps like Adaway tend to overwrite when updating, although Adaway's whitelisting option may do the trick. I've never tried it.
I'm in a similar boat since jumping from Android 9 to 12 when I bought a Pixel 6. Eventually I'd like to use my Pixel for accessing a localhost web server. Until a better idea comes along I'll either use my old Pie phone for local browsing or simply publish to the www server (for testing layouts and responsiveness, etc.). I haven't gotten serious about it yet but I'm interested in any method that doesn't involve /system modifications or reconfiguring my router.
manjaroid said:
I think what you are facing is less about su rights and privileges and more about modern versus legacy partitioning and file systems. See this StackExhange Q&A, in particular the second answer about a hosts file solution. ...
Click to expand...
Click to collapse
Thank you, that got me excited as termux allowed a root prompt. "mount -o rw,remount /" executed, the vi alias was created, but "vi /system/etc/hosts" informed me that the file was read-only.
Not sure what to do next, but again, thank you.
hstroph said:
Thank you, that got me excited as termux allowed a root prompt. "mount -o rw,remount /" executed, the vi alias was created, but "vi /system/etc/hosts" informed me that the file was read-only.
Not sure what to do next, but again, thank you.
Click to expand...
Click to collapse
We need to approach our hosts files differently than was possible with Oreo or Pie. The path with least resistance will be Magisk's built-in systemless hosts module. Mounting /system as rw may have worked for Android 10 or 11, but 12 is stricter and messing with anything on /system could cause a cascade of problems.
Also, the /system partition dynamically stays full despite usage reported in Settings/Storage, so there's no elbow room for even the smallest change and you might even see out of space errors if not read-only errors.
What to try? I don't have a good answer yet, only ideas. I will be looking into it and am happy to report back. Hopefully somebody smarter than me will chime in.
Thank you for your interest and efforts.
This XDA thread was revisited today and it reminded me to take a stab at my Pixel's hosts file. With little effort I'm now browsing web server hosts on a Windows laptop from Android 12. All I did was edit its hosts file same way I've always done. Obviously I didn't have have a good grasp of the Magisk overlay and how it symlinks Android's native hosts file.
/system in Android 10+ may be off limits to many legacy operations but not the hosts file as long as Magisk's systemless hosts module is enabled. For su access it's just a matter of granting it to a root capable file manager with a text editor, such as MiXplorer or Solid Explorer.
Here's an example of what's needed for Android 12 browsers to connect to Apache virtualhosts on Windows:
Windows 10 laptop (192.168.1.234) - c:\Windows\System32\drivers\etc\hosts
127.0.0.1 site1.local
127.0.0.1 site2.local
Android 12 Pixel - /system/etc/hosts
192.168.1.234 site1.local
192.168.1.234 site2.local
Hope this is pertinent to what you're trying. Sorry for making it sound impossible earlier.
manjaroid said:
This XDA thread was revisited today and it reminded me to take a stab at my Pixel's hosts file. With little effort I'm now browsing web server hosts on a Windows laptop from Android 12. All I did was edit its hosts file same way I've always done. Obviously I didn't have have a good grasp of the Magisk overlay and how it symlinks Android's native hosts file.
/system in Android 10+ may be off limits to many legacy operations but not the hosts file as long as Magisk's systemless hosts module is enabled. For su access it's just a matter of granting it to a root capable file manager with a text editor, such as MiXplorer or Solid Explorer.
...
Click to expand...
Click to collapse
I'd very much like to know what "little effort" it took, please.
Magisk has the systemless module enabled, both MIXplorer and Solid Explorer have root privileges, but neither can copy my downloaded hosts file to /system/etc/hosts ... no success using the MIXplorer text editor either as per your suggestion
hstroph said:
I'd very much like to know what "little effort" it took, please.
Click to expand...
Click to collapse
I edited the hosts file directly by tapping it in MiXplorer and picking an editor. Then I just added a few lines, saved, and that was it. If you have lots of tedious entries try copy/pasting your text instead of trying to replace the file.
I know it doesn't quite make sense since your file managers have root. But overwriting a file on read-only /system is something completely different than opening and editing the hosts file like an ad blocker would do, which is only possible because of the systemless hosts module.
manjaroid said:
... But overwriting a file on read-only /system is something completely different than opening and editing the hosts file like an ad blocker would do, which is only possible because of the systemless hosts module.
Click to expand...
Click to collapse
Which hosts file are you successfully editing, please? Android 12 absolute pathname, if you would be so kind.
hstroph said:
Which hosts file are you successfully editing, please? Android 12 absolute pathname, if you would be so kind.
Click to expand...
Click to collapse
Edit /system/etc/hosts just as you would have done before Android 10, which didn't require the systemless hosts module.
I don't understand most of how systemless root works. But as far as I know, Magisk's systemless hosts module 'hijacks' (for lack of better discription) the hosts file from the system and makes it systemless, similar to a system app converting to a user app.
manjaroid said:
Edit /system/etc/hosts just as you would have done before Android 10, which didn't require the systemless hosts module.
Click to expand...
Click to collapse
I have attempted that many times:
$ adb shell
oriole:/ $ su
Permission denied
13|oriole:/ $
This was in anticipation of a "mount -o rw,remount /system" command in Android 8.2 on a Nexus 6P phone. It no longer works on Android 12 on a Pixel 6. Even a successful su in Termux fails to edit the /system/etc/hosts, or to make either / or /system rw.
Are you actually using Android 12, or are you reciting from memory? Your screen shots are appreciated.
hstroph said:
Are you actually using Android 12, or are you reciting from memory? Your screen shots are appreciated.
Click to expand...
Click to collapse
My Pixel runs Android 12 build SPA2A.220405.004 and Magisk 24.3. Screen shots won't show anything useful.
The su command in adb shell or Termux aren't needed even if mounting /system with write permission was possible. You're chasing your tail going about it this way.
A root file manager used as described is all that's needed to edit the hosts file. If you're being denied write access there must be something wrong with Magisk, systemless hosts, interference from other Magisk modules or something else.
To trouble shoot Magisk,
- try disabling systemless hosts in Magisk, reboot, re-enable it again & reboot again
- if using Magisk Canary try the more stable 24.3
A simple way to test systemless hosts is to install Adaway, choose the root option and grant su access. If the module is working Adaway will build a large hosts file from preset lists.
- a storage full error on the first run isn't unusual, but it should write to the hosts file next run
- if there's constant errors something isn't right, probably with Magisk or systemless hosts
- if it does write to the hosts file you should be able to edit it manually
- disable all block lists before uninstalling Adaway to empty the hosts file
manjaroid said:
My Pixel runs Android 12 build SPA2A.220405.004 and Magisk 24.3. ...
Click to expand...
Click to collapse
My Pixel 6 runs Android 12 build SPA2A.220305.013.A3 with Magisk 24.3
manjaroid said:
A root file manager used as described is all that's needed to edit the hosts file. If you're being denied write access there must be something wrong with Magisk, systemless hosts, interference from other Magisk modules or something else.
...
A simple way to test systemless hosts is to install Adaway, choose the root option and grant su access. If the module is working Adaway will build a large hosts file from preset lists.
Click to expand...
Click to collapse
Before Adaway (from adb shell):
oriole:/ $ wc -l /system/etc/hosts
2 /system/etc/hosts
After Adaway:
oriole:/ $ wc -l /system/etc/hosts
110315 /system/etc/hosts
manjaroid said:
- if it does write to the hosts file you should be able to edit it manually
Click to expand...
Click to collapse
I can add a LAN line before all the 127.0.0.1 entries using the rooted MIXplorer text editor, but the file still won't save.
manjaroid said:
- disable all block lists before uninstalling Adaway to empty the hosts file
Click to expand...
Click to collapse
There were no previous block lists of any kind. I have simply been trying to add a couple dozen LAN entries on this new phone.
I think I've followed instructions as carefully as possible, but still no luck.
hstroph said:
My Pixel 6 runs Android 12 build SPA2A.220305.013.A3 with Magisk 24.3
Before Adaway (from adb shell):
oriole:/ $ wc -l /system/etc/hosts
2 /system/etc/hosts
After Adaway:
oriole:/ $ wc -l /system/etc/hosts
110315 /system/etc/hosts
I can add a LAN line before all the 127.0.0.1 entries using the rooted MIXplorer text editor, but the file still won't save.
There were no previous block lists of any kind. I have simply been trying to add a couple dozen LAN entries on this new phone.
I think I've followed instructions as carefully as possible, but still no luck.
Click to expand...
Click to collapse
Systemless hosts appears to be working if there were no errors and 110315 entries were written to hosts.
In MiXplorer's Settings/More Settings, is the first item for Allow Root checked? I don't remember if the default is checked or not but it needs to be checked. The equivalent setting in Solid Explorer is off by default.
My two screenshots show before and after enabling/disabling Adaway's block lists. The second image shows Adaway's leftovers along with my own lines added manually and the file is saved (save button being greyed out). If you're unable to get the same results I'm stumped and need to think about what's going wrong.
manjaroid said:
..
In MiXplorer's Settings/More Settings, is the first item for Allow Root checked? I don't remember if the default is checked or not but it needs to be checked.
Click to expand...
Click to collapse
It is checked in MIXplorer.
manjaroid said:
The equivalent setting in Solid Explorer is off by default.
Click to expand...
Click to collapse
I'm unable to locate an equivalent setting in Solid Explorer (SE), but root usage was granted through Magisk 24.3 when I used SE for the first time.
manjaroid said:
My two screenshots show before and after enabling/disabling Adaway's block lists. The second image shows Adaway's leftovers along with my own lines added manually and the file is saved (save button being greyed out). If you're unable to get the same results I'm stumped and need to think about what's going wrong.
Click to expand...
Click to collapse
My attached image shows a failure to save in MIXplorer after adding a single "192.168.1.13 tncpi" line.
I've been stumped on the matter ever since Android 12 on this new Pixel 6.
Is Zygisk enabled in Magisk? I assume you followed this guide for rooting.
[GUIDE] Pixel 6 "oriole": Unlock Bootloader, Update, Root, Pass SafetyNet
⚠️⚠️⚠️WARNING! IF YOU ARE UPDATING TO ANDROID 13 FOR THE FIRST TIME, READ THIS FIRST! ⚠️⚠️⚠️ If you are looking for my guide on a different Pixel, find it here: Pixel 3 Pixel 3XL Pixel 3a Pixel 3aXL Pixel 4 Pixel 4XL Pixel 4a Pixel 4a (5G)...
forum.xda-developers.com
Appending a line using Termux works for me also. Are you denied when you try?
Code:
$ su
# echo 192.186.1.234 site3.local >> /system/etc/hosts
If that works there's no reason a root file manager shouldn't work. (To enable root in Solid Explorer tap the hamburger icon upper left then the sprocket icon and scroll down.)
If nothing works I'm thinking either 1) root isn't complete or 2) attempts at /system mounting had a negative effect. Options to consider:
- remove Magisk and repeat the root process
- remove Magisk, install the April OTA update, then root
- factory reset or flash the April factory zip, then root
My suggestion: Might as well go the full route and factory reset or clean flash. Particularly if there's any chance something went wrong in the root file system.
manjaroid said:
Is Zygisk enabled in Magisk?
Click to expand...
Click to collapse
It is now, so I have more to learn what Zygisk enables.
manjaroid said:
I assume you followed this guide for rooting.
[GUIDE] Pixel 6 "oriole": Unlock Bootloader, Update, Root, Pass SafetyNet
⚠️⚠️⚠️WARNING! IF YOU ARE UPDATING TO ANDROID 13 FOR THE FIRST TIME, READ THIS FIRST! ⚠️⚠️⚠️ If you are looking for my guide on a different Pixel, find it here: Pixel 3 Pixel 3XL Pixel 3a Pixel 3aXL Pixel 4 Pixel 4XL Pixel 4a Pixel 4a (5G)...
forum.xda-developers.com
Click to expand...
Click to collapse
Correct ... re-flashed factory image, then rooted with Magisk. Process repeated several times carefully, all with same results.
manjaroid said:
Appending a line using Termux works for me also. Are you denied when you try?
Click to expand...
Click to collapse
Appending a line works with Termux. Saving /system/etc/hosts after editing within Termux or Solid Explorer fails.
manjaroid said:
Code:
$ su
# echo 192.186.1.234 site3.local >> /system/etc/hosts
Click to expand...
Click to collapse
Success.
manjaroid said:
If that works there's no reason a root file manager shouldn't work. (To enable root in Solid Explorer tap the hamburger icon upper left then the sprocket icon and scroll down.)
Click to expand...
Click to collapse
Well, neither root file explorer works to save the file, but appending other text to /system/etc/hosts works, so I'll just write a simple shell script that I can run as needed.
I want to thank you so much for your patient help. I never thought Google would make things so difficult for those of us who need the use of a pocket Linux computer.
Please consider this thread closed.

Categories

Resources