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.
- Create a virtual machine on your local computer in a minimal configuration with a single disk and no additional logical partitions.
- Connect the VM to a network with Internet access.
- Configure an SSH connection to the VM.
- Install the target OS on the local VM as described in the official Arch Linux documentation.
- Connect to the VM via SSH.
-
Install and configure the software for cloud initialization of the virtual machine:
-
Install the
cloud-initpackage on the VM as described in the official Arch Linux documentation. -
Enable autostart of
cloud-initby running the command:systemctl enable cloud-init -
(Optional) Edit the settings in the
/etc/cloud/cloud.cfgconfiguration file.
-
-
Install and configure the QEMU guest agent:
-
Install the
qemu-guest-agentpackage:apt-get install qemu-guest-agent -
Enable autostart of
qemu-guest-agentby running the command:systemctl enable qemu-guest-agent
-
-
Disable all data sources in
cloud-initexcept OpenStack. To do this, create the/etc/cloud/cloud.cfg.d/15_datasource.cfgconfiguration file with the following content:datasource:OpenStack:max_wait: 180 -
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
-
Make a copy of the local VM hard drive:
dd if=/dev/sda of=~/Arch.raw bs=64K conv=noerror,sync status=progressThis will create an
Arch.rawfile containing the VM image in RAW format. -
Install the OpenStack client on the local VM and authenticate in your VK Cloud project.
-
Upload the
Arch.rawimage to VK Cloud under the nameArch: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' \ArchHere, arguments of the form
--property <KEY>=<VALUE>are used to assign metatags to the image.
- Go to the VK Cloud management console.
- Go to the Cloud Computing → Images section.
- Make sure that the list contains the image named
Arch.
If you no longer need the uploaded image, delete it.