From Fedora Project Wiki

(save the first draft)
 
Line 8: Line 8:
 
<li>If you just installed the whole libvirt virtualization stack (you didn't have it before), it's recommended that you reboot your machine.
 
<li>If you just installed the whole libvirt virtualization stack (you didn't have it before), it's recommended that you reboot your machine.
 
<li>Download the preferred [https://alt.fedoraproject.org/cloud/ Fedora Cloud] image that you want to test. It's recommended to pick the ''qcow2'' image (''raw.xz'' works too, if you prefer it, just make sure you don't forget to decompress it).
 
<li>Download the preferred [https://alt.fedoraproject.org/cloud/ Fedora Cloud] image that you want to test. It's recommended to pick the ''qcow2'' image (''raw.xz'' works too, if you prefer it, just make sure you don't forget to decompress it).
 +
<li>Create a file named `cloudinit-user-data.yaml` and populate it with the following content:
 +
<pre>#cloud-config
 +
password: 'CLOUDPASSWORD'
 +
chpasswd: { expire: False }</pre>
 +
Replace `CLOUDPASSWORD` with the password you want to authenticate with into the Cloud VM.
 
</ol>
 
</ol>
  
Line 13: Line 18:
 
<ol>
 
<ol>
 
<li>Create the VM using the following command:
 
<li>Create the VM using the following command:
<pre>virt-install --name localcloud1 --memory 2000 --disk=size=10,backing_store="/path/to/Cloud.qcow2" --cloud-init --noreboot --os-variant detect=on,name=fedora-unknown</pre>
+
<pre>virt-install --name localcloud1 --memory 2000 --disk=size=10,backing_store="/path/to/Cloud.qcow2" --cloud-init user-data="/path/to/cloudinit-user-data.yaml" --noreboot --os-variant detect=on,name=fedora-unknown</pre>
You can of course adjust all the values. Be sure to replace `/path/to/Cloud.qcow2` with an ''absolute'' path to your downloaded Fedora Cloud image.
+
You can of course adjust all the values. Be sure to replace `/path/to/Cloud.qcow2` with an ''absolute'' path to your downloaded Fedora Cloud image, and `/path/to/cloudinit-user-data.yaml` with a path to the config file you created in the [[#Setup|Setup]] section.
 
{{admon/tip|The original image is unchanged|Thanks to using the `backing_store{{=}}` option, a new ''overlay'' image is created (with the maximum size specified in `size{{=}}`) in a default libvirt image location, called `localcloud1.qcow2`, which only contains the changes you'd made on disk against the original Cloud image (`Cloud.qcow2`). The original Cloud image is kept untouched, and so you can reuse it repeatedly in future VMs.}}
 
{{admon/tip|The original image is unchanged|Thanks to using the `backing_store{{=}}` option, a new ''overlay'' image is created (with the maximum size specified in `size{{=}}`) in a default libvirt image location, called `localcloud1.qcow2`, which only contains the changes you'd made on disk against the original Cloud image (`Cloud.qcow2`). The original Cloud image is kept untouched, and so you can reuse it repeatedly in future VMs.}}
<li>A root password for the first login is printed out in terminal, note it down or put it into the clipboard
+
<li>When a login prompt appears, log in as user `fedora` and the password you specified in the config file.
<li>In a login prompt, log in as `root` with the password printed out earlier. You'll probably be forced to immediately change the password.
+
<li>Do whatever is needed in the VM (your current user can invoke `sudo` if you need to perform some administrative commands).
<li>Do whatever is needed in the VM.
+
<li>You can either power the machine down using `sudo poweroff`, or just disconnect from the serial console using {{key|Ctrl|]}}.
<li>You can either power the machine down using `poweroff`, or just disconnect from the serial console using {{key|Ctrl|]}}.
 
 
</ol>
 
</ol>
  

Revision as of 14:36, 26 November 2020

This guide shows how to test Fedora Cloud images using virt-install (which is a part of virt-manager).

Setup

  1. Install virt-install:
    sudo dnf install virt-install
    Important.png
    Minimum package version
    You need to have virt-install at at least version 3.2.0 for this guide to work.
  2. If you just installed the whole libvirt virtualization stack (you didn't have it before), it's recommended that you reboot your machine.
  3. Download the preferred Fedora Cloud image that you want to test. It's recommended to pick the qcow2 image (raw.xz works too, if you prefer it, just make sure you don't forget to decompress it).
  4. Create a file named cloudinit-user-data.yaml and populate it with the following content:
    #cloud-config
    password: 'CLOUDPASSWORD'
    chpasswd: { expire: False }

    Replace CLOUDPASSWORD with the password you want to authenticate with into the Cloud VM.

Create the virtual machine

  1. Create the VM using the following command:
    virt-install --name localcloud1 --memory 2000 --disk=size=10,backing_store="/path/to/Cloud.qcow2" --cloud-init user-data="/path/to/cloudinit-user-data.yaml" --noreboot --os-variant detect=on,name=fedora-unknown

    You can of course adjust all the values. Be sure to replace /path/to/Cloud.qcow2 with an absolute path to your downloaded Fedora Cloud image, and /path/to/cloudinit-user-data.yaml with a path to the config file you created in the Setup section.

    Idea.png
    The original image is unchanged
    Thanks to using the backing_store= option, a new overlay image is created (with the maximum size specified in size=) in a default libvirt image location, called localcloud1.qcow2, which only contains the changes you'd made on disk against the original Cloud image (Cloud.qcow2). The original Cloud image is kept untouched, and so you can reuse it repeatedly in future VMs.
  2. When a login prompt appears, log in as user fedora and the password you specified in the config file.
  3. Do whatever is needed in the VM (your current user can invoke sudo if you need to perform some administrative commands).
  4. You can either power the machine down using sudo poweroff, or just disconnect from the serial console using Ctrl+].

Connect to the virtual machine later

  • If you want to connect to an existing localcloud1 VM later, first make sure it is started:
    virsh start localcloud1

    and then connect to the serial console:

    virsh console localcloud1

    (hit Enter to see the command/login prompt)

  • You can also control and connect to the VM from virt-manager.

Clean up the virtual machine

  • You can easily remove your VM together with the overlay disk drive. Fist make sure the VM is shut down:
    virsh destroy localcloud1

    and then remove the VM and its disk:

    virsh undefine --remove-all-storage localcloud1
  • You can also remove your VM from virt-manager.