Skip to content

Instantly share code, notes, and snippets.

@assiless
Last active October 2, 2024 08:12
Show Gist options
  • Save assiless/a23fb52e8c6156db0474ee8973c4be66 to your computer and use it in GitHub Desktop.
Save assiless/a23fb52e8c6156db0474ee8973c4be66 to your computer and use it in GitHub Desktop.
MagiskOnRedroid
setup variables for commands
echo -e "\n
export image=redroid/redroid:11.0.0-amd64
export image_tar=${HOME}/redroid:11.0.0-amd64" >> ${HOME}/.bashrc
source ${HOME}/.bashrc

1 is recommended

1. using docker method

preserve original redroid image
sudo docker pull $image
sudo docker save --output redroidBak.tar $image
backup or install original redroid image
# remove the changed image if exist
sudo docker image rmi -f $image
# install the original image
sudo docker load -i redroidBak.tar

2.using moby method

preserve original redroid image
wget -q "https://raw.githubusercontent.com/moby/moby/master/contrib/download-frozen-image-v2.sh" -P ~ ; chmod u+x ~/download-frozen-image-v2.sh

~/download-frozen-image-v2.sh "$image_tar" redroid/redroid:11.0.0-amd64
backup or install original redroid image
# remove the changed image if exist
sudo docker image rmi -f $image
# install the original image
tar -cC "$image_tar" . | sudo docker load

setting up

mkdir ~/MagiskOnRedroid
cd ~/MagiskOnRedroid
download+extract magisk
find -maxdepth 1 -iname "magisk*" -not -name "*.apk" -exec rm -r {} \;
magisk_file="app-debug.apk"
# download Magisk 9b61bdfc(25201) debug as you did i guess
if [ ! -f $magisk_file ]; then
  wget "https://cdn.jsdelivr.net/gh/topjohnwu/magisk-files@1cea72840fbf690f9a95512d03721f6a710fe02e/app-debug.apk"
fi
# because my machine x64 i will choose x86_64
unzip -j $magisk_file "lib/x86_64/libmagisk64.so" -d magisk
unzip -j $magisk_file "lib/x86_64/libbusybox.so" -d magisk
mv -v magisk/libmagisk64.so magisk/magisk
mv -v magisk/libbusybox.so magisk/busybox
# $ tree ~/MagiskOnRedroid
# .
# ├── app-debug.apk
# └── magisk
#     ├── busybox
#     └── magisk
compress magisk
tar --transform 's/.*\///g' -cf ~/magisk.tar --absolute-names $( find ~/MagiskOnRedroid | grep -E "magisk/|app-debug.apk$" )
remove.rc
cat <<\EOF > ~/remove.rc
on early-init
	export PATH /sbin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
	chmod 0700 /magisk.tar
	chown root root /magisk.tar
	chmod 0700 /setup.sh
	chown root root /setup.sh
	exec root root -- /setup.sh
service magisk-d /sbin/magisk --daemon
	user root
	oneshot
on boot
	start magisk-d
on post-fs-data
	start logd
	rm /dev/.magisk-unblock
	start s1
	wait /dev/.magisk-unblock 5
	rm /dev/.magisk-unblock
service s1 /sbin/magisk --post-fs-data
	user root
	oneshot
service s2 /sbin/magisk --service
	class late_start
	user root
	oneshot
on property:sys.boot_completed=1
	exec /sbin/magisk --boot-complete
on property:init.svc.zygote=restarting
	exec /sbin/magisk --zygote-restart
on property:init.svc.zygote=stopped
	exec /sbin/magisk --zygote-restart
EOF
sudo chmod 644 ~/remove.rc
sudo chown root:root ~/remove.rc
setup.sh
cat <<\EOF > ~/setup.sh
#!/system/bin/sh

# rm /system/fonts/NotoColorEmoji.ttf
tmpPushed=/magisk
rm -rf $tmpPushed
mkdir $tmpPushed
tar -xvf /magisk.tar --no-same-owner -C $tmpPushed
umount /magisk.tar ; rm -v /magisk.tar
mkdir /sbin
chown root:root /sbin
# chmod 0700 /sbin
chmod 0751 /sbin
cp $tmpPushed/magisk /sbin/
cp $tmpPushed/app-debug.apk /sbin/stub.apk
find /sbin -type f -exec chmod 0755 {} \;
find /sbin -type f -exec chown root:root {} \;
# add /sbin
# /sbin/
# ├── magisk
# └── stub.apk


ln -f -s /sbin/magisk /system/xbin/su
mkdir /product/bin
chmod 751 /product/bin
ln -f -s /sbin/magisk /product/bin/su
# add su (override `/system/xbin/su`)
# /product/bin/
# └── su -> /sbin/magisk

