Skip to content

Commit

Permalink
Auto deploy from GitHub Actions build 491
Browse files Browse the repository at this point in the history
[0e3bf10] iBug: Update virtiofsd.sh for docker2
  • Loading branch information
web-flow authored Dec 22, 2024
1 parent 3c58436 commit 0dc654d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 104 deletions.
14 changes: 9 additions & 5 deletions assets/pve/mirrorlog.sh → assets/pve/virtiofsd.sh
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
60 changes: 32 additions & 28 deletions infrastructure/proxmox/pve/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3071,45 +3071,49 @@ <h3 id="virtiofs">VirtIO FS<a class="headerlink" href="#virtiofs" title="Permane
<p>其中 <code>path=</code> 指向 virtiofsd 的 socket 文件,<code>tag=</code> 可以任意指定,用于区分多个 virtiofsd 实例(对应虚拟机内的 mount source),<code>size=</code> 是共享内存大小。</p>
<p>然后安装 virtiofsd,直接 <code>apt install virtiofsd</code> 即可(PVE 打包了 Rust 重写的新版 virtiofsd)。</p>
<p>接下来需要配置 virtiofsd 在虚拟机开机前启动。注意一个 virtiofsd 只能供一个虚拟机访问一个主机上的目录,因此需要使用 PVE 的 hook script 来启动 virtiofsd。这个 hook script 放在 <code>/var/lib/vz</code> 目录下,接收两个命令行参数(VMID 和启动阶段):</p>
<div class="highlight"><span class="filename">/var/lib/vz/snippets/mirrorlog.sh</span><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="ch">#!/bin/sh</span>
<div class="highlight"><span class="filename">/var/lib/vz/snippets/virtiofsd.sh</span><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="ch">#!/bin/sh</span>
<a id="__codelineno-9-2" name="__codelineno-9-2" href="#__codelineno-9-2"></a>
<a id="__codelineno-9-3" name="__codelineno-9-3" href="#__codelineno-9-3"></a><span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="nv">$#</span><span class="w"> </span>-ne<span class="w"> </span><span class="m">2</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<a id="__codelineno-9-3" name="__codelineno-9-3" href="#__codelineno-9-3"></a><span class="k">if</span><span class="w"> </span><span class="nb">test</span><span class="w"> </span><span class="nv">$#</span><span class="w"> </span>-ne<span class="w"> </span><span class="m">2</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<a id="__codelineno-9-4" name="__codelineno-9-4" href="#__codelineno-9-4"></a><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Need exactly 2 arguments&quot;</span><span class="w"> </span>&gt;<span class="p">&amp;</span><span class="m">2</span>
<a id="__codelineno-9-5" name="__codelineno-9-5" href="#__codelineno-9-5"></a><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
<a id="__codelineno-9-6" name="__codelineno-9-6" href="#__codelineno-9-6"></a><span class="k">fi</span>
<a id="__codelineno-9-7" name="__codelineno-9-7" href="#__codelineno-9-7"></a>
<a id="__codelineno-9-8" name="__codelineno-9-8" href="#__codelineno-9-8"></a><span class="nv">VMID</span><span class="o">=</span><span class="s2">&quot;</span><span class="nv">$1</span><span class="s2">&quot;</span>
<a id="__codelineno-9-9" name="__codelineno-9-9" href="#__codelineno-9-9"></a><span class="nv">PHASE</span><span class="o">=</span><span class="s2">&quot;</span><span class="nv">$2</span><span class="s2">&quot;</span>
<a id="__codelineno-9-10" name="__codelineno-9-10" href="#__codelineno-9-10"></a>
<a id="__codelineno-9-11" name="__codelineno-9-11" href="#__codelineno-9-11"></a><span class="o">[</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$VMID</span><span class="s2">&quot;</span><span class="w"> </span>-eq<span class="w"> </span><span class="m">230</span><span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">0</span>
<a id="__codelineno-9-12" name="__codelineno-9-12" href="#__codelineno-9-12"></a>
<a id="__codelineno-9-13" name="__codelineno-9-13" href="#__codelineno-9-13"></a><span class="nv">NAME</span><span class="o">=</span>virtiofsd-230
<a id="__codelineno-9-14" name="__codelineno-9-14" href="#__codelineno-9-14"></a><span class="nv">SOCKPATH</span><span class="o">=</span><span class="s2">&quot;/run/</span><span class="nv">$NAME</span><span class="s2">.sock&quot;</span>
<a id="__codelineno-9-15" name="__codelineno-9-15" href="#__codelineno-9-15"></a>
<a id="__codelineno-9-16" name="__codelineno-9-16" href="#__codelineno-9-16"></a><span class="k">case</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$PHASE</span><span class="s2">&quot;</span><span class="w"> </span><span class="k">in</span>
<a id="__codelineno-9-17" name="__codelineno-9-17" href="#__codelineno-9-17"></a><span class="w"> </span>pre-start<span class="o">)</span>
<a id="__codelineno-9-18" name="__codelineno-9-18" href="#__codelineno-9-18"></a><span class="w"> </span>systemctl<span class="w"> </span>stop<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$NAME</span><span class="s2">&quot;</span>.service
<a id="__codelineno-9-19" name="__codelineno-9-19" href="#__codelineno-9-19"></a><span class="w"> </span>rm<span class="w"> </span>-f<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span>.pid
<a id="__codelineno-9-20" name="__codelineno-9-20" href="#__codelineno-9-20"></a>
<a id="__codelineno-9-21" name="__codelineno-9-21" href="#__codelineno-9-21"></a><span class="w"> </span>systemd-run<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-22" name="__codelineno-9-22" href="#__codelineno-9-22"></a><span class="w"> </span>--collect<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-23" name="__codelineno-9-23" href="#__codelineno-9-23"></a><span class="w"> </span>--unit<span class="o">=</span><span class="s2">&quot;</span><span class="nv">$NAME</span><span class="s2">&quot;</span><span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-24" name="__codelineno-9-24" href="#__codelineno-9-24"></a><span class="w"> </span>/usr/libexec/virtiofsd<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-25" name="__codelineno-9-25" href="#__codelineno-9-25"></a><span class="w"> </span>--syslog<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-26" name="__codelineno-9-26" href="#__codelineno-9-26"></a><span class="w"> </span>--socket-path<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span><span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-27" name="__codelineno-9-27" href="#__codelineno-9-27"></a><span class="w"> </span>--shared-dir<span class="w"> </span>/mnt/mirrorlog<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-28" name="__codelineno-9-28" href="#__codelineno-9-28"></a><span class="w"> </span>--announce-submounts<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-29" name="__codelineno-9-29" href="#__codelineno-9-29"></a><span class="w"> </span>--inode-file-handles<span class="o">=</span>mandatory
<a id="__codelineno-9-30" name="__codelineno-9-30" href="#__codelineno-9-30"></a><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-31" name="__codelineno-9-31" href="#__codelineno-9-31"></a><span class="w"> </span>pre-stop<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-32" name="__codelineno-9-32" href="#__codelineno-9-32"></a><span class="w"> </span>post-start<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-33" name="__codelineno-9-33" href="#__codelineno-9-33"></a><span class="w"> </span>post-stop<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-34" name="__codelineno-9-34" href="#__codelineno-9-34"></a><span class="w"> </span>*<span class="o">)</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Unknown phase </span><span class="nv">$PHASE</span><span class="s2">&quot;</span><span class="w"> </span>&gt;<span class="p">&amp;</span><span class="m">2</span><span class="p">;</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span><span class="p">;;</span>
<a id="__codelineno-9-35" name="__codelineno-9-35" href="#__codelineno-9-35"></a><span class="k">esac</span>
<a id="__codelineno-9-11" name="__codelineno-9-11" href="#__codelineno-9-11"></a><span class="k">case</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$VMID</span><span class="s2">&quot;</span><span class="w"> </span><span class="k">in</span>
<a id="__codelineno-9-12" name="__codelineno-9-12" href="#__codelineno-9-12"></a><span class="w"> </span><span class="m">201</span><span class="o">)</span><span class="w"> </span><span class="nv">SHARED_DIR</span><span class="o">=</span>/mnt/docker2<span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-13" name="__codelineno-9-13" href="#__codelineno-9-13"></a><span class="w"> </span><span class="m">230</span><span class="o">)</span><span class="w"> </span><span class="nv">SHARED_DIR</span><span class="o">=</span>/mnt/mirrorlog<span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-14" name="__codelineno-9-14" href="#__codelineno-9-14"></a><span class="w"> </span>*<span class="o">)</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">0</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-15" name="__codelineno-9-15" href="#__codelineno-9-15"></a><span class="k">esac</span>
<a id="__codelineno-9-16" name="__codelineno-9-16" href="#__codelineno-9-16"></a>
<a id="__codelineno-9-17" name="__codelineno-9-17" href="#__codelineno-9-17"></a><span class="nv">NAME</span><span class="o">=</span><span class="s2">&quot;virtiofsd-</span><span class="nv">$VMID</span><span class="s2">&quot;</span>
<a id="__codelineno-9-18" name="__codelineno-9-18" href="#__codelineno-9-18"></a><span class="nv">SOCKPATH</span><span class="o">=</span><span class="s2">&quot;/run/</span><span class="nv">$NAME</span><span class="s2">.sock&quot;</span>
<a id="__codelineno-9-19" name="__codelineno-9-19" href="#__codelineno-9-19"></a>
<a id="__codelineno-9-20" name="__codelineno-9-20" href="#__codelineno-9-20"></a><span class="k">case</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$PHASE</span><span class="s2">&quot;</span><span class="w"> </span><span class="k">in</span>
<a id="__codelineno-9-21" name="__codelineno-9-21" href="#__codelineno-9-21"></a><span class="w"> </span>pre-start<span class="o">)</span>
<a id="__codelineno-9-22" name="__codelineno-9-22" href="#__codelineno-9-22"></a><span class="w"> </span>systemctl<span class="w"> </span>stop<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$NAME</span><span class="s2">&quot;</span>.service<span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nb">true</span>
<a id="__codelineno-9-23" name="__codelineno-9-23" href="#__codelineno-9-23"></a><span class="w"> </span>rm<span class="w"> </span>-f<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span>.pid
<a id="__codelineno-9-24" name="__codelineno-9-24" href="#__codelineno-9-24"></a>
<a id="__codelineno-9-25" name="__codelineno-9-25" href="#__codelineno-9-25"></a><span class="w"> </span>systemd-run<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-26" name="__codelineno-9-26" href="#__codelineno-9-26"></a><span class="w"> </span>--collect<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-27" name="__codelineno-9-27" href="#__codelineno-9-27"></a><span class="w"> </span>--unit<span class="o">=</span><span class="s2">&quot;</span><span class="nv">$NAME</span><span class="s2">&quot;</span><span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-28" name="__codelineno-9-28" href="#__codelineno-9-28"></a><span class="w"> </span>/usr/libexec/virtiofsd<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-29" name="__codelineno-9-29" href="#__codelineno-9-29"></a><span class="w"> </span>--syslog<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-30" name="__codelineno-9-30" href="#__codelineno-9-30"></a><span class="w"> </span>--socket-path<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SOCKPATH</span><span class="s2">&quot;</span><span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-31" name="__codelineno-9-31" href="#__codelineno-9-31"></a><span class="w"> </span>--shared-dir<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$SHARED_DIR</span><span class="s2">&quot;</span><span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-32" name="__codelineno-9-32" href="#__codelineno-9-32"></a><span class="w"> </span>--announce-submounts<span class="w"> </span><span class="se">\</span>
<a id="__codelineno-9-33" name="__codelineno-9-33" href="#__codelineno-9-33"></a><span class="w"> </span>--inode-file-handles<span class="o">=</span>mandatory
<a id="__codelineno-9-34" name="__codelineno-9-34" href="#__codelineno-9-34"></a><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-35" name="__codelineno-9-35" href="#__codelineno-9-35"></a><span class="w"> </span>pre-stop<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-36" name="__codelineno-9-36" href="#__codelineno-9-36"></a><span class="w"> </span>post-start<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-37" name="__codelineno-9-37" href="#__codelineno-9-37"></a><span class="w"> </span>post-stop<span class="o">)</span><span class="w"> </span><span class="p">;;</span>
<a id="__codelineno-9-38" name="__codelineno-9-38" href="#__codelineno-9-38"></a><span class="w"> </span>*<span class="o">)</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Unknown phase </span><span class="nv">$PHASE</span><span class="s2">&quot;</span><span class="w"> </span>&gt;<span class="p">&amp;</span><span class="m">2</span><span class="p">;</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span><span class="p">;;</span>
<a id="__codelineno-9-39" name="__codelineno-9-39" href="#__codelineno-9-39"></a><span class="k">esac</span>
</code></pre></div>
<p>相比于 Proxmox 论坛里的教程贴,这里最重要的修改是给 <code>systemd-run</code> 加上了 <code>--collect</code> 参数,这样 virtiofsd 退出时无论是否 failed,systemd 都会清理掉这个临时的 service unit。</p>
<p>然后通过命令行配置使用:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a>qm<span class="w"> </span><span class="nb">set</span><span class="w"> </span><span class="m">230</span><span class="w"> </span>--hookscript<span class="w"> </span>local:snippets/mirrorlog.sh
<div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a>qm<span class="w"> </span><span class="nb">set</span><span class="w"> </span><span class="m">230</span><span class="w"> </span>--hookscript<span class="w"> </span>local:snippets/virtiofsd.sh
</code></pre></div>
<p>然后将虚拟机关机,通过 <code>qm start</code> 或者 web 界面启动,即可在虚拟机内挂载 virtiofsd 提供的目录。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="c1"># Manual</span>
Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Loading

0 comments on commit 0dc654d

Please sign in to comment.