zoukankan      html  css  js  c++  java
  • 使用派生镜像(qcow2)

    当创建的虚拟机越来越多,并且你发现好多虚拟机都是同一个操作系统,它们的区别就是安装的软件不大一样,那么你肯定会希望把他们公共的部分提取出来,只保存那些与公共部分不同的东西,这样镜像大小下去了,空间变多了,管理也方便了。派生镜像就是用来干这事的!

    首先看一个原始镜像

    hzgatt@hzgatt:~/images$ qemu-img info vm3_base.raw
    image: vm3_base.raw
    file format: raw
    virtual size: 2.0G (2147483648 bytes)
    disk size: 2.0G
    现在我们新建一个镜像,但是派生自它

    hzgatt@hzgatt:~/images$ qemu-img create -f qcow2 vm3_5.qcow2 -o backing_file=vm3_base.raw 5G
    Formatting 'vm3_5.qcow2', fmt=qcow2 size=5368709120 backing_file='vm3_base.raw' encryption=off cluster_size=65536
     

    hzgatt@hzgatt:~/images$ ll-rw-r--r-- 1 hzgatt hzgatt 193K 6月 29 15:00 vm3_5.qcow2
    -rw-r--r-- 1 hzgatt hzgatt 2.0G 6月 29 14:51 vm3_base.raw
     


    hzgatt@hzgatt:~/images$ qemu-img info vm3_5.qcow2
    image: vm3_5.qcow2
    file format: qcow2
    virtual size: 5.0G (5368709120 bytes)
    disk size: 136K
    cluster_size: 65536
    backing file: vm3_base.raw (actual path: vm3_base.raw)

     ^_^,这个镜像才136K,够省了吧。DRY永远的真理啊!


    现在我们在vm3_5.qcow2上打了很多安全补丁,然后发现我又想在vm3_5.qcow2上派生新的虚拟机,o(∩∩)o...哈哈,这下怎么办呢?

    hzgatt@hzgatt:~/images$ qemu-img convert -O raw vm3_5.qcow2 vm3_base2.raw
     

    hzgatt@hzgatt:~/images$ qemu-img info vm3_base2.raw
    image: vm3_base2.raw
    file format: raw
    virtual size: 5.0G (5368709120 bytes)
    disk size: 592M
     

    这个转化将会将vm3_5和base合并,生成新的vm3_base2.raw,然后你就可以继续无穷无尽的派生之旅了!

  • 相关阅读:
    正则表达式match方法和search方法
    正则表达式(基础篇1)
    动画
    重绘和重排(回流)
    数组常用的10个方法
    css3只需一招,将网站变成灰色的
    Python-类的几种调用方法
    Codeforces Global Round 8 C. Even Picture(构造)
    Codeforces Global Round 8 D. AND, OR and square sum(位运算)
    Codeforces Round #650 (Div. 3) C. Social Distance
  • 原文地址:https://www.cnblogs.com/zqyanywn/p/11446943.html
Copyright © 2011-2022 走看看