Skip to content
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

use quay.io qm - kvm #661

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rpm/qm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ install -d %{buildroot}%{_sysconfdir}/containers/containers.conf.d
# START - qm dropin sub-package - mount kvm #
########################################################
%if %{enable_qm_mount_bind_kvm}
<<<<<<< HEAD
mkdir -p %{buildroot}%{_sysconfdir}/containers/systemd/qm.container.d
# Add config for qm only - add drop-in file in /etc/containers/systemd/qm.container.d/qm_dropin_mount_bind_kvm.conf
# to QM env mount bind it in /dev/kvm
Expand Down
28 changes: 7 additions & 21 deletions subsystems/kvm/ContainerFile
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@
# How to build
# ==================
# podman login quay.io
# podman build -t quay.io/qm-images/kvm:latest -f ContainerFile
# use build_kvm_container.sh to build container
# podman push quay.io/qm-images/kvm:latest
FROM fedora:latest
FROM fedora-minimal:latest

ENV PASSWORD_FEDORA_USER=fedora

RUN dnf -y install virt-install \
libvirt-daemon \
libvirt-daemon-qemu \
libvirt-daemon-kvm \
libvirt-daemon-config-network \
guestfs-tools \
wget \
vim -y \
&& dnf clean all && rm -rf /var/cache/dnf
RUN dnf install qemu-system-$(arch) -y \
&& dnf clean all && rm -rf /var/cache/dnf

RUN wget -O /var/lib/libvirt/images/Fedora-Cloud-Base-Generic.qcow2 https://cofractal-ewr.mm.fcix.net/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2
COPY ./Fedora-Cloud-Base-Generic.qcow2 /var/lib/libvirt/images/

# Set fedora user pass as fedora
RUN export LIBGUESTFS_BACKEND=direct && \
virt-customize -a /var/lib/libvirt/images/Fedora-Cloud-Base-Generic.qcow2 --password fedora:password:$PASSWORD_FEDORA_USER

# Permission to qemu user/group
RUN chown qemu:qemu /var/lib/libvirt/images/Fedora-Cloud-Base-Generic.qcow2

# Set systemd as the init system for the container
ENTRYPOINT ["/usr/sbin/init"]
# Set container stay alive
ENTRYPOINT ["/usr/bin/qemu-system-x86_64","-smp","12","-enable-kvm","-m","2G","-machine","q35","-cpu","host","-device","virtio-net-pci,netdev=n0,mac=FE:30:26:a6:91:2d","-netdev","user,id=n0,net=10.0.2.0/24,hostfwd=tcp::2226-:22","-drive","file=/var/lib/libvirt/images/Fedora-Cloud-Base-Generic.qcow2,index=0,media=disk,format=qcow2,if=virtio,snapshot=off","-nographic"]
21 changes: 21 additions & 0 deletions subsystems/kvm/build_kvm_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/bash

# Install required repos
dnf install guestfs-tools \
curl \
perl -y

# Download fedora cloud image
curl -Lo ./Fedora-Cloud-Base-Generic.qcow2 https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/"$(arch)"/images/Fedora-Cloud-Base-Generic-41-1.4."$(arch)".qcow2

# Customize user:pass
export LIBGUESTFS_BACKEND=direct && \
virt-customize -a ./Fedora-Cloud-Base-Generic.qcow2 \
--edit '/etc/ssh/sshd_config: s/#PasswordAuthentication.*/PasswordAuthentication yes/' \
--uninstall cloud-init \
--firstboot-command "useradd -m -s /bin/bash -G wheel fedora" \
--firstboot-command "echo 'fedora:fedora' | chpasswd"

# Container build
podman build -t quay.io/qm-images/kvm:latest -f ContainerFile

Loading