可以从硬盘而不是从镜像启动一个实例。
To complete these tasks, use these parameters on the openstack server create command:
任务 | openstack server create parameter | 基本信息 |
---|---|---|
从镜像启动实例并连接一个非启动盘。 | --block-device-mapping |
从镜像启动实例并连接非启动卷 |
从镜像创建一个硬盘并从该硬盘启动实例。 | --volume |
从镜像创建硬盘并启动实例 |
Boot from an existing source volume or snapshot. | --volume |
从镜像创建硬盘并启动实例 |
注解
将卷连接到正在运行的实例上,参考`Attach_a_volume_to_an_instance`.
创建一个非启动硬盘并连接到从镜像启动的实例。
创建一个非启动盘,不要从镜像创建。该硬盘要求完全空白,不能包含分区表和文件系统。
创建一个非启动盘
$ openstack volume create --size 8 my-volume
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2017-06-10T13:45:19.588269 |
| description | None |
| encrypted | False |
| id | e77b30a9-2c1b-4f3a-b161-e09685296a83 |
| migration_status | None |
| multiattach | False |
| name | my-volume |
| properties | |
| replication_status | disabled |
| size | 8 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | lvmdriver-1 |
| updated_at | None |
| user_id | 07a3f50419714d90b55edb6505b7cc1d |
+---------------------+--------------------------------------+
列出硬盘。
$ openstack volume list
+--------------------------------------+--------------+-----------+------+-------------+
| ID | Display Name | Status | Size | Attached to |
+--------------------------------------+--------------+-----------+------+-------------+
| e77b30a9-2c1b-4f3a-b161-e09685296a83 | my-volume | available | 8 | |
+--------------------------------------+--------------+-----------+------+-------------+
Boot an instance from an image and attach the empty volume to the
instance, use the --block-device-mapping
parameter.
例如:
$ openstack server create --flavor FLAVOR --image IMAGE \
--block-device-mapping DEV-NAME=ID:TYPE:SIZE:DELETE_ON_TERMINATE \
NAME
参数:
--flavor
The flavor ID or name.
--image
The image ID or name.
--block-device-mapping
DEV-NAME=ID:TYPE:SIZE:DELETE_ON_TERMINATE
The device name to attch the volume when the instance is booted.
源对象的ID.
Which type object to create the volume.
volume
chooses volume to create. snapshot
chooses snapshot
to create.
The size(GB) of the volume that is created.
What to do with the volume when the instance is terminated.
false
does not delete the volume. true
deletes the
volume.
NAME
. 云主机名称。
$ openstack server create --flavor 2 --image c76cf108-1760-45aa-8559-28176f2c0530 \
--block-device-mapping \
myVolumeAttach=e77b30a9-2c1b-4f3a-b161-e09685296a83:volume:8:false \
myInstanceWithVolume
+--------------------------------------+--------------------------------------------+
| Field | Value |
+--------------------------------------+--------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-SRV-ATTR:host | None |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None |
| OS-EXT-SRV-ATTR:instance_name | instance-00000004 |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | UAwJJ7FZWxmA |
| config_drive | |
| created | 2017-06-10T13:50:47Z |
| flavor | m1.small (2) |
| hostId | |
| id | 555cf3e2-9ba3-46bf-9aa5-0a0c73d5b538 |
| image | cirros-0.3.5-x86_64-uec (c76cf108-1760-... |
| key_name | None |
| name | InstanceWithVolume |
| os-extended-volumes:volumes_attached | [{u'id': u'e77b30a9-2c1b-4f3a-b161-e096... |
| progress | 0 |
| project_id | ff903e4825c74f8dbc1aea6432e4f2fd |
| properties | |
| security_groups | [{u'name': u'default'}] |
| status | BUILD |
| updated | 2017-06-10T13:50:48Z |
| user_id | 07a3f50419714d90b55edb6505b7cc1d |
+--------------------------------------+--------------------------------------------+
可以使用已有的镜像、硬盘或快照创建硬盘。该过程展示了如何从一个镜像创建硬盘并从该硬盘启动实例。
列出可用镜像。
$ openstack image list
+-----------------+---------------------------------+--------+
| ID | Name | Status |
+-----------------+---------------------------------+--------+
| dfcd8407-486... | Fedora-x86_64-20-20131211.1-sda | active |
| c76cf108-176... | cirros-0.3.5-x86_64-uec | active |
| 02d6b27f-40b... | cirros-0.3.5-x86_64-uec-kernel | active |
| 47b90a42-8f4... | cirros-0.3.5-x86_64-uec-ramdisk | active |
+-----------------+---------------------------------+--------+
记录用以创建硬盘的镜像的ID.
如果需要将硬盘创建到一个具体的存储后端,需要使用包含*cinder_img_volume_type* 属性的镜像。在该例中,新创建的硬盘为*storage_backend1* 类型。
$ openstack image show dfcd8407-4865-4d82-93f3-7fef323a5951
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | eb9139e4942121f22bbc2afc0400b2a4 |
| container_format | bare |
| created_at | 2017-06-10T06:46:26Z |
| disk_format | qcow2 |
| file | /v2/images/dfcd8407-4865-4d82-93f3-7fef323a5951/file |
| id | dfcd8407-4865-4d82-93f3-7fef323a5951 |
| min_disk | 0 |
| min_ram | 0 |
| name | Fedora-x86_64-20-20131211.1-sda |
| owner | 5ed8a204e27d462a8709bc8ec491e873 |
| protected | False |
| schema | /v2/schemas/image |
| size | 25165824 |
| status | active |
| tags | |
| updated_at | 2017-06-10T13:36:55Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
列出可用云主机类型。
$ openstack flavor list
+-----+-----------+-------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is_Public |
+-----+-----------+-------+------+-----------+-------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | 1 | True |
| 2 | m1.small | 2048 | 20 | 0 | 1 | True |
| 3 | m1.medium | 4096 | 40 | 0 | 2 | True |
| 4 | m1.large | 8192 | 80 | 0 | 4 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | 8 | True |
+-----+-----------+-------+------+-----------+-------+-----------+
记录用以创建硬盘的类型ID.
从镜像创建可启动卷。传入``–image``参数可将一个卷设置为可启动。
$ openstack volume create --image IMAGE_ID --size SIZE_IN_GB bootable_volume
Create a VM from previously created bootable volume,
use the --volume
parameter. The volume is not
deleted when the instance is terminated.
$ openstack server create --flavor 2 --volume VOLUME_ID \
myInstanceFromVolume
+--------------------------------------+----------------------------------+
| Field | Value |
+--------------------------------------+----------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-SRV-ATTR:host | None |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None |
| OS-EXT-SRV-ATTR:instance_name | instance-00000005 |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | dizZcBMnWH8i |
| config_drive | |
| created | 2017-06-10T14:15:10Z |
| flavor | m1.small (2) |
| hostId | |
| id | 7074c21a-22b3-4e91-9ea1-6a22c... |
| image | |
| key_name | None |
| name | myInstanceFromVolume |
| os-extended-volumes:volumes_attached | [{u'id': u'3da01e5a-7d81-4a34... |
| progress | 0 |
| project_id | ff903e4825c74f8dbc1aea6432e4f2fd |
| properties | |
| security_groups | [{u'name': u'default'}] |
| status | BUILD |
| updated | 2017-06-10T14:15:11Z |
| user_id | 07a3f50419714d90b55edb6505b7cc1d |
+--------------------------------------+----------------------------------+
列出硬盘以查看启动盘以及它连接的``myInstanceFromVolume``实例。
$ openstack volume list
+---------------------+-----------------+--------+------+---------------------------------+
| ID | Display Name | Status | Size | Attached to |
+---------------------+-----------------+--------+------+---------------------------------+
| 3da01e5a-7d81-4a34- | bootable_volume | in-use | 2 | Attached to myInstanceFromVolume|
| a182-1958d10f7758 | | | | on /dev/vda |
+---------------------+-----------------+--------+------+---------------------------------+
To attach swap or ephemeral disk to an instance, you need create new flavor first. This procedure shows you how to boot an instance with a 512 MB swap disk and 2 GB ephemeral disk.
Create a new flavor.
$ openstack flavor create --vcpus 1 --ram 64 --disk 1 \
--swap 512 --ephemeral 2 my_flavor
注解
云主机类型定义了最大交换空间以及临时磁盘大小。不可超过此限制。
Create a server with 512 MB swap disk and 2 GB ephemeral disk.
$ openstack server create --image IMAGE_ID --flavor \
my_flavor NAME
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.