Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
551 lines (434 loc) · 28 KB
/
Copy pathindex.html
File metadata and controls
551 lines (434 loc) · 28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<meta name="baidu-site-verification" content="NkA6ndXFZC">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
<script class="next-config" data-name="main" type="application/json">{"hostname":"www.xi4oyu.top","root":"/","images":"/images","scheme":"Gemini","version":"8.7.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"gitalk","storage":true,"lazyload":false,"nav":null,"activeClass":"gitalk"},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果:${query}","hits_time":"找到 ${hits} 个搜索结果(用时 ${time} 毫秒)","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>
<meta name="description" content="这篇文章的起因是:本人笔记本电脑的硬盘太小了,换了个大的,需要重新配置系统(manjaro),重新虚拟机环境过于繁琐且没必要,于是乎考虑直接迁移虚拟机">
<meta property="og:type" content="article">
<meta property="og:title" content="kvm 虚拟机迁移笔记">
<meta property="og:url" content="http://www.xi4oyu.top/8c042604/index.html">
<meta property="og:site_name" content="feather's blog">
<meta property="og:description" content="这篇文章的起因是:本人笔记本电脑的硬盘太小了,换了个大的,需要重新配置系统(manjaro),重新虚拟机环境过于繁琐且没必要,于是乎考虑直接迁移虚拟机">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://www.xi4oyu.top/images/8c042604/pasted-0.png">
<meta property="og:image" content="http://www.xi4oyu.top/images/8c042604/pasted-1.png">
<meta property="article:published_time" content="2022-07-24T08:40:00.000Z">
<meta property="article:modified_time" content="2022-07-24T08:40:00.000Z">
<meta property="article:author" content="feather">
<meta property="article:tag" content="kvm">
<meta property="article:tag" content="virsh">
<meta property="article:tag" content="migrate">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://www.xi4oyu.top/images/8c042604/pasted-0.png">
<link rel="canonical" href="http://www.xi4oyu.top/8c042604/">
<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://www.xi4oyu.top/8c042604/","path":"8c042604/","title":"kvm 虚拟机迁移笔记"}</script>
<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>kvm 虚拟机迁移笔记 | feather's blog</title>
<noscript>
<link rel="stylesheet" href="/css/noscript.css">
</noscript>
<link rel="alternate" href="/atom.xml" title="feather's blog" type="application/atom+xml">
</head>
<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
<div class="headband"></div>
<main class="main">
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="切换导航栏" role="button">
<span class="toggle-line"></span>
<span class="toggle-line"></span>
<span class="toggle-line"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<i class="logo-line"></i>
<h1 class="site-title">feather's blog</h1>
<i class="logo-line"></i>
</a>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
<i class="fa fa-search fa-fw fa-lg"></i>
</div>
</div>
</div>
<nav class="site-nav">
<ul class="main-menu menu">
<li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
<li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
<li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
<li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
<li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
<li class="menu-item menu-item-search">
<a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
</a>
</li>
</ul>
</nav>
<div class="search-pop-overlay">
<div class="popup search-popup"><div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocapitalize="off" maxlength="80" placeholder="搜索..." spellcheck="false" type="search" class="search-input">
</div>
<span class="popup-btn-close" role="button">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div class="search-result-container no-result">
<div class="search-result-icon">
<i class="fa fa-spinner fa-pulse fa-5x"></i>
</div>
</div>
</div>
</div>
</div>
<div class="toggle sidebar-toggle" role="button">
<span class="toggle-line"></span>
<span class="toggle-line"></span>
<span class="toggle-line"></span>
</div>
<aside class="sidebar">
<div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
<ul class="sidebar-nav">
<li class="sidebar-nav-toc">
文章目录
</li>
<li class="sidebar-nav-overview">
站点概览
</li>
</ul>
<div class="sidebar-panel-container">
<!--noindex-->
<div class="post-toc-wrap sidebar-panel">
<div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E4%BA%9B%E5%89%8D%E6%8F%90"><span class="nav-number">1.</span> <span class="nav-text">一些前提</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A4%87%E4%BB%BD%E8%99%9A%E6%8B%9F%E6%9C%BA"><span class="nav-number">2.</span> <span class="nav-text">备份虚拟机</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%81%A2%E5%A4%8D%E8%99%9A%E6%8B%9F%E6%9C%BA"><span class="nav-number">3.</span> <span class="nav-text">恢复虚拟机</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83"><span class="nav-number">4.</span> <span class="nav-text">参考</span></a></li></ol></div>
</div>
<!--/noindex-->
<div class="site-overview-wrap sidebar-panel">
<div class="site-overview">
<div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
<img class="site-author-image" itemprop="image" alt="feather" src="/images/avatar.jpeg">
<p class="site-author-name" itemprop="name">feather</p>
<div class="site-description" itemprop="description">计算机技术&个人琐碎事</div>
</div>
<div class="site-state-wrap site-overview-item animated">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">63</span>
<span class="site-state-item-name">日志</span>
</a>
</div>
<div class="site-state-item site-state-categories">
<a href="/categories/">
<span class="site-state-item-count">13</span>
<span class="site-state-item-name">分类</span></a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">42</span>
<span class="site-state-item-name">标签</span></a>
</div>
</nav>
</div>
<div class="links-of-author site-overview-item animated">
<span class="links-of-author-item">
<a href="https://github.com/featherl" title="GitHub → https://github.com/featherl" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
</span>
<span class="links-of-author-item">
<a href="mailto:featherm@126.com" title="E-Mail → mailto:featherm@126.com" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
</span>
</div>
<div class="links-of-blogroll site-overview-item animated">
<div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
Links
</div>
<ul class="links-of-blogroll-list">
<li class="links-of-blogroll-item">
<a href="https://0x4qe.github.io/" title="https://0x4qe.github.io/" rel="noopener" target="_blank">0x4qE</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://wzyxv1n.top/" title="https://wzyxv1n.top/" rel="noopener" target="_blank">转爷</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://github.red/" title="https://github.red/" rel="noopener" target="_blank">茄皇</a>
</li>
<li class="links-of-blogroll-item">
<a href="http://fl0.top/" title="http://fl0.top/" rel="noopener" target="_blank">qz</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://legr4ndk.github.io/" title="https://legr4ndk.github.io/" rel="noopener" target="_blank">Legrandk</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://hikawa.ml/" title="https://hikawa.ml/" rel="noopener" target="_blank">Akira</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://ugi57.github.io/" title="https://ugi57.github.io/" rel="noopener" target="_blank">_357</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://altonhe.github.io/" title="https://altonhe.github.io/" rel="noopener" target="_blank">Trotsky</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://www.thesoldierjack.cn/" title="https://www.thesoldierjack.cn/" rel="noopener" target="_blank">digger</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://wr-web.github.io/" title="https://wr-web.github.io/" rel="noopener" target="_blank">wr</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://annevi.cn/" title="https://annevi.cn/" rel="noopener" target="_blank">annevi</a>
</li>
<li class="links-of-blogroll-item">
<a href="http://www.zhouweitong.site/" title="http://www.zhouweitong.site/" rel="noopener" target="_blank">obj</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://blog.wz22.cc/" title="https://blog.wz22.cc/" rel="noopener" target="_blank">Moesang</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://me.liki.link/" title="https://me.liki.link/" rel="noopener" target="_blank">kg</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://cosmos.red/" title="https://cosmos.red/" rel="noopener" target="_blank">boss-c</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://jacksonyu1334.github.io/" title="https://jacksonyu1334.github.io" rel="noopener" target="_blank">jackson</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://cjovi.icu/" title="https://cjovi.icu/" rel="noopener" target="_blank">cj</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</aside>
<div class="sidebar-dimmer"></div>
</header>
<div class="back-to-top" role="button" aria-label="返回顶部">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<noscript>
<div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>
<div class="main-inner post posts-expand">
<div class="post-block">
<article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="http://www.xi4oyu.top/8c042604/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpeg">
<meta itemprop="name" content="feather">
<meta itemprop="description" content="计算机技术&个人琐碎事">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="feather's blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
kvm 虚拟机迁移笔记
</h1>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2022-07-24 16:40:00" itemprop="dateCreated datePublished" datetime="2022-07-24T16:40:00+08:00">2022-07-24</time>
</span>
<span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
<span class="post-meta-item-icon">
<i class="far fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读次数:</span>
<span id="busuanzi_value_page_pv"></span>
</span>
<span class="post-meta-break"></span>
<span class="post-meta-item" title="本文字数">
<span class="post-meta-item-icon">
<i class="far fa-file-word"></i>
</span>
<span class="post-meta-item-text">本文字数:</span>
<span>1.9k</span>
</span>
<span class="post-meta-item" title="阅读时长">
<span class="post-meta-item-icon">
<i class="far fa-clock"></i>
</span>
<span class="post-meta-item-text">阅读时长 ≈</span>
<span>2 分钟</span>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>这篇文章的起因是:本人笔记本电脑的硬盘太小了,换了个大的,需要重新配置系统(manjaro),重新虚拟机环境过于繁琐且没必要,于是乎考虑直接迁移虚拟机</p>
<span id="more"></span>
<blockquote>
<p><del>其实有一个非常粗暴的方法,直接把相关目录全拷贝一遍就好了</del></p>
</blockquote>
<h2 id="一些前提"><a href="#一些前提" class="headerlink" title="一些前提"></a>一些前提</h2><p>这篇文章是基于笔者的笔记本环境的,其中的一些操作要根据读者实际情况自行调整</p>
<ul>
<li>系统:manjaro linux</li>
<li>分区情况:<code>/</code> 和 <code>/home</code> 独立分区,之后打算虚拟机放到 <code>/home</code> 分区里,主要考虑到了重装系统,重装系统也只要覆盖根分区就好了,只需要简单调整下配置就能无缝衔接了</li>
<li>虚拟机环境:由 libvirt 工具管理的 kvm 虚拟机,一个 windows 10 ,一个 ubuntu 20.04(<del>不要问为什么主系统是 linux 还要配虚拟机 ubuntu</del>)</li>
</ul>
<h2 id="备份虚拟机"><a href="#备份虚拟机" class="headerlink" title="备份虚拟机"></a>备份虚拟机</h2><blockquote>
<p>因为笔者的笔记本只有一个硬盘插槽,所以在换硬盘前得做好虚拟机的备份</p>
</blockquote>
<p><strong>首先</strong>,要备份的虚拟机首先要处于<strong>关机</strong>状态,其他情况本文不考虑</p>
<p><strong>其次</strong>,备份虚拟机<strong>配置文件</strong>,也就是 virsh 使用的 xml 文件,下面以笔者的 ubuntu 20.04 虚拟机为例:</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">virsh</span> dumpxml ubuntu20.04 <span class="token operator">></span> <span class="token variable">$backup</span>/ubuntu/ubuntu20.04.xml<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<blockquote>
<p>其中的 $backup 存放备份虚拟机所有文件的目录,迁移的时候只要拷贝这个目录就好了</p>
</blockquote>
<p><strong>然后</strong>,备份虚拟机的<strong>硬盘镜像文件</strong>,虚拟机的镜像存储在 <code>/var/lib/libvirt/images/</code> 目录下,把对应虚拟机的镜像备份好就行,例</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">cp</span> /var/lib/libvirt/images/ubuntu20.04.qcow2 <span class="token variable">$backup</span>/ubuntu/ubuntu20.04.qcow2<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<blockquote>
<p>在这一步,突然意识到了问题,就是原有的盘存储空间不足以再存放一份镜像,并且笔者的 U 盘也无法存储足足有 100G 的镜像文件,直接上传到云盘上得等到猴年马月<br>于是乎马上下单外置硬盘盒,打算换好新硬盘装完系统后,直接把旧的硬盘插硬盘盒里接上电脑用,所以这一步笔者其实是直接从外置硬盘拷贝到换好新硬盘的笔记本上的</p>
</blockquote>
<p><strong>最后</strong>,理论上第三步就做好了,<strong>但是</strong>,<strong>虚拟机快照</strong>还没有备份,如果读者不需要备份虚拟机快照可以跳过这一步</p>
<p>笔者虚拟机使用的硬盘镜像格式都是 <strong>qcow2</strong>,快照是记录在镜像里的,使用如下命令查看:</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell">qemu-img snapshot -l xxx.qcow2<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p><img src="/images/8c042604/pasted-0.png" alt="snapshot1"></p>
<p>第一步已经备份好了镜像,那么快照是不是也备份好了呢?</p>
<p>是,也<strong>不完全是</strong>,对于镜像而言,快照就存储在镜像里,但是 libvirt 工具并不知道这些快照的状态,就是处于这些快照的时候,<strong>配置文件</strong>是什么样的无法通过镜像文件得知,所以还需要备份这些快照的配置文件</p>
<p>这些快照文件存储在 <code>/var/lib/libvirt/qemu/snapshot</code> 目录下:<br><img src="/images/8c042604/pasted-1.png" alt="snapshot2"></p>
<p>由于全部虚拟机都要迁移,所以直接备份整个目录就行了</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">cp</span> -r /var/lib/libvirt/qemu/snapshot <span class="token variable">$backup</span>/snapshot<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h2 id="恢复虚拟机"><a href="#恢复虚拟机" class="headerlink" title="恢复虚拟机"></a>恢复虚拟机</h2><p>在上一步中备份好了虚拟机,然后把 $backup 的内容都拷贝到了新硬盘的 <code>$HOME/virtualmachine</code> 目录下,接下来就是恢复虚拟机了</p>
<p><strong>第一歩</strong>,导入虚拟机配置</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">virsh</span> define --file <span class="token environment constant">$HOME</span>/virtualmachine/ubuntu/ubuntu20.04.xml<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p><strong>第二步</strong>,恢复镜像</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">cp</span> <span class="token environment constant">$HOME</span>/virtualmachine/ubuntu/ubuntu20.04.qcow2 /var/lib/libvirt/images/ubuntu20.04.qcow2<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>笔者并不打算把虚拟机拷贝到根分区使用,重装系统前还得重新备份,所以这一步实际上笔者是直接用<strong>软连接</strong></p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">ln</span> -sf <span class="token environment constant">$HOME</span>/virtualmachine/ubuntu/ubuntu20.04.qcow2 /var/lib/libvirt/images/ubuntu20.04.qcow2<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p><strong>第三步</strong>,恢复快照</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">cp</span> -r <span class="token environment constant">$HOME</span>/virtualmachine/snapshot/ubuntu20.04 /var/lib/libvirt/qemu/snapshot/ubuntu20.04<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>同理,笔者这一步用的也是软连接</p>
<pre class="line-numbers language-shell" data-language="shell"><code class="language-shell"><span class="token function">sudo</span> <span class="token function">ln</span> -sf <span class="token environment constant">$HOME</span>/virtualmachine/snapshot/ubuntu20.04 /var/lib/libvirt/qemu/snapshot/ubuntu20.04<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>最后将虚拟机开启验证就好了,如果备份虚拟机的镜像文件名有更改,记得在配置文件里也修改为对应的路径</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ol>
<li><a target="_blank" rel="external nofollow noopener noreferrer" href="https://www.cnblogs.com/djlsunshine/p/10278363.html">https://www.cnblogs.com/djlsunshine/p/10278363.html</a></li>
<li><a target="_blank" rel="external nofollow noopener noreferrer" href="https://cloud.tencent.com/developer/article/1671091">https://cloud.tencent.com/developer/article/1671091</a></li>
</ol>
</div>
<footer class="post-footer">
<div class="post-copyright">
<ul>
<li class="post-copyright-author">
<strong>原作者: </strong>feather
</li>
<li class="post-copyright-link">
<strong>本文链接:</strong>
<a href="http://www.xi4oyu.top/8c042604/" title="kvm 虚拟机迁移笔记">http://www.xi4oyu.top/8c042604/</a>
</li>
<li class="post-copyright-license">
<strong>版权声明: </strong>本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处!
</li>
</ul>
</div>
<div class="followme">
<span>欢迎关注我的其它发布渠道</span>
<div class="social-list">
<div class="social-item">
<a target="_blank" class="social-link" href="/atom.xml">
<span class="icon">
<i class="fa fa-rss"></i>
</span>
<span class="label">RSS</span>
</a>
</div>
</div>
</div>
<div class="post-tags">
<a href="/tags/kvm/" rel="tag"># kvm</a>
<a href="/tags/virsh/" rel="tag"># virsh</a>
<a href="/tags/migrate/" rel="tag"># migrate</a>
</div>
<div class="post-nav">
<div class="post-nav-item">
<a href="/4161b49f/" rel="prev" title="CVE-2022-0185">
<i class="fa fa-chevron-left"></i> CVE-2022-0185
</a>
</div>
<div class="post-nav-item">
<a href="/2663df8d/" rel="next" title="syzkaller 源码阅读笔记 —— syz-manager">
syzkaller 源码阅读笔记 —— syz-manager <i class="fa fa-chevron-right"></i>
</a>
</div>
</div>
</footer>
</article>
</div>
<div class="comments gitalk-container"></div>
</div>
</main>
<footer class="footer">
<div class="footer-inner">
<div class="copyright">
©
<span itemprop="copyrightYear">2022</span>
<span class="with-love">
<i class="fa fa-heart"></i>
</span>
<span class="author" itemprop="copyrightHolder">feather</span>
</div>
<div class="wordcount">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-chart-line"></i>
</span>
<span title="站点总字数">380k</span>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-coffee"></i>
</span>
<span title="站点阅读时长">5:46</span>
</span>
</div>
<div class="busuanzi-count">
<span class="post-meta-item" id="busuanzi_container_site_uv">
<span class="post-meta-item-icon">
<i class="fa fa-user"></i>
</span>
<span class="site-uv" title="总访客量">
<span id="busuanzi_value_site_uv"></span>
</span>
</span>
<span class="post-meta-item" id="busuanzi_container_site_pv">
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
<span class="site-pv" title="总访问量">
<span id="busuanzi_value_site_pv"></span>
</span>
</span>
</div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>
<script src="/js/third-party/search/local-search.js"></script>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.css" integrity="sha256-AJnUHL7dBv6PGaeyPQJcgQPDjt/Hn/PvYZde1iqfp8U=" crossorigin="anonymous">
<script class="next-config" data-name="gitalk" type="application/json">{"enable":true,"github_id":"featherl","repo":"BlogComment","client_id":"675720f495795eee8627","client_secret":"969c2822176976bcb997f7d6fd07767ce6356043","admin_user":"featherl","distraction_free_mode":true,"proxy":"https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token","language":"zh-CN","js":{"url":"https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.min.js","integrity":"sha256-Pmj85ojLaPOWwRtlMJwmezB/Qg8BzvJp5eTzvXaYAfA="},"path_md5":"12a5c6cbf926050b1adc839a6890b063"}</script>
<script src="/js/third-party/comments/gitalk.js"></script>
</body>
</html>