Travailler avec des images

From Alliance Doc
Revision as of 15:28, 14 November 2022 by Diane27 (talk | contribs) (Created page with "==Démarrer depuis un volume==")
Jump to navigation Jump to search
Other languages:

Page enfant de Service infonuagique de Calcul Canada

Images are files which contain the contents of a virtual disk. Often Images contain a base operating system used to create a volume or an ephemeral disk from which a virtual machine boots. An ephemeral disk is a virtual disk file which resides on the host (or hypervisor) where the virtual machine runs. Ephemeral disk files are destroyed when a VM is destroyed, in contrast to volumes. Images are portable in that they can be downloaded from the cloud, used to create a virtual machine using virtual box or similar on your laptop, and uploaded to another cloud and used to create a new virtual machine. This is not the case with volumes or ephemeral disks. Images come in a variety of formats. Some commonly encountered formats are, raw, qcow2, vmdk, and vdi.

If sharing your virtual machine images, be sure to remove sensitive information such as public/private keys, configuration files containing passwords, etc. If uploading an image created from a virtual box virtual machine to our clouds, it must have cloud-init installed and configured correctly (see openstack docs on creating images manually for more details).

Voyez la liste des images fournies par l'équipe de soutien technique.

Créer une image depuis une instance

La procédure est différente selon que l'instance démarre depuis un disque éphémère (généralement les gabarits de type c) ou un volume (généralement les gabarits de type p).

Démarrer depuis un disque éphémère

Démarrer depuis un volume

Partager une image avec un autre projet

C'est un processus en deux étapes ː

  1. Un membre du projet auquel l'image appartient doit partager l'image avec l'autre projet.
  2. Un membre de l'autre projet doit accepter la nouvelle image qui est partagée.

Le membre du projet propriétaire utilise la commande OpenStack

[name@server]$  glance member-create <IMAGE_ID> <MEMBER_ID>
+------------+-------------+---------+
| Image ID   | Member ID   | Status  |
+------------+-------------+---------+
| <IMAGE_ID> | <MEMBER_ID> | pending |
+------------+-------------+---------+

<IMAGE_ID> est l'identifiant de l'image à partager et <MEMBER_ID> est l'identifiant du projet avec lequel partager l'image.

To accept the shared image a member in the second project uses the OpenStack command below.

[name@server]$  glance member-update <IMAGE_ID> <MEMBER_ID> <MEMBER_STATUS>
+------------+-------------+----------+
| Image ID   | Member ID   | Status   |
+------------+-------------+----------+
| <IMAGE_ID> | <MEMBER_ID> | accepted |
+------------+-------------+----------+

where <IMAGE_ID> is ID of the image to update, <MEMBER_ID> is the ID of the second project, and <MEMBER_STATUS> is the new status of the image. Valid Values for status are accepted, rejected, and pending. The image will then be available for use and appear in the OpenStack dashboard's list of images in the second project.


To check the status of image membership use the following command.

[name@server]$ glance member-list --image-id <IMAGE_ID>
+------------+-------------+----------+
| Image ID   | Member ID   | Status   |
+------------+-------------+----------+
| <IMAGE_ID> | <MEMBER_ID> | accepted |
+------------+-------------+----------+

Downloading an Image

The first step is to install the OpenStack client and download the OpenStack RC file and source it (see OpenStack Command Line Clients). The OpenStack client can list the available images on your OpenStack project with

Question.png
[name@server ~]$ openstack image list

producing something like:

+--------------------------------------+---------------------------------------+-------------+------------------+-------------+--------+
| ID                                   | Name                                  | Disk Format | Container Format | Size        | Status |
+--------------------------------------+---------------------------------------+-------------+------------------+-------------+--------+
| 982761b2-c77b-4852-8ae3-bf98b32b8894 | Hadoop-2.2.4                          | qcow2       | bare             | 10253107200 | active |
| b7bd3033-9836-406d-a8f2-2e91978026b4 | hadoopmaster                          | qcow2       | bare             | 3493527552  | active |
| 2c751755-854d-49c3-af82-d501e51e7159 | hadoopmaster-active                   | qcow2       | bare             | 13134004224 | active |
| c41012f4-ed82-4478-a81f-5efb96a31b1a | hadoopmaster-old                      | qcow2       | bare             | 3493527552  | active |
| 78e61a3f-b546-441a-b476-a7077b04ca36 | hadoopslave                           | qcow2       | bare             | 3490971648  | active |
| 516845c3-b256-4c6d-a2cb-e31e822c7e34 | hadoopslave1-active                   | qcow2       | bare             | 8345026560  | active |
| 1546bd86-5314-4fce-9576-e2f6930dad30 | hadoopslave1-old                      | qcow2       | bare             | 3490971648  | active |
| baf78e8d-8288-4854-a66b-812cdf3ccbca | TestVM                                | qcow2       | bare             | 13167616    | active |
| 2faf97d7-5b0b-44ce-8024-3bef5a634570 | test_ubuntu_initial                   | qcow2       | bare             | 1799487488  | active |
| 308b6614-396a-4360-9c33-4e86f41ea0ec | trusty                                | qcow2       | bare             | 256180736   | active |
| 9b3c3fda-2aca-43b5-a3e7-662a94f5e7fb | Ubuntu_14.04_Trusty-amd64-20150708    | qcow2       | bare             | 257884672   | active |
| f93e66cf-fec1-4460-8fc7-506e716fbf30 | ucernvm-prod.1.18-10                  | raw         | bare             | 20971520    | active |
+--------------------------------------+---------------------------------------+-------------+------------------+-------------+--------+

Dépendant de la version de votre client, il est possible que vous ayez besoin d'une option additionnelle comme --long pour voir toutes ces colonnes.

Pour télécharger une image en particulier, utilisez la commande

Question.png
[name@server ~]$ openstack image save --file ./<file-name-for-image>.<format> 2c751755-854d-49c3-af82-d501e51e7159

où <format> correspond à la valeur dans la colonne Disk Format et <ID> correspond à la valeur dans la colonne ID.

Uploading an Image

The first step is to install the OpenStack client and download the OpenStack RC file and source it (see OpenStack Command Line Clients). Then run the command

Question.png
[name@server ~]$ openstack image create --file <path-to-local-file-image> --disk-format <format> <new-image-name>

  • <path-to-local-file-image> est le chemin vers le fichier qui contient l'image à téléverser;
  • <format> est le format du disque; si aucun format n'est spécifié, le format raw s'applique, ce qui est incorrect et peut causer des problèmes pour l'image dans OpenStack;
  • <new-image-name> est le nom de l'image sur le tableau de bord OpenStack.

Créer une instance VirtualBox depuis une image dans un nuage

VirtualBox est un logiciel qui permet de créer des instances et de les exécuter sur votre ordinateur personnel. Il fonctionne sous divers systèmes d'exploitation (Windows, Linux, Mac) et les instances créées peuvent utiliser des systèmes d'exploitation différents.

To use a QCOW2 image downloaded from an OpenStack cloud, as shown above, with VirtualBox you will need to convert the image in the qcow2 format to the vmdk format. This can be done with the qemu-img tool. This can be installed with something like

Question.png
[name@server ~]$ sudo apt-get install qemu-utils

(previously the package was called qemu-img) then do the conversion with

Question.png
[name@server ~]$ qemu-img convert -f qcow2 vdisk.qcow2 -O vmdk vdisk.vmdk

You can then create a new virtual machine and attach the vmdk image to it (see how to run a vmdk file in virtualbox for detailed instructions on this).