Code Monkey home page Code Monkey logo

ums-interface's Introduction

English Description | 中文描述 | APP Description

English Description

Basic function: Use the usb gadget driver to make the specified image or block device accessible by the PC as a USB Drive; at the same time, mount the image or block device to the Android local.

Scenes to be used:

  • Get rid of MTP, realize file transfer between PC and Android, Mass Storage is more compatible than MTP.
  • Use a mobile phone to replace a physical USB flash drive.
  • Use an existing iso or pe image for PC system maintenance, no need to burn the disk.

The UMSInterface APP is no longer maintained. If you still want to use this APP, please refer to the APP Description.

As an alternative, the following provides an example of a shell script based on the Termux environment to accomplish roughly the same function. This method requires users to have a certain understanding of linux and shell. At the same time, mounting/unmounting partitions, and operations on block devices are High-risk operations, if the user is not familiar with the Linux environment, it may brick the phone.

The alternative method is as follows:

  1. This shell script running environment is based on Termux, please install Termux first.

    In order to facilitate one-click operation, it is recommended to install Termux:Widget.

    In order to display toast messages conveniently, it is recommended to install Termux:API.

  2. Copy mass_storage.sh to /data/data/com.termux/files/home/.shortcuts/.

    Some of the parameters can be modified according to actual conditions. For example:

    https://github.com/outofmemo/UMS-Interface/blob/87ce4fe5ae81baaf5a846c680f3fcff3fed9292e/mass_storage.sh#L17

    • default_size_mb: The size of the image created by default, unit: MB.
    • dst: Mount point path. Leave blank to not mount.
    • src: Image or block device path.
      • You can specify a path that does not exist, and an empty image will be created automatically.
      • You can specify a block device path. But be careful to do so, otherwise operating errors may cause the phone to become bricked.
      • You can specify an existing image. For example, you can specify an iso image or a pe disk image for PC system maintenance. You can also specify a disk image copied with dd command.
  3. Add executable permissions to mass_storage.sh:

    chmod +x /data/data/com.termux/files/home/.shortcuts/mass_storage.sh
  4. If Termux: Widget is installed, you can add the corresponding widget on the desktop, and click mass_storage.sh on the widget to execute this script.

    If it is not installed, you can execute this script directly in Termux.

  5. If you want to run this script automatically at boot:

    1. Install Termux:Boot.

    2. Grant Termux:Boot self-start permission in the application settings.

    3. Copy mass_storage.sh to /data/data/com.termux/files/home/.termux/boot, and add executable permissions.

      cp /data/data/com.termux/files/home/.shortcuts/mass_storage.sh /data/data/com.termux/files/home/.termux/boot
      chmod +x /data/data/com.termux/files/home/.termux/boot/mass_storage.sh

Precautions:

  • After the PC writes the file to the USB Driver, Android cannot perceive the file system changes. You can refresh by executing mass_storage.sh again.
  • After the Android writes a file to the image or block device, the PC cannot perceive the change of the file system. You can refresh it by plugging and unplugging the USB or executing mass_storage.sh again.
  • Do not write to the file system at the same time on the PC and Android (such as: file movement, copy, rename, create, delete, write), otherwise the file system will be damaged and the file will be lost.
  • Don't store important files in the image or block device specified by the above script without a copy.

中文描述

基本功能: 使用 usb gadget 驱动使指定的镜像或块设备可作为 USB Drive 被PC访问; 同时将此镜像或块设备挂载到Android本地.

使用场景:

  • 摆脱MTP, 实现PC与Android的文件传输, Mass Storage 比 MTP 兼容性更好.
  • 替代实体U盘, 携带手机后, 无需再带U盘.
  • 使用已有的iso或pe镜像, 用于PC系统维护, 无需刻盘, 替代PC启动盘.

UMSInterface APP后面不再维护. 如果仍然想使用此APP, 可参考 APP Description.

