Preparing your disk image
Note
You can only use images prepared following this guide.
You can also view out-of-the-box images in Yandex Cloud Marketplace.
You can use your own file with a Linux-based VM disk image. Once your image is prepared, upload it to Compute Cloud.
If you made software that might be helpful to other others, offer it on Yandex Cloud Marketplace.
Configure the OS to meet the requirements
Boot disk images must meet the following requirements:
- The
virtio-net
,virtio-blk
, andvirtio-pci
drivers are installed. If you are going to attach file storages to your VM, you also need to install thevirtiofs
driver. For more information, refer to this guide. - The
ttyS0
terminal (COM1 port) is set up as a serial console. For more information, refer to this guide. - The network interface runs correctly when starting a VM and obtains the IP address via DHCP.
- The
cloud-init
package is installed and configured to work with our metadata service. To install the package for CentOS, run thesudo yum install cloud-init
command. To install it for Debian or Ubuntu, runsudo apt update && sudo apt install -y cloud-init
. - If you created an image based on an Amazon Machine Image (AMI), verification of the cloud platform where the VM instance is run is disabled in the
cloud-init
settings. For more information, refer to this guide. - In the system firewall settings, the minimum required set of ports for running your applications and a port for SSH access (by default, 22 TCP) are open.
- The SSH server starts automatically at VM startup.
- Services running your application are resistant to VM reboots.
- The boot disk uses MBR partitioning.
- The disk is mounted by its UUID rather than by name.
- The file system is not encrypted.
Install the virtio drivers
To successfully upload your image, make sure to install the virtio-blk
, virtio-net
, and virtio-pci
drivers. To use Compute Cloud file storage, install virtiofs
drivers.
Most modern distributions contain the virtio
drivers by default. They can be compiled as separate .ko
files or be part of the kernel itself.
Follow the guide below to check if the drivers are installed; if they are not, add them.
-
Find out whether the drivers are included in the kernel configuration:
How do I find out?
Run this command:
grep -E -i "VIRTIO_(BLK|NET|PCI|FS)" /boot/config-$(uname -r)
If no lines starting with
CONFIG_VIRTIO_BLK=
,CONFIG_VIRTIO_NET=
,CONFIG_VIRTIO_PCI=
, andCONFIG_VIRTIO_FS=
are displayed, you should recompile the Linux kernel with the virtio drivers. Otherwise, proceed to the next steps. -
If the
CONFIG_VIRTIO_BLK=y
,CONFIG_VIRTIO_NET=y
,CONFIG_VIRTIO_PCI=y
, andCONFIG_VIRTIO_FS=y
lines are returned in step 1, check whether the drivers are included in the kernel:How to check if drivers are included in a kernel
Run this command:
grep -E "virtio(_blk|_net|_pci|fs)" /lib/modules/"$(uname -r)"/modules.builtin
- If the lines with the
virtio_net.ko
,virtio_blk.ko
,virtio_pci.ko
, andvirtiofs.ko
filenames are returned, the drivers are part of the kernel and you do not need to install them. - If not, recompile the Linux kernel with the virtio drivers.
- If the lines with the
-
If the
CONFIG_VIRTIO_BLK=m
,CONFIG_VIRTIO_NET=m
,CONFIG_VIRTIO_PCI=m
, andCONFIG_VIRTIO_FS=m
lines are returned in step 1, check whether the drivers are installed as kernel modules:How to check if drivers belong to a module
CentOS/FedoraDebian/UbuntuRun the following command:
sudo lsinitrd /boot/initramfs-$(uname -r).img | grep -E "virtio(_blk|_net|_pci|fs)"
-
If the lines with the
virtio_net.ko.xz
,virtio_blk.ko.xz
,virtio_pci.ko.xz
, andvirtiofs.ko.xz
filenames are returned, the drivers are installed as kernel modules. -
If not, create a backup of the
initramfs
file and install the drivers:sudo cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak sudo mkinitrd -f --with=virtio_blk --with=virtio_net --with=virtio_pci --with=virtiofs /boot/initramfs-$(uname -r).img $(uname -r)
If you receive an error saying
Command 'mkinitrd' not found
, usedracut
to install the drivers:sudo dracut -f --add-drivers "virtio_blk virtio_net virtio_pci virtiofs" /boot/initramfs-$(uname -r).img $(uname -r)
Then restart the OS and check that the drivers appear in the
initramfs
file and are loaded:sudo lsinitrd /boot/initramfs-$(uname -r).img | grep -E "virtio(_blk|_net|_pci|fs)" find /lib/modules/"$(uname -r)"/ -name "virtio*" | grep -E "(blk|net|pci|fs)"
After running each of the commands, the lines with the
virtio_net.ko.xz
,virtio_blk.ko.xz
,virtio_pci.ko.xz
, andvirtiofs.ko.xz
filenames should be returned.
Run the following command:
lsinitramfs /boot/initrd.img-$(uname -r) | grep -E "virtio(_blk|_net|_pci|fs)"
-
If the lines with the
virtio_net.ko
,virtio_blk.ko
,virtio_pci.ko
, andvirtiofs.ko
filenames are returned, the drivers are installed as kernel modules. -
If not, install the drivers:
echo -e "virtio_blk\nvirtio_net\nvirtio_pci\nvirtiofs" | sudo tee -a /etc/initramfs-tools/modules sudo update-initramfs -u
Then restart the OS and check that the drivers appear in the
initrd
file and are loaded:lsinitramfs /boot/initrd.img-$(uname -r) | grep -E "virtio(_blk|_net|_pci|fs)" find /lib/modules/"$(uname -r)"/ -name "virtio*" | grep -E "(blk|net|pci|fs)"
After running each of the commands, the lines with the
virtio_net.ko
,virtio_blk.ko
,virtio_pci.ko
, andvirtiofs.ko
filenames should be returned.
-
Configure the serial console
The serial console allows you to access your VM regardless of the network or OS status. Use the serial console to troubleshoot your VM or when you have issues with SSH access. For more information, see Getting started with the serial console.
To connect to your VM using the serial console, set up the ttyS0
terminal (COM1 port) as a system console for your image:
-
In the
/etc/default/grub
file with GRUB settings, addconsole=ttyS0
to theGRUB_CMDLINE_LINUX
parameter value. The line with this parameter should look like this:GRUB_CMDLINE_LINUX="foo=bar baz console=ttyS0"
-
Check that the
/etc/securetty
file with a list of terminals, through which theroot
user can log in to the OS, contains thettyS0
line. If there is no such file, create one.Note
In some operating systems, the
/etc/securetty
file is disabled and theroot
user is allowed to access all terminals by default. To configure access using this file, add to the/etc/pam.d/login
file a pointer to thepam_securetty.so
module. For more information, seeman pam_securetty
andman pam.d
. -
Run the following commands:
CentOS/FedoraDebian/Ubuntusudo stty -F /dev/ttyS0 9600 # Sets the recommended baud rate for the ttyS0 terminal at 9600. sudo grub2-mkconfig -o /boot/grub2/grub.cfg # Generates a configuration file for GRUB. sudo systemctl start getty@ttyS0 # Starts getty on the ttyS0 terminal. sudo systemctl enable getty@ttyS0 # Specifies that getty should be run every time the OS is started.
sudo stty -F /dev/ttyS0 9600 # Sets the recommended baud rate for the ttyS0 terminal at 9600. sudo update-grub # Generates a configuration file for GRUB. sudo systemctl start getty@ttyS0 # Starts getty on the ttyS0 terminal. sudo systemctl enable getty@ttyS0 # Specifies that getty should be run every time the OS is started.
-
Restart the OS.
After creating a VM from your image, you should additionally configure it to work with the serial console.
Disable verification of the cloud platform when creating an image in Amazon EC2
If you are creating an image in Amazon EC2 based on an Amazon Machine Image, cloud-init
checks that the VM can be run in Amazon EC2. VMs in Yandex Compute Cloud will fail the check and may run incorrectly.
To avoid this, disable metadata verification on your VMs. To do this, in the /etc/cloud/cloud.cfg.d
directory, create a configuration file, e.g., 99-ec2-datasource.cfg
, and add the following code to it:
#cloud-config
datasource:
Ec2:
strict_id: false
Install drivers to enable compatibility with GPUs
If working with a VM requires a GPU, install NVIDIA drivers while preparing the image.
Create an image file
The supported formats include Qcow2
, VMDK
, RAW
, and VHD
.
We recommend that you use Qcow2
format with an optimized cluster size for faster import. To convert your image from other formats, use the qemu-img
utility:
qemu-img convert -p -O qcow2 -o cluster_size=2M <your_image_file_name> <new_image_file_name>
Note
Do not use file compression or archiving software when preparing the image file. To speed up creating VMs from an image, you can optimize it.