No edit summary |
(add instructions to connect via ssh (also, I forgot to describe the previous commit: "instead of having root account auto-enabled, enable the default 'fedora' user instead, to be consistent with other Fedora Cloud set-up instructions")) |
||
Line 6: | Line 6: | ||
<pre>sudo dnf install virt-install</pre> | <pre>sudo dnf install virt-install</pre> | ||
{{admon/important|Minimum package version|You need to have `virt-install` at at least version `3.2.0` for this guide to work.}} | {{admon/important|Minimum package version|You need to have `virt-install` at at least version `3.2.0` for this guide to work.}} | ||
<li>If you just installed the whole libvirt virtualization stack (you didn't have it before), it's recommended that you reboot your machine. | <ul><li>If you just installed the whole libvirt virtualization stack with this command (you didn't have it before), it's recommended that you reboot your machine.</ul> | ||
<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: | <li>Create a file named `cloudinit-user-data.yaml` and populate it with the following content: | ||
Line 36: | Line 36: | ||
<li>You can also control and connect to the VM from `virt-manager`. | <li>You can also control and connect to the VM from `virt-manager`. | ||
</ul> | </ul> | ||
==== Connecting through the network ==== | |||
If you want to SSH into the VM (connect through the network), then the VM must be created in `qemu:///system` scope (the default is `qemu:///session`). | |||
# Delete the existing VM and create it again, but this time append `--connect qemu:///system` argument to all `virt-install` and `virsh` commands. | |||
#* Alternatively, you can run <pre>export LIBVIRT_DEFAULT_URI=qemu:///system</pre> in your terminal and then all future commands in that terminal will use the system scope by default. | |||
# Once you have your VM running in the system scope, connect to it via the serial console as usual: <pre>virsh --connect qemu:///system console localcloud1</pre> and figure out its IP address from within the VM using: <pre>ip address</pre> | |||
#* Alternatively, you can figure out the VM's IP address from the host using: <pre>virsh --connect qemu:///system domifaddr localcloud1</pre> | |||
# SSH to the VM as usual: <pre>ssh fedora@IP_ADDRESS</pre> | |||
=== Clean up the virtual machine === | === Clean up the virtual machine === |
Revision as of 16:50, 26 November 2020
This guide shows how to test Fedora Cloud images using virt-install
(which is a part of virt-manager).
Setup
- Install
virt-install
:sudo dnf install virt-install
- If you just installed the whole libvirt virtualization stack with this command (you didn't have it before), it's recommended that you reboot your machine.
- 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).
- 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
- 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. - When a login prompt appears, log in as user
fedora
and the password you specified in the config file. - Do whatever is needed in the VM (your current user can invoke
sudo
if you need to perform some administrative commands). - 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
.
Connecting through the network
If you want to SSH into the VM (connect through the network), then the VM must be created in qemu:///system
scope (the default is qemu:///session
).
- Delete the existing VM and create it again, but this time append
--connect qemu:///system
argument to allvirt-install
andvirsh
commands.- Alternatively, you can run
export LIBVIRT_DEFAULT_URI=qemu:///system
in your terminal and then all future commands in that terminal will use the system scope by default.
- Alternatively, you can run
- Once you have your VM running in the system scope, connect to it via the serial console as usual:
virsh --connect qemu:///system console localcloud1
and figure out its IP address from within the VM using:ip address
- Alternatively, you can figure out the VM's IP address from the host using:
virsh --connect qemu:///system domifaddr localcloud1
- Alternatively, you can figure out the VM's IP address from the host using:
- SSH to the VM as usual:
ssh fedora@IP_ADDRESS
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
.