作为替代, 下面提供一个基于Termux环境的shell脚本示例, 来完成大致相同的功能. 此方法需要使用者对linux和shell有一定的了解. 同时, 挂载/卸载分区, 以及对块设备的操作本来就是高危操作, 如果使用者对linux环境不熟悉, 可能会使手机变砖.

替代方法如下:

  1. 此shell脚本运行环境基于Termux, 请先安装 Termux.

    同时, 为了方便一键操作, 建议安装 Termux:Widget.

    为了方便显示toast消息, 建议安装 Termux:API.

  2. mass_storage.sh 拷贝至 /data/data/com.termux/files/home/.shortcuts/.

    其中的部分参数可根据实际情况进行修改. 如:

    https://github.com/outofmemo/UMS-Interface/blob/87ce4fe5ae81baaf5a846c680f3fcff3fed9292e/mass_storage.sh#L17

    • default_size_mb: 默认创建的镜像大小, 单位: MB.
    • dst: 挂载点路径. 留空则不挂载.
    • src: 镜像文件或块设备路径.
      • 可以指定一个不存在的路径, 此时会自动创建一个空的镜像.
      • 可以指定一个块设备路径. 但要谨慎这么做, 否则操作失误可能会导致手机无法启动.
      • 可以指定一个已存在的镜像. 比如可以指定iso镜像 或 pe磁盘镜像用于PC的系统维护. 或者也可以指定一个使用dd命令拷贝的磁盘镜像.
  3. mass_storage.sh添加可执行权限:

    chmod +x /data/data/com.termux/files/home/.shortcuts/mass_storage.sh
  4. 如果有安装 Termux:Widget, 则可在桌面添加相应的小部件, 点击小部件上的 mass_storage.sh 即可执行此脚本.

    如果没有安装, 可直接在 Termux 中执行此脚本.

  5. 如果希望开机时自动运行此脚本:

    1. 安装 Termux:Boot.

    2. 应用设置中授予 Termux:Boot 自启动权限

    3. mass_storage.sh 拷贝至 /data/data/com.termux/files/home/.termux/boot, 并添加可执行权限.

      cp /data/data/com.termux/files/home/.shortcuts/mass_storage.sh /data/data/com.termux/files/home/.termux/boot
      chmod +x /data/data/com.termux/files/home/.termux/boot/mass_storage.sh

注意事项:

  • PC 端向 USB Driver 中写入文件后, Android 无法感知文件系统的变化. 可以通过再次执行 mass_storage.sh 来刷新.
  • 同理, Android 端向镜像或块设备中写入文件后, PC也无法感知文件系统的变化. 可以通过重新插拔USB或再次执行 mass_storage.sh 来刷新.
  • PC 和 Android 端不要同时对文件系统进行写操作(如: 文件的移动, 复制, 重命名, 创建, 删除, 写入), 否则会损坏文件系统, 导致文件丢失.
  • 不要在没有副本的情况下, 把重要文件存放到上述脚本指定的镜像或块设备中.

ums-interface's People

Contributors

freed-wu avatar oufm avatar outofmemo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ums-interface's Issues

Fails to mount on Android 11

Error message reads "UMS fail:MassStorageSysfs is not ready!"

Affected device: Google Pixel 3a
Affested OS: Android 11, build RQ1A.210105.002
App version: 1.4.1
Happens every time when mounting iso as usb or mounting to directory

[question] cannot read the part of disk when set external SD as ums

ums_log.tar.gz

when set disk image file as ums, it can work normally.

when i try to set an external sd as ums, the disk can be listed by lsblk in
linux or diskmgmt.msc in windows, but the part of the disk cannot be read.

i have formatted the external sd and try again, but nothing changed. and i make
sure that the mount namespace is global and the software coming from github
is latest.

thanks!

镜像文件格式化是否增加ext4