mkdir -p /data/adb/magisk
chmod 700 /data/adb
mv $tmpPushed/busybox /data/adb/magisk/
chmod -R 755 /data/adb/magisk
chmod -R root:root /data/adb/magisk
# /data/adb/
# ├── magisk
# │   └── busybox

# rm -rf $tmpPushed
EOF
sudo chmod 700 ~/setup.sh
sudo chown root:root ~/setup.sh

to get magisk working do this:

  1. phase
    • boot with magisk support
    (
    sudo docker stop a11
    clear
    sudo docker run -itd --rm --privileged \
      --name a11 \
      -v ~/data:/data \
      -v ~/remove.rc:/vendor/etc/init/remove.rc \
      -v ~/setup.sh:/setup.sh \
      -v ~/magisk.tar:/magisk.tar \
      -p 5555:5555 \
      redroid/redroid:11.0.0-amd64 \
      ro.secure=0
    )
    
@assiless
Copy link
Author

assiless commented Apr 15, 2023

@theorland have you tried https://github.com/ayasa520/redroid-script method
I see from README of redroid-script there is support for 8.1.0 ... 13.0.0

@web3-coder-hub
Copy link

not working on redroid:12.0.0-latest

@theorland
Copy link

@theorland have you tried https://github.com/ayasa520/redroid-script method I see from README of redroid-script there is support for 8.1.0 ... 13.0.0

have but it has issue on latest build I think

@longforus
Copy link

working on redroid/redroid:11.0.0-arm64

@x64life
Copy link

x64life commented Nov 20, 2023

Many errors and zygisk not work

---Magisk Logs---
9b61bdfc (25201)

11-20 13:17:35.089 91 91 I : Magisk 9b61bdfc(25201) daemon started
11-20 13:17:35.097 91 91 D : resetprop: prop [ro.config.per_app_memcg] does not exist
11-20 13:17:35.097 91 91 I : * Device API level: 30
11-20 13:17:35.100 91 93 D : resetprop: prop [ro.crypto.state] does not exist
11-20 13:17:35.100 91 93 I : ** post-fs-data mode running
11-20 13:17:35.100 91 93 I : * Mounting mirrors
11-20 13:17:35.101 91 93 E : mkdir /sbin/.magisk/mirror/data 493 failed with 2: No such file or directory
11-20 13:17:35.101 91 93 E : mount /sbin/.magisk/block/data->/sbin/.magisk/mirror/data failed with 2: No such file or directory
11-20 13:17:35.101 91 93 I : mount: /sbin/.magisk/mirror/data
11-20 13:17:35.101 91 93 E : symlink ./system_root/system->/sbin/.magisk/mirror/system failed with 2: No such file or directory
11-20 13:17:35.101 91 93 I : link: /sbin/.magisk/mirror/system
11-20 13:17:35.101 91 93 E : mkdir /sbin/.magisk/mirror/system_root 493 failed with 2: No such file or directory
11-20 13:17:35.101 91 93 E : mount /sbin/.magisk/block/system_root->/sbin/.magisk/mirror/system_root failed with 2: No such file or directory
11-20 13:17:35.101 91 93 I : mount: /sbin/.magisk/mirror/system_root
11-20 13:17:35.101 91 93 E : symlink ./system/product->/sbin/.magisk/mirror/product failed with 2: No such file or directory
11-20 13:17:35.101 91 93 I : link: /sbin/.magisk/mirror/product
11-20 13:17:35.101 91 93 E : symlink ./system/system_ext->/sbin/.magisk/mirror/system_ext failed with 2: No such file or directory
11-20 13:17:35.101 91 93 I : link: /sbin/.magisk/mirror/system_ext
11-20 13:17:35.118 91 93 I : * Initializing Magisk environment
11-20 13:17:35.126 91 93 D : resetprop: decode with protobuf [/data/property/persistent_properties]
11-20 13:17:35.126 91 93 D : resetprop: prop [persist.sys.safemode] does not exist
11-20 13:17:35.186 91 93 I : * Running post-fs-data.d scripts
11-20 13:17:35.189 91 93 E : mount /sbin/.magisk/mirror/data/adb/modules->/sbin/.magisk/modules failed with 2: No such file or directory
11-20 13:17:35.190 91 93 I : * Running module post-fs-data scripts
11-20 13:17:35.190 91 93 I : * Loading modules
11-20 13:17:42.756 91 93 I : ** late_start service mode running
11-20 13:17:42.756 91 93 I : * Running service.d scripts
11-20 13:17:42.756 91 93 I : * Running module service scripts
11-20 13:17:46.144 91 93 I : ** boot-complete triggered
11-20 13:31:34.815 91 93 D : su: request from pid=[2274], client=[12]
11-20 13:31:34.815 91 93 D : su: request from uid=[10116]
11-20 13:31:34.818 91 93 D : su: waiting child pid=[2277]
11-20 13:31:34.818 2277 2277 D : su: fork handler
11-20 13:31:34.818 2277 2277 D : su: use global namespace

