VK Cloud logo
Updated at March 27, 2024   03:20 PM

Creating an image using Packer

Packer allows you to create virtual machine images with the necessary parameters using a configuration file. The Alt Linux P9 OS image in QCOW format will be used as an example.

Preparatory steps

  1. Install the latest version of Packer.

  2. Make sure that OpenStack client is installed and authenticate to the project.

  3. Load the image OS Alt Linux P9 to your computer (file alt-p9-cloud-x86_64.qcow2).

1. Convert image to RAW format

Use the utility qemu-img:

  1. Install 'qemu-img' if not done before:

    sudo yum install qemu-img
  2. Run the file conversion using the command:

    qemu-img convert -f qcow2 -O raw alt-p9-cloud-x86_64.qcow2 alt-p9-cloud-x86_64.raw

    The syntax of the conversion command is given in the official QEMU documentation.

2. Upload the base image to the cloud

Import the image according to instructions.

3. Create a Packer configuration file

  1. Determine the details of the network and the downloaded image:

    1. Get id of the external network to which the virtual machine being created will be connected.

    2. Copy the name of the downloaded image, getting a list of images using the command openstack image list.

    3. Write the received values into variables:

      export SOURCE_IMAGE=8b64c09b-7141-41ad-XXXX-9f5a8dbbd87eexport NETWORK_ID=f19e1e54-bce9-4c25-XXXX-e0f40e2cff14
  2. Create the file altlinux.pkr.hcl:

  3. Check the created configuration using the command:

    packer validate altlinux.pkr.hcl

4. Upload the prepared image to the cloud

  1. Run the image creation using the command:

    packer build altlinux.pkr.hcl
  2. Wait for the successful download message to appear:

    ==> Builds finished. The artifacts of successful builds are:--> openstack.altlinux: An image was created: c6320138-035f-40d8-XXXX-e814edb2ce5f
  3. Write down the ID c6320138-035f-40d8-XXXX-e814edb2ce5f — you will need it in the next step.

5. Complete the image setup

  1. Set meta tags to the created image using the command:

    openstack image set \--property hw_video_model='qxl' \--property hw_watchdog_action='reset' \--property hw_vif_multiqueue_enabled='true' \--property hw_qemu_guest_agent='yes' \--property os_require_quiesce='yes' \--property mcs_name='Alt Linux P9 Starter Kit' \--property mcs_os_distro='debian' \--property mcs_os_type='linux' \--property mcs_os_version='P9' \--property os_admin_user='altlinux' \--property os_distro='altlinux-p9' \--property os_type='linux' \--property os_version='p9' \c6320138-035f-40d8-XXXX-e814edb2ce5f
  2. Make sure that the image is displayed correctly.

    1. Go to personal account VK Cloud.
    2. Go to Cloud computing → Images.
    3. Find the image in the list and click on it. The image page opens.

    The image will also become available when creating a VM.

Delete unused resources

If you no longer need the image, delete it.