Skip to content

Commit 9b90a13

Browse files
committed
testing: Add gentoo
Signed-off-by: Alexey Gladkov <[email protected]>
1 parent e8eae6a commit 9b90a13

File tree

4 files changed

+328
-1
lines changed

4 files changed

+328
-1
lines changed

testing/ks-gentoo-initrd.cfg

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
%post --erroronfail
2+
set -xefu
3+
4+
export PATH="/srv/.build/dest/usr/sbin:/srv/.build/dest/usr/bin:$PATH"
5+
kver="$(find /lib/modules -mindepth 1 -maxdepth 1 -printf '%f\n' -quit)"
6+
7+
mkdir -p /proc /sys /dev
8+
9+
mount -t proc proc /proc
10+
mount -t sysfs sysfs /sys
11+
mount -t devtmpfs devfs /dev
12+
13+
! blkid -L "EFI" >/dev/null ||
14+
mount -t efivarfs none /sys/firmware/efi/efivars
15+
16+
blkid
17+
findmnt
18+
19+
tee /etc/initrd.mk <<-EOF
20+
IMAGEFILE = /boot/initramfs-\$(KERNEL)\$(IMAGE_SUFFIX).img
21+
AUTODETECT = all
22+
`[ ! -f /etc/initrd.mk.addon ] || cat /etc/initrd.mk.addon`
23+
EOF
24+
25+
tee /sbin/init.once <<-EOF
26+
#!/bin/sh
27+
printf '\n\n\n%s\n\n\n' 'IT WORKS!'
28+
exec systemctl reboot
29+
EOF
30+
chmod +x /sbin/init.once
31+
32+
tee -a /usr/lib/systemd/system/init-once.service <<-EOF
33+
[Unit]
34+
Description=Make-initrd target
35+
DefaultDependencies=no
36+
After=systemd-user-sessions.service plymouth-quit-wait.service
37+
Before=system-getty.slice
38+
[Service]
39+
Type=oneshot
40+
ExecStart=/sbin/init.once
41+
RemainAfterExit=yes
42+
StandardOutput=tty
43+
[Install]
44+
WantedBy=sysinit.target
45+
EOF
46+
47+
systemctl enable init-once
48+
49+
env -i PATH="$PATH" \
50+
/srv/.build/dest/usr/sbin/make-initrd -k "$kver"
51+
52+
if blkid -L "EFI" >/dev/null; then
53+
bootctl install
54+
55+
bootdir="$(bootctl --print-esp-path)"
56+
57+
mkdir -p -- "$bootdir"/loader/entries
58+
mv -f -- \
59+
"/boot/vmlinuz-$kver" \
60+
"/boot/initramfs-$kver.img" \
61+
"$bootdir"
62+
63+
tee "$bootdir"/loader/loader.conf <<-EOF
64+
default default-kernel
65+
timeout 0
66+
EOF
67+
68+
tee "$bootdir"/loader/entries/default-kernel.conf <<-EOF
69+
title Default Linux
70+
linux /vmlinuz-$kver
71+
initrd /initramfs-$kver.img
72+
options console=ttyS0,115200n8 @CMDLINE@
73+
EOF
74+
75+
bootctl --no-pager
76+
else
77+
grub_install="$( for f in grub-install grub2-install; do type -P "$f" && break; done )"
78+
grub_mkconfig="$( for f in grub-mkconfig grub2-mkconfig; do type -P "$f" && break; done )"
79+
grub_bootdir="$( find /boot -type d \( -name 'grub' -o -name 'grub2' \) )"
80+
grub_params="/etc/default/grub"
81+
82+
tee -a "$grub_params" <<-EOF
83+
GRUB_CMDLINE_LINUX_DEFAULT='console=ttyS0,115200n8 @CMDLINE@'
84+
GRUB_TIMEOUT=3
85+
GRUB_TERMINAL_INPUT='serial console'
86+
GRUB_TERMINAL_OUTPUT='serial console'
87+
GRUB_SERIAL_COMMAND='serial --unit=0 --speed=115200'
88+
GRUB_DISABLE_LINUX_UUID=true
89+
GRUB_DISABLE_LINUX_PARTUUID=true
90+
GRUB_ENABLE_BLSCFG=false
91+
GRUB_DEVICE=root=LABEL=root
92+
EOF
93+
94+
bootdev=$(findmnt -k -no SOURCE -T /boot)
95+
syspath="$(readlink -ev "/sys/class/block/${bootdev#/dev/}")"
96+
syspath="${syspath%/*}/uevent"
97+
bootdev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "$syspath")"
98+
99+
"$grub_install" "$bootdev"
100+
"$grub_mkconfig" -o "$grub_bootdir/grub.cfg"
101+
102+
cat "$grub_params"
103+
fi
104+
105+
{
106+
find /boot \! -type d -printf '%M %p\n'
107+
find /boot -type l -printf '%M %p -> %l\n'
108+
} | sort -t\ -k1,1
109+
110+
umount /proc /sys /dev
111+
%end