@moyuwuhen601
Copy link

Hi, your tutorial is very helpful, I succeeded on my oracle arm server. But there is an error in your tutorial:
mv -v magisk/libbusybox.so magisk/busybo
It should be changed to:
mv -v magisk/libbusybox.so magisk/busybox
Sorry my English is not good so I am using Google Translate.

@chaixiang2002
Copy link

Dear author of the teaching article, when I tried to integrate Magisk according to your method, there were some problems. What scripts and files are there in the system after the container is run, but there is no Magisk application.
image

This is my build script.

rm -rf ~/MagiskOnRedroid setup.sh remove.rc magisk.tar data

mkdir ~/MagiskOnRedroid

cd ~/MagiskOnRedroid

download+extract magisk

echo'download+extract magisk' ############

find -maxdepth 1 -iname "magisk*" -not -name "*.apk" -exec rm -r {} ;

magisk_file="app-debug.apk"

download Magisk 9b61bdfc(25201) debug as you did i guess

if [ ! -f $magisk_file ]; then

wget "https://cdn.jsdelivr.net/gh/topjohnwu/magisk-files@1cea72840fbf690f9a95512d03721f6a710fe02e/app-debug.apk"

fi

because my machine x64 i will choose x86_64

unzip -j $magisk_file"lib/x86_64/libmagisk64.so" -d magisk

unzip -j $magisk_file"lib/x86_64/libbusybox.so" -d magisk

mv -v magisk/libmagisk64.so magisk/magisk

mv -v magisk/libbusybox.so magisk/busybox

$ tree ~/MagiskOnRedroid

.

├── app-debug.apk

└── magisk

├── busybox

└── magisk

compress magisk

tar --transform 's/.*///g' -cf ~/magisk.tar --absolute-names $( find ~/MagiskOnRedroid | grep -E "magisk/|app-debug.apk$" )

remove.rc

cat <<\EOF > ~/remove.rc

on early-init

export PATH /sbin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin

chmod 0700 /magisk.tar

chown root root /magisk.tar

chmod 0700 /setup.sh

chown root root /setup.sh

exec root root -- /setup.sh

service magisk-d /sbin/magisk --daemon

user root

oneshot

on boot

start magisk-d

on post-fs-data

start logd

rm /dev/.magisk-unblock

start s1

wait /dev/.magisk-unblock 5

rm /dev/.magisk-unblock

service s1 /sbin/magisk --post-fs-data

user root

oneshot

service s2 /sbin/magisk --service

class late_start

user root

oneshot

on property:sys.boot_completed=1

exec /sbin/magisk --boot-complete

on property:init.svc.zygote=restarting

exec /sbin/magisk --zygote-restart

on property:init.svc.zygote=stopped

exec /sbin/magisk --zygote-restart

EOF

sudo chmod 644 ~/remove.rc

sudo chown root:root ~/remove.rc

setup.sh

cat <<\EOF > ~/setup.sh

#!/system/bin/sh

rm /system/fonts/NotoColorEmoji.ttf

tmpPushed=/magisk

rm -rf $tmpPushed

mkdir $tmpPushed

tar -xvf /magisk.tar --no-same-owner -C $tmpPushed

umount /magisk.tar ; rm -v /magisk.tar

mkdir /sbin

chown root:root /sbin

chmod 0700 /sbin

chmod 0751 /sbin

cp $tmpPushed/magisk /sbin/

cp $tmpPushed/app-debug.apk /sbin/stub.apk

find /sbin -type f -exec chmod 0755 {} ;

find /sbin -type f -exec chown root:root {} ;

add /sbin

/sbin/

├── magisk

└── stub.apk

ln -f -s /sbin/magisk /system/xbin/su

mkdir /product/bin

chmod 751 /product/bin

ln -f -s /sbin/magisk /product/bin/su

add su (override /system/xbin/su)

/product/bin/

└── su -> /sbin/magisk

mkdir -p /data/adb/magisk

chmod 700 /data/adb

mv $tmpPushed/busybox /data/adb/magisk/

chmod -R 755 /data/adb/magisk

chmod -R root:root /data/adb/magisk

/data/adb/

├── magisk

│ └── busybox

rm -rf $tmpPushed

EOF

