Launching an Instance from a Volume

You need the parameters gathered in Launching Instances to proceed: flavor, image, key pair, security group, and a private network ID.

You can boot an instance from a volume instead of from an image. There are many approaches to booting an instance involving a volume:

  • Boot an instance from an image and attach a non-bootable volume.
  • Create a volume from an image and boot an instance from the new volume.
  • Use an existing source image, volume, or snapshot.
  • Attach a swap disk to an instance.
  • Attach an ephemeral disk to an instance.

Creating a Non-bootable Volume and Attaching it to an Instance

In this example, you create a non-bootable volume and attach that volume to an instance. Do not create a non-bootable volume from an image. The volume must be entirely empty with no partition table and no file system.

  1. Create a non-bootable volume and specify the size in GB.

    $ openstack volume create myVolume --size 8
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | attachments         | []                                   |
    | availability_zone   | nova                                 |
    | bootable            | false                                |
    | created_at          | 2016-10-11T22:08:27.634109           |
    | display_description | None                                 |
    | display_name        | myVolume                             |
    | encrypted           | False                                |
    | id                  | <volume_id>                          |
    | properties          |                                      |
    | size                | 8                                    |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | type                | None                                 |
    +---------------------+--------------------------------------+
    
  2. List volumes to confirm creation and note the volume ID.

    $ openstack volume list
    +-----------------+--------------+-----------+------+-------------+
    | ID              | Display Name | Status    | Size | Attached to |
    +-----------------+--------------+-----------+------+-------------+
    | <volume_id>     | myVolume     | available |    8 |             |
    | <volume_id>     | demo         | available |    1 |             |
    +-----------------+--------------+-----------+------+-------------+
    
  3. Boot an instance from an image. See Launching an Instance from an Image.

  4. Attach the empty volume to the instance.

    $ openstack server add volume myInstance myVolume
    
  5. List volumes to confirm successful attachment. The volume status changes to in-use and the Attached to column shows the instance.

    $ openstack volume list
    +-----------------+--------------+-----------+------+-------------------------------------+
    | ID              | Display Name | Status    | Size | Attached to                         |
    +-----------------+--------------+-----------+------+-------------------------------------+
    | <volume_id>     | myVolume     | in-use    |    8 | Attached to myInstance on /dev/vdb  |
    | <volume_id>     | demo         | available |    1 |                                     |
    +-----------------+--------------+-----------+------+-------------------------------------+
    

Creating a Volume from an Image and Booting an Instance

To create a bootable volume from an image and launch an instance from the volume, you must use the nova boot --block-device option. The syntax for --block-device:

   --block-device source=SOURCE,id=ID,dest=DEST,size=SIZE,shutdown=PRESERVE,bootindex=INDEX
Parameters Description
source= The type of object used to create the block device. Valid values are volume, snapshot, and image.
id= The ID of the source object.
dest= The type of the target virtual device. Valid values are volume and local.
size= The size in GB of the volume that is created. The size must be sufficient to accomodate the source.
shutdown= What to do with the volume when the instance is deleted.
preserve—does not delete the volume.
remove—deletes the volume.
bootindex= Order of the boot disks. Use 0 to boot from this volume.

Note
You can not specify a blank or non-bootable source.

In the following example, the source is the image for creating the volume (dest) and the id is the image ID. Specify the volume size in GB to accomodate the image.

$ nova boot newInstance \
  --flavor 2 \
  --security-groups default \
  --nic net-id=<NETWORK-ID> \
  --block-device source=image,
      id=<IMAGE_ID>,
      dest=volume,
      size=30,
      shutdown=preserve,
      bootindex=0

