Using host /etc/hosts in AlienDalvik/AndroidAppSupport (AD/AAS) via bind mount on SFOS 4.5

[DISCLAIMER]
have no idea if this interferes with system updates!
[/DISCLAIMER]
I see 2 ways to get the /etc/hosts file to be used in AD/AAS.

  1. Add the script /usr/libexec/appsupport/alien-generate-extra-config.sh
    with this:
    lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0. Make it executable. Didn't test this one, though.
  2. Patch /usr/libexec/appsupport/prepare-aliendalvik.sh. After …"$CONTAINER_CONFIG_PATH/10-bsp_config" put echo “lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0” >> “$CONTAINER_CONFIG_PATH/10-bsp_config” This has been used by several people, including me.
Don't forget to restart AD/AAS.
Verify:
devel-su appsupport-attach cat /etc/hosts
(this changed in 4.5, see https://docs.sailfishos.org/Develop/Platform/Testing_Advice/#android-apps)
references:
sfos-4-5-feedback-thread: #229, #256
Patch (I hope there wasn't loss characters...):
--- /usr/libexec/appsupport/prepare-aliendalvik.org.sh  2023-01-25 20:52:12.000000000 +0000
+++ /usr/libexec/appsupport/prepare-aliendalvik.sh      2023-02-11 23:47:29.737036812 +0000
@@ -121,6 +121,7 @@
 /usr/libexec/appsupport/alien-generate-rootfs-config.sh "$CONTAINER_CONFIG_PATH/40-rootfs_config"
 
 /usr/libexec/appsupport/appsupport-generate-config --type lxc --user-id "$ALIEN_USER_ID" --instance "$INSTANCE_NAME" --base-uid "$ALIEN_BASE_UID" "$CONTAINER_CONFIG_PATH/10-bsp_config" || exit 32
+echo "lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0" >> "$CONTAINER_CONFIG_PATH/10-bsp_config"
 
 /usr/libexec/appsupport/alien-generate-net-config.sh $PRIVILEGED "$CONTAINER_CONFIG_PATH/30-net_config"

6 Likes

I’ve been using method 2 for a few days, works like a charm. Thank you!

We used to be able to block ads by editing the DNS (setting up AdGuard DNS, for example) in the Android settings. It seems like this is not working anymore. What happened with that option?

Have you considered Blokada?

1 Like

Not necessary for now. I’m blocking the ads in the browser, but I’m just curious to know what happened with that option.

Thank you. Method Nr. 2 has worked and considering what it does, method Nr. 1 cannot work ( lxc.mount.entry is not a command; it’s a config setting).