sudo chmod 700 ~/setup.sh

sudo chown root:root ~/setup.sh

sudo docker stop a12

docker system prune -af

clear

sudo docker run -itd --privileged \

--name a12 \

-v ~/data:/data \

-v ~/remove.rc:/vendor/etc/init/remove.rc \

-v ~/setup.sh:/setup.sh \

-v ~/magisk.tar:/magisk.tar \

-p 1109:5555 \

re_18_2321 \

redroid.gpu.mode=guest \

ro.secure=0

The directory where I am running the script is the/root directory
Hope to get your advice and help.

@chaixiang2002
Copy link

Many errors and zygisk not work

许多错误和zygisk不起作用

---Magisk Logs--- 9B61BDFC(25201)

11-20 13:17:35.089 91 I:Magisk 9b61bdfc(25201)守护进程启动 11-20 13:17:35.097 91 D:resetprop:prop[ro.config.per_app_memcg]不存在 11-20 13:17:35.097 91 I:*设备API级别:30 11-20 13:17:35.100 91 93 D:resetprop:prop[ro.cryp.state]不存在 11-20 13:17:35.100 91 93 I:**post-fs-data模式正在运行 11-20 13:17:35.100 91 93 I:*挂载镜 11-20 13:17:35.101 91 93 E:mkdir /sbin/.magisk/mirror/data493失败,2:没有这样的文件或目录 11-20 13:17:35.101 91 93 E:挂载 /sbin/.magisk/屏蔽/数据->/sbin/.magisk/镜像/数据失败2:没有这样的文件或目录 11-20 13:17:35.101 91 93 I:挂载: /sbin/.magisk/mirror/data 11-20 13:17:35.101 91 93 E:symlink./system_root/系统->/sbin/.magisk/镜像/系统失败2:没有这样的文件或目录 11-20 13:17:35.101 91 93 I:link: /sbin/.magisk/mirror/系统 11-20 13:17:35.101 91 93 E:mkdir /sbin/.magisk/mirror/system_root493失败,2:没有这样的文件或目录 11-20 13:17:35.101 91 93 E:挂载 /sbin/.magisk/屏蔽/system_root->/sbin/.magisk/镜像/system_root失败2:没有这样的文件或目录 11-20 13:17:35.101 91 93 I:挂载: /sbin/.magisk/mirror/system_root 11-20 13:17:35.101 91 93 E:symlink./系统/产品->/sbin/.magisk/镜像/产品失败2:没有这样的文件或目录 11-20 13:17:35.101 91 93 I:link: /sbin/.magisk/mirror/product 11-20 13:17:35.101 91 93 E:symlink./系统/system_ext->/sbin/.magisk/镜像/system_ext失败2:没有这样的文件或目录 11-20 13:17:35.101 91 93 I:link: /sbin/.magisk/mirror/system_ext 11-20 13:17:35.118 91 93 I:*初始化Magisk环境 11-20 13:17:35.126 91 93 D:resetprop:使用pro buf解码[/data/properties/persistent_properties] 11-20 13:17:35.126 91 93 D:resetprop:prop[持续.sys.safemode]不存在 11-20 13:17:35.186 91 93 I:*运行post-fs-data.d脚本 11-20 13:17:35.189 91 93 E:挂载 /sbin/.magisk/mirror/data/adb/modules->/sbin/.magisk/模块失败2:没有这样的文件或目录 11-20 13:17:35.190 91 93 I:*运行模块post-fs-data脚本 11-20 13:17:35.190 91 93 I:*加载模块 11-20 13:17:42.756 91 93 I:**late_start服务模式运行 11-20 13:17:42.756 91 93 I:*运行service.d脚本 11-20 13:17:42.756 91 93 I:*运行模块服务脚本 11-20 13:17:46.144 91 93 I:**引导完成触发 11-20 13:31:34.815 91 93 D:su:来自pid=[2274],client=[12] 11-20 13:31:34.815 91 93 D:su:request from uid=[10116] 11-20 13:31:34.818 91 93 D:su:等待子pid=[2277] 11-20 13:31:34.818 2277 2277 D:su:fork handler 11-20 13:31:34.818 2277 2277 D:su:use global命名空间

请问一下,我现在也是这种问题,请问一下,这个怎么解决?

@Gentleman36
Copy link

How to create more than one redroid with magisk? Thanks.

@Lua12138
Copy link

Lua12138 commented Sep 27, 2024

How to make it works with latest Magisk?

I try to change the app-debug.apk to https://github.com/topjohnwu/Magisk/releases/download/v27.0/Magisk-v27.0.apk ,it does not work.

command magisk --daemon says Start daemon on magisk tmpfs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment