Nova image create

本文详细介绍了QCOW2磁盘映像格式的特点,包括其优势、创建方法以及在OpenStack环境下的具体应用。通过使用qemu-img命令进行操作,了解如何利用QCOW2实现快速创建瘦装备虚拟机实例,并在OpenStack中实现多个VM共用一个baseimage(backingfile)的方法。

QCOW2 (qemu copy-on-write)                                                      

Is one of the disk image formats supported by the QEMUprocessor emulator. It is a representation of a fixed size block device in afile. Benefits it offers over using raw dump representation include:

      1.    Smaller file size, even on filesystems whichdon't support holes (i.e. sparse files)

      2.    Copy-on-write support, where the image onlyrepresents changes made to an underlying disk image

      3.    Snapshot support, where the image can containmultiple snapshots of the images history

      4.    Optional zlib based compression

      5.    Optional AES encryption

The qemu-img command is the most common way of manipulatingthese images e.g.

  $> qemu-imgcreate -f qcow2 test.qcow2 4G

  Formating'test.qcow2', fmt=qcow2, size=4194304 kB

  $> qemu-imgconvert test.qcow2 -O raw test.img


QCOW2 backing files and overlays                                                   

qcow2(qemu copy-on-write)具有创建一个base-image,以及在base-image(即backingfile)

的基础上创建多个copy-on-write overlays镜像(image)的能力.backingfiles和overlays十分有用,可以迅速的创建瘦装备虚拟机的实例,特别是在开发测试的时候可以迅速的回滚到之前的某个已知状态,丢弃overlay.如图1所示,Base_image是Snap_1的backingfile,反过来Snap_1是Base_image的overlay。


QCOW2Openstack中的实际应用                                                

多个VM的root disk image是基于同一个base image (backing file),公共的base image为只读的。


nova image-create                                                               

Create a new image by taking a snapshot of a running server (VM instance), and upload the newimage file to Glance.

Step1: create imagebased on Base_image:  “/var/lib/nova/instances/

_base/020496fa009f00d1b1d69de8d42222b56afd9ec8”

# qemu-img create  -fqcow2 backing_file=’/var/lib/nova/instances/_base/

 020496fa009f00d1b1d69de8d42222b56afd9ec8’/var/lib/nova/instances/snapshots/tmpOEeP4A/2bf3a7f8d7094360824b9e14f2f48338

Step2: blockRebase cannotbe executed on persistent domains, so we need to temporarily undefine it. domain.undefine().

Step3: blockRebase();pull the entire source chain into the destination file ‘New_image(v1)’ .

Step4: convert format

# qemu-img convert -f qcow2 -O qcow2 -s 2bf3a7f8d7094360824b9e14f2f48338/var/lib/nova/instances/7bf40411-88ac-43d1-8e38-382d8af1915b/disk/var/lib/nova/instances/snapshots/tmpOEeP4A/2bf3a7f8d7094360824b9e14f2f48338

Step5: Upload toGlance




### OpenStack Nova 常用命令 OpenStack Nova 是用于管理计算资源的核心组件,它提供了丰富的命令行工具来操作虚拟机实例、镜像、密钥对等资源。以下是一些常用的 Nova 命令及其用途: #### 实例管理 - 启动一个新的虚拟机实例: ```bash nova boot --image <image-id> --flavor <flavor-name-or-id> --key_name <keypair-name> --availability_zone <zone-name:hostname> <vm-name> ``` 这条命令可以根据指定的镜像 ID、规格名称或 ID、密钥对名称以及可用区域信息来创建一个新实例 [^1]。 - 列出所有运行中的实例: ```bash nova list ``` - 获取特定实例的信息: ```bash nova show <instance-id> ``` - 停止(关闭)一个实例: ```bash nova stop <instance-id> ``` - 开启一个已停止的实例: ```bash nova start <instance-id> ``` - 删除一个实例: ```bash nova delete <instance-id> ``` #### 镜像与快照 - 创建一个实例的快照: ```bash nova image-create <instance-id> <snapshot-name> ``` 在执行此命令之前,通常建议先暂停实例以确保数据一致性。该过程会对实例的系统盘进行全量备份,并将生成的快照保存到 Glance 中 [^2]。 - 列出所有的镜像: ```bash nova image-list ``` - 显示特定镜像的详细信息: ```bash nova image-show <image-id> ``` #### 密钥对管理 - 添加新的 SSH 密钥对: ```bash nova keypair-add <keypair-name> > <filename>.pub ``` - 列出所有可用的密钥对: ```bash nova keypair-list ``` - 删除一个密钥对: ```bash nova keypair-delete <keypair-name> ``` #### 可用性区域和主机 - 查看可用的可用性区域: ```bash nova availability-zone-list ``` - 获取主机的相关信息: ```bash nova host-list ``` 这些命令覆盖了使用 Nova CLI 时最常见的操作场景。在实际环境中,根据部署的具体配置,可能还需要提供额外的身份验证参数或者使用环境变量设置认证信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值