<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>阿海</name>
  </author>
  <generator uri="https://hexo.io/">Hexo</generator>
  <id>https://rhsy.moe/</id>
  <link href="https://rhsy.moe/" rel="alternate"/>
  <link href="https://rhsy.moe/atom.xml" rel="self"/>
  <rights>All rights reserved 2026, 阿海</rights>
  <subtitle>Sakura Journal</subtitle>
  <title>夜樱手帐</title>
  <updated>2026-10-20T14:05:52.728Z</updated>
  <entry>
    <author>
      <name>阿海</name>
    </author>
    <category term="手帐" scheme="https://rhsy.moe/categories/%E6%89%8B%E5%B8%90/"/>
    <category term="日常" scheme="https://rhsy.moe/tags/%E6%97%A5%E5%B8%B8/"/>
    <content>
      <![CDATA[<p>第一篇日志！</p><p>这里以后会记录写代码和日常的碎片。</p>]]>
    </content>
    <id>https://rhsy.moe/2026/09/29/hello-world/</id>
    <link href="https://rhsy.moe/2026/09/29/hello-world/"/>
    <published>2026-09-29T02:00:00.000Z</published>
    <summary>
      <![CDATA[<p>第一篇日志！</p>
<p>这里以后会记录写代码和日常的碎片。</p>]]>
    </summary>
    <title>hello world ～</title>
    <updated>2026-10-20T14:05:52.728Z</updated>
  </entry>
  <entry>
    <author>
      <name>阿海</name>
    </author>
    <category term="运维" scheme="https://rhsy.moe/categories/%E8%BF%90%E7%BB%B4/"/>
    <category term="Bitwarden" scheme="https://rhsy.moe/tags/Bitwarden/"/>
    <category term="服务器" scheme="https://rhsy.moe/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/"/>
    <content>
      <![CDATA[<p>bitwarden是一个自由开源、跨平台的密码管理器，且提供浏览器插件，支持自动填充、totp、passkey等功能。</p><h2 id="服务端选择"><a href="#服务端选择" class="headerlink" title="服务端选择"></a>服务端选择</h2><p>Vaultwarden 是一个基于Rust开发的<strong>轻量级</strong> Bitwarden 服务端，支持MFA、多用户、多设备同步等。</p><h2 id="使用-Docker-Compose-构建"><a href="#使用-Docker-Compose-构建" class="headerlink" title="使用 Docker Compose 构建"></a>使用 Docker Compose 构建</h2><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">mkdir</span> vaultwarden &amp;&amp; <span class="hljs-built_in">cd</span> vaultwarden<br>$ vim compose.yml<br><br>services:<br>  vaultwarden:<br>    image: vaultwarden/server:1.35.1 <span class="hljs-comment"># 显式指定版本号，防止使用latest拉取到n年前的版本</span><br>    container_name: vaultwarden<br>    restart: always<br>    environment:<br>      DOMAIN: <span class="hljs-string">&quot;https://example.com&quot;</span> <span class="hljs-comment"># 使用反向代理时必填；您的域名；Vaultwarden 需要知道它是 https 才能正确处理附件</span><br>      SIGNUPS_ALLOWED: <span class="hljs-string">&quot;true&quot;</span> <span class="hljs-comment"># 创建账户后，使用 &quot;false&quot; 停用此选项，这样就不会有陌生人注册了</span><br><br>    volumes:<br>      - ./vw-data:/data <span class="hljs-comment"># : 前面的路径可以修改</span><br>    ports:<br>      - 1145:80 <span class="hljs-comment"># 您可以将 1145 替换为您喜欢的端口</span><br><br><br><br>$ <span class="hljs-built_in">sudo</span> docker compose up -d<br></code></pre></td></tr></table></figure><h3 id="使用nginx反代"><a href="#使用nginx反代" class="headerlink" title="使用nginx反代"></a>使用nginx反代</h3><p>先在<code>/etc/nginx/sites-available</code>创建一个<code>.conf</code>配置文件</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> vim /etc/nginx/sites-available/example.conf<br><br><span class="hljs-comment"># 默认服务器块 - 拒绝所有其他访问</span><br>server &#123;<br>    listen 1146 ssl default_server; <span class="hljs-comment"># 1146改为外网访问使用的端口</span><br>    listen [::]:1146 ssl default_server; <span class="hljs-comment"># 1146改为外网访问使用的端口</span><br><br>    ssl_certificate /path/to/cert.pem; <span class="hljs-comment"># ssl证书公钥</span><br>    ssl_certificate_key /path/to/private.key; <span class="hljs-comment"># ssl证书私钥</span><br><br>    <span class="hljs-comment"># 默认拒绝所有请求</span><br>    <span class="hljs-built_in">return</span> 403;<br>&#125;<br><br><span class="hljs-comment"># vaultwarden 专用服务器块</span><br>server &#123;<br>    listen 1146 ssl; <span class="hljs-comment"># 1146改为外网访问使用的端口</span><br>    server_name example.com; <span class="hljs-comment"># 保持与compose.yml里设置的一致</span><br><br>    ssl_certificate /path/to/cert.pem; <span class="hljs-comment"># ssl证书公钥</span><br>    ssl_certificate_key /path/to/private.key; <span class="hljs-comment"># ssl证书私钥</span><br><br>    <span class="hljs-comment"># SSL 配置</span><br>    ssl_protocols TLSv1.2 TLSv1.3;<br>    ssl_ciphers HIGH:!aNULL:!MD5;<br>    ssl_prefer_server_ciphers on;<br><br>    <span class="hljs-comment"># 安全头</span><br>    add_header X-Frame-Options DENY;<br>    add_header X-Content-Type-Options nosniff;<br>    add_header X-XSS-Protection <span class="hljs-string">&quot;1; mode=block&quot;</span>;<br><br>    <span class="hljs-comment"># 反向代理配置</span><br>    location / &#123;<br>        proxy_pass http://127.0.0.1:1145; <span class="hljs-comment"># 1145改为vaultwarden的端口</span><br>        proxy_set_header Host <span class="hljs-variable">$host</span>;<br>        proxy_set_header X-Real-IP <span class="hljs-variable">$remote_addr</span>;<br>        proxy_set_header X-Forwarded-For <span class="hljs-variable">$proxy_add_x_forwarded_for</span>;<br>        proxy_set_header X-Forwarded-Proto <span class="hljs-variable">$scheme</span>;<br><br>        <span class="hljs-comment"># 限制只允许特定域名访问</span><br>        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$host</span> != <span class="hljs-string">&#x27;example.com&#x27;</span>) &#123; <span class="hljs-comment"># 保持与compose.yml里设置的一致</span><br>            <span class="hljs-built_in">return</span> 403;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure><p>软链接到<code>/etc/nginx/sites-enabled/</code>启用配置文件</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> <span class="hljs-built_in">ln</span> -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.com.conf<br></code></pre></td></tr></table></figure><p>检查并重载nginx</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> nginx -t<br><br><br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf <span class="hljs-built_in">test</span> is successful<br><br><br><span class="hljs-variable">$sudo</span> nginx -s reload<br></code></pre></td></tr></table></figure><p>随后访问<code>https://example.com:1146</code>检查是否正常运行</p>]]>
    </content>
    <id>https://rhsy.moe/2026/01/08/%E4%BD%BF%E7%94%A8%20Vaultwarden%20%E8%87%AA%E5%BB%BA%20Bitwarden%20%E6%9C%8D%E5%8A%A1%E7%AB%AF/</id>
    <link href="https://rhsy.moe/2026/01/08/%E4%BD%BF%E7%94%A8%20Vaultwarden%20%E8%87%AA%E5%BB%BA%20Bitwarden%20%E6%9C%8D%E5%8A%A1%E7%AB%AF/"/>
    <published>2026-01-08T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>bitwarden是一个自由开源、跨平台的密码管理器，且提供浏览器插件，支持自动填充、totp、passkey等功能。</p>
<h2 id="服务端选择"><a href="#服务端选择" class="headerlink" title="服务端选择"></a>服务端选]]>
    </summary>
    <title>使用 Vaultwarden 自建 Bitwarden 服务端</title>
    <updated>2026-10-20T14:05:52.728Z</updated>
  </entry>
  <entry>
    <author>
      <name>阿海</name>
    </author>
    <category term="Linux" scheme="https://rhsy.moe/categories/Linux/"/>
    <category term="ArchLinux" scheme="https://rhsy.moe/tags/ArchLinux/"/>
    <category term="btrfs" scheme="https://rhsy.moe/tags/btrfs/"/>
    <content>
      <![CDATA[<h2 id="配置swap"><a href="#配置swap" class="headerlink" title="配置swap"></a>配置swap</h2><p>为防止swapfile被拍进快照里，我们需要单独为swapfile建一个子卷</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> mount /dev/nvme0n1p4 -o subvolid=0 /mnt <span class="hljs-comment">#挂载父卷</span><br>$ <span class="hljs-built_in">sudo</span> btrfs subvolume create /mnt/@swap<br></code></pre></td></tr></table></figure><p> 创建并启用swapfile</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> btrfs filesystem mkswapfile --size 16G /mnt/@swap/swapfile<br>$ <span class="hljs-built_in">sudo</span> chattr +C /mnt/@swap/swapfile <span class="hljs-comment">#禁用CoW</span><br>$ <span class="hljs-built_in">sudo</span> swapon /mnt/@swap/swapfile<br></code></pre></td></tr></table></figure><p>随后查看<code>/proc/swaps</code>，确保成功激活</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">cat</span> /proc/swaps<br>Filename                Type        Size        Used        Priority<br>/mnt/@swap/swapfile                          file        16777212    0        -2<br></code></pre></td></tr></table></figure><p>编辑<code>/etc/fstab</code>，永久启用swapfile</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 首先将@swap子卷挂载到/swap</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458     /swap        btrfs        subvol=@swap    0 0<br><br><span class="hljs-comment"># 然后启用swapfile</span><br>/swap/swapfile        none        swap        sw    0 0<br></code></pre></td></tr></table></figure><p>重启系统，再查看<code>/proc/swaps</code>，确保swapfile成功启用</p><h4 id="配置zswap"><a href="#配置zswap" class="headerlink" title="配置zswap"></a>配置zswap</h4><p>在稳定版的官方内核中，zswap被默认启用，有：</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">cat</span> /sys/module/zswap/parameters/enabled<br>Y<br></code></pre></td></tr></table></figure><p>要使用zstd作为默认压缩算法，要启动<code>zstd</code>和<code>zstd_compress</code>这两个内核模块</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> vim /etc/mkinitcpio.conf<br><br><br>MODULES=(zstd zstd_compress)<br></code></pre></td></tr></table></figure><p>随后运行<code>mkinitcpio</code>更新initramfs</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> mkinitcpio -p linux<br></code></pre></td></tr></table></figure><p>修改内核参数，指定zstd为默认压缩算法</p><p>rEFInd引导下，修改<code>/boot/refind_linux.conf</code>，添加参数<code>zswap.compressor=zstd</code></p><p>重启系统，查看<code>/sys/module/zswap/parameters/compressor</code></p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">cat</span> /sys/module/zswap/parameters/compressor<br>zstd<br></code></pre></td></tr></table></figure><h2 id="配置并启动休眠"><a href="#配置并启动休眠" class="headerlink" title="配置并启动休眠"></a>配置并启动休眠</h2><p>配置<strong>initramfs</strong>，在<strong>udev</strong>钩子后加入<strong>resume</strong>钩子</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> vim /etc/mkinitcpio.conf<br><br><br>HOOKS=(base udev ... resume)<br><br><br>$ <span class="hljs-built_in">sudo</span> mkinitcpio -p linux<br></code></pre></td></tr></table></figure><p>在Btrfs下，需要使用<code>$ sudo btrfs inspect-internal map-swapfile /swap/swapfile -r</code>获取偏移量</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ <span class="hljs-built_in">sudo</span> btrfs inspect-internal map-swapfile /swap/swapfile -r<br>2982144<br></code></pre></td></tr></table></figure><p>添加内核参数</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">resume=UUID=f3e8494a-ff37-4932-9085-e03dce5ab458 resume_offset=2982144 hibernate.compressor=zstd<br></code></pre></td></tr></table></figure><p>随后重启系统运行<code>systemctl hibernate</code>测试休眠是否正常</p><p>Gnome下可以安装 <a href="https://extensions.gnome.org/extension/8189/power-off-options/">Power Off Options</a> 插件来添加休眠按钮</p><h3 id="参考资料："><a href="#参考资料：" class="headerlink" title="参考资料："></a>参考资料：</h3><ul><li><p><a href="https://bbs.deepin.org.cn/post/270814">[内容投稿] 一文说清swap,zram,zswap，交换空间和内存压缩方案</a></p></li><li><p><a href="https://wiki.archlinuxcn.org/wiki/%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86/%E6%8C%82%E8%B5%B7%E4%B8%8E%E4%BC%91%E7%9C%A0">电源管理&#x2F;挂起与休眠</a></p></li></ul>]]>
    </content>
    <id>https://rhsy.moe/2026/01/04/Btrfs%E4%B8%8B%E9%85%8D%E7%BD%AEswapfile%E5%B9%B6%E5%90%AF%E7%94%A8%E4%BC%91%E7%9C%A0/</id>
    <link href="https://rhsy.moe/2026/01/04/Btrfs%E4%B8%8B%E9%85%8D%E7%BD%AEswapfile%E5%B9%B6%E5%90%AF%E7%94%A8%E4%BC%91%E7%9C%A0/"/>
    <published>2026-01-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="配置swap"><a href="#配置swap" class="headerlink" title="配置swap"></a>配置swap</h2><p>为防止swapfile被拍进快照里，我们需要单独为swapfile建一个子卷</p>
<figure cla]]>
    </summary>
    <title>Btrfs下配置swapfile并启用休眠</title>
    <updated>2026-10-20T14:05:52.727Z</updated>
  </entry>
  <entry>
    <author>
      <name>阿海</name>
    </author>
    <category term="Linux" scheme="https://rhsy.moe/categories/Linux/"/>
    <category term="ArchLinux" scheme="https://rhsy.moe/tags/ArchLinux/"/>
    <content>
      <![CDATA[<p>原先使用的shell是<code>fish</code>，虽然开箱即用方便，但是posix兼容性差于zsh，且配置灵活度不如zsh，遂决定改用zsh</p><h2 id="安装zsh和oh-my-zsh并启用"><a href="#安装zsh和oh-my-zsh并启用" class="headerlink" title="安装zsh和oh-my-zsh并启用"></a>安装zsh和oh-my-zsh并启用</h2><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">sudo</span> pacman -S zsh zsh-completions <br>chsh -s /bin/zsh <span class="hljs-comment">#设置zsh为默认shell</span><br></code></pre></td></tr></table></figure><h3 id="安装oh-my-zsh"><a href="#安装oh-my-zsh" class="headerlink" title="安装oh-my-zsh"></a>安装oh-my-zsh</h3><p>这里用pacman安装，需要添加<strong>archlinuxcn</strong>源</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">sudo</span> pacman -Ss oh-my-zsh-git<br><span class="hljs-built_in">cp</span> /usr/share/oh-my-zsh/zshrc ~/.zshrc<br><span class="hljs-built_in">source</span> ~/.zshrc<br></code></pre></td></tr></table></figure><p>为了在root账户上使用oh-my-zsh，可以</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">sudo</span> <span class="hljs-built_in">ln</span> -s ~/.zshrc /root/.zshrc<br></code></pre></td></tr></table></figure><h2 id="终端配置"><a href="#终端配置" class="headerlink" title="终端配置"></a>终端配置</h2><h3 id="主题"><a href="#主题" class="headerlink" title="主题"></a>主题</h3><p>根据 <a href="https://www.slant.co/topics/7553/~theme-for-oh-my-zsh">What’s the best theme for Oh My Zsh?</a> ,我选择 Powerlevel10k 主题</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">git <span class="hljs-built_in">clone</span> --depth=1 https://github.com/romkatv/powerlevel10k.git <span class="hljs-variable">$&#123;ZSH_CUSTOM:-<span class="hljs-variable">$HOME</span>/.oh-my-zsh/custom&#125;</span>/themes/powerlevel10k<br></code></pre></td></tr></table></figure><p>修改 <code>~/.zshrc</code></p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">ZSH_THEME=<span class="hljs-string">&quot;powerlevel10k/powerlevel10k&quot;</span><br></code></pre></td></tr></table></figure><p>再重新加载.zshrc，按提示配置主题，不满意可运行以下命令重新配置</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">p10k configure<br></code></pre></td></tr></table></figure><h3 id="插件"><a href="#插件" class="headerlink" title="插件"></a>插件</h3><p>安装方式：在 <code>~/.zshrc</code> 的plugin中添加相应插件，如：</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">plugins=(git<br>        python<br>        z<br>        copypath<br>        extract<br>        zsh-autosuggestions<br>        zsh-syntax-highlighting<br>        )<br></code></pre></td></tr></table></figure><p>仅介绍自用插件，更多内置插件请查看 <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins">ohmyzsh&#x2F;ohmyzsh&#x2F;wiki&#x2F;Plugins</a> ,外置插件可前往 <a href="https://github.com/unixorn/awesome-zsh-plugins">awesome-zsh-plugins</a> 寻找</p><h4 id="1-zsh-autosuggestions"><a href="#1-zsh-autosuggestions" class="headerlink" title="1. zsh-autosuggestions"></a>1. zsh-autosuggestions</h4><p>这是一个fish-like的推测、命令补全插件</p><p>安装方式：丢到 <code>/usr/share/oh-my-zsh/custom/plugins</code> 中</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">git <span class="hljs-built_in">clone</span> https://github.com/zsh-users/zsh-autosuggestions <span class="hljs-variable">$&#123;ZSH_CUSTOM:-~/.oh-my-zsh/custom&#125;</span>/plugins/zsh-autosuggestions<br></code></pre></td></tr></table></figure><h4 id="2-zsh-syntax-highlighting"><a href="#2-zsh-syntax-highlighting" class="headerlink" title="2. zsh-syntax-highlighting"></a>2. zsh-syntax-highlighting</h4><p>这是一个fish-like的语法高亮插件</p><p>安装方式同上，丢到 <code>/usr/share/oh-my-zsh/custom/plugins</code> 中</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">git <span class="hljs-built_in">clone</span> https://github.com/zsh-users/zsh-syntax-highlighting.git <span class="hljs-variable">$&#123;ZSH_CUSTOM:-~/.oh-my-zsh/custom&#125;</span>/plugins/zsh-syntax-highlighting<br></code></pre></td></tr></table></figure><h4 id="3-其他内置插件"><a href="#3-其他内置插件" class="headerlink" title="3. 其他内置插件"></a>3. 其他内置插件</h4><ul><li><p><strong>python</strong>插件给<code>python</code>命令一个<code>py</code>的别名，方便运行python脚本</p></li><li><p><strong>z</strong>是一个类似<code>cd</code>的目录跳转插件，配合tab补全可以模糊模糊跳转最近使用过的目录</p></li><li><p><strong>copypath</strong>用于复制文件路径</p></li><li><p><strong>extract</strong>用于解压任何压缩包，命令为<code>x</code></p></li></ul>]]>
    </content>
    <id>https://rhsy.moe/2026/01/04/%E9%85%8D%E7%BD%AEzsh/</id>
    <link href="https://rhsy.moe/2026/01/04/%E9%85%8D%E7%BD%AEzsh/"/>
    <published>2026-01-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>原先使用的shell是<code>fish</code>，虽然开箱即用方便，但是posix兼容性差于zsh，且配置灵活度不如zsh，遂决定改用zsh</p>
<h2 id="安装zsh和oh-my-zsh并启用"><a href="#安装zsh和oh-my-zsh并启用"]]>
    </summary>
    <title>配置zsh</title>
    <updated>2026-10-20T14:05:52.728Z</updated>
  </entry>
  <entry>
    <author>
      <name>阿海</name>
    </author>
    <category term="Linux" scheme="https://rhsy.moe/categories/Linux/"/>
    <category term="ArchLinux" scheme="https://rhsy.moe/tags/ArchLinux/"/>
    <category term="btrfs" scheme="https://rhsy.moe/tags/btrfs/"/>
    <content>
      <![CDATA[<p>想更换桌面环境，苦于ext4的快照不够方便、优雅，遂折腾转为btrfs</p><h2 id="使用btrfs-convert转换"><a href="#使用btrfs-convert转换" class="headerlink" title="使用btrfs-convert转换"></a>使用<code>btrfs-convert</code>转换</h2><p>确保磁盘有一定的空间，进入到livecd</p><p>首先检查磁盘问题，防止带着问题上战场。</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">fsck.ext4 /dev/nvme0n1p4<br></code></pre></td></tr></table></figure><p>随后双手合十，祈求执行以下命令转换。</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs-convert /dev/nvme0n1p4<br></code></pre></td></tr></table></figure><p>在转换途中会在目标分区中生成快照，如果报错执行以下命令回滚。</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs-convert -r /dev/nvme0n1p4<br></code></pre></td></tr></table></figure><h2 id="重建初始化内存盘"><a href="#重建初始化内存盘" class="headerlink" title="重建初始化内存盘"></a>重建初始化内存盘</h2><p>挂载磁盘、<strong>chroot</strong>并重建<strong>initramfs</strong>：</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">mount /dev/nvme0n1p4 /mnt<br>arch-chroot /mnt<br>mkinitcpio --preset linux<br></code></pre></td></tr></table></figure><h2 id="启动透明压缩"><a href="#启动透明压缩" class="headerlink" title="启动透明压缩"></a>启动透明压缩</h2><p>启动透明压缩前保证磁盘有足够的空间，否则先保证可以正常进入系统后删除快照：</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs subvolume delete /mnt/ext2_saved<br></code></pre></td></tr></table></figure><p>启动透明压缩（需要较长时间）：</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs filesystem defragment -r -v -czstd /mnt<br></code></pre></td></tr></table></figure><h2 id="创建子卷（subvolume）"><a href="#创建子卷（subvolume）" class="headerlink" title="创建子卷（subvolume）"></a>创建子卷（subvolume）</h2><p>创建子卷并迁移数据</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs subvolume create /mnt/@<br>btrfs subvolume create /mnt/@home<br>btrfs subvolume create /mnt/@var<br>btrfs subvolume create /mnt/@usr_local<br>btrfs subvolume create /mnt/@opt<br>btrfs subvolume create /mnt/@snapshots<br>btrfs subvolume set-default /mnt/@<br><span class="hljs-built_in">mkdir</span> /mnt/.snapshots<br><span class="hljs-built_in">mv</span> /mnt/home/* /mnt/@home/<br>...<br></code></pre></td></tr></table></figure><p>挂载子卷并创建fstab</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 先卸载已挂载的分区</span><br>umount /mnt<br><br><span class="hljs-comment"># 分别挂载</span><br>mount /dev/nvme0n1p4 -o subvolume=@,compress=zstd /mnt<br>mount /dev/nvme0n1p4 -o subvolume=@home,compress=zstd /mnt/home<br>mount /dev/nvme0n1p4 -o subvolume=@var,compress=zstd /mnt/var<br>mount /dev/nvme0n1p4 -o subvolume=@usr_local,compress=zstd /mnt/usr/local<br>mount /dev/nvme0n1p4 -o subvolume=@opt,compress=zstd /mnt/opt<br>mount /dev/nvme0n1p4 -o subvolume=@snapshots,compress=zstd /mnt/.snapshots<br>mount /dev/nvme0n1p1 /mnt/boot/efi<br><br><span class="hljs-comment"># 创建fstab</span><br>genfstab -U /mnt &gt; /mnt/etc/fstab<br></code></pre></td></tr></table></figure><p>检查<code>/etc/fstab</code>，将根分区调整为<strong>rw</strong>，将快照的压缩去除</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /             btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /home         btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@home    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /opt          btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@opt    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /usr/local    btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@usr_local    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /var          btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@var    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p4</span><br>UUID=f3e8494a-ff37-4932-9085-e03dce5ab458    /.snapshots    btrfs         rw,relatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvol=/@snapshots    0 0<br><br><span class="hljs-comment"># /dev/nvme0n1p1</span><br>UUID=C4EE-5413          /boot/efi     vfat          rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro    0 2<br></code></pre></td></tr></table></figure><h2 id="更新引导"><a href="#更新引导" class="headerlink" title="更新引导"></a>更新引导</h2><p>rEFInd下：</p><p>修改<code>/mnt/boot/refind_linux.conf</code></p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-string">&quot;Boot with standard options&quot;</span>  <span class="hljs-string">&quot;root=UUID=f3e8494a-ff37-4932-9085-e03dce5ab458 rootflags=subvol=@ rootfstype=btrfs rw quiet splash loglevel=3 nvidia-drm.modeset=1 nvidia-drm.fbdev=1&quot;</span><br><span class="hljs-string">&quot;Boot to single-user mode&quot;</span>    <span class="hljs-string">&quot;root=UUID=f3e8494a-ff37-4932-9085-e03dce5ab458 rootflags=subvol=@ rootfstype=btrfs rw quiet splash loglevel=3 nvidia-drm.modeset=1 nvidia-drm.fbdev=1 single&quot;</span><br><span class="hljs-string">&quot;Boot with minimal options&quot;</span>   <span class="hljs-string">&quot;ro root=/dev/nvme0n1p4&quot;</span><br></code></pre></td></tr></table></figure><h2 id="通过balance回收数据"><a href="#通过balance回收数据" class="headerlink" title="通过balance回收数据"></a>通过balance回收数据</h2><p>引导进入系统后终端执行以下命令（需要较长一段时间）</p><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">btrfs balance start /<br></code></pre></td></tr></table></figure><h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><h3 id="禁用var目录的CoW"><a href="#禁用var目录的CoW" class="headerlink" title="禁用var目录的CoW"></a>禁用var目录的CoW</h3><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">chattr +C /mnt/var<br></code></pre></td></tr></table></figure>]]>
    </content>
    <id>https://rhsy.moe/2026/01/03/%E8%AE%B0%E4%B8%80%E6%AC%A1%E5%B0%86ext4%E8%BF%81%E7%A7%BB%E5%88%B0btrfs%E5%B9%B6%E5%BC%80%E5%90%AF%E9%80%8F%E6%98%8E%E5%8E%8B%E7%BC%A9/</id>
    <link href="https://rhsy.moe/2026/01/03/%E8%AE%B0%E4%B8%80%E6%AC%A1%E5%B0%86ext4%E8%BF%81%E7%A7%BB%E5%88%B0btrfs%E5%B9%B6%E5%BC%80%E5%90%AF%E9%80%8F%E6%98%8E%E5%8E%8B%E7%BC%A9/"/>
    <published>2026-01-03T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>想更换桌面环境，苦于ext4的快照不够方便、优雅，遂折腾转为btrfs</p>
<h2 id="使用btrfs-convert转换"><a href="#使用btrfs-convert转换" class="headerlink" title="使用btrfs-convert]]>
    </summary>
    <title>记一次将ext4迁移到btrfs并开启透明压缩</title>
    <updated>2026-10-20T14:05:52.728Z</updated>
  </entry>
</feed>
