Guide - Installing Shizuku

Since we cant actually get root permissions in appsupport, the next best thing would be Shizuku. I thought some of the users here would be interested, especially after the 4.6.0.12 update. Since I mainly use Shizuku for aurora store to automatically install apps without the need to confirm install/update for each and every app over and over (not to be confused with automatic updates). I also use it (with FreezeYou! from F-droid) to freeze some apps that stay active in the background and never respect the setting to be disabled in the background.
I have found this list of apps utilizing Shizuku if anyone’s interested. Many of them are cosmetic and related to Android UI, but, few others we can use in Appsupport.
Normally, (if an android device is not rooted) Shizuku needs to be started after every reboot with adb. Luckily for us we have a system.img that could be easily unpacked.

So,
1-Install Shizuku (available in Aurora store)
From my experience, one should open the app once for the rest to work.

A script then could be found: /home/defaultuser/android_storage/Android/data/moe.shizuku.privileged.api/start.sh

This script activates shiziku - If you’re satisfied with manually activating it after every appsupport reboot/start :
devel-su
appsupport-attach /system/bin/sh /storage/emulated/0/Android/data/moe.shizuku.privileged.api/start.sh
(most probably chmod +x is needed, can’t remember ).

2- To make it permanent, I have created a service(shizuku.rc) that activates the Shiziku start.sh script whenever appsupport is started:

service runapp /system/bin/start.sh class main 
         seclabel u:r:su:s0 user root group root 
         oneshot
 
 on property:dev.bootcomplete=1
         start runapp

3- Unpacked system.img:

  • placed shizuku.rc in /system/etc/init
  • chmod 644 shizuku.rc
  • placed start.sh in /system/bin . Not sure if granting it executable permissions is necessary, but thats what I did anyway.

Since this process has to be repeated each time Appsupport gets updated, I’ve made a simple script. It unpacks system.img and repacks it keeping the original one as backup. I put the 2 files needed (start.sh & shizuku.rc) in my working directory and execute as root. Note that squashfs-tools & lzip(??-depending on the version of squashfs-tools installed I suppose) should be already installed.

Edit :
& for clarification:

  • Added missing step (chmod 644 shizuku.rc) & uploaded the corrected script again to Mega
  • squashfs-tools from Jolla’s repo doesn’t work for this purpose.
  • I’m not sure what exactly @NettoHikari is talking about(regarding uid) but if you have a 64bit device and faced an error, check his post below

I’ll post the correct script here

#!/bin/sh

set -e

WORK_DIR="/home/defaultuser/work"

echo "Stoping appsupport..."
systemctl stop aliendalvik
sleep 4

echo "Checking if system.img exists..."
if [ ! -f "$WORK_DIR/origsystem.img" ]; then
echo "copying system.img..."
cp /opt/appsupport/system.img "$WORK_DIR/origsystem.img"
echo "system.img copied"
else
echo "system.img already exists, skipping copy"
fi

echo "extracting system.img..."
unsquashfs "$WORK_DIR/origsystem.img"

cp "$WORK_DIR/start.sh" squashfs-root/system/bin/
chmod +x "$WORK_DIR/squashfs-root/system/bin/start.sh"
echo "start.sh copied and permission set"

cp "$WORK_DIR/shizuku.rc" squashfs-root/system/etc/init
chmod 644 "$WORK_DIR/squashfs-root/system/etc/init/shizuku.rc"
echo "shizuku.rc copied and permission set"

echo "building new system.img..."
mksquashfs "$WORK_DIR/squashfs-root" "$WORK_DIR/system.img" -comp lz4 -Xhc -noappend -no-exports -no-duplicates -no->

echo "Cleaning up..."
rm -r -f "$WORK_DIR/squashfs-root"
echo "new system.img built"

while true; do
read -p "Do you wish to replace the old system.img in /opt/appsupport with the new one? (yes/no): " yn
case $yn in
[Yy]* )
echo "Replacing old system.img in /opt/appsupport..."
mv "$WORK_DIR/system.img" /opt/appsupport
break;;
[Nn]* )
echo "Operation cancelled. The new system.img will not be moved."
break;;
* )
echo "Please answer yes or no.";;
esac
done
12 Likes

