{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "延的杂货铺",
  "home_page_url": "https://haresora.uk",
  "feed_url": "https://haresora.uk/feed.json",
  "description": "记录技术、思考与生活 —— 一个安静的角落。",
  "language": "zh-CN",
  "authors": [
    {
      "name": "延",
      "avatar": "https://haresora.uk/assets/avatar-cat.jpg"
    }
  ],
  "items": [
    {
      "id": "https://haresora.uk/blog/welcome",
      "url": "https://haresora.uk/blog/welcome",
      "title": "你好，世界",
      "content_html": "<h2 id=\"为什么要有一个自己的小站\">为什么要有一个自己的小站<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#为什么要有一个自己的小站\">#</a></h2>\n<p>在这个被信息流推着走的时代，拥有一个<strong>安静的、属于自己的角落</strong>变得格外珍贵。</p>\n<p>这里没有算法推荐，没有信息茧房，只有我想记录的东西：</p>\n<ul>\n<li>技术上的思考与折腾</li>\n<li>和人类接触后的深思</li>\n<li>设计与审美的探索</li>\n<li>一些生活的碎片</li>\n</ul>\n<blockquote>\n<p>写作是为了更好地思考。</p>\n</blockquote>\n<p>希望你在这里读得舒服。☕</p>",
      "summary": "这是这个小站的第一篇文章 —— 关于为什么要有一个自己的角落。",
      "image": "https://haresora.uk/assets/covers/flower.svg",
      "date_published": "2026-06-14T00:00:00.000Z",
      "date_modified": "2026-06-12T00:00:00.000Z",
      "tags": [
        "随笔",
        "开始"
      ]
    },
    {
      "id": "https://haresora.uk/blog/frp-ollama-remote-access",
      "url": "https://haresora.uk/blog/frp-ollama-remote-access",
      "title": "通过 frp 远程调用服务端的 ollama 模型",
      "content_html": "<h2 id=\"前情提要\">前情提要<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#前情提要\">#</a></h2>\n<p>我为了出门轻便于是用的是 MacBook Air，我也做好了接受无法跑重量级项目的准备，所以我希望把能跑在云上的都跑在云上。大部分服务可以通过 AI 算力提供商的 API 来解决，但针对一些不希望上传到第三方云端的信息那么就需要本地部署的大模型来处理了。</p>\n<p>在我家里的台式电脑为了低成本的大 VRAM 特意选配了<code>NVIDIA RTX 4060Ti 16GiB</code>，跑一些 20B+ 的模型甚至一些量化过的 30B+ 模型还是绰绰有余的。</p>\n<p>最近 Google DeepMind 团队推出了 <strong>Gemma 4</strong> 的系列模型，除了为边缘计算设备准备的 E2B、E4B，以及对我电脑来说负担有些重的 31B 以外，还有一个中等量级的 26B，当通过 ollama 部署在本地时，会调用 <strong>30%CPU + 70%GPU</strong>，用起来推理速度和响应速度也非常快，于是我便打算采用本地部署 <code>gemma4:26b</code> 并在 MacBook Air 上通过 frp 端口转发远程调用的方案。</p>\n<h2 id=\"准备\">准备<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#准备\">#</a></h2>\n<ul>\n<li><strong>一台算力满足你要求的电脑</strong></li>\n<li><strong>VPS</strong></li>\n</ul>\n<div class=\"admonition admonition-warning\" data-title=\"注意\"><p>VPS 不要做一些有被封 IP 风险的事，最后需要关闭代理。</p></div>\n<h2 id=\"step-1--服务端的准备\">Step 1 · 服务端的准备<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-1--服务端的准备\">#</a></h2>\n<h3 id=\"1-安装-ollama\">1. 安装 ollama<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#1-安装-ollama\">#</a></h3>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">macOS &#x26; Linux</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">curl</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -fsSL</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> https://ollama.com/install.sh</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> |</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> sh</span></span></code></pre></div></figure>\n<figure class=\"code-block\" data-lang=\"powershell\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">Windows PowerShell</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">irm https:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">//</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">ollama.com</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">install.ps1 </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">|</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> iex</span></span></code></pre></div></figure>\n<div class=\"admonition admonition-tip\" data-title=\"提示\"><p>在中国大陆网络环境下载时请使用代理</p></div>\n<h3 id=\"2-更改环境变量\">2. 更改环境变量<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#2-更改环境变量\">#</a></h3>\n<p>将一个关键的环境变量 <code>OLLAMA_HOST</code> 更改为 <code>0.0.0.0</code> (默认为<code>127.0.0.1</code>)：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">macOS &#x26; Linux</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> OLLAMA_HOST</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"http://0.0.0.0:11434\"</span></span></code></pre></div></figure>\n<p><em>可以将其写入 <code>~/.bashrc</code> 或 <code>~/.zshrc</code> 等，来自动设置变量。</em></p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"powershell\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">Windows PowerShell</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 仅用于当前会话</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">$</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">env:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">OLLAMA_HOST</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"0.0.0.0\"</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 用于当前用户的所有会话</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">Environment</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]::SetEnvironmentVariable(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"OLLAMA_HOST\"</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">,</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"0.0.0.0\"</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">,</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"User\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)</span></span></code></pre></div></figure>\n<p>默认的设置只能通过本机访问 ollama 服务，但我们要从互联网访问这个服务，所以需要将其改为 <code>0.0.0.0</code> （这里我使用了默认的11434端口，若希望自定义，请在后续的 <code>frpc.toml</code> 文件中将本地端口改为自定义的端口）。</p>\n<h3 id=\"3-运行-ollama\">3. 运行 ollama<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#3-运行-ollama\">#</a></h3>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ollama</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> serve</span></span></code></pre></div></figure>\n<p>如果看到那一串日志中有 <code>Listening on [:]:11434</code> 字段，就代表成功了。</p>\n<div class=\"admonition admonition-danger\" data-title=\"如果 Windows 系统报错\"><figure class=\"code-block\" data-lang=\"powershell\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">powershell</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">listen tcp </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">0.0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">0.0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">11434</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: bind: only one usage of each socket address (protocol</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">network address</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">port) is normally permitted.</span></span></code></pre></div></figure><p>那请<strong>在托盘右键小图标退出 ollama 再重新运行上面那行命令</strong>，它和命令行中运行的 ollama 是不同的进程，我们作为服务端是用不到它的 GUI 软件的，这个进程会与我们从命令行启动的服务端抢占 11434 端口。</p></div>\n<h2 id=\"step-21--配置-frp-内网穿透服务端\">Step 2.1 · 配置 frp 内网穿透：服务端<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-21--配置-frp-内网穿透服务端\">#</a></h2>\n<p>如果拥有公网 IP 那么配置一个 DDNS 服务即可，但大多数情况下是获取不到公网 IPv4 的，所以内网穿透是个不错的方案。</p>\n<p>我一开始想着使用公益的第三方内网穿透服务，比如 SakuraFRP。但国内节点在访问时都要求备案，这是一个很麻烦的事情，我个人也很讨厌备案，于是利用了自己用于部署个人网站的 VPS 来部署内网穿透服务。</p>\n<h3 id=\"1-ssh-登录到-vps\">1. ssh 登录到 VPS<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#1-ssh-登录到-vps\">#</a></h3>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 替换为自己的用户名和服务器 IP 地址</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 建议使用 root 用户</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ssh</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> &#x3C;</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">use</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">r</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">></span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">&#x3C;</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">Server</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> I</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">P</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">></span></span></code></pre></div></figure>\n<h3 id=\"2-获取-frp-并解压缩\">2. 获取 frp 并解压缩<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#2-获取-frp-并解压缩\">#</a></h3>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 下载 frp</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">wget</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> https://github.com/fatedier/frp/releases/download/v0.68.1/frp_0.68.1_linux_amd64.tar.gz</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 解压缩</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">tar</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -xzvf</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frp_0.68.1_linux_amd64.tar.gz</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 将解压缩后的文件夹直接改名为 frp 方便管理</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">mv</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frp_0.68.1_linux_amd64</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frp</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 删除压缩包</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">rm</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frp_0.68.1_linux_amd64.tar.gz</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 把 frp/ 放在 /usr/local 中</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">mv</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frp</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /usr/local</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 进入 frp 目录</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">cd</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /usr/local/frp</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> </span></span></code></pre></div></figure>\n<p>这个目录里既有服务端也有客户端，我们只需要在 VPS 上配置服务端。</p>\n<h3 id=\"3-配置-frpstoml\">3. 配置 frps.toml<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#3-配置-frpstoml\">#</a></h3>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">vim</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> ./frps.toml</span></span></code></pre></div></figure>\n<p>配置下列选项:</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"toml\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">frps.toml</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 与客户端通信的端口，默认7000</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">bindPort = </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">7000</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 认证方式，默认使用令牌（token）</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">auth.method = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"token\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 设置你的令牌，也就是密码</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">auth.token = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"your_secure_token\"</span></span></code></pre></div></figure>\n<p>这时候其实就可以运行了^_^</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">./frps</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -c</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> ./frps.toml</span></span></code></pre></div></figure>\n<h3 id=\"4-创建守护进程\">4. 创建守护进程<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#4-创建守护进程\">#</a></h3>\n<p>这时当然可以用 <code>screen</code> 工具使其后台运行,但那样即不优雅也不安全，我们还是停止这个进程来创建一个 <strong>守护进程（daemon）</strong> 吧：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">vim</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /etc/systemd/system/frps.service</span></span></code></pre></div></figure>\n<p>在里面写如下内容：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"ini\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">/etc/systemd/system/frps.service</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">[Unit]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">Description</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=FRP Server Daemon</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">After</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=network.target</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">[Service]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">Type</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=simple</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">ExecStart</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=/usr/local/frp/frps -c /usr/local/frp/frps.toml</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">Restart</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=always</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">RestartSec</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=2s</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">User</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=nobody</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">[Install]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">WantedBy</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">=multi-user.target</span></span></code></pre></div></figure>\n<p>启用 <code>frps.service</code>:</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">systemctl</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> enable</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --now</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> frps.service</span></span></code></pre></div></figure>\n<p>这时，我们 VPS 上的 frp 服务就配置好了。</p>\n<h2 id=\"step-22--配置-frp-内网穿透客户端\">Step 2.2 · 配置 frp 内网穿透：客户端<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-22--配置-frp-内网穿透客户端\">#</a></h2>\n<h3 id=\"1-下载-frp-压缩包到算力主机上\">1. 下载 frp 压缩包到算力主机上<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#1-下载-frp-压缩包到算力主机上\">#</a></h3>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<table><thead><tr><th>平台</th><th>下载链接</th></tr></thead><tbody><tr><td>Windows (amd64)</td><td><a href=\"https://github.com/fatedier/frp/releases/download/v0.68.1/frp_0.68.1_windows_amd64.zip\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"external-link\">frp_0.68.1_windows_amd64.zip</a></td></tr><tr><td>Linux (amd64)</td><td><a href=\"https://github.com/fatedier/frp/releases/download/v0.68.1/frp_0.68.1_linux_amd64.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"external-link\">frp_0.68.1_linux_amd64.tar.gz</a></td></tr><tr><td>macOS (Apple Sillicon)</td><td><a href=\"https://github.com/fatedier/frp/releases/download/v0.68.1/frp_0.68.1_darwin_arm64.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"external-link\">frp_0.68.1_darwin_arm64.tar.gz</a></td></tr></tbody></table>\n<p><em>如需其它平台可以在仓库里自行返翻找。我不觉得会有人拿 Intel 芯片的 macOS 跑 LLM。真的有吗？</em></p>\n<h3 id=\"2-编辑-frpctoml\">2. 编辑 frpc.toml<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#2-编辑-frpctoml\">#</a></h3>\n<p>解压后进入目录，我们需要用两个文件。分别是可执行文件 <code>frpc</code> 或 <code>frpc.exe</code> ，以及它的配置文件 <code>frpc.toml</code> ，编辑 <code>frpc.toml</code> :</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"toml\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">frpc.toml</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">serverAddr = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"127.0.0.1\"</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 与之前在 VPS 上配置的 frps.toml 中的 bindPort 端口号相同</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">serverPort = </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">7000</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[[</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">proxies</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">name = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"ollama\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">type = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"tcp\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">localIP = </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"127.0.0.1\"</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 如果之前更改了 ollama 的监听端口，在这里也要修改成相同的</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">localPort = </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">11434</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 远程端口，可以自定义，我用的还是 11434</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 后续 ollama 客户端上的环境变量中的端口须于此相同</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">remotePort = </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">11434</span></span></code></pre></div></figure>\n<h3 id=\"3-运行-frp-客户端\">3. 运行 frp 客户端<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#3-运行-frp-客户端\">#</a></h3>\n<p>保存并退出，即可运行 frp 客户端了：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">macOS &#x26; Linux</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">./frpc</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -c</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> ./frpc.toml</span></span></code></pre></div></figure>\n<figure class=\"code-block\" data-lang=\"powershell\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">Windows PowerShell</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.\\</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">frpc.exe</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> -</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">c .\\frpc.toml</span></span></code></pre></div></figure>\n<p><em>也可将其写作快捷脚本乃至守护进程/系统服务。</em></p>\n<p>此时，ollama 的 <code>0.0.0.0:11434</code> 将被转发至 <code>&#x3C;VPS 的 IP 地址>:&#x3C;远程端口></code>。我们可以进行下一步了，也就是最后在便携平台上连接我们配置的 ollama 服务。</p>\n<h2 id=\"step-3--ollama-客户端\">Step 3 · ollama 客户端<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-3--ollama-客户端\">#</a></h2>\n<h3 id=\"1-更改希望作为-ollama-客户端的电脑的环境变量\">1. 更改希望作为 ollama 客户端的电脑的环境变量<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#1-更改希望作为-ollama-客户端的电脑的环境变量\">#</a></h3>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">macOS &#x26; Linux</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 将 VPS IP 和 remotePort 分别替换为 VPS 的 IPv4 地址和之前设置的远程端口</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> OLLAMA_HOST</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"http://&#x3C;VPS IP>:&#x3C;remotePort>\"</span></span></code></pre></div></figure>\n<figure class=\"code-block has-line-numbers\" data-lang=\"powershell\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">Windows PowerShell</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># 将 VPS IP 和 remotePort 分别替换为 VPS 的 IPv4 地址和之前设置的远程端口</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">Environment</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]::SetEnvironmentVariable(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"OLLAMA_HOST\"</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">,</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"http://&#x3C;VPS IP>:&#x3C;remotePort>\"</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">,</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"User\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)</span></span></code></pre></div></figure>\n<h3 id=\"2-运行-llm-吧\">2. 运行 LLM 吧！<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#2-运行-llm-吧\">#</a></h3>\n<p>这时就可以使用 ollama 命令来远程运行自己搭建的 LLM 服务了：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ollama</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> run</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> &#x3C;</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">模型的具体名</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">称</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">></span></span></code></pre></div></figure>\n<p>也可以在 opencode 之类的 agent 中启动它：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ollama</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> launch</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> opencode</span></span></code></pre></div></figure>",
      "summary": "其实本质上很简单，但有一些小坑需要绕一下。",
      "image": "https://haresora.uk/assets/covers/ollama.svg",
      "date_published": "2026-03-14T00:00:00.000Z",
      "date_modified": "2026-07-03T00:00:00.000Z",
      "tags": [
        "技术",
        "折腾"
      ]
    },
    {
      "id": "https://haresora.uk/blog/raspberry-pi-usb-boot",
      "url": "https://haresora.uk/blog/raspberry-pi-usb-boot",
      "title": "如何将树莓Pi系统拷贝至硬盘中运行",
      "content_html": "<blockquote>\n<p>前情提要：前些天想搭建一个简易NAS存一些文件、图片、音乐、电影，也正好把吃灰好久的树莓派和一块4TB HDD用起来。但因为TF卡频繁的读写会导致TF卡很快挂掉，我这张又是128GB的闪迪金卡，所以很舍不得把它用来当树莓派的系统。尽管我会关掉swap和日志写入，但我还是希望更保险一点——通过USB外置硬盘来运行整个Raspi OS，空间又大又安全 ✔️。</p>\n</blockquote>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>设备</td><td><code>Raspberry Pi 4 Model B (with 4GiB RAM)</code></td></tr><tr><td>系统</td><td><code>Raspberry Pi OS Lite (64 bit) based on Debian 13 Trixie</code></td></tr><tr><td>硬盘</td><td><code>西数红盘 4TiB</code></td></tr></tbody></table>\n<div class=\"admonition admonition-note\" data-title=\"笔记\"><p>PS: 尽管是个较为复杂的工作，但全命令行是可以实现的，因此实际并不需要显示器连接或远程桌面，因此为了最小化和纯净的体验，Lite系统就足以支撑起简单的samba甚至OpenMediaVault配置了，如果选择了桌面环境反而会有些臃肿。</p></div>\n<h2 id=\"step-0--前期准备\">Step 0 · 前期准备<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-0--前期准备\">#</a></h2>\n<p>使用 CAT 5e 以上的网线连接到路由器或交换机，保证树莓派跑满千兆有线网络，不要使用WLAN进行这类存储设备的配置，会非常不稳定。</p>\n<h2 id=\"step-1--写入系统到tf卡并进行初始配置\">Step 1 · 写入系统到TF卡并进行初始配置<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-1--写入系统到tf卡并进行初始配置\">#</a></h2>\n<p>将系统通过Raspberry Pi Imager写入到TF卡并启动，这是不可避免的。也许你希望直接把系统写入到硬盘并启动了事，但这在大容量存储设备上不可行。</p>\n<div class=\"admonition admonition-warning\" data-title=\"注意\"><p><strong>Raspberry Pi Imager会自动将你的硬盘设置为MBR，这会导致你驱动器上大于2TiB的部分不被支持，被浪费掉。</strong>\n同时强烈建议不管硬盘大小都使用更为先进的GPT，而不是老旧的MBR。</p></div>\n<p>在写入TF卡时要在Imager中进行的配置：</p>\n<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> 账户与密码</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> 时区与键盘</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> ssh</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> WLAN留空 (我们已经使用了有线连接，没有必要再配置无线网连接。)</li>\n</ul>\n<p>待系统启动后，通过路由器的管理面板找到raspi的IP地址，并将其与树莓派有线网卡的MAC地址绑定，使其IP不再变动，这样方便后续的管理与使用。</p>\n<p>最后更新一下系统：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> apt</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> update</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> apt</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> upgrade</span></span></code></pre></div></figure>\n<p>还可以安装一下自己想要的软件，比如我安装了更为习惯的<code>vim</code>并删除了<code>nano</code>，<code>samba</code>等服务可以后期再装，否则稍后拷贝系统会需要更长时间。</p>\n<h2 id=\"step-2--初始化hdd并拷贝系统\">Step 2 · 初始化HDD并拷贝系统<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-2--初始化hdd并拷贝系统\">#</a></h2>\n<div class=\"admonition admonition-danger\" data-title=\"警告\"><p><strong>这一步会清空你的磁盘，请做好备份</strong></p></div>\n<p>首先我们需要将整个磁盘转为GPT格式并分区，先检查磁盘的位置：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">lsblk</span></span></code></pre></div></figure>\n<p>假设磁盘位于<code>/dev/sda</code>，使用<code>parted</code>来修改分区表并创建分区:</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">parted</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda</span></span></code></pre></div></figure>\n<p>在<code>parted</code>中运行：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"text\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">parted</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>mklabel gpt                         # 将整个磁盘转化为GPT分区表</span></span>\n<span class=\"line\"><span>yes                                 # 确认</span></span>\n<span class=\"line\"><span>mkpart primary fat32 1MiB 512MiB    # 创建一个512MiB大小的EFI分区，用于存放引导文件</span></span>\n<span class=\"line\"><span>set 1 boot on                       # 使EFI分区被标记为可引导启动</span></span>\n<span class=\"line\"><span>mkpart primary ext4 512MiB 100%     # 创建主分区，从512MiB的位置开始直到填满100%的磁盘空间</span></span>\n<span class=\"line\"><span>quit                                # 退出parted</span></span></code></pre></div></figure>\n<p>这一步完成后在<code>/dev/sda</code>下会分别存在<code>/dev/sda1</code>和<code>/dev/sda2</code>两个分区，分别是EFI和主分区，我们接下来格式化这两个分区：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mkfs.vfat</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -F32</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda1</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mkfs.ext4</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda2</span></span></code></pre></div></figure>\n<h3 id=\"之后开始拷贝我们的系统到hdd中并确保它可以被引导启动\">之后开始拷贝我们的系统到HDD中并确保它可以被引导启动<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#之后开始拷贝我们的系统到hdd中并确保它可以被引导启动\">#</a></h3>\n<p><del>（就在这一步我被AI大人坑了一下午！！！）</del></p>\n<p>首先分别把当前TF卡的两个分区和HDD的两个分区挂载到两个位置，我选择把当前系统挂载到<code>/mnt/src</code>，HDD挂载到<code>/mnt/dst</code>，在这之前可以再用<code>lsblk</code>看一下TF卡和HDD的位置，我的分别是<code>/dev/mmcblk0</code>和<code>/dev/sda</code>：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">挂载 TF 卡与 HDD</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># TF 卡</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mount</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --mkdir</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/mmcblk0p2</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/src</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mount</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --mkdir</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/mmcblk0p1</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/src/boot/firmware</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"># HDD</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mount</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --mkdir</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda2</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/dst</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> mount</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --mkdir</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda1</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/dst/boot/firmware</span></span></code></pre></div></figure>\n<p>AI没有提到的是：</p>\n<div class=\"admonition admonition-danger\" data-title=\"警告\"><p><strong>在Debian 12 Bookworm的Raspi OS之后，所有引导文件都被放在了/boot/firmware中，所以挂载时要格外注意这一点。</strong></p></div>\n<p>我们不用<code>cp</code>或者<code>dd</code>来拷贝系统，而是用<code>rsync</code>这个工具，并将一些没有必要的目录排除在外不拷贝：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> rsync</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -aAXHv</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  --exclude=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">{</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/dev/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/proc/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/sys/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/tmp/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/run/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/mnt/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/media/*\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">,</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">\"/lost+found\"</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">}</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  /mnt/src/</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/dst/</span></span></code></pre></div></figure>\n<h2 id=\"step-3--修改新系统的fstab等\">Step 3 · 修改新系统的fstab等<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#step-3--修改新系统的fstab等\">#</a></h2>\n<p>在<code>/mnt/dst/etc/fstab</code>（也就是新系统的<code>/etc/fstab</code>）文件中存放了“自动挂载”相关的信息，它告诉系统哪些分区在开机时自动挂载到何处。如果这里配置有误，系统就找不到正确的分区从而无法启动。由于我们刚才拷贝的内容来自原系统，所以这里面的信息还是指向了原来的TF卡，因此我们要把它改成HDD的分区们。</p>\n<div class=\"admonition admonition-info\" data-title=\"关于 UUID\"><p>这里补充一个关于UUID的知识，UUID是一种通用唯一身份识别符，在这里用来给我们的存储设备和它们的分区标记唯一身份信息。一个磁盘或分区的UUID在创建时就已经固定，不会变动，而系统内的路径比如<code>/dev/sda</code>有可能会改变，因此我们在<code>fstab</code>中使用UUID和磁盘分区的PARTUUID来指代它们，而不是<code>/dev/sda</code>这样的路径。</p></div>\n<p>使用<code>blkid &#x3C;设备></code>来查看指定设备的UUID，如：</p>\n<figure class=\"code-block has-line-numbers\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">blkid</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda1</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">blkid</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /dev/sda2</span></span></code></pre></div></figure>\n<p>这样就分别拥有了我们EFI分区和主分区的PARTUUID。</p>\n<p>AI在这里再次坑了我：</p>\n<div class=\"admonition admonition-danger\" data-title=\"警告\"><p><strong>一定找后面的PARTUUID=，而不是前面的UUID=，Raspi OS在<code>fstab</code>中使用的是PARTUUID=xxxx-xxxx</strong></p></div>\n<p>将它们复制到剪贴板备用，接下来：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> vim</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/dst/etc/fstab</span></span></code></pre></div></figure>\n<p>将其中<code>/boot/firmware</code>和<code>/</code>前面的PARTUUID=xxxx-xxxx分别改为刚刚获取到的<code>sda1</code>和<code>sda2</code>的PARTUUID。</p>\n<p>最后我们修改一下<code>/mnt/dst/boot/firmware/cmdline.txt</code>(在Raspi OS，<code>cmdline.txt</code>的位置也被放进了<code>/boot/firmware</code>)</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> vim</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt/dst/boot/firmware/cmdline.txt</span></span></code></pre></div></figure>\n<p>将其中<code>root=PARTUUID=xxxx-xxxx</code>的PARTUUID该为我们主分区<code>sda2</code>的PARTUUID并保存。</p>\n<hr>\n<p>最后更改一下系统引导顺序，把USB设置成第一位（其实不改也可以，到时候拔掉TF卡系统找不到TF卡会自动找下一级USB启动）：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> raspi-config</span></span></code></pre></div></figure>\n<p><code>Advanced Options</code> → <code>Boot Order</code> → <code>NVMe USB Boot</code></p>\n<p>保存后<code>umount</code>刚刚的挂载防止使用中的情况：</p>\n<figure class=\"code-block\" data-lang=\"bash\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">bash</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">sudo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> umount</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -R</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> /mnt</span></span></code></pre></div></figure>\n<p>现在可以关闭电源，拔下TF卡并重新上电了！</p>\n<p><strong>至此，我们的树莓派系统成功跑在了HDD上（或者你有SSD的话性能会更好），之后的Samba或者Open Media Vault以及性能优化全看你的选择~</strong></p>\n<p><em>2025-12-18_15:41 by 晴れ空☀️</em></p>\n<h2 id=\"后记\">后记<a class=\"heading-anchor\" aria-label=\"链接到此标题\" href=\"#后记\">#</a></h2>\n<p>我最后选择了samba（公网配置OpenVPN）的方案，于是在samba的配置这里又踩了个坑。</p>\n<p>如果你的手机是iOS，首先要在<code>/etc/samba/smb.conf</code>中<code>[global]</code>模块下面加一条</p>\n<figure class=\"code-block\" data-lang=\"ini\"><figcaption class=\"code-bar\"><span class=\"code-dots\" aria-hidden=\"true\"><i></i><i></i><i></i></span><span class=\"code-title\">/etc/samba/smb.conf</span><button type=\"button\" class=\"code-copy\" data-code-copy=\"\" aria-label=\"复制代码\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" class=\"icon-copy\"><path d=\"M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z\"></path></svg><span class=\"code-copied\">已复制</span></button></figcaption><div class=\"code-scroll\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">vfs </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">objects</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> = fruit streams_xattr</span></span></code></pre></div></figure>\n<div class=\"admonition admonition-warning\" data-title=\"注意\"><p>这对iOS的文件App至关重要，如果不加上它会导致iOS系统对你分享的目录只读。T_T</p></div>\n<p><em>Last Edited: 2026-03-31_01:20 by 晴れ空☀️</em></p>",
      "summary": "通过这件事我学到的最大教训就是不要完全相信AI，至少目前不要。。。",
      "image": "https://haresora.uk/assets/covers/raspi.svg",
      "date_published": "2026-06-14T00:00:00.000Z",
      "date_modified": "2026-07-03T00:00:00.000Z",
      "tags": [
        "技术",
        "Linux"
      ]
    }
  ]
}