+--------------------------------------+-------------------------------------------------+
| Property                             | Value                                           |
+--------------------------------------+-------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                          |
| OS-EXT-AZ:availability_zone          |                                                 |
| OS-EXT-SRV-ATTR:host                 | -                                               |
| OS-EXT-SRV-ATTR:hostname             | newinstance                                     |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                               |
| OS-EXT-SRV-ATTR:instance_name        | instance-000029b5                               |
| OS-EXT-SRV-ATTR:kernel_id            |                                                 |
| OS-EXT-SRV-ATTR:launch_index         | 0                                               |
| OS-EXT-SRV-ATTR:ramdisk_id           |                                                 |
| OS-EXT-SRV-ATTR:reservation_id       | r-id3cqs8p                                      |
| OS-EXT-SRV-ATTR:root_device_name     | -                                               |
| OS-EXT-SRV-ATTR:user_data            | -                                               |
| OS-EXT-STS:power_state               | 0                                               |
| OS-EXT-STS:task_state                | scheduling                                      |
| OS-EXT-STS:vm_state                  | building                                        |
| OS-SRV-USG:launched_at               | -                                               |
| OS-SRV-USG:terminated_at             | -                                               |
| accessIPv4                           |                                                 |
| accessIPv6                           |                                                 |
| adminPass                            | <admin_pass>                                    |
| config_drive                         |                                                 |
| created                              | 2017-01-11T16:41:31Z                            |
| flavor                               | m1.small (2)                                    |
| hostId                               |                                                 |
| id                                   | <instance_id>                                   |
| image                                | Attempt to boot from volume - no image supplied |
| key_name                             | -                                               |
| locked                               | False                                           |
| metadata                             | {}                                              |
| name                                 | newInstance                                     |
| os-extended-volumes:volumes_attached | []                                              |
| progress                             | 0                                               |
| security_groups                      | default                                         |
| status                               | BUILD                                           |
| tenant_id                            | <tenant_id>                                     |
| updated                              | 2017-01-11T16:41:32Z                            |
| user_id                              | <user_id>                                       |
+--------------------------------------+-------------------------------------------------+

List volumes to verify the attached volume to the new instance.

$ openstack volume list
+-----------------+-----------------+-----------+------+-------------------------------------+
| ID              | Display Name    | Status    | Size | Attached to                         |
+-----------------+-----------------+-----------+------+-------------------------------------+
| <volume_id>     |                 | in-use    |   30 | Attached to newInstance on /dev/vda |
| <volume_id>     | demo            | available |    1 |                                     |
+-----------------+-----------------+-----------+------+-------------------------------------+

Using a Source to Create a Volume and Boot an Instance

You can create a volume from an existing image, volume, or snapshot.

Source Command
image $ openstack volume create --size <SIZE> --image <IMAGE_ID> <VOLUME>
volume $ openstack volume create --size <SIZE> --source <VOLUME_ID> <VOLUME>
snapshot $ openstack volume create --size <SIZE> --snapshot <SNAPSHOT_ID> <VOLUME>

Note
To create a volume for a specific storage backend, select from the available types as shown by openstack volume type list and use the volume create --type option; see Managing Volumes.

Launch an instance using an existing volume with the --block-device option. In this case, the source and the id refer to the original volume.

$ nova boot newInstancefromvolume \
   --flavor m1.small \
   --security-groups default \
   --nic net-id=<NETWORK_ID> \
   --block-device source=volume,
                  id=<VOLUME_ID>,
                  dest=volume,
                  size=10,
                  shutdown=preserve,
                  bootindex=0

List volumes to verify the attached volume to the new instance.

$ openstack volume list
+-----------------+---------------+-----------+------+-----------------------------------------------+
| ID              | Display Name  | Status    | Size | Attached to                                   |
+-----------------+---------------+-----------+------+-----------------------------------------------+
| <volume_id>     | myVolume      | in-use    |   10 | Attached to newInstancefromvolume on /dev/vda |
| <volume_id>     | demo          | available |    1 |                                               |
+-----------------+---------------+-----------+------+-----------------------------------------------+

Attaching Swap or Ephemeral Disks to an Instance

You can attach a swap and an ephemeral disk to an instance using additional options with the nova boot command.

Option Description
--swap <SIZE> Attach a swap disk on boot
--ephemeral size=<SIZE> Attach an ephemeral disk on boot

Note
When you terminate the instance, both disks are deleted.

Example: boot an instance with a 512 MB swap disk and 2 GB ephemeral disk:

$ nova boot <INSTANCE> \
   --flavor <FLAVOR> \
   --image <IMAGE_ID> \
   --swap 512 \
   --ephemeral size=2 \
   --security-groups default \
   --nic net-id-<NETWORK_ID> \

Note
The flavor defines the maximum swap and ephemeral disk size. You cannot exceed these maximum values.