Skip to content

Commit 8119f2d

Browse files
committed
zh: add ums guide.
1 parent a5752ec commit 8119f2d

2 files changed

Lines changed: 121 additions & 3 deletions

File tree

.vitepress/zh.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function sidebarDocs(): DefaultTheme.SidebarItem[] {
5454
items: [
5555
{ text: '教程收集', link: '/InstallationGuides/GuidesCollection'},
5656
{ text: 'Windows安装简述', link: '/InstallationGuides/WindowsInstallation' },
57-
{ text: '驱动安装', link: '/InstallationGuides/InstallDrivers'}
57+
{ text: '驱动安装', link: '/InstallationGuides/InstallDrivers'},
58+
{ text: '进入USB大容量存储模式', link: '/InstallationGuides/EnterUMS'},
5859
]
5960
},
6061
{

zh/InstallationGuides/EnterUMS.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,119 @@
1-
# 进入大容量模式
2-
## TODO
1+
# 如何进入 USB 大容量存储 (UMS) 模式
2+
> 本文介绍几种在不同环境下进入 USB 大容量存储模式(UMS)的方法:UEFI 启动、Android/Recovery 下通过 USB Gadget,以及使用 initrd 与不同内核的方式。
3+
4+
主要有两种进入 UMS 的途径:
5+
- UEFI 应用
6+
- Linux USB Gadget
7+
8+
## 在 UEFI 中进入 UMS
9+
[bootpkg.zip](/InstallationGuides/EnterUMS/bootpkg.zip) 解压到一个 FAT 分区(例如 modem_a 或 modem_b)。另外也可以在备份后格式化分区为 FAT 并把文件写入。
10+
例如,如果你的设备目前在 A slot,而 B slot 空闲,则把文件放到 modem_b。假设 `bootpkg.zip` 位于 `/sdcard/`
11+
12+
```shell
13+
adb shell
14+
su
15+
mkdir /dev/ums && cd /dev/ums
16+
unzip /sdcard/bootpkg.zip
17+
cd ..
18+
umount /dev/ums
19+
```
20+
:::tip
21+
另有预打包的 FAT 镜像可在此处获取 [bootpkg_image.zip](/InstallationGuides/EnterUMS/bookpkg_image.gz)。你可以在电脑上解压并通过 fastboot 写入任何未使用的分区。
22+
:::
23+
24+
将设备重启到 fastboot 模式,然后运行下面命令尝试通过 UEFI 启动。手机将在几秒后显示引导菜单,可以选择进入大容量存储模式:
25+
26+
```shell
27+
fastboot boot /path/to/uefi-XXXX.img
28+
```
29+
:::tip
30+
大多数终端模拟器支持将文件拖放到窗口并自动转换为完整路径。
31+
:::
32+
33+
启动 UEFI 后,在 Windows Boot Manager 中选择 `Mass Storage Mode`
34+
35+
## 在 Android 或 Recovery 下进入 UMS
36+
:::tip
37+
当 userdata 分区在 Android 或 Recovery 中被挂载时,通常不建议修改该分区。
38+
:::
39+
40+
:::warning
41+
如果设备在内核层强制启用了 SELinux(例如某些 Oplus 设备),本方法可能无法生效。
42+
:::
43+
44+
将下面脚本保存为 `msc.sh`
45+
46+
```shell
47+
#!/sbin/bash
48+
setenforce 0
49+
echo 0xEF > /config/usb_gadget/g1/bDeviceClass; echo 0x02 > /config/usb_gadget/g1/bDeviceSubClass; echo 0x01 > /config/usb_gadget/g1/bDeviceProtocol
50+
ln -s /config/usb_gadget/g1/functions/mass_storage.0/ /config/usb_gadget/g1/configs/b.1/
51+
echo /dev/block/sda > /config/usb_gadget/g1/configs/b.1/mass_storage.0/lun.0/file
52+
echo 0 > /config/usb_gadget/g1/configs/b.1/mass_storage.0/lun.0/removable
53+
sh -c 'echo > /config/usb_gadget/g1/UDC; echo a600000.dwc3 > /config/usb_gadget/g1/UDC' &
54+
```
55+
56+
把脚本 push 到 `/sdcard``/dev`,或者在 adb shell 中直接执行这些命令:
57+
58+
```shell
59+
adb push /path/to/msc.sh /sdcard
60+
adb shell
61+
su
62+
sh /sdcard/msc.sh
63+
```
64+
65+
或者直接在 shell 中按步骤执行:
66+
67+
```shell
68+
adb shell
69+
su
70+
setenforce 0
71+
echo 0xEF > /config/usb_gadget/g1/bDeviceClass; echo 0x02 > /config/usb_gadget/g1/bDeviceSubClass; echo 0x01 > /config/usb_gadget/g1/bDeviceProtocol
72+
ln -s /config/usb_gadget/g1/functions/mass_storage.0/ /config/usb_gadget/g1/configs/b.1/
73+
echo /dev/block/sda > /config/usb_gadget/g1/configs/b.1/mass_storage.0/lun.0/file
74+
echo 0 > /config/usb_gadget/g1/configs/b.1/mass_storage.0/lun.0/removable
75+
sh -c 'echo > /config/usb_gadget/g1/UDC; echo a600000.dwc3 > /config/usb_gadget/g1/UDC' &
76+
```
77+
78+
## 使用 initrd + Android 内核进入 UMS
79+
:::warning
80+
如果设备在内核层强制启用了 SELinux(例如某些 Oplus 设备),本方法可能无法生效。
81+
:::
82+
83+
你可以将上面的脚本打包到通用的 [mass.cpio.gz](/InstallationGuides/EnterUMS/mass.cpio.gz)。下载并解压该文件,然后替换手机 `boot`/`vendorboot` 中的 initrd,在启动时会自动启用 UMS。
84+
下载适用于 Linux/Android 的 MagiskBoot 预构建工具(例如:
85+
[TeamWin external_magisk-prebuilt](https://github.com/TeamWin/external_magisk-prebuilt/tree/android-12.1/prebuilt)),或用于 Windows 的预构建版本(
86+
[svoboda18/magiskboot releases](https://github.com/svoboda18/magiskboot/releases))。
87+
88+
使用该工具 unpack/repack boot/vendorboot 镜像(解包后对可执行文件赋予执行权限)。示例命令:
89+
90+
```shell
91+
adb push mass.cpio /sdcard/
92+
su
93+
mkdir -p /sdcard/bootunpack && cd /sdcard/bootunpack
94+
./path/to/magiskboot unpack /dev/block/by-name/boot_a
95+
ls . # If ramdisk does not exist in boot, try edit vendor boot.
96+
cp ../mass.cpio ramdisk.cpio
97+
./path/to/magiskboot repack ums.img
98+
# You will get a ums.img here
99+
ls .
100+
```
101+
102+
接下来你需要将生成的镜像引导或在备份后刷入 vendorboot。设备启动后几秒内将进入 UMS 模式。
103+
104+
```shell
105+
adb pull /sdcard/bootunpack/ums.img .
106+
# Reboot device into fastboot
107+
fastboot boot ums.img # If boot.img
108+
# or
109+
fastboot flash vendorboot ums.img # if vendor boot
110+
```
111+
112+
:::warning
113+
请在刷写前备份你的 boot/vendorboot,使用完毕后再刷回原镜像。
114+
:::
115+
116+
## 使用 initrd + mainline 内核进入 UMS
117+
你也可以尝试在 UEFI 中或通过 ABL 启动 mainline Linux,并在 configfs 中启用 UMS gadget 模式。该方式较为高级,此处仅作简要介绍。
118+
119+
# 结束

0 commit comments

Comments
 (0)