-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qm sub-package Kernel-based Virtual Machine (KVM) #608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
- [Installing QM sub-packages](Installing-qm-sub-packages) | ||
- [Removing QM sub-packages](Removing-qm-sub-packages) | ||
- [Creating your own drop-in QM sub-package](Creating-your-own-drop-in-QM-sub-package) | ||
- [QM sub-package kvm](QM-sub-package-kvm) | ||
- [QM sub-package Sound](QM-sub-package-Sound) | ||
3. [SELinux Policy](#selinux-policy) | ||
4. [BlueChi](#bluechi) | ||
|
@@ -288,6 +289,134 @@ Example changing the spec and triggering the build via make (feel free to automa | |
$ make clean && VERSION=YOURVERSIONHERE make rpm | ||
``` | ||
|
||
## QM sub-package KVM | ||
|
||
The QM sub-package KVM includes drop-in configuration that enables the integration of Kernel-based Virtual Machine (KVM) management into the QM (Quality Management) container environment. This configuration allows users to easily configure and manage KVM virtual machines within the QM system, streamlining virtualization tasks in containerized setups. | ||
|
||
Below example step by step: | ||
|
||
Step 1: clone QM repo, install libvirt packages, prepare some files inside QM and start the libvirt daemon. | ||
|
||
```bash | ||
$host> git clone https://github.com/containers/qm.git && cd qm | ||
$host> make qm_dropin_mount_bind_kvm | ||
$host> sudo dnf install rpmbuild/RPMS/noarch/qm_mount_bind_kvm-0.6.7-1.fc40.noarch.rpm | ||
$host> sudo podman restart qm # if you have qm already running | ||
$host> sudo dnf --installroot /usr/lib/qm/rootfs/ install virt-install libvirt-daemon libvirt-daemon-qemu libvirt-daemon-kvm -y | ||
|
||
# Copy default network settings to /root dir inside QM (/usr/lib/qm/rootfs/root) | ||
$host> sudo cp /usr/share/libvirt/networks/default.xml /usr/lib/qm/rootfs/root | ||
|
||
Step 2: Preparing cloudinit files inside QM (/usr/lib/qm/rootfs/root) | ||
|
||
# Cloud-init files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using cloud-init? i assume it is for the guest? I prefer to use this command after that one
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds a good plan. If we merge can you test and improve it for us? |
||
------------------------------ | ||
$host> cd /usr/lib/qm/rootfs/root/ | ||
$host> cat meta-data | ||
instance-id: fedora-cloud | ||
local-hostname: fedora-vm | ||
|
||
# We are setting to user fedora the default password as fedora | ||
$host> cd /usr/lib/qm/rootfs/root/ | ||
$host> cat user-data | ||
#cloud-config | ||
password: fedora | ||
chpasswd: { expire: False } | ||
ssh_pwauth: True | ||
|
||
# Download the Fedora Cloud image for tests and save it /usr/lib/qm/rootfs/var/lib/libvirt/images/ | ||
$ wget -O /usr/lib/qm/rootfs/root/Fedora-Cloud-Base-Generic.qcow2 https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2 | ||
|
||
# Generate the cloud-init.iso and move it to /usr/lib/qm/rootfs/var/lib/libvirt/images/ | ||
$host> cloud-localds cloud-init.iso user-data meta-data | ||
$host> mv cloud-init.iso /usr/lib/qm/rootfs/var/lib/libvirt/images/ | ||
|
||
# Change permission to qemu:qemu | ||
$host> chown qemu:qemu /usr/lib/qm/rootfs/var/lib/libvirt/* | ||
|
||
Step 3: Starting libvirtd and checking if it's active inside QM | ||
Comment on lines
+335
to
+337
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you hit selinux issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, must be addressed in a next patch. |
||
|
||
################################################################## | ||
# Keep in mind for the next steps: | ||
# Depending on the distro you are running SELinux might complain | ||
# about libvirtd running on QM / udev errors | ||
################################################################## | ||
|
||
# Going inside QM | ||
$ sudo podman exec -it qm bash | ||
|
||
# Starting libvirtd | ||
bash-5.2# systemctl start libvirt | ||
|
||
# Check if it's running: | ||
bash-5.2# systemctl is-active libvirtd | ||
active | ||
``` | ||
|
||
Step 4: Creating a script inside QM and running the VM | ||
|
||
```bash | ||
$host> cd /usr/lib/qm/rootfs/root/ | ||
$host> vi run | ||
##### START SCRIPT ############ | ||
# Set .cache to /tmp | ||
export XDG_CACHE_HOME=/tmp/.cache | ||
|
||
# Remove previous instance | ||
virsh destroy fedora-cloud-vm 2> /dev/null | ||
virsh undefine fedora-cloud-vm 2> /dev/null | ||
|
||
# Network | ||
virsh net-define ./default.xml 2> /dev/null | ||
virsh net-start default 2> /dev/null | ||
virsh net-autostart default 2> /dev/null | ||
|
||
# Install | ||
virt-install \ | ||
--name fedora-cloud-vm \ | ||
--memory 20048 \ | ||
--vcpus 4 \ | ||
--disk path=/var/lib/libvirt/images/Fedora-Cloud-Base-Generic.qcow2,format=qcow2 \ | ||
--disk path=/var/lib/libvirt/images/cloud-init.iso,device=cdrom \ | ||
--os-variant fedora-unknown \ | ||
--network network=default \ | ||
--import \ | ||
--graphics none \ | ||
--console pty,target_type=serial \ | ||
--noautoconsole | ||
|
||
##### END SCRIPT ############ | ||
``` | ||
|
||
Step 5: Running the script | ||
|
||
```bash | ||
qm$ sudo podman exec -it qm bash | ||
bash-5.2# cd /root | ||
bash-5.2# ./run | ||
Domain 'fedora-cloud-vm' destroyed | ||
|
||
Domain 'fedora-cloud-vm' has been undefined | ||
|
||
Network default marked as autostarted | ||
|
||
Starting install... | ||
Creating domain... | 0 B 00:00:00 | ||
Domain creation completed. | ||
bash-5.2# virsh list | ||
Id Name State | ||
--------------------------------- | ||
4 fedora-cloud-vm running | ||
|
||
bash-5.2# virsh console fedora-cloud-vm | ||
|
||
fedora-vm login: fedora | ||
Password: | ||
|
||
Last login: Tue Oct 8 06:01:18 on ttyS0 | ||
[fedora@fedora-vm ~]$ | ||
``` | ||
|
||
## RPM building dependencies | ||
|
||
In order to build qm package on CentOS Stream 9 you'll need Code Ready Builder | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Drop-in configuration for Podman to mount bind /dev/kvm from host to container | ||
# | ||
[containers] | ||
devices = [ | ||
"/dev/kvm:/dev/kvm", | ||
"/dev/net/tun:/dev/net/tun" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use this one
qemu-system-x86_64 --version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically,
qemu
should be containerized. This is nice for testing that the kvm device has been mounted correctly, but it is not the way to run a VM inside the QM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aesteve-rh ah, yes, the whole things should be containerized,
Step 1:
is running qemu in qm
Step 2:
qemu containerized in qm
Is it?
One more,
Do you think we should use virt-* packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 2 should be supported already, so we can aim for that directly.
You mean for this documented example or in general? Probably, as a response to both, it should not be necessary to use them. I agree with you in that qemu would be preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yarboa yes, should work like that. @aesteve-rh can you share more about your vision so all of us are in the same page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am only saying that workloads inside the qm are supposed to be containerized. Like, the image should be stored inside the qm and launched through a quadlet file. That allows to set rules to ensure FFI, control the system's surface that the process has access to, and also allows applying SELinux labels to allow only a correct subset of operations.
For developers, it may suffice to install all those packages directly on the qm container and test it there. But imo, this is not how virtualization should be documented for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aesteve-rh completed agreed. It's just a documentation.