From 0e3bf102c9a1a925d847cb9798fdaa2b8219fa1c Mon Sep 17 00:00:00 2001 From: iBug Date: Mon, 23 Dec 2024 04:33:10 +0800 Subject: [PATCH] Update virtiofsd.sh for docker2 --- docs/assets/pve/{mirrorlog.sh => virtiofsd.sh} | 14 +++++++++----- docs/infrastructure/proxmox/pve.md | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) rename docs/assets/pve/{mirrorlog.sh => virtiofsd.sh} (68%) mode change 100644 => 100755 diff --git a/docs/assets/pve/mirrorlog.sh b/docs/assets/pve/virtiofsd.sh old mode 100644 new mode 100755 similarity index 68% rename from docs/assets/pve/mirrorlog.sh rename to docs/assets/pve/virtiofsd.sh index b2746af5..27f15eb5 --- a/docs/assets/pve/mirrorlog.sh +++ b/docs/assets/pve/virtiofsd.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ $# -ne 2 ]; then +if test $# -ne 2; then echo "Need exactly 2 arguments" >&2 exit 1 fi @@ -8,14 +8,18 @@ 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 \ @@ -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 ;; diff --git a/docs/infrastructure/proxmox/pve.md b/docs/infrastructure/proxmox/pve.md index efe9a9aa..91dccc1c 100644 --- a/docs/infrastructure/proxmox/pve.md +++ b/docs/infrastructure/proxmox/pve.md @@ -187,8 +187,8 @@ 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。 @@ -196,7 +196,7 @@ args: -chardev socket,id=virtfs0,path=/run/virtiofsd-230.sock -device vhost-user 然后通过命令行配置使用: ```shell -qm set 230 --hookscript local:snippets/mirrorlog.sh +qm set 230 --hookscript local:snippets/virtiofsd.sh ``` 然后将虚拟机关机,通过 `qm start` 或者 web 界面启动,即可在虚拟机内挂载 virtiofsd 提供的目录。