Linux玲珑商店安装的应用程序访问外部硬盘

Linux玲珑商店安装的应用程序访问外部硬盘

由于玲珑(Linglong)应用商店使用了容器化机制,因此在玲珑商店安装的软件默认运行在一个隔离环境里,它只能访问容器允许的目录(通常是 /Downloads、/Documents、~/Music 等),而不会直接看到你系统里挂载的移动硬盘路径(例如 /mnt/xxx 或 /media/xxx)。

在翻阅玲珑安装目录的文档后,我找到了一份有关设置容器的挂载点的设置文档:

# OCI configurations for linglong containers Directory [config.d] contains OCI configuration patches and generators. They will be applied in file name order. ## generator Files in [config.d] that is executable for linglong runtime program are treated as OCI configuration generators for linglong. They will be executed by linglong runtime program with the constructing OCI configuration writed into their stdin. They should print **FULL** content of that modified OCI configuration to their **stdout**, and print error message or warning to their **stderr**. If anything goes wrong, for example: - the OCI configuration read from stdout failed to be parsed; - generator exit with non-zero return code; - generator crashed; - ... That generator will be ignored. ## OCI configuration patches Files in [config.d] that is **NOT** executable for linglong runtime program and ends with .jsonare treated as OCI configuration patches. They will be read by linglong runtime program, then the items inpatchfield will be parsed as [JSON Patch] then be applied one by one. [JSON Patch]: https://jsonpatch.com/ If anything goes wrong, for example: - the json file failed to be parsed as OCI configuration patch; - theociVersionfield is not equals to constructing configuration; - ... That patch will be ignored. The json schema definition of OCI configuration patch file can be found at [/api/schema/v1.yaml]. [/api/schema/v1.yaml]: ../../../../api/schema/v1.yaml ## Application-specific patches Patches in application ID-named directories are application-specific and apply after global patches ## Examples - Global patch:99-dump-conf- App patch:com.example.app/99-test.jsoncom.example.app/99-test.json: ```json { "ociVersion": "1.0.1", "patch": [ { "op": "add", "path": "/mounts/-", "value": { "destination": "/opt/host-apps/", "type": "bind", "source": "/opt/apps", "options": [ "rbind" ] } } ] } ``` com.example.app/99-test.json add an extra mounts, which bind host's/opt/appsto container's/opt/host-apps, this patch will applied after 99-dump-conf. 99-dump-conf can write following content to print the container's configuration: ``` bash #!/bin/sh content=$(cat -) echo $content >&2 echo ${content} ```

这份文档正好解释了 玲珑容器的扩展机制,它允许通过 OCI 配置补丁 (patch) 或 生成器 (generator) 来修改容器的挂载点和权限

因此可以通过如下方式,配置容器的挂载点,从而实现应用访问外部储存器空间:

  1. 确认应用 ID

玲珑的应用配置目录通常在:

~/.config/linglong/config.d/<app-id>/

可以通过:

ll-cli list

找到准确的应用 ID。

  1. 创建应用专属补丁

以“迅雷”为例:

~/.config/linglong/config.d/com.thunder.download/ 下新建一个 JSON 文件,例如 99-mount-disk.json:

{ "ociVersion": "1.0.1", "patch": [ { "op": "add", "path": "/mounts/-", "value": { "destination": "/mnt/usb", "type": "bind", "source": "/mnt/usb", "options": [ "rbind", "rw" ] } } ] }

解释:

source:宿主机的移动硬盘挂载点(比如 /mnt/usb)。

destination:容器内的路径(你可以保持一致 /mnt/usb,迅雷就能访问)。

options:rbind 保证子目录也挂载进去,rw 允许读写。
  1. 重启应用

保存补丁后,重启迅雷容器:

ll-cli restart com.xunlei.download