我希望生成镜像文件的格式化选项能添加格式化为ext4这个选项,顺便一提,挂载镜像文件在我的手机上会失败,即使是/data目录

Can't find lun file ?

+ dirname /data/data/com.termux/files/home/usb_mass_storage.sh
+ cd /data/data/com.termux/files/home
+ pwd
+ basename /data/data/com.termux/files/home/usb_mass_storage.sh
+ script_path=/data/data/com.termux/files/home/usb_mass_storage.sh 
+ basename /data/data/com.termux/files/home/usb_mass_storage.sh
+ log_path=/sdcard/usb_mass_storage.sh.log 
+ termux_bin=/data/data/com.termux/files/usr/bin 
+ mount=/data/data/com.termux/files/usr/bin/mount 
+ umount=/data/data/com.termux/files/usr/bin/umount 
+ losetup=/data/data/com.termux/files/usr/bin/losetup 
+ find=/data/data/com.termux/files/usr/bin/find 
+ truncate=/data/data/com.termux/files/usr/bin/truncate 
+ toast=/data/data/com.termux/files/usr/bin/termux-toast 
+ mkfs='' 
+ lun_file='' 
+ default_size_mb=2048 
+ src=/storage/emulated/0/mass_storage.img 
+ dst=/sdcard/mass_storage 
+ '[' namespace '=' root ']'
+ '[' namespace '=' namespace ']'
+ run_with_namespace
+ typeset block
+ '[' -z '' ']'
+ search_lun_file
+ typeset configfs_mount
+ typeset config_path
+ /data/data/com.termux/files/usr/bin/mount
+ grep configfs
+ configfs_mount=$'none on /config type configfs (rw,nosuid,nodev,noexec,relatime)\nnone on /debug_ramdisk/.magisk/mirror/config type configfs (rw,nosuid,nodev,noexec,relatime)\n/dev/block/dm-14 on /system/etc/init/hw/init.usb.configfs.rc type ext4 (ro,seclabel,relatime,discard)' 
+ '[' -n $'none on /config type configfs (rw,nosuid,nodev,noexec,relatime)\nnone on /debug_ramdisk/.magisk/mirror/config type configfs (rw,nosuid,nodev,noexec,relatime)\n/dev/block/dm-14 on /system/etc/init/hw/init.usb.configfs.rc type ext4 (ro,seclabel,relatime,discard)' ']'
+ echo $'none on /config type configfs (rw,nosuid,nodev,noexec,relatime)\nnone on /debug_ramdisk/.magisk/mirror/config type configfs (rw,nosuid,nodev,noexec,relatime)\n/dev/block/dm-14 on /system/etc/init/hw/init.usb.configfs.rc type ext4 (ro,seclabel,relatime,discard)'
+ awk '{print $3}'
+ config_path=$'/config\n/debug_ramdisk/.magisk/mirror/config\n/system/etc/init/hw/init.usb.configfs.rc' 
+ /data/data/com.termux/files/usr/bin/find $'/config\n/debug_ramdisk/.magisk/mirror/config\n/system/etc/init/hw/init.usb.configfs.rc' -type f -name file
find: ‘/config\n/debug_ramdisk/.magisk/mirror/config\n/system/etc/init/hw/init.usb.configfs.rc’: No such file or directory
+ lun_file='' 
+ '[' -e '' ']'
+ /data/data/com.termux/files/usr/bin/termux-toast 'can'\''t find lun file'
+ exit 1

What's going on ?

[advice] how about release this app in fdroid?

hey, i believe it is a good application. how about release it in fdroid?
i believe the app is worth more one to use it!

it is just a suggestion. no offense. Thanks for your effort again!

镜像文件在重启后无法读取

系统是安卓10的类原生,机型魅族16th。
镜像原本是可以被挂载的,但是重启后就提示

  [ ERR]>>mount: mounting /dev/loop0 on /data/media/0/ums_mnt/mnt0 failed: Invalid argument

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.