Skip to content

Commit

Permalink
Adding build script for kvm
Browse files Browse the repository at this point in the history
To reduce size and time od contianer quay.io/qm-images/kvm
Build, qcow2 images is manipulated on host

Signed-off-by: Yariv Rachmani <[email protected]>
  • Loading branch information
Yarboa authored and dougsland committed Dec 12, 2024
1 parent 3ae7b49 commit cac7300
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
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

0 comments on commit cac7300

Please sign in to comment.