0

我正在从 AppImage(使用 appimage-builder v0.9.2 创建)中的脚本创建覆盖 FS(使用 unionfs-fuse)。
覆盖已成功挂载,但在脚本结束时,无法使用“ Operation not permitted”正确卸载。
在 AppImage 结束后,fusermount -u工作正常。

这是脚本script.sh

#!/bin/sh

ROOT_DIR=$(mktemp -d -t test-XXXXXX)
myUID=$(id -u)
myGID=$(id -g)
USER_DIR=/tmp/a
mkdir -p ${USER_DIR}

echo "Hello world!" > ${USER_DIR}/hello.txt

# create an overlay of $USER_DIR (rw) over $APPDIR (ro) into $ROOT_DIR
UNIONFS="unionfs -o cow,uid=${myUID},gid=${myGID} ${USER_DIR}=RW:${APPDIR} ${ROOT_DIR}"
if ! $( ${UNIONFS} ); then
    echo "mount failed!"
    exit 1
fi
echo "overlay created in ${ROOT_DIR}"

# files in $USER_DIR may be read/written from the overlay
cat ${ROOT_DIR}/hello.txt

# unmount overlay before closing the AppImage
fusermount -zu ${ROOT_DIR}
rmdir ${ROOT_DIR}

这是 AppImage 配方AppImageBuilder.yml

version: 1

AppDir:
  path: /home/user/bugreport

  app_info:
    id: org.appimage.test
    name: AppimageTest
    icon: terminal
    version: 0.0.1
    exec: bin/dash
    exec_args: "script.sh"

  apt:
    arch: amd64
    sources:
      - sourceline: 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse'
        key_url: 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3b4fe6acc0b21f32'
      - sourceline: 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse'
      - sourceline: 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse'

    include: [unionfs-fuse, dash, coreutils]
    exclude: []

AppImage:
  arch: x86_64
  update-information: None
  sign-key: None

terminal.png(构建 AppImage还需要一个随机图标文件)。

AppImage 是使用以下工具构建的:

$ appimage-builder --recipe ./AppImageBuilder.yml

任何帮助,将不胜感激!

4

1 回答 1

0

一种解决方法是:

  • 使用选项启动 unionfsauto_unmount
  • 而不是fusermount -u, 杀死最后一个 unionfs 进程pkill -nf ${ROOT_DIR}
    (杀死参数中包含 ${ROOT_DIR} 的最新进程)

结果脚本:

#!/bin/sh

ROOT_DIR=$(mktemp -d -t test-XXXXXX)
myUID=$(id -u)
myGID=$(id -g)
USER_DIR=/tmp/a
mkdir -p ${USER_DIR}

echo "Hello world!" > ${USER_DIR}/hello.txt

# create an overlay of $USER_DIR (rw) over $APPDIR (ro) into $ROOT_DIR
UNIONFS="unionfs -o cow,auto_unmount,uid=${myUID},gid=${myGID} ${USER_DIR}=RW:${APPDIR} ${ROOT_DIR}"
if ! $( ${UNIONFS} ); then
    echo "mount failed!"
    exit 1
fi
echo "overlay created in ${ROOT_DIR}"

# files in $USER_DIR may be read/written from the overlay
cat ${ROOT_DIR}/hello.txt

# killing unionfs will unmount the overlay
pkill -nf ${ROOT_DIR}
sleep 0.1
rmdir ${ROOT_DIR}
于 2021-10-27T12:36:44.880 回答