VK Cloud logo

Creating an image using a local VM

An image of a cloud VM can be created using a local virtual machine.

As an example, this guide covers creating and configuring a VM image with the Arch Linux OS.

Preparatory steps

  1. Create a virtual machine on your local computer in a minimal configuration with a single disk and no additional logical partitions.
  2. Connect the VM to a network with Internet access.
  3. Configure an SSH connection to the VM.

1. Install the target OS

  1. Install the target OS on the local VM as described in the official Arch Linux documentation.
  2. Connect to the VM via SSH.

2. Install software for cloud virtualization

  1. Install and configure the software for cloud initialization of the virtual machine:

    1. Install the cloud-init package on the VM as described in the official Arch Linux documentation.

    2. Enable autostart of cloud-init by running the command:

      systemctl enable cloud-init
    3. (Optional) Edit the settings in the /etc/cloud/cloud.cfg configuration file.

  2. Install and configure the QEMU guest agent:

    1. Install the qemu-guest-agent package:

      apt-get install qemu-guest-agent
    2. Enable autostart of qemu-guest-agent by running the command:

      systemctl enable qemu-guest-agent

3. (Optional) Perform additional settings on the local VM

  1. Disable all data sources in cloud-init except OpenStack. To do this, create the /etc/cloud/cloud.cfg.d/15_datasource.cfg configuration file with the following content:

    datasource: OpenStack:  max_wait: 180
  2. Clean the VM from unnecessary artifacts by running the commands one after another:

    rm /etc/udev/rules.d/*rm -rf /var/lib/cloud/*rm -rf /tmp/*find /var/log -maxdepth 5 -type f -exec rm -fv {} \;sudo truncate -s 0 /etc/udev/rules.d/70-persistent-net.rulessed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0sudo truncate -s 0 /etc/resolv.confsudo rm -f /etc/NetworkManager/conf.d/99-cloud-init.confrpm-ostree cleanup -b -p -r -m

4. Import the local VM disk image into VK Cloud

  1. Make a copy of the local VM hard drive:

    dd if=/dev/sda of=~/Arch.raw bs=64K conv=noerror,sync status=progress

    This will create an Arch.raw file containing the VM image in RAW format.

  2. Install the OpenStack client on the local VM and authenticate in your VK Cloud project.

  3. Upload the Arch.raw image to VK Cloud under the name Arch:

    openstack image create \    --progress \    --private \    --container-format bare \    --disk-format raw \    --file ~/Arch.raw \    --property store=s3 \    --property hw_qemu_guest_agent=True \    --property os_require_quiesce=yes \    --property mcs_name='Arch' \    Arch

    Here, arguments of the form --property <KEY>=<VALUE> are used to assign metatags to the image.

5. Verify that the image was uploaded successfully

  1. Go to the VK Cloud management console.
  2. Go to the Cloud Computing → Images section.
  3. Make sure that the list contains the image named Arch.

Delete unused resources

If you no longer need the uploaded image, delete it.

Was this article helpful?