testing/packages-gentoo

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
MAKE_INITRD_PACKAGES="app-alternatives/cpio app-arch/tar dev-build/make"
5+
MAKE_INITRD_PACKAGES+=" dev-libs/elfutils net-libs/libtirpc sys-apps/coreutils"
6+
MAKE_INITRD_PACKAGES+=" sys-apps/findutils sys-apps/grep sys-apps/kmod sys-apps/util-linux"
7+
MAKE_INITRD_PACKAGES+=" virtual/libcrypt:= virtual/udev app-arch/bzip2 app-arch/xz-utils"
8+
MAKE_INITRD_PACKAGES+=" app-text/scdoc sys-libs/zlib app-arch/zstd dev-libs/json-c"
9+
10+
MAKE_INITRD_PACKAGES_DEVEL="$MAKE_INITRD_PACKAGES dev-build/autoconf dev-build/automake"
11+
MAKE_INITRD_PACKAGES_DEVEL+=" dev-util/intltool sys-devel/bison sys-devel/flex"
12+
MAKE_INITRD_PACKAGES_DEVEL+=" virtual/pkgconfig"
13+
14+
KERNEL_PACKAGES="sys-kernel/gentoo-kernel-bin"
15+
16+
INIT_PACKAGES="sys-apps/systemd"
17+
ZFS_PACKAGES="sys-fs/zfs sys-fs/zfs-kmod"
18+
19+
SYSIMAGE_PACKAGES="$MAKE_INITRD_PACKAGES $INIT_PACKAGES"
20+
SYSIMAGE_PACKAGES+=" app-admin/pwgen sys-fs/mdadm sys-fs/lvm2 sys-fs/cryptsetup"
21+
SYSIMAGE_PACKAGES+=" sys-fs/btrfs-progs sys-fs/e2fsprogs sys-fs/xfsprogs sys-fs/dosfstools"
22+
SYSIMAGE_PACKAGES+=" sys-boot/grub"
23+
SYSIMAGE_PACKAGES+=" $ZFS_PACKAGES"
24+
25+
KICKSTART_PACKAGES="$MAKE_INITRD_PACKAGES_DEVEL $INIT_PACKAGES"
26+
KICKSTART_PACKAGES+=" sys-fs/e2fsprogs sys-fs/btrfs-progs sys-fs/xfsprogs sys-fs/dosfstools"
27+
KICKSTART_PACKAGES+=" sys-fs/cryptsetup sys-fs/lvm2 sys-fs/mdadm sys-apps/util-linux"
28+
KICKSTART_PACKAGES+=" net-misc/rsync net-misc/wget app-arch/unzip app-arch/tar"
29+
KICKSTART_PACKAGES+=" app-arch/cpio app-admin/pwgen app-arch/zstd sys-fs/f2fs-tools"
30+
KICKSTART_PACKAGES+=" $ZFS_PACKAGES"

