1
0
wiki/Technology/OperatingSystem/Virtualization/2.KVM虚拟化/5.-KVM-存储管理.html

569 lines
551 KiB
HTML
Raw Normal View History

2024-09-06 10:58:26 +08:00
<!DOCTYPE html>
<html lang="zh"><head><title>5. KVM 存储管理</title><meta charset="utf-8"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com"/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM Plex Mono&amp;family=Noto Serif Simplified Chinese:wght@400;700&amp;family=Source Sans Pro:ital,wght@0,400;0,600;1,400;1,600&amp;display=swap"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta property="og:title" content="5. KVM 存储管理"/><meta property="og:description" content="本文深入探讨了KVM虚拟化环境中的存储管理涵盖了磁盘映像文件、逻辑卷管理LVM、网络存储NFS、iSCSI的配置方法以及存储池和存储卷的创建与管理。."/><meta property="og:image" content="https://wiki.7wate.com/static/og-image.png"/><meta property="og:width" content="1200"/><meta property="og:height" content="675"/><link rel="icon" href="../../../../static/icon.png"/><meta name="description" content="本文深入探讨了KVM虚拟化环境中的存储管理涵盖了磁盘映像文件、逻辑卷管理LVM、网络存储NFS、iSCSI的配置方法以及存储池和存储卷的创建与管理。."/><meta name="generator" content="Quartz"/><link href="../../../../index.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css" rel="stylesheet" type="text/css" spa-preserve/><script src="../../../../prescript.js" type="application/javascript" spa-preserve></script><script type="application/javascript" spa-preserve>const fetchData = fetch("../../../../static/contentIndex.json").then(data => data.json())</script></head><body data-slug="Technology/OperatingSystem/Virtualization/2.KVM虚拟化/5.-KVM-存储管理"><div id="quartz-root" class="page"><div id="quartz-body"><div class="left sidebar"><h2 class="page-title"><a href="../../../..">🪴 X·Eden</a></h2><div class="spacer mobile-only"></div><div class="search"><button class="search-button" id="search-button"><p>搜索</p><svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7"><title>Search</title><g class="search-path" fill="none"><path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4"></path><circle cx="8" cy="8" r="7"></circle></g></svg></button><div id="search-container"><div id="search-space"><input autocomplete="off" id="search-bar" name="search" type="text" aria-label="搜索些什么" placeholder="搜索些什么"/><div id="search-layout" data-preview="true"></div></div></div></div><button class="darkmode" id="darkmode"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="dayIcon" x="0px" y="0px" viewBox="0 0 35 35" style="enable-background:new 0 0 35 35" xml:space="preserve" aria-label="暗色模式"><title>暗色模式</title><path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5
<h3 id="存储概念">存储概念<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存储概念" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>KVMKernel-based Virtual Machine存储是指在 KVM 虚拟化环境中为虚拟机提供的存储资源。KVM 支持多种存储类型包括磁盘映像文件、逻辑卷管理LVM和网络存储。虚拟机的存储设备可以像物理机的硬盘一样使用并且可以通过不同的存储格式和协议进行管理和访问。</p>
<h3 id="虚拟机存储类型">虚拟机存储类型<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#虚拟机存储类型" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="磁盘映像文件qcow2-raw">磁盘映像文件qcow2, raw<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#磁盘映像文件qcow2-raw" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<div class="table-container"><table><thead><tr><th>类型</th><th>特点</th><th>使用场景</th></tr></thead><tbody><tr><td><strong>qcow2</strong> (QEMU Copy On Write version 2)</td><td>支持动态分配、快照、压缩和加密。磁盘空间在实际使用时才分配,可以节省存储空间。</td><td>适合需要多快照和动态存储分配的环境。</td></tr><tr><td><strong>raw</strong></td><td>不支持快照、压缩和加密,直接映射磁盘数据。性能更高,适合需要最大化性能的场景。</td><td>适合高性能需求和简单存储管理的环境。</td></tr></tbody></table></div>
<h4 id="其他常见磁盘映像文件类型">其他常见磁盘映像文件类型<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#其他常见磁盘映像文件类型" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<div class="table-container"><table><thead><tr><th>类型</th><th>特点</th><th>使用场景</th></tr></thead><tbody><tr><td><strong>qcow</strong> (QEMU Copy On Write)</td><td>qcow2 的前身,支持动态分配和快照,但性能和功能不及 qcow2。</td><td>已有 qcow 格式的旧环境。</td></tr><tr><td><strong>vmdk</strong> (Virtual Machine Disk)</td><td>主要用于 VMware 虚拟机,可以兼容 KVM。支持多种虚拟磁盘格式和快照。</td><td>需要在 KVM 和 VMware 之间进行迁移的环境。</td></tr><tr><td><strong>vdi</strong> (Virtual Disk Image)</td><td>主要用于 Oracle VirtualBox 虚拟机,可以兼容 KVM。支持动态分配和快照。</td><td>需要在 KVM 和 VirtualBox 之间进行迁移的环境。</td></tr><tr><td><strong>vhd/vhdx</strong> (Virtual Hard Disk)</td><td>主要用于 Microsoft Hyper-V 虚拟机,可以兼容 KVM。vhdx 是 vhd 的改进版本,支持更大容量和更高性能。</td><td>需要在 KVM 和 Hyper-V 之间进行迁移的环境。</td></tr></tbody></table></div>
<h4 id="逻辑卷管理lvm">逻辑卷管理LVM<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#逻辑卷管理lvm" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>逻辑卷管理LVM提供灵活的存储管理可以动态调整逻辑卷大小、快照和卷组管理。性能较高适合企业级应用和需要高性能、灵活存储管理的环境。</p>
<ol>
<li>
<p>创建物理卷和卷组:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pvcreate</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vgcreate</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vg_kvm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span></code></pre></figure>
</li>
<li>
<p>创建逻辑卷:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvcreate</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lv_myvm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -L</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vg_kvm</span></span></code></pre></figure>
</li>
</ol>
<h4 id="网络存储nfs-iscsi">网络存储NFS, iSCSI<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#网络存储nfs-iscsi" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>NFSNetwork File System通过网络共享文件系统适合共享存储和集中存储管理以及多台虚拟机需要共享同一存储资源的环境。</p>
<p>挂载 NFS 存储:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-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;"> -t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> server:/path/to/nfs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /mnt/nfs</span></span></code></pre></figure>
<p><strong>iSCSIInternet Small Computer Systems Interface</strong></p>
<p>通过网络提供块级存储,适合高性能需求的存储应用,以及需要集中管理和高性能存储访问的环境。</p>
<ol>
<li>安装 iSCSI 客户端:</li>
</ol>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-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;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> open-iscsi</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # Ubuntu</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> yum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-initiator-utils</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # CentOS/RHEL</span></span></code></pre></figure>
<ol>
<li>发现和登录 iSCSI 目标:</li>
</ol>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsiadm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -m</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> discovery</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sendtargets</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">iSCSI_server_I</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">P</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsiadm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -m</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> node</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --login</span></span></code></pre></figure>
<h3 id="配置系统存储支持">配置系统存储支持<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置系统存储支持" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="确认存储驱动加载情况">确认存储驱动加载情况<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#确认存储驱动加载情况" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>检查存储驱动</strong></p>
<p>使用 <code>lsmod</code> 命令检查存储驱动是否加载:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lsmod</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> grep</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -E</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'virtio_blk|virtio_scsi'</span></span></code></pre></figure>
</li>
<li>
<p><strong>加载存储驱动</strong></p>
<p>如果存储驱动未加载,可以手动加载:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> modprobe</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virtio_blk</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> modprobe</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virtio_scsi</span></span></code></pre></figure>
</li>
</ol>
<h4 id="准备存储设备和挂载点">准备存储设备和挂载点<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#准备存储设备和挂载点" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>准备本地存储设备</strong></p>
<p>分区和格式化存储设备:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> fdisk</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span>
<span data-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/sdX1</span></span></code></pre></figure>
<p>创建挂载点并挂载:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /mnt/kvm_storage</span></span>
<span data-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:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /mnt/kvm_storage</span></span></code></pre></figure>
</li>
<li>
<p><strong>准备网络存储设备NFS 例子)</strong></p>
<p>安装 NFS 客户端:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-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;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-common</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # Ubuntu</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> yum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-utils</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # CentOS/RHEL</span></span></code></pre></figure>
<p>挂载 NFS 共享:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /mnt/nfs_storage</span></span>
<span data-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;"> -t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> server:/path/to/nfs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /mnt/nfs_storage</span></span></code></pre></figure>
</li>
<li>
<p><strong>配置自动挂载</strong></p>
<p>编辑 <code>/etc/fstab</code> 文件,添加以下内容确保重启后自动挂载:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="text" data-theme="github-light github-dark"><code data-language="text" data-theme="github-light github-dark" style="display:grid;"><span data-line><span>/dev/sdX1 /mnt/kvm_storage ext4 defaults 0 2</span></span>
<span data-line><span>server:/path/to/nfs /mnt/nfs_storage nfs defaults 0 0</span></span></code></pre></figure>
</li>
</ol>
<p>通过以上步骤,可以为 KVM 环境配置各种存储支持包括磁盘映像文件、LVM 和网络存储。确保存储驱动已加载,并准备好存储设备和挂载点,为虚拟机提供可靠的存储资源。</p>
<h2 id="配置存储池">配置存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<h3 id="存储池是什么">存储池是什么<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存储池是什么" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="存储池的概念">存储池的概念<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存储池的概念" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>存储池Storage Pool是 KVM 虚拟化环境中的一种抽象概念用于管理和组织底层存储资源。存储池可以包含多个存储卷Storage Volume每个存储卷对应虚拟机的一个磁盘映像文件、逻辑卷或网络存储块。通过存储池管理员可以更方便地管理和分配存储资源。</p>
<h4 id="存储池的类型">存储池的类型<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存储池的类型" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<div class="table-container"><table><thead><tr><th>类型</th><th>特点</th><th>使用场景</th></tr></thead><tbody><tr><td><strong>目录存储池</strong> (Directory Storage Pool)</td><td>使用本地或挂载的目录作为存储池。简单易用,适合中小型部署。</td><td>适合中小型部署。</td></tr><tr><td><strong>逻辑卷存储池</strong> (LVM Storage Pool)</td><td>基于 LVMLogical Volume Manager创建和管理逻辑卷。提供灵活的卷管理和快照功能。</td><td>适合企业级部署。</td></tr><tr><td><strong>网络存储池</strong> (Network Storage Pool)</td><td>使用网络存储协议(如 NFS、iSCSI创建存储池。适合分布式存储和集中存储管理。</td><td>适合分布式存储和集中存储管理。</td></tr></tbody></table></div>
<h3 id="创建和管理目录存储池">创建和管理目录存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理目录存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="使用-virsh-创建目录存储池">使用 <code>virsh</code> 创建目录存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建目录存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建目录存储池</strong></p>
<p>创建一个目录存储池的 XML 配置文件,例如 <code>dir-pool.xml</code></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'dir'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>dir-pool&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/mnt/kvm_storage&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p><strong>定义并启动存储池</strong></p>
<p>使用 <code>virsh</code> 命令定义并启动目录存储池:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-define</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool.xml</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-autostart</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置目录存储池">配置目录存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置目录存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>查看存储池信息</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>查看存储池中的存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-list</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>创建存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> volume1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 10G</span></span></code></pre></figure>
</li>
</ol>
<h3 id="创建和管理逻辑卷存储池">创建和管理逻辑卷存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理逻辑卷存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="使用-virsh-创建-lvm-存储池">使用 <code>virsh</code> 创建 LVM 存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建-lvm-存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建 LVM 存储池</strong></p>
<p>创建一个 LVM 存储池的 XML 配置文件,例如 <code>lvm-pool.xml</code></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'logical'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>lvm-pool&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">device</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/dev/vg_kvm'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>vg_kvm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">format</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'lvm2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/dev/vg_kvm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p><strong>定义并启动存储池</strong></p>
<p>使用 <code>virsh</code> 命令定义并启动 LVM 存储池:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-define</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool.xml</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-autostart</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置-lvm-存储池">配置 LVM 存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置-lvm-存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>查看存储池信息</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>查看存储池中的存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-list</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>创建存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lv_volume1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span></span></code></pre></figure>
</li>
</ol>
<h3 id="创建和管理网络存储池">创建和管理网络存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理网络存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="使用-virsh-创建-nfs-存储池">使用 <code>virsh</code> 创建 NFS 存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建-nfs-存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建 NFS 存储池</strong></p>
<p>创建一个 NFS 存储池的 XML 配置文件,例如 <code>nfs-pool.xml</code></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'netfs'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>nfs-pool&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">host</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'nfs-server'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">dir</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/path/to/nfs'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/mnt/nfs_storage&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p><strong>定义并启动存储池</strong></p>
<p>使用 <code>virsh</code> 命令定义并启动 NFS 存储池:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-define</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool.xml</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-autostart</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="使用-virsh-创建-iscsi-存储池">使用 <code>virsh</code> 创建 iSCSI 存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建-iscsi-存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建 iSCSI 存储池</strong></p>
<p>创建一个 iSCSI 存储池的 XML 配置文件,例如 <code>iscsi-pool.xml</code></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'iscsi'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>iscsi-pool&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">host</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'iscsi-server'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">device</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/dev/sdX'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/dev/disk/by-path/&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">path</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">pool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p><strong>定义并启动存储池</strong></p>
<p>使用 <code>virsh</code> 命令定义并启动 iSCSI 存储池:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-define</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool.xml</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-autostart</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置网络存储池">配置网络存储池<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置网络存储池" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>查看存储池信息</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>查看存储池中的存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-list</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-list</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool</span></span></code></pre></figure>
</li>
<li>
<p><strong>创建存储卷</strong></p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nfs-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> volume1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 10G</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> iscsi-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> volume2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span></span></code></pre></figure>
</li>
</ol>
<h2 id="配置存储卷">配置存储卷<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置存储卷" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<h3 id="存储卷的概念">存储卷的概念<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存储卷的概念" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>**存储卷Storage Volume是存储池Storage Pool中的一个逻辑单元类似于传统文件系统中的文件。**存储卷为虚拟机提供存储空间,用于存储操作系统、应用程序和数据。每个存储卷可以对应一个磁盘映像文件、逻辑卷或网络存储块。通过存储卷,管理员可以灵活管理和分配存储资源。</p>
<h3 id="创建和管理磁盘映像文件">创建和管理磁盘映像文件<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理磁盘映像文件" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="使用-virsh-创建磁盘映像文件">使用 <code>virsh</code> 创建磁盘映像文件<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建磁盘映像文件" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建磁盘映像文件</strong></p>
<p>使用 <code>virsh</code> 创建一个磁盘映像文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --format</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span></span></code></pre></figure>
<p>以上命令将在 <code>dir-pool</code> 存储池中创建一个名为 <code>mydisk.qcow2</code> 的磁盘映像文件,大小为 20GB格式为 qcow2。</p>
</li>
<li>
<p><strong>查看磁盘映像文件信息</strong></p>
<p>查看创建的磁盘映像文件信息:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mydisk.qcow2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置磁盘映像文件的大小和格式">配置磁盘映像文件的大小和格式<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置磁盘映像文件的大小和格式" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>调整磁盘映像文件大小</strong></p>
<p>可以使用 <code>qemu-img</code> 工具调整磁盘映像文件的大小:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> resize</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +10G</span></span></code></pre></figure>
<p>以上命令将 <code>mydisk.qcow2</code> 的大小增加 10GB。</p>
</li>
<li>
<p><strong>转换磁盘映像文件格式</strong></p>
<p>可以使用 <code>qemu-img</code> 工具转换磁盘映像文件的格式:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> convert</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -O</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> raw</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/mydisk.raw</span></span></code></pre></figure>
<p>以上命令将 <code>mydisk.qcow2</code> 转换为 <code>mydisk.raw</code>,格式从 qcow2 转换为 raw。</p>
</li>
</ol>
<h3 id="创建和管理逻辑卷">创建和管理逻辑卷<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理逻辑卷" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="使用-virsh-创建逻辑卷">使用 <code>virsh</code> 创建逻辑卷<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-创建逻辑卷" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>创建逻辑卷</strong></p>
<p>使用 <code>virsh</code> 创建一个逻辑卷:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-create-as</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lv_mydisk</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span></span></code></pre></figure>
<p>以上命令将在 <code>lvm-pool</code> 存储池中创建一个名为 <code>lv_mydisk</code> 的逻辑卷,大小为 20GB。</p>
</li>
<li>
<p><strong>查看逻辑卷信息</strong></p>
<p>查看创建的逻辑卷信息:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vol-info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lv_mydisk</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --pool</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置逻辑卷的大小和格式">配置逻辑卷的大小和格式<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置逻辑卷的大小和格式" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p><strong>调整逻辑卷大小</strong></p>
<p>可以使用 <code>lvresize</code> 工具调整逻辑卷的大小:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvresize</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -L</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +10G</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/vg_kvm/lv_mydisk</span></span></code></pre></figure>
<p>以上命令将 <code>lv_mydisk</code> 的大小增加 10GB。</p>
</li>
<li>
<p><strong>格式化逻辑卷</strong></p>
<p>在使用逻辑卷之前,需要对其进行格式化:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-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/vg_kvm/lv_mydisk</span></span></code></pre></figure>
</li>
</ol>
<p>通过以上步骤,可以使用 <code>virsh</code> 创建和管理磁盘映像文件和逻辑卷,并灵活配置其大小和格式。这些存储卷为虚拟机提供了可靠和高效的存储解决方案。</p>
<h2 id="虚拟机的存储配置">虚拟机的存储配置<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#虚拟机的存储配置" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<h3 id="使用-virsh-添加和删除虚拟机磁盘">使用 <code>virsh</code> 添加和删除虚拟机磁盘<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#使用-virsh-添加和删除虚拟机磁盘" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p><strong>添加虚拟机磁盘</strong></p>
<ol>
<li>
<p>创建一个新的磁盘映像文件(如果需要):</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> create</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/lib/libvirt/images/mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span></span></code></pre></figure>
</li>
<li>
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> edit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
<li>
<p><code>&lt;devices></code> 部分中添加以下内容,指定新的磁盘设备:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'file'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> device</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'disk'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">driver</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qemu'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> file</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/var/lib/libvirt/images/mydisk.qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> dev</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'vdb'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'virtio'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">address</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pci'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> domain</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0000'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x00'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> slot</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x09'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> function</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p>保存并退出编辑器,启动或重启虚拟机以使新磁盘生效:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
</ol>
<p><strong>删除虚拟机磁盘</strong></p>
<ol>
<li>
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> edit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
<li>
<p>找到需要删除的 <code>&lt;disk></code> 节点,并将其删除:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'file'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> device</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'disk'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">driver</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qemu'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> file</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/var/lib/libvirt/images/mydisk.qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> dev</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'vdb'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'virtio'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">address</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pci'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> domain</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0000'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x00'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> slot</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x09'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> function</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
</ol>
<h3 id="virsh-配置虚拟机的启动磁盘"><code>virsh</code> 配置虚拟机的启动磁盘<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#virsh-配置虚拟机的启动磁盘" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<ol>
<li>
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> edit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
<li>
<p><code>&lt;os></code> 部分中,找到 <code>&lt;boot dev='...'></code> 节点并调整顺序。例如,将磁盘设备设为首选启动设备:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> arch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'x86_64'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> machine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pc-i440fx-2.9'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>hvm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">boot</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> dev</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'hd'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">boot</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> dev</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'cdrom'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
</ol>
<h4 id="配置虚拟机-bios-设置">配置虚拟机 BIOS 设置<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#配置虚拟机-bios-设置" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> edit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
<li>
<p><code>&lt;os></code> 部分中,添加或修改 <code>&lt;bios></code> 节点。例如,启用 BIOS 引导菜单:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> arch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'x86_64'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> machine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pc-i440fx-2.9'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>hvm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">loader</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> readonly</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'yes'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pflash'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/usr/share/OVMF/OVMF_CODE.fd&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">loader</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">nvram</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>/var/lib/libvirt/qemu/nvram/&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">vm_name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>.fd&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">nvram</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">bootmenu</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> enable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'yes'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
</li>
</ol>
<h2 id="高级存储管理">高级存储管理<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#高级存储管理" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<h3 id="快照管理">快照管理<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#快照管理" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="创建和管理磁盘快照">创建和管理磁盘快照<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建和管理磁盘快照" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>快照是虚拟机在某一时刻的状态,包括虚拟机的磁盘和内存状态。通过快照,您可以在需要时恢复虚拟机到之前的状态。</p>
<p><strong>创建磁盘快照</strong></p>
<p>使用 <code>virsh</code> 创建磁盘快照:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> snapshot-create-as</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">snapshot_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --disk-only</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --atomic</span></span></code></pre></figure>
<p>以上命令创建一个仅包含磁盘状态的快照。</p>
<p><strong>管理磁盘快照</strong></p>
<p>使用 <code>virsh</code> 列出所有快照:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> snapshot-list</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
<p><strong>恢复快照</strong></p>
<p>使用 <code>virsh</code> 恢复快照:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> snapshot-revert</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">vm_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">snapshot_nam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span></span></code></pre></figure>
<h4 id="扩展存储池容量">扩展存储池容量<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#扩展存储池容量" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p><strong>扩展目录存储池</strong></p>
<p>确保文件系统有足够的空间,然后直接添加更多存储卷到目录存储池即可。</p>
<p><strong>扩展 LVM 存储池</strong></p>
<ol>
<li>
<p>添加新的物理卷到卷组:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pvcreate</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vgextend</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vg_kvm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span></code></pre></figure>
</li>
<li>
<p>更新存储池配置:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pool-refresh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lvm-pool</span></span></code></pre></figure>
</li>
</ol>
<p><strong>扩展网络存储池</strong></p>
<p>对于 NFS 和 iSCSI直接在网络存储服务器上扩展存储容量然后刷新存储池即可。</p>
<h4 id="缩减存储池容量">缩减存储池容量<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#缩减存储池容量" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p><strong>缩减 LVM 存储池</strong></p>
<ol>
<li>
<p>移动逻辑卷中的数据到其他物理卷:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pvmove</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span></code></pre></figure>
</li>
<li>
<p>移除物理卷并减少卷组大小:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vgreduce</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vg_kvm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pvremove</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /dev/sdX</span></span></code></pre></figure>
</li>
</ol>
<p><strong>缩减目录存储池和网络存储池</strong></p>
<p>一般不直接缩减这些存储池,建议清理不需要的存储卷以释放空间。</p>
<h3 id="磁盘镜像和克隆">磁盘镜像和克隆<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#磁盘镜像和克隆" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="创建磁盘镜像">创建磁盘镜像<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#创建磁盘镜像" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p><strong>创建磁盘镜像</strong></p>
<p>使用 <code>qemu-img</code> 创建磁盘镜像:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> create</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/lib/libvirt/images/mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20G</span></span></code></pre></figure>
<p><strong>转换磁盘镜像格式</strong></p>
<p>使用 <code>qemu-img</code> 转换磁盘镜像格式:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> convert</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -O</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> raw</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/mydisk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/mydisk.raw</span></span></code></pre></figure>
<h4 id="克隆虚拟机磁盘">克隆虚拟机磁盘<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#克隆虚拟机磁盘" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<ol>
<li>
<p>使用 <code>qemu-img</code> 克隆磁盘映像:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qemu-img</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> create</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> qcow2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/lib/libvirt/images/source-disk.qcow2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/lib/libvirt/images/clone-disk.qcow2</span></span></code></pre></figure>
</li>
<li>
<p>使用 <code>virsh</code> 定义新的虚拟机,并指定克隆的磁盘映像:</p>
<p>创建虚拟机 XML 文件:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="xml" data-theme="github-light github-dark"><code data-language="xml" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">domain</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'kvm'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>clone-vm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">memory</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> unit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'KiB'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>1048576&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">memory</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">vcpu</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> placement</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'static'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>1&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">vcpu</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> arch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'x86_64'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> machine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pc-i440fx-2.9'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>hvm&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">os</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">devices</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'file'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> device</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'disk'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">driver</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qemu'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">source</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> file</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'/var/lib/libvirt/images/clone-disk.qcow2'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">target</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> dev</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'vda'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'virtio'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">address</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'pci'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> domain</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0000'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bus</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x00'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> slot</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x04'</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> function</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'0x0'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">disk</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">devices</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">domain</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></figure>
</li>
<li>
<p>使用 <code>virsh</code> 定义并启动新的虚拟机:</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> define</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/clone-vm.xml</span></span>
<span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> virsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone-vm</span></span></code></pre></figure>
</li>
</ol></article><hr/><div class="page-footer"></div></div><div class="right sidebar"><div class="graph"><h3>关系图谱</h3><div class="graph-outer"><div id="graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:1,&quot;scale&quot;:1.1,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[],&quot;focusOnHover&quot;:false}"></div><button id="global-graph-icon" aria-label="Global Graph"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 55 55" fill="currentColor" xml:space="preserve"><path d="M49,0c-3.309,0-6,2.691-6,6c0,1.035,0.263,2.009,0.726,2.86l-9.829,9.829C32.542,17.634,30.846,17,29,17
s-3.542,0.634-4.898,1.688l-7.669-7.669C16.785,10.424,17,9.74,17,9c0-2.206-1.794-4-4-4S9,6.794,9,9s1.794,4,4,4
c0.74,0,1.424-0.215,2.019-0.567l7.669,7.669C21.634,21.458,21,23.154,21,25s0.634,3.542,1.688,4.897L10.024,42.562
C8.958,41.595,7.549,41,6,41c-3.309,0-6,2.691-6,6s2.691,6,6,6s6-2.691,6-6c0-1.035-0.263-2.009-0.726-2.86l12.829-12.829
c1.106,0.86,2.44,1.436,3.898,1.619v10.16c-2.833,0.478-5,2.942-5,5.91c0,3.309,2.691,6,6,6s6-2.691,6-6c0-2.967-2.167-5.431-5-5.91
v-10.16c1.458-0.183,2.792-0.759,3.898-1.619l7.669,7.669C41.215,39.576,41,40.26,41,41c0,2.206,1.794,4,4,4s4-1.794,4-4
s-1.794-4-4-4c-0.74,0-1.424,0.215-2.019,0.567l-7.669-7.669C36.366,28.542,37,26.846,37,25s-0.634-3.542-1.688-4.897l9.665-9.665
C46.042,11.405,47.451,12,49,12c3.309,0,6-2.691,6-6S52.309,0,49,0z M11,9c0-1.103,0.897-2,2-2s2,0.897,2,2s-0.897,2-2,2
S11,10.103,11,9z M6,51c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S8.206,51,6,51z M33,49c0,2.206-1.794,4-4,4s-4-1.794-4-4
s1.794-4,4-4S33,46.794,33,49z M29,31c-3.309,0-6-2.691-6-6s2.691-6,6-6s6,2.691,6,6S32.309,31,29,31z M47,41c0,1.103-0.897,2-2,2
s-2-0.897-2-2s0.897-2,2-2S47,39.897,47,41z M49,10c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S51.206,10,49,10z"></path></svg></button></div><div id="global-graph-outer"><div id="global-graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:-1,&quot;scale&quot;:0.9,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[],&quot;focusOnHover&quot;:true}"></div></div></div><div class="toc desktop-only"><button type="button" id="toc" class aria-controls="toc-content" aria-expanded="true"><h3>目录</h3><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="fold"><polyline points="6 9 12 15 18 9"></polyline></svg></button><div id="toc-content" class><ul class="overflow"><li class="depth-0"><a href="#kvm-存储" data-for="kvm-存储">KVM 存储</a></li><li class="depth-1"><a href="#存储概念" data-for="存储概念">存储概念</a></li><li class="depth-1"><a href="#虚拟机存储类型" data-for="虚拟机存储类型">虚拟机存储类型</a></li><li class="depth-1"><a href="#配置系统存储支持" data-for="配置系统存储支持">配置系统存储支持</a></li><li class="depth-0"><a href="#配置存储池" data-for="配置存储池">配置存储池</a></li><li class="depth-1"><a href="#存储池是什么" data-for="存储池是什么">存储池是什么</a></li><li class="depth-1"><a href="#创建和管理目录存储池" data-for="创建和管理目录存储池">创建和管理目录存储池</a></li><li class="depth-1"><a href="#创建和管理逻辑卷存储池" data-for="创建和管理逻辑卷存储池">创建和管理逻辑卷存储池</a></li><li class="depth-1"><a href="#创建和管理网络存储池" data-for="创建和管理网络存储池">创建和管理网络存储池</a></li><li class="depth-0"><a href="#配置存储卷" data-for="配置存储卷">配置存储卷</a></li><li class="depth-1"><a href="#存储卷的概念" data-for="存储卷的概念">存储卷的概念</a></li><li class="depth-1"><a href="#创建和管理磁盘映像文件" data-for="创建和管理磁盘映像文件">创建和管理磁盘映像文件</a></li><li class="depth-1"><a href="#创建和管理逻辑卷" data-for="创建和管理逻辑卷">创建和管理逻辑卷</a></li><li class="depth-0"><a href="#虚拟机的存储配置" data-for="虚拟机的存储配置">虚拟机的存储配置</a></li><li class="depth-1"><a href="#使用-virsh-添加和删除虚拟机磁盘" data-for="使用-virsh-添加和删除虚拟机磁盘">使用 virsh 添加和删除虚拟机磁盘</a></li><li class="depth-1"><a href="#virsh-配置虚拟机的启动磁盘" data-for="virsh-配置虚拟机的启动磁盘">virsh 配置虚拟机的启动磁盘</a></li><li class="depth-0"><a href="#高级存储管理" data-for="高级存储管理">高级存储管理</a></li><li class="depth-1"><a href="#快照管理" data-for="快照管理">快照管理</a></li><li class="depth-1"><a href="#磁盘镜像和克隆" data-for="磁盘镜像和克隆">磁盘镜像和克隆</a></li></ul></div></div><div class="explorer mobile-only"><button type="button" id="explorer" data-behavior="collapse" data-collapsed="collapsed" data-savestate="true" data-tree="[{&quot;path&quot;:&quot;Personal&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2018&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2020&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2021&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2022&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2023&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2024&quot;,&quot;collapsed&quot;:true},{&quot;path&quo
</script><script type="module">
let mermaidImport = undefined
document.addEventListener('nav', async () => {
if (document.querySelector("code.mermaid")) {
mermaidImport ||= await import('https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs')
const mermaid = mermaidImport.default
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
mermaid.initialize({
startOnLoad: false,
securityLevel: 'loose',
theme: darkMode ? 'dark' : 'default'
})
await mermaid.run({
querySelector: '.mermaid'
})
}
});
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/contrib/copy-tex.min.js" type="application/javascript"></script><script src="../../../../postscript.js" type="module"></script></html>