617 lines
563 KiB
HTML
617 lines
563 KiB
HTML
|
<!DOCTYPE html>
|
|||
|
<html><head><title>5. KVM 存储管理</title><meta charSet="utf-8"/><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 rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com"/><script async src="https://umami.7wate.com/script.js" data-website-id="c061efdc-95dd-4d21-9d04-a1ffda0a85b9"></script><script>
|
|||
|
var _hmt = _hmt || [];
|
|||
|
(function() {
|
|||
|
var hm = document.createElement("script");
|
|||
|
hm.src = "https://hm.baidu.com/hm.js?94d8ccb156eb7c65abf317e6e01cdba9";
|
|||
|
var s = document.getElementsByTagName("script")[0];
|
|||
|
s.parentNode.insertBefore(hm, s);
|
|||
|
})();
|
|||
|
</script><script async src="https://www.googletagmanager.com/gtag/js?id=G-MHMEL0F832"></script><script>
|
|||
|
(function() {
|
|||
|
window.dataLayer = window.dataLayer || [];
|
|||
|
function gtag() {
|
|||
|
window.dataLayer.push(arguments);
|
|||
|
}
|
|||
|
gtag('js', new Date());
|
|||
|
gtag('config', 'G-MHMEL0F832');
|
|||
|
})();
|
|||
|
</script><link href="../../../../index.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://fonts.googleapis.com/css2?family=IBM Plex Mono&family=Schibsted Grotesk:wght@400;700&family=Source Sans Pro:ital,wght@0,400;0,600;1,400;1,600&display=swap" 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"><h1 class="page-title "><a href="../../../..">📚 X·Eden</a></h1><div class="spacer mobile-only"></div><div class="search "><div id="search-icon"><p>Search</p><div></div><svg tabIndex="0" aria-labelledby="title desc" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7"><title id="title">Search</title><desc id="desc">Search</desc><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></div><div id="search-container"><div id="search-space"><input autocomplete="off" id="search-bar" name="search" type="text" aria-label="Search for something" placeholder="Search for something"/><div id="results-container"></div></div></div></div><div class="darkmode "><input class="toggle" id="darkmode-toggle" type="checkbox" tabIndex="-1"/><label id="toggle-label-light" for="darkmode-toggle" tabIndex="-1"><svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="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;" xmlSpace="preserve"><title>Light mode</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,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path></svg></label><label id="toggle-label-dark" for="darkmode-toggle" tabIndex="-1"><svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1" id="nightIcon" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background='new 0 0 100 100'" xmlSpace="preserve"><title>Dark mode</title><path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,
|
|||
|
<h3 id="存储概念">存储概念<a aria-hidden="true" tabindex="-1" href="#存储概念" class="internal"> §</a></h3>
|
|||
|
<p>KVM(Kernel-based Virtual Machine)存储是指在 KVM 虚拟化环境中,为虚拟机提供的存储资源。KVM 支持多种存储类型,包括磁盘映像文件、逻辑卷管理(LVM)和网络存储。虚拟机的存储设备可以像物理机的硬盘一样使用,并且可以通过不同的存储格式和协议进行管理和访问。</p>
|
|||
|
<h3 id="虚拟机存储类型">虚拟机存储类型<a aria-hidden="true" tabindex="-1" href="#虚拟机存储类型" class="internal"> §</a></h3>
|
|||
|
<h4 id="磁盘映像文件qcow2-raw">磁盘映像文件(qcow2, raw)<a aria-hidden="true" tabindex="-1" href="#磁盘映像文件qcow2-raw" class="internal"> §</a></h4>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<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>
|
|||
|
<h4 id="其他常见磁盘映像文件类型">其他常见磁盘映像文件类型<a aria-hidden="true" tabindex="-1" href="#其他常见磁盘映像文件类型" class="internal"> §</a></h4>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<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>
|
|||
|
<h4 id="逻辑卷管理lvm">逻辑卷管理(LVM)<a aria-hidden="true" tabindex="-1" href="#逻辑卷管理lvm" class="internal"> §</a></h4>
|
|||
|
<p>逻辑卷管理(LVM)提供灵活的存储管理,可以动态调整逻辑卷大小、快照和卷组管理。性能较高,适合企业级应用和需要高性能、灵活存储管理的环境。</p>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>创建物理卷和卷组:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pvcreate</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vgcreate</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vg_kvm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>创建逻辑卷:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvcreate</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-n</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lv_myvm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-L</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vg_kvm</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="网络存储nfs-iscsi">网络存储(NFS, iSCSI)<a aria-hidden="true" tabindex="-1" href="#网络存储nfs-iscsi" class="internal"> §</a></h4>
|
|||
|
<p>NFS(Network File System)通过网络共享文件系统,适合共享存储和集中存储管理,以及多台虚拟机需要共享同一存储资源的环境。</p>
|
|||
|
<p>挂载 NFS 存储:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mount</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-t</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">server:/path/to/nfs</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/mnt/nfs</span></span></code></pre></div>
|
|||
|
<p><strong>iSCSI(Internet Small Computer Systems Interface)</strong>:</p>
|
|||
|
<p>通过网络提供块级存储,适合高性能需求的存储应用,以及需要集中管理和高性能存储访问的环境。</p>
|
|||
|
<ol>
|
|||
|
<li>安装 iSCSI 客户端:</li>
|
|||
|
</ol>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">apt</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">install</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">open-iscsi</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-comment);"># Ubuntu</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">yum</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">install</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-initiator-utils</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-comment);"># CentOS/RHEL</span></span></code></pre></div>
|
|||
|
<ol>
|
|||
|
<li>发现和登录 iSCSI 目标:</li>
|
|||
|
</ol>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsiadm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-m</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">discovery</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-t</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">sendtargets</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-p</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">iSCSI_server_I</span><span style="color:var(--shiki-color-text);">P</span><span style="color:var(--shiki-token-keyword);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsiadm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-m</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">node</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--login</span></span></code></pre></div>
|
|||
|
<h3 id="配置系统存储支持">配置系统存储支持<a aria-hidden="true" tabindex="-1" href="#配置系统存储支持" class="internal"> §</a></h3>
|
|||
|
<h4 id="确认存储驱动加载情况">确认存储驱动加载情况<a aria-hidden="true" tabindex="-1" href="#确认存储驱动加载情况" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>检查存储驱动</strong>:</p>
|
|||
|
<p>使用 <code>lsmod</code> 命令检查存储驱动是否加载:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">lsmod</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">|</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">grep</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-E</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">'virtio_blk|virtio_scsi'</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>加载存储驱动</strong>:</p>
|
|||
|
<p>如果存储驱动未加载,可以手动加载:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">modprobe</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virtio_blk</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">modprobe</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virtio_scsi</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="准备存储设备和挂载点">准备存储设备和挂载点<a aria-hidden="true" tabindex="-1" href="#准备存储设备和挂载点" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>准备本地存储设备</strong>:</p>
|
|||
|
<p>分区和格式化存储设备:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">fdisk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mkfs.ext4</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX1</span></span></code></pre></div>
|
|||
|
<p>创建挂载点并挂载:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mkdir</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-p</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/mnt/kvm_storage</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mount</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX1</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/mnt/kvm_storage</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>准备网络存储设备(NFS 例子)</strong>:</p>
|
|||
|
<p>安装 NFS 客户端:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">apt</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">install</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-common</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-comment);"># Ubuntu</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">yum</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">install</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-utils</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-comment);"># CentOS/RHEL</span></span></code></pre></div>
|
|||
|
<p>挂载 NFS 共享:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mkdir</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-p</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/mnt/nfs_storage</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mount</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-t</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">server:/path/to/nfs</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/mnt/nfs_storage</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>配置自动挂载</strong>:</p>
|
|||
|
<p>编辑 <code>/etc/fstab</code> 文件,添加以下内容确保重启后自动挂载:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="text" data-theme="default"><code data-language="text" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);">/dev/sdX1 /mnt/kvm_storage ext4 defaults 0 2</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);">server:/path/to/nfs /mnt/nfs_storage nfs defaults 0 0</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p>通过以上步骤,可以为 KVM 环境配置各种存储支持,包括磁盘映像文件、LVM 和网络存储。确保存储驱动已加载,并准备好存储设备和挂载点,为虚拟机提供可靠的存储资源。</p>
|
|||
|
<h2 id="配置存储池">配置存储池<a aria-hidden="true" tabindex="-1" href="#配置存储池" class="internal"> §</a></h2>
|
|||
|
<h3 id="存储池是什么">存储池是什么<a aria-hidden="true" tabindex="-1" href="#存储池是什么" class="internal"> §</a></h3>
|
|||
|
<h4 id="存储池的概念">存储池的概念<a aria-hidden="true" tabindex="-1" href="#存储池的概念" class="internal"> §</a></h4>
|
|||
|
<p>存储池(Storage Pool)是 KVM 虚拟化环境中的一种抽象概念,用于管理和组织底层存储资源。存储池可以包含多个存储卷(Storage Volume),每个存储卷对应虚拟机的一个磁盘映像文件、逻辑卷或网络存储块。通过存储池,管理员可以更方便地管理和分配存储资源。</p>
|
|||
|
<h4 id="存储池的类型">存储池的类型<a aria-hidden="true" tabindex="-1" href="#存储池的类型" class="internal"> §</a></h4>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<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>基于 LVM(Logical Volume Manager)创建和管理逻辑卷。提供灵活的卷管理和快照功能。</td><td>适合企业级部署。</td></tr><tr><td><strong>网络存储池</strong> (Network Storage Pool)</td><td>使用网络存储协议(如 NFS、iSCSI)创建存储池。适合分布式存储和集中存储管理。</td><td>适合分布式存储和集中存储管理。</td></tr></tbody></table>
|
|||
|
<h3 id="创建和管理目录存储池">创建和管理目录存储池<a aria-hidden="true" tabindex="-1" href="#创建和管理目录存储池" class="internal"> §</a></h3>
|
|||
|
<h4 id="使用-virsh-创建目录存储池">使用 <code>virsh</code> 创建目录存储池<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建目录存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建目录存储池</strong>:</p>
|
|||
|
<p>创建一个目录存储池的 XML 配置文件,例如 <code>dir-pool.xml</code>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'dir'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>dir-pool</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">>/mnt/kvm_storage</</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>定义并启动存储池</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 命令定义并启动目录存储池:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-define</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool.xml</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-autostart</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置目录存储池">配置目录存储池<a aria-hidden="true" tabindex="-1" href="#配置目录存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池信息</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池中的存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-list</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>创建存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">volume1</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">10</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h3 id="创建和管理逻辑卷存储池">创建和管理逻辑卷存储池<a aria-hidden="true" tabindex="-1" href="#创建和管理逻辑卷存储池" class="internal"> §</a></h3>
|
|||
|
<h4 id="使用-virsh-创建-lvm-存储池">使用 <code>virsh</code> 创建 LVM 存储池<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建-lvm-存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建 LVM 存储池</strong>:</p>
|
|||
|
<p>创建一个 LVM 存储池的 XML 配置文件,例如 <code>lvm-pool.xml</code>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'logical'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>lvm-pool</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">device</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">path</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/dev/vg_kvm'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>vg_kvm</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">format</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'lvm2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">>/dev/vg_kvm</</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>定义并启动存储池</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 命令定义并启动 LVM 存储池:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-define</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool.xml</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-autostart</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置-lvm-存储池">配置 LVM 存储池<a aria-hidden="true" tabindex="-1" href="#配置-lvm-存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池信息</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池中的存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-list</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>创建存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lv_volume1</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h3 id="创建和管理网络存储池">创建和管理网络存储池<a aria-hidden="true" tabindex="-1" href="#创建和管理网络存储池" class="internal"> §</a></h3>
|
|||
|
<h4 id="使用-virsh-创建-nfs-存储池">使用 <code>virsh</code> 创建 NFS 存储池<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建-nfs-存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建 NFS 存储池</strong>:</p>
|
|||
|
<p>创建一个 NFS 存储池的 XML 配置文件,例如 <code>nfs-pool.xml</code>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'netfs'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>nfs-pool</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">host</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">name</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'nfs-server'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">dir</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">path</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/path/to/nfs'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">>/mnt/nfs_storage</</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>定义并启动存储池</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 命令定义并启动 NFS 存储池:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-define</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool.xml</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-autostart</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="使用-virsh-创建-iscsi-存储池">使用 <code>virsh</code> 创建 iSCSI 存储池<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建-iscsi-存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建 iSCSI 存储池</strong>:</p>
|
|||
|
<p>创建一个 iSCSI 存储池的 XML 配置文件,例如 <code>iscsi-pool.xml</code>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'iscsi'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>iscsi-pool</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">host</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">name</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'iscsi-server'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">device</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">path</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/dev/sdX'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">>/dev/disk/by-path/</</span><span style="color:var(--shiki-token-string-expression);">path</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">pool</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>定义并启动存储池</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 命令定义并启动 iSCSI 存储池:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-define</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool.xml</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-autostart</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置网络存储池">配置网络存储池<a aria-hidden="true" tabindex="-1" href="#配置网络存储池" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池信息</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>查看存储池中的存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-list</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-list</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>创建存储卷</strong>:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">nfs-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">volume1</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">10</span><span style="color:var(--shiki-token-string);">G</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">iscsi-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">volume2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h2 id="配置存储卷">配置存储卷<a aria-hidden="true" tabindex="-1" href="#配置存储卷" class="internal"> §</a></h2>
|
|||
|
<h3 id="存储卷的概念">存储卷的概念<a aria-hidden="true" tabindex="-1" href="#存储卷的概念" class="internal"> §</a></h3>
|
|||
|
<p>**存储卷(Storage Volume)是存储池(Storage Pool)中的一个逻辑单元,类似于传统文件系统中的文件。**存储卷为虚拟机提供存储空间,用于存储操作系统、应用程序和数据。每个存储卷可以对应一个磁盘映像文件、逻辑卷或网络存储块。通过存储卷,管理员可以灵活管理和分配存储资源。</p>
|
|||
|
<h3 id="创建和管理磁盘映像文件">创建和管理磁盘映像文件<a aria-hidden="true" tabindex="-1" href="#创建和管理磁盘映像文件" class="internal"> §</a></h3>
|
|||
|
<h4 id="使用-virsh-创建磁盘映像文件">使用 <code>virsh</code> 创建磁盘映像文件<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建磁盘映像文件" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建磁盘映像文件</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 创建一个磁盘映像文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--format</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span></span></code></pre></div>
|
|||
|
<p>以上命令将在 <code>dir-pool</code> 存储池中创建一个名为 <code>mydisk.qcow2</code> 的磁盘映像文件,大小为 20GB,格式为 qcow2。</p>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>查看磁盘映像文件信息</strong>:</p>
|
|||
|
<p>查看创建的磁盘映像文件信息:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">dir-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置磁盘映像文件的大小和格式">配置磁盘映像文件的大小和格式<a aria-hidden="true" tabindex="-1" href="#配置磁盘映像文件的大小和格式" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>调整磁盘映像文件大小</strong>:</p>
|
|||
|
<p>可以使用 <code>qemu-img</code> 工具调整磁盘映像文件的大小:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">resize</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">+10G</span></span></code></pre></div>
|
|||
|
<p>以上命令将 <code>mydisk.qcow2</code> 的大小增加 10GB。</p>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>转换磁盘映像文件格式</strong>:</p>
|
|||
|
<p>可以使用 <code>qemu-img</code> 工具转换磁盘映像文件的格式:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">convert</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-f</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-O</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">raw</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/mydisk.raw</span></span></code></pre></div>
|
|||
|
<p>以上命令将 <code>mydisk.qcow2</code> 转换为 <code>mydisk.raw</code>,格式从 qcow2 转换为 raw。</p>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h3 id="创建和管理逻辑卷">创建和管理逻辑卷<a aria-hidden="true" tabindex="-1" href="#创建和管理逻辑卷" class="internal"> §</a></h3>
|
|||
|
<h4 id="使用-virsh-创建逻辑卷">使用 <code>virsh</code> 创建逻辑卷<a aria-hidden="true" tabindex="-1" href="#使用-virsh-创建逻辑卷" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>创建逻辑卷</strong>:</p>
|
|||
|
<p>使用 <code>virsh</code> 创建一个逻辑卷:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lv_mydisk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
<p>以上命令将在 <code>lvm-pool</code> 存储池中创建一个名为 <code>lv_mydisk</code> 的逻辑卷,大小为 20GB。</p>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>查看逻辑卷信息</strong>:</p>
|
|||
|
<p>查看创建的逻辑卷信息:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vol-info</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lv_mydisk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--pool</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置逻辑卷的大小和格式">配置逻辑卷的大小和格式<a aria-hidden="true" tabindex="-1" href="#配置逻辑卷的大小和格式" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p><strong>调整逻辑卷大小</strong>:</p>
|
|||
|
<p>可以使用 <code>lvresize</code> 工具调整逻辑卷的大小:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvresize</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-L</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">+10G</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/vg_kvm/lv_mydisk</span></span></code></pre></div>
|
|||
|
<p>以上命令将 <code>lv_mydisk</code> 的大小增加 10GB。</p>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><strong>格式化逻辑卷</strong>:</p>
|
|||
|
<p>在使用逻辑卷之前,需要对其进行格式化:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">mkfs.ext4</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/vg_kvm/lv_mydisk</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p>通过以上步骤,可以使用 <code>virsh</code> 创建和管理磁盘映像文件和逻辑卷,并灵活配置其大小和格式。这些存储卷为虚拟机提供了可靠和高效的存储解决方案。</p>
|
|||
|
<h2 id="虚拟机的存储配置">虚拟机的存储配置<a aria-hidden="true" tabindex="-1" href="#虚拟机的存储配置" class="internal"> §</a></h2>
|
|||
|
<h3 id="使用-virsh-添加和删除虚拟机磁盘">使用 <code>virsh</code> 添加和删除虚拟机磁盘<a aria-hidden="true" tabindex="-1" href="#使用-virsh-添加和删除虚拟机磁盘" class="internal"> §</a></h3>
|
|||
|
<p><strong>添加虚拟机磁盘</strong></p>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>创建一个新的磁盘映像文件(如果需要):</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">create</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-f</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/var/lib/libvirt/images/mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">edit</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>在 <code><devices></code> 部分中添加以下内容,指定新的磁盘设备:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'file'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">device</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'disk'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">driver</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">name</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qemu'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">file</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/var/lib/libvirt/images/mydisk.qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">dev</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'vdb'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'virtio'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">address</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pci'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">domain</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0000'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x00'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">slot</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x09'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">function</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>保存并退出编辑器,启动或重启虚拟机以使新磁盘生效:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p><strong>删除虚拟机磁盘</strong></p>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">edit</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>找到需要删除的 <code><disk></code> 节点,并将其删除:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'file'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">device</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'disk'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">driver</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">name</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qemu'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">file</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/var/lib/libvirt/images/mydisk.qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">dev</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'vdb'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'virtio'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">address</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pci'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">domain</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0000'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x00'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">slot</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x09'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">function</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h3 id="virsh-配置虚拟机的启动磁盘"><code>virsh</code> 配置虚拟机的启动磁盘<a aria-hidden="true" tabindex="-1" href="#virsh-配置虚拟机的启动磁盘" class="internal"> §</a></h3>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">edit</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>在 <code><os></code> 部分中,找到 <code><boot dev='...'></code> 节点并调整顺序。例如,将磁盘设备设为首选启动设备:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">arch</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'x86_64'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">machine</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pc-i440fx-2.9'</span><span style="color:var(--shiki-color-text);">>hvm</</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">boot</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">dev</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'hd'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">boot</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">dev</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'cdrom'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h4 id="配置虚拟机-bios-设置">配置虚拟机 BIOS 设置<a aria-hidden="true" tabindex="-1" href="#配置虚拟机-bios-设置" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 命令编辑虚拟机的 XML 配置文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">edit</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>在 <code><os></code> 部分中,添加或修改 <code><bios></code> 节点。例如,启用 BIOS 引导菜单:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">arch</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'x86_64'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">machine</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pc-i440fx-2.9'</span><span style="color:var(--shiki-color-text);">>hvm</</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">loader</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">readonly</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'yes'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pflash'</span><span style="color:var(--shiki-color-text);">>/usr/share/OVMF/OVMF_CODE.fd</</span><span style="color:var(--shiki-token-string-expression);">loader</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">nvram</span><span style="color:var(--shiki-color-text);">>/var/lib/libvirt/qemu/nvram/<</span><span style="color:var(--shiki-token-string-expression);">vm_name</span><span style="color:var(--shiki-color-text);">>.fd</</span><span style="color:var(--shiki-token-string-expression);">nvram</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">bootmenu</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">enable</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'yes'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>保存并退出编辑器,启动或重启虚拟机以应用更改:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<h2 id="高级存储管理">高级存储管理<a aria-hidden="true" tabindex="-1" href="#高级存储管理" class="internal"> §</a></h2>
|
|||
|
<h3 id="快照管理">快照管理<a aria-hidden="true" tabindex="-1" href="#快照管理" class="internal"> §</a></h3>
|
|||
|
<h4 id="创建和管理磁盘快照">创建和管理磁盘快照<a aria-hidden="true" tabindex="-1" href="#创建和管理磁盘快照" class="internal"> §</a></h4>
|
|||
|
<p>快照是虚拟机在某一时刻的状态,包括虚拟机的磁盘和内存状态。通过快照,您可以在需要时恢复虚拟机到之前的状态。</p>
|
|||
|
<p><strong>创建磁盘快照</strong></p>
|
|||
|
<p>使用 <code>virsh</code> 创建磁盘快照:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">snapshot-create-as</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">snapshot_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--disk-only</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">--atomic</span></span></code></pre></div>
|
|||
|
<p>以上命令创建一个仅包含磁盘状态的快照。</p>
|
|||
|
<p><strong>管理磁盘快照</strong></p>
|
|||
|
<p>使用 <code>virsh</code> 列出所有快照:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">snapshot-list</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
<p><strong>恢复快照</strong></p>
|
|||
|
<p>使用 <code>virsh</code> 恢复快照:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">snapshot-revert</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">vm_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);"><</span><span style="color:var(--shiki-token-string);">snapshot_nam</span><span style="color:var(--shiki-color-text);">e</span><span style="color:var(--shiki-token-keyword);">></span></span></code></pre></div>
|
|||
|
<h4 id="扩展存储池容量">扩展存储池容量<a aria-hidden="true" tabindex="-1" href="#扩展存储池容量" class="internal"> §</a></h4>
|
|||
|
<p><strong>扩展目录存储池</strong></p>
|
|||
|
<p>确保文件系统有足够的空间,然后直接添加更多存储卷到目录存储池即可。</p>
|
|||
|
<p><strong>扩展 LVM 存储池</strong></p>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>添加新的物理卷到卷组:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pvcreate</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vgextend</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vg_kvm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>更新存储池配置:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pool-refresh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">lvm-pool</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p><strong>扩展网络存储池</strong></p>
|
|||
|
<p>对于 NFS 和 iSCSI,直接在网络存储服务器上扩展存储容量,然后刷新存储池即可。</p>
|
|||
|
<h4 id="缩减存储池容量">缩减存储池容量<a aria-hidden="true" tabindex="-1" href="#缩减存储池容量" class="internal"> §</a></h4>
|
|||
|
<p><strong>缩减 LVM 存储池</strong></p>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>移动逻辑卷中的数据到其他物理卷:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pvmove</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>移除物理卷并减少卷组大小:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vgreduce</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">vg_kvm</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">pvremove</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/dev/sdX</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p><strong>缩减目录存储池和网络存储池</strong></p>
|
|||
|
<p>一般不直接缩减这些存储池,建议清理不需要的存储卷以释放空间。</p>
|
|||
|
<h3 id="磁盘镜像和克隆">磁盘镜像和克隆<a aria-hidden="true" tabindex="-1" href="#磁盘镜像和克隆" class="internal"> §</a></h3>
|
|||
|
<h4 id="创建磁盘镜像">创建磁盘镜像<a aria-hidden="true" tabindex="-1" href="#创建磁盘镜像" class="internal"> §</a></h4>
|
|||
|
<p><strong>创建磁盘镜像</strong></p>
|
|||
|
<p>使用 <code>qemu-img</code> 创建磁盘镜像:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">create</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-f</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/var/lib/libvirt/images/mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-constant);">20</span><span style="color:var(--shiki-token-string);">G</span></span></code></pre></div>
|
|||
|
<p><strong>转换磁盘镜像格式</strong></p>
|
|||
|
<p>使用 <code>qemu-img</code> 转换磁盘镜像格式:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">convert</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-f</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-O</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">raw</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/mydisk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/mydisk.raw</span></span></code></pre></div>
|
|||
|
<h4 id="克隆虚拟机磁盘">克隆虚拟机磁盘<a aria-hidden="true" tabindex="-1" href="#克隆虚拟机磁盘" class="internal"> §</a></h4>
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
<p>使用 <code>qemu-img</code> 克隆磁盘映像:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">qemu-img</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">create</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-f</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">-b</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/var/lib/libvirt/images/source-disk.qcow2</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/var/lib/libvirt/images/clone-disk.qcow2</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 定义新的虚拟机,并指定克隆的磁盘映像:</p>
|
|||
|
<p>创建虚拟机 XML 文件:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="xml" data-theme="default"><code data-language="xml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);"><</span><span style="color:var(--shiki-token-string-expression);">domain</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'kvm'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">>clone-vm</</span><span style="color:var(--shiki-token-string-expression);">name</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">memory</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">unit</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'KiB'</span><span style="color:var(--shiki-color-text);">>1048576</</span><span style="color:var(--shiki-token-string-expression);">memory</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">vcpu</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">placement</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'static'</span><span style="color:var(--shiki-color-text);">>1</</span><span style="color:var(--shiki-token-string-expression);">vcpu</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">arch</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'x86_64'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">machine</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pc-i440fx-2.9'</span><span style="color:var(--shiki-color-text);">>hvm</</span><span style="color:var(--shiki-token-string-expression);">type</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">os</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">devices</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'file'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">device</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'disk'</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">driver</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">name</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qemu'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">source</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">file</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'/var/lib/libvirt/images/clone-disk.qcow2'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">target</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">dev</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'vda'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'virtio'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> <</span><span style="color:var(--shiki-token-string-expression);">address</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">type</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'pci'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">domain</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0000'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">bus</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x00'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">slot</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x04'</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-function);">function</span><span style="color:var(--shiki-color-text);">=</span><span style="color:var(--shiki-token-string-expression);">'0x0'</span><span style="color:var(--shiki-color-text);">/></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">disk</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"> </</span><span style="color:var(--shiki-token-string-expression);">devices</span><span style="color:var(--shiki-color-text);">></span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-color-text);"></</span><span style="color:var(--shiki-token-string-expression);">domain</span><span style="color:var(--shiki-color-text);">></span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p>使用 <code>virsh</code> 定义并启动新的虚拟机:</p>
|
|||
|
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="shell" data-theme="default"><code data-language="shell" data-theme="default"><span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">define</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">/path/to/clone-vm.xml</span></span>
|
|||
|
<span data-line><span style="color:var(--shiki-token-function);">sudo</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">virsh</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">start</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string);">clone-vm</span></span></code></pre></div>
|
|||
|
</li>
|
|||
|
</ol></article></div><div class="right sidebar"><div class="graph "><h3>Graph View</h3><div class="graph-outer"><div id="graph-container" data-cfg="{"drag":true,"zoom":true,"depth":1,"scale":1.1,"repelForce":0.5,"centerForce":0.3,"linkDistance":30,"fontSize":0.6,"opacityScale":1,"showTags":true,"removeTags":[]}"></div><svg version="1.1" id="global-graph-icon" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 55 55" fill="currentColor" xmlSpace="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></div><div id="global-graph-outer"><div id="global-graph-container" data-cfg="{"drag":true,"zoom":true,"depth":-1,"scale":0.9,"repelForce":0.5,"centerForce":0.3,"linkDistance":30,"fontSize":0.6,"opacityScale":1,"showTags":true,"removeTags":[]}"></div></div></div><div class="toc desktop-only"><button type="button" id="toc" class><h3>Table of Contents</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"><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="backlinks "><h3>Backlinks</h3><ul class="overflow"><li>No backlinks found</li></ul></div><div class="explorer mobile-only"><button type="button" id="explorer" data-behavior="collapse" data-collapsed="collapsed" data-savestate="true" data-tree="[{"path":"Journal","collapsed":true},{"path":"Journal/2024","collapsed":true},{"path":"Journal/2024/W33","collapsed":true},{"path":"Obsidian","collapsed":true},{"path":"Obsidian/Templates","collapsed":true},{"path":"Personal","collapsed":true},{"path":"Personal/Blog","collapsed":true},{"path":"Personal/Blog/2018","collapsed":true},{"path":"Personal/Blog/202
|
|||
|
function toggleCallout() {
|
|||
|
const outerBlock = this.parentElement;
|
|||
|
outerBlock.classList.toggle(`is-collapsed`);
|
|||
|
const collapsed = outerBlock.classList.contains(`is-collapsed`);
|
|||
|
const height = collapsed ? this.scrollHeight : outerBlock.scrollHeight;
|
|||
|
outerBlock.style.maxHeight = height + `px`;
|
|||
|
let current = outerBlock;
|
|||
|
let parent = outerBlock.parentElement;
|
|||
|
while (parent) {
|
|||
|
if (!parent.classList.contains(`callout`)) {
|
|||
|
return;
|
|||
|
}
|
|||
|
const collapsed2 = parent.classList.contains(`is-collapsed`);
|
|||
|
const height2 = collapsed2 ? parent.scrollHeight : parent.scrollHeight + current.scrollHeight;
|
|||
|
parent.style.maxHeight = height2 + `px`;
|
|||
|
current = parent;
|
|||
|
parent = parent.parentElement;
|
|||
|
}
|
|||
|
}
|
|||
|
function setupCallout() {
|
|||
|
const collapsible = document.getElementsByClassName(
|
|||
|
`callout is-collapsible`
|
|||
|
);
|
|||
|
for (const div of collapsible) {
|
|||
|
const title = div.firstElementChild;
|
|||
|
if (title) {
|
|||
|
title.removeEventListener(`click`, toggleCallout);
|
|||
|
title.addEventListener(`click`, toggleCallout);
|
|||
|
const collapsed = div.classList.contains(`is-collapsed`);
|
|||
|
const height = collapsed ? title.scrollHeight : div.scrollHeight;
|
|||
|
div.style.maxHeight = height + `px`;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
document.addEventListener(`nav`, setupCallout);
|
|||
|
window.addEventListener(`resize`, setupCallout);
|
|||
|
</script><script type="module">
|
|||
|
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
|
|||
|
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
|
|||
|
mermaid.initialize({
|
|||
|
startOnLoad: false,
|
|||
|
securityLevel: 'loose',
|
|||
|
theme: darkMode ? 'dark' : 'default'
|
|||
|
});
|
|||
|
document.addEventListener('nav', async () => {
|
|||
|
await mermaid.run({
|
|||
|
querySelector: '.mermaid'
|
|||
|
})
|
|||
|
});
|
|||
|
</script><script src="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/contrib/copy-tex.min.js" type="application/javascript"></script><script src="../../../../postscript.js" type="module"></script></html>
|