testing/sh-functions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pack_sysimage()
6666
#!/bin/bash -efux
6767
6868
bytes=\$(du -sb /image |cut -f1)
69-
bytes=\$(( \$bytes + ( ( \$bytes * 30 ) / 100 ) ))
69+
bytes=\$(( \$bytes * 2 ))
7070
7171
dd count=1 bs=\$bytes if=/dev/zero of=/host/$workdir/sysimage.img
7272
/sbin/mke2fs -t ext3 -L SYSIMAGE -d /image /host/$workdir/sysimage.img

testing/testing-gentoo-local

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash -efu
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
topdir="$(readlink -ev "$0")"
5+
topdir="${topdir%/*/*}"
6+
7+
. "$topdir/testing/sh-functions"
8+
9+
readonly VENDOR=fedora
10+
readonly ARCH=x86_64
11+
readonly IMAGE=gentoo/stage3:systemd
12+
13+
. "$topdir/testing/packages-$VENDOR"
14+
15+
if [ "$#" -gt 1 ]; then
16+
TESTNAME="$1"; shift
17+
eval $(sed -n -e 's/^# param //p' "$topdir/testing/$TESTNAME.cfg")
18+
else
19+
TESTNAME=
20+
fi
21+
22+
readonly builddir=/srv
23+
24+
readonly workdir="testing/cache/$VENDOR/$TESTNAME"
25+
readonly logdir="testing/logs/$VENDOR/$TESTNAME"
26+
readonly statusdir="$topdir/testing/status"
27+
28+
readonly top_workdir="$topdir/$workdir"
29+
readonly top_logdir="$topdir/$logdir"
30+
31+
prepare_testsuite
32+
33+
n=$(grep -c '^processor' /proc/cpuinfo 2>/dev/null || echo 1)
34+
n=$(( $n * 2 ))
35+
36+
emerge_args="--quiet --ask=n --getbinpkg --autounmask-write --jobs=$n"
37+
38+
image_cleanup()
39+
{
40+
printf '%s ||:; ' \
41+
"find /usr/share/locale/ -mindepth 3 -maxdepth 3 -type f -name '*.mo' -delete" \
42+
"find /usr/share/doc/ -mindepth 1 -delete" \
43+
"find /usr/share/groff/ -mindepth 1 -delete" \
44+
"find /usr/share/info/ -mindepth 1 -delete" \
45+
"find /usr/share/man/ -mindepth 1 -delete" \
46+
"find /var/cache/distfiles/ -mindepth 1 -delete" \
47+
"find /var/db/repos/ -mindepth 1 -delete" \
48+
"find /var/tmp/portage/ -mindepth 1 -delete" \
49+
"find /lib/modules $(find_ignore_kmodules) -delete"
50+
printf '\n'
51+
}
52+
53+
for step in "$@"; do
54+
case "$step" in
55+
create-images)
56+
run podman image build --squash --force-rm \
57+
--pull=missing \
58+
-t "localhost/image-$VENDOR:sysimage" \
59+
-f - <<-EOF
60+
FROM $IMAGE
61+
RUN getuto >/dev/null
62+
RUN emerge-webrsync --quiet
63+
RUN emerge $emerge_args $KERNEL_PACKAGES
64+
RUN emerge $emerge_args $SYSIMAGE_PACKAGES
65+
RUN emerge --depclean --with-bdeps=n --ask=n
66+
RUN $(image_depmod)
67+
RUN $(image_cleanup)
68+
EOF
69+
70+
run podman image build --squash --force-rm \
71+
--pull=never \
72+
-t "localhost/image-$VENDOR:devel" \
73+
-f - <<-EOF
74+
FROM localhost/image-$VENDOR:sysimage
75+
RUN emerge $emerge_args $KERNEL_PACKAGES
76+
RUN emerge $emerge_args $KICKSTART_PACKAGES
77+
RUN emerge --depclean --with-bdeps=n --ask=n
78+
RUN $(image_depmod)
79+
RUN $(image_cleanup)
80+
EOF
81+
;;
82+
build-sources)
83+
gh_group_start "building from git tree"
84+
85+
cat_exec "$top_workdir/run.sh" <<-EOF
86+
#!/bin/bash -efux
87+
88+
cd "$builddir"
89+
rc=0
90+
91+
./autogen.sh
92+
./configure \
93+
--enable-local-build \
94+
--with-runtimedir=/lib/initrd1 || rc=\$?
95+
96+
if [ "\$rc" != 0 ]; then
97+
echo '========================================='
98+
cat config.log
99+
exit 1
100+
fi
101+
102+
make || rc=\$?
103+
104+
if [ "\$rc" != 0 ]; then
105+
echo '========================================='
106+
cat config.log
107+
exit 1
108+
fi
109+
EOF
110+
run podman run --rm -i --volume="$topdir:$builddir" \
111+
"localhost/image-$VENDOR:devel" \
112+
"$builddir/$workdir/run.sh"
113+
114+
gh_group_end
115+
;;
116+
build-sysimage)
117+
gh_group_start "packing sysimage"
118+
pack_sysimage
119+
gh_group_end
120+
;;
121+
build-kickstart)
122+
gh_group_start "creating kickstart image"
123+
124+
cat_exec "$top_workdir/run.sh" <<-EOF
125+
#!/bin/bash -efux
126+
127+
kver="\$(find /lib/modules -mindepth 1 -maxdepth 1 -printf '%f\n' -quit)"
128+
129+
cat > /etc/initrd.mk <<EOF1
130+
AUTODETECT =
131+
IMAGEFILE = /boot/initrd-ks.img
132+
DISABLE_FEATURES += ucode
133+
FEATURES = add-modules add-udev-rules kickstart qemu rdshell modules-virtio modules-blockdev
134+
MODULES_ADD += sd_mod
135+
MODULES_PRELOAD += virtio-blk virtio-scsi virtio-pci
136+
KICKSTART_CONFIGS = $builddir/$workdir/ks.cfg
137+
PUT_PROGS += pwgen
138+
EOF1
139+
140+
for i in vmlinuz System.map config; do
141+
[ ! -e "/lib/modules/\$kver/\$i" ] || cp -a "/lib/modules/\$kver/\$i" "/boot/\$i-\$kver"
142+
done
143+
144+
export PATH="$builddir/.build/dest/usr/sbin:$builddir/.build/dest/usr/bin:\$PATH"
145+
146+
$builddir/.build/dest/usr/sbin/make-initrd -v -k \$kver
147+
148+
cp -L /boot/vmlinuz-\$kver $builddir/$workdir/boot-ks-vmlinuz
149+
cp -L /boot/initrd-ks.img $builddir/$workdir/boot-ks-initrd.img
150+
EOF
151+
152+
podman run --rm -i \
153+
--volume="$topdir:$builddir" \
154+
"localhost/image-$VENDOR:devel" \
155+
"$builddir/$workdir/run.sh"
156+
157+
gh_group_end
158+
;;
159+
run-kickstart)
160+
gh_group_start "creating qemu kickstart disks"
161+
162+
BOOT_PROG=
163+
BOOT_KERNEL="$top_workdir/boot-ks-vmlinuz"
164+
BOOT_INITRD="$top_workdir/boot-ks-initrd.img"
165+
BOOT_APPEND='console=ttyS0,115200n8 quiet rdlog=console ksfile=ks.cfg'
166+
167+
qemu_setup_cpu
168+
qemu_setup_kickstart_disks
169+
qemu_exec
170+
171+
gh_group_end
172+
;;
173+
run-boot)
174+
gh_group_start "checking the ability to boot"
175+
176+
qemu_setup_cpu
177+
qemu_setup_boot_disks
178+
qemu_exec
179+
180+
gh_group_end
181+
;;
182+
*)
183+
fatal "unknown step: $step"
184+
;;
185+
esac
186+
done

0 commit comments

Comments
 (0)