Skip to content

Commit

Permalink
Update virtiofsd.sh for docker2
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Dec 22, 2024
1 parent ad5f96e commit 0e3bf10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions docs/assets/pve/mirrorlog.sh → docs/assets/pve/virtiofsd.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#!/bin/sh

if [ $# -ne 2 ]; then
if test $# -ne 2; then
echo "Need exactly 2 arguments" >&2
exit 1
fi

VMID="$1"
PHASE="$2"

[ "$VMID" -eq 230 ] || exit 0
case "$VMID" in
201) SHARED_DIR=/mnt/docker2 ;;
230) SHARED_DIR=/mnt/mirrorlog ;;
*) exit 0 ;;
esac

NAME=virtiofsd-230
NAME="virtiofsd-$VMID"
SOCKPATH="/run/$NAME.sock"

case "$PHASE" in
pre-start)
systemctl stop "$NAME".service
systemctl stop "$NAME".service || true
rm -f "$SOCKPATH" "$SOCKPATH".pid

systemd-run \
Expand All @@ -24,7 +28,7 @@ case "$PHASE" in
/usr/libexec/virtiofsd \
--syslog \
--socket-path "$SOCKPATH" \
--shared-dir /mnt/mirrorlog \
--shared-dir "$SHARED_DIR" \
--announce-submounts \
--inode-file-handles=mandatory
;;
Expand Down
6 changes: 3 additions & 3 deletions docs/infrastructure/proxmox/pve.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ args: -chardev socket,id=virtfs0,path=/run/virtiofsd-230.sock -device vhost-user

接下来需要配置 virtiofsd 在虚拟机开机前启动。注意一个 virtiofsd 只能供一个虚拟机访问一个主机上的目录,因此需要使用 PVE 的 hook script 来启动 virtiofsd。这个 hook script 放在 `/var/lib/vz` 目录下,接收两个命令行参数(VMID 和启动阶段):

```shell title="/var/lib/vz/snippets/mirrorlog.sh"
--8<-- "pve/mirrorlog.sh"
```shell title="/var/lib/vz/snippets/virtiofsd.sh"
--8<-- "pve/virtiofsd.sh"
```

相比于 Proxmox 论坛里的教程贴,这里最重要的修改是给 `systemd-run` 加上了 `--collect` 参数,这样 virtiofsd 退出时无论是否 failed,systemd 都会清理掉这个临时的 service unit。

然后通过命令行配置使用:

```shell
qm set 230 --hookscript local:snippets/mirrorlog.sh
qm set 230 --hookscript local:snippets/virtiofsd.sh
```

然后将虚拟机关机,通过 `qm start` 或者 web 界面启动,即可在虚拟机内挂载 virtiofsd 提供的目录。
Expand Down

0 comments on commit 0e3bf10

Please sign in to comment.