Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount an external drive's ext4 partition on android and make it rw-available to all the apps

Tags:

linux

android

I have written the following shell script:

alias mount='/system/xbin/busybox mount'
set -e
set -x

MNT=sda1

function mkdir_ext() {
  if [ ! -d $1 ]; then
    mkdir -p $1
  fi
  chown $2 $1
  chmod $3 $1
}

mkdir_ext /storage/emulated/$MNT root:media_rw 777
mount -t ext4 /dev/block/$MNT /storage/emulated/$MNT

mkdir_ext /data/media/$MNT root:media_rw 777
sdcard -u 1023 -g 1023 /storage/emulated/$MNT /data/media/$MNT

After executing the commands above, mount reports:

root@NEO-X8:/sdcard # mount|grep sda
/dev/block/sda1 /storage/emulated/sda1 ext4 rw,seclabel,relatime,data=ordered 0 0
/dev/fuse /data/media/sda1 fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

I am working via ssh, remotely, using rooted ssh/sftp daemon, and while logged in as root, I can list the files in /storage/emulated/sda1.

From what I understand, android is case-insensitive in regards to filesystems by design, so the filesystem has to be fused.

The problem is, I see just an empty directory in /data/media/sda1. Even stranger is that, if I navigate to /storage/emulated/sda1 from the device as root with bash shell X, I also see an empty directory.

I have tried different other apps and I've tried to also use sdcard_rw instead of media_rw (with the uid / gid 1015 instead of 1023), nothing works.

How to get ext4 to work for all apps on a rooted Minix NEO X8-H? Using anything but ext4 is not an option, the 4TB drive already contains important data. As a side note, sda1 is just a small 1GB partition.

like image 686
Flavius Avatar asked Oct 19 '22 14:10

Flavius


1 Answers

I will assume that your device is rooted from what you have done so far so will not go into that. Though I cannot be certain this is your issue I shall explain how I solved a similar problem.

Resent versions of android with the intent on improving device security are now using the (somewhat half arsed) feature of making mounts performed by most processes not visible to other processes. Working around this is frustratingly device specific, however it appears the Minix NEO X8-H is using a "vanilla" style source build of android. Therefore you have a good chance of using StickMount in order to mount the USB stick, it should enable the global mounting of USB devices running any file-system supported by your ROM (which should include ext4 given you have already mounted it before).

I have not tested this personally on your device so cannot guarantee it will work but have had success with a number of other android devices so this is certainly worth a shot.

like image 66
Vality Avatar answered Oct 22 '22 04:10

Vality