Posting @babo’s script here, because files at Mega are much less persistent than Jolla’s forum (in my experience):

#!/bin/sh

set -e

WORK_DIR="/home/defaultuser/work"

echo "Stoping appsupport..."
systemctl stop aliendalvik
sleep 4

echo "Checking if system.img exists..."
if [ ! -f "$WORK_DIR/origsystem.img" ]; then
   echo "copying system.img..."
   cp /opt/appsupport/system.img "$WORK_DIR/origsystem.img"
   echo "system.img copied"
else
   echo "system.img already exists, skipping copy"
fi

echo "extracting system.img..."
  unsquashfs "$WORK_DIR/origsystem.img"

  cp "$WORK_DIR/start.sh" squashfs-root/system/bin/
echo "start.sh copied"

  chmod +x "$WORK_DIR/squashfs-root/system/bin/start.sh"
echo "executable permissions set"

  cp "$WORK_DIR/shizuku.rc" squashfs-root/system/etc/init
echo "shizuku.rc copied"

echo "building new system.img..."
  mksquashfs "$WORK_DIR/squashfs-root" "$WORK_DIR/system.img" -comp lz4 -Xhc -noappend -no-exports -no-duplicates -no-fragments

echo "Cleaning up..."
  rm -r -f "$WORK_DIR/squashfs-root"
echo "new system.img built"

while true; do
   read -p "Do you wish to replace the old system.img in /opt/appsupport with the new one? (yes/no): " yn
   case $yn in
   [Yy]* )
     echo "Replacing old system.img in /opt/appsupport..."
     mv "$WORK_DIR/system.img" /opt/appsupport
      break;;
   [Nn]* )
     echo "Operation cancelled. The new system.img will not be moved."
      break;;
   * )
     echo "Please answer yes or no.";;
esac
done
4 Likes

Thanks. Yes that makes sense

Just tried to get it to work using your script, but it unfortunately results in an error:

Stoping appsupport...
Checking if system.img exists...
system.img already exists, skipping copy
extracting system.img...
Filesystem uses lz4 compression, this is unsupported by this version
Decompressors available:
	gzip
	lzo
	xz
	lzma
1 Like

Try installing squashfs-tools (remove the package installed from Jolla’s repo) from here Index of /pub/archive/fedora/linux/releases/30/Everything/armhfp/os/Packages

Thanks. Installed the aarch64 version and your script ran without issues. However, shizuku doesn’t seem to be executed when appsupport starts up. When attaching to appsupport, I can see that all files are where they belong.

Is there a way to check logs in appsupport? Could it be because all things that are copied into the image are in the end owned by “overflowuid”?

@babo Maybe you could add that to the Wiki?

Alright, fixed it.

On my aarch64 install, there seems to be some kind of uid / gid matching issue or whatever. I had to modify the installation script a bit, as UID and GID 50000 seem to be mapped to appsupport-root. Also, shizuku.rc must have a permission mask of 644 in order to have it executed on startup.

install.sh

#!/bin/sh

set -e

WORK_DIR="/home/defaultuser/work"

echo "Stopping appsupport..."
systemctl stop aliendalvik
sleep 4

echo "Checking if system.img exists..."
if [ ! -f "$WORK_DIR/origsystem.img" ]; then
   echo "Copying system.img..."
   cp /opt/appsupport/system.img "$WORK_DIR/origsystem.img"
   echo "system.img copied"
else
   echo "system.img already exists, skipping copy"
fi

echo "Extracting system.img..."
unsquashfs "$WORK_DIR/origsystem.img"

echo "Copying start.sh..."
cp "$WORK_DIR/start.sh" squashfs-root/system/bin/
chmod +x "squashfs-root/system/bin/start.sh"
chown 500000:500000 "squashfs-root/system/bin/start.sh"
echo "start.sh copied and permissions set"

echo "Copying shizuku.rc..."
cp "$WORK_DIR/shizuku.rc" squashfs-root/system/etc/init
chmod 644 "squashfs-root/system/etc/init/shizuku.rc"
chown 500000:500000 "squashfs-root/system/etc/init/shizuku.rc"
echo "shizuku.rc copied and ownership set"

