Skip to content

Commit c57f78e

Browse files
authored
Merge pull request #7 from mook-as/reduce-image-size
Create smaller VM qcow2 disk images
2 parents ab318a8 + 4f411d9 commit c57f78e

14 files changed

Lines changed: 594 additions & 10 deletions

File tree

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/g
1212
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod \
1313
go build -ldflags '-s -w' -o /go/bin/rancher-desktop-guest-agent ./src/go/guestagent
1414

15+
COPY src /rd
16+
WORKDIR /rd/rd-init
17+
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod \
18+
go build -ldflags '-s -w' -o /go/bin/rd-init .
19+
1520
FROM registry.opensuse.org/opensuse/bci/kiwi:10 AS builder
1621
ARG type=qcow2
1722
ARG NERDCTL_VERSION

config.kiwi

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818
<rpm-excludedocs>true</rpm-excludedocs>
1919
</preferences>
2020
<preferences profiles="lima">
21-
<type image="oem" format="qcow2" filesystem="ext4" firmware="efi" />
21+
<type image="oem" format="qcow2" filesystem="ext4" fsmountoptions="x-systemd.growfs"
22+
firmware="efi">
23+
<oemconfig>
24+
<!--
25+
Disable Kiwi's built-in partition resizing; that is very generic and
26+
pulls in lots of dependencies. We use systemd-repart + x-systemd.growfs
27+
-->
28+
<oem-resize>false</oem-resize>
29+
</oemconfig>
30+
</type>
2231
</preferences>
2332
<preferences profiles="wsl">
2433
<type image="tbz" />
@@ -71,6 +80,7 @@
7180
<package name="mkcert" /> <!-- used by the image-allow-list feature -->
7281
<package name="iptables-backend-nft" />
7382
<package name="openssh-server" />
83+
<package name="sudo" />
7484
<package name="system-user-nobody" />
7585
<package name="systemd" />
7686
<package name="rd-openresty" />
@@ -79,17 +89,15 @@
7989
</packages>
8090
<packages type="image" profiles="wsl">
8191
<package name="hostname" /> <!-- needed for lima on WSL (getWslSSHAddress) -->
82-
<package name="sudo" />
8392
<package name="systemd &gt;= 255.7" />
8493
</packages>
8594
<packages type="image" profiles="lima">
86-
<package name="cloud-init" />
8795
<package name="cni-plugin-flannel" />
88-
<package name="dracut-kiwi-oem-repart" />
8996
<package name="dracut" />
9097
<package name="grub2" />
91-
<package name="kernel-default" />
92-
<package name="NetworkManager" />
98+
<package name="kernel-default-base" />
99+
<package name="systemd-networkd" />
100+
<package name="systemd-resolved" />
93101
<package name="grub2-x86_64-efi" arch="x86_64" />
94102
</packages>
95103
<users>

config.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ done
7575
# tini-static has a different name
7676
ln /usr/sbin/tini-static /usr/sbin/tini
7777

78+
# This file name is invalid on Windows, so we have to rename it as part of the
79+
# build process to prevent issues checking the repository out.
80+
mv /usr/local/lib/systemd/system/mnt-lima{-,\\x2d}cidata.mount
81+
7882
#======================================
7983
# Fix permissions
8084
#--------------------------------------
@@ -99,11 +103,12 @@ if [[ ${kiwi_profiles:-} =~ lima ]]; then
99103
# Enable services
100104
systemctl enable buildkitd
101105
systemctl enable containerd
102-
systemctl enable cloud-config
103-
systemctl enable cloud-final
104-
systemctl enable cloud-init
105106
systemctl enable docker
106-
systemctl enable NetworkManager # Needed for cloud-init to work correctly
107+
systemctl enable systemd-networkd
108+
systemctl enable systemd-resolved
109+
110+
systemctl enable lima-init.service
111+
systemctl enable rd-init.service
107112
# Disable network namespace related functionality (WSL only)
108113
rm -f /usr/local/lib/systemd/system/*/network-namespace.conf
109114
# Remove the docker config that is only used on Windows

root/etc/dracut.conf.d/repart.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Enable systemd-repart instead of the kiwi one
2+
add_dracutmodules+=" systemd-repart "
3+
# Add the repart configuration file so it gets run in initrd
4+
install_items+=" /etc/dracut.conf.d/repart.conf "
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Partition]
2+
Type=root
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=Minimal cloud-init for Rancher Desktop
3+
ConditionVirtualization=vm
4+
Wants=rd-init.service ssh-keygen.service sshd.service
5+
After=rd-init.service systemd-networkd-wait-online.service
6+
After=network.service NetworkManager.service NetworkManager-wait-online.service
7+
RequiresMountsFor=/mnt/lima-cidata
8+
Before=network-online.target sshd-keygen.service sshd.service shutdown.target
9+
Conflicts=shutdown.target
10+
11+
[Service]
12+
Type=exec
13+
Environment=LIMA_CIDATA_MNT=/mnt/lima-cidata
14+
EnvironmentFile=/mnt/lima-cidata/lima.env
15+
ExecStart=/mnt/lima-cidata/boot.sh
16+
RemainAfterExit=yes
17+
TimeoutSec=0
18+
StandardOutput=journal+console
19+
20+
[Install]
21+
WantedBy=multi-user.target
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=/mnt/lima-cidata Mount Point
3+
ConditionVirtualization=vm
4+
5+
[Mount]
6+
Where=/mnt/lima-cidata
7+
What=/dev/disk/by-label/cidata
8+
Options=ro,mode=0700,dmode=0700,overriderockperm,exec,uid=0
9+
DirectoryMode=0700
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=Minimal cloud-init for Rancher Desktop (pre-networking)
3+
ConditionVirtualization=vm
4+
Wants=network-pre.target
5+
After=systemd-remount-fs.service
6+
Requires=systemd-udevd.service
7+
After=systemd-udevd.service
8+
Before=network-pre.target
9+
Before=shutdown.target
10+
RequiresMountsFor=/mnt/lima-cidata
11+
12+
[Service]
13+
Type=notify
14+
EnvironmentFile=/mnt/lima-cidata/lima.env
15+
ExecStart=/usr/local/bin/rd-init
16+
RemainAfterExit=yes
17+
TimeoutSec=0
18+
StandardOutput=journal+console
19+
20+
[Install]
21+
WantedBy=multi-user.target

src/rd-init/go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/rancher-sandbox/rancher-desktop-opensuse/src/rd-init
2+
3+
go 1.24.2
4+
5+
require (
6+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
7+
github.com/coreos/go-systemd/v22 v22.5.0
8+
github.com/goccy/go-yaml v1.17.1
9+
golang.org/x/sys v0.33.0
10+
)
11+
12+
require github.com/godbus/dbus/v5 v5.0.4 // indirect

src/rd-init/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
2+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
3+
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
4+
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
5+
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
6+
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
7+
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
8+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
9+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
10+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

0 commit comments

Comments
 (0)