echo "Building new system.img..."
mksquashfs "$WORK_DIR/squashfs-root" "$WORK_DIR/system.img" -comp lz4 -Xhc -noappend -no-exports -no-duplicates -no-fragments

echo "Cleaning up..."
rm -r -f "$WORK_DIR/squashfs-root"
echo "new system.img built"

while true; do
   read -p "Do you wish to replace the old system.img in /opt/appsupport with the new one? (yes/no): " yn
   case $yn in
   [Yy]* )
     echo "Replacing old system.img in /opt/appsupport..."
     mv "$WORK_DIR/system.img" /opt/appsupport
      break;;
   [Nn]* )
     echo "Operation cancelled. The new system.img will not be moved."
      break;;
   * )
     echo "Please answer yes or no.";;
   esac
done

Another thing that may or may not have relevance is the formatting of shizuku.rc. All other *.rc files only have 4 spaces indentation.

shizuku.rc

service runapp /system/bin/start.sh class main 
    seclabel u:r:su:s0 user root group root 
    oneshot
 
on property:dev.bootcomplete=1
    start runapp

start.sh was fine from the get-go, I think. Gonna include it in my post anyway.

start.sh

#!/system/bin/sh

SOURCE_PATH="/storage/emulated/0/Android/data/moe.shizuku.privileged.api/starter"
STARTER_PATH="/data/local/tmp/shizuku_starter"

echo "info: start.sh begin"

recreate_tmp() {
  echo "info: /data/local/tmp is possible broken, recreating..."
  rm -rf /data/local/tmp
  mkdir -p /data/local/tmp
}

broken_tmp() {
  echo "fatal: /data/local/tmp is broken, please try reboot the device or manually recreate it..."
  exit 1
}

if [ -f "$SOURCE_PATH" ]; then
    echo "info: attempt to copy starter from $SOURCE_PATH to $STARTER_PATH"
    rm -f $STARTER_PATH

    cp "$SOURCE_PATH" $STARTER_PATH
    res=$?
    if [ $res -ne 0 ]; then
      recreate_tmp
      cp "$SOURCE_PATH" $STARTER_PATH

      res=$?
      if [ $res -ne 0 ]; then
        broken_tmp
      fi
    fi

    chmod 700 $STARTER_PATH
    chown 2000 $STARTER_PATH
    chgrp 2000 $STARTER_PATH
fi

if [ -f $STARTER_PATH ]; then
  echo "info: exec $STARTER_PATH"
    $STARTER_PATH "$1"
    result=$?
    if [ ${result} -ne 0 ]; then
        echo "info: shizuku_starter exit with non-zero value $result"
    else
        echo "info: shizuku_starter exit with 0"
    fi
else
    echo "Starter file not exist, please open Shizuku and try again."
fi

So, installation instructions are:

  • Turn on SSH in developer options
  • Connect via SSH or use the inbuilt terminal app (if you like pain)
  • Create the work folder: mkdir work
  • Enter the folder: cd work
  • Create the script files from above
  • Make install.sh executable: chmod +x install.sh
  • Download the right squashfs-tools package for aarch64 from here, right now, that would be: curl -O https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/Everything/aarch64/os/Packages/s/squashfs-tools-4.3-16.fc28.aarch64.rpm
  • Become root: devel-su
  • Install lzip: pkcon refresh && pkcon install lzip
  • Install squashfs-tools: pkcon install-local squashfs-tools-4.3-16.fc28.aarch64.rpm
  • Install: ./install.sh

Now you should be good to go.

1 Like

I believe you are absolutely right. I have made this file some time ago and I just use the same file over and over after updates. I forgot about it.

However, regarding the uid thing, I cant say. I never did that and it just worked. I have a 32bit XA2 though, maybe its different on 64bit…
Anyways, thanks for clarifying and explaining your process :slight_smile: glad it worked eventually.

1 Like

Did you mean turn this topic into a wiki? Because I’m not sure I can do that. Maybe @rainemak could help here

No, I meant if you could put this tutorial here: https://sailfishos.wiki/