Skip to content

Commit f959969

Browse files
committed
Make some "different" packages
This splits things into two source packages: dracut-nmbl, which contains the dracut plugin, and nmbl-builder, which expect dracut-nmbl to be installed in the buildroot. The second package makes three different[0] nmbl UKIs, one "monolith", which is what we've been building, one "cloud", and one "workstation". It also deletes 10_linux because we haven't been using it. Right now I have to build it like `make OS_DIST=.fc38 OS_VERSION=38 KVRA=6.2.9-300.fc38.x86_64 nmbl-6.2.9-300.fc38.x86_64.rpm`, but that wouldn't be true if my /etc/os-release and the kernel version in the dnf repo matched better. [0] These aren't actually different yet. Signed-off-by: Peter Jones <[email protected]>
1 parent 6e0f287 commit f959969

File tree

9 files changed

+247
-4
lines changed

9 files changed

+247
-4
lines changed

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
*~
22
*.rpm
3+
*.spec
34
*.sw?
45
*.tar
56
*.tar.?z
67
/build.log
78
/hw_info.log
89
/installed_pkgs.log
9-
/nmbl*/
10-
/nmbl.initramfs.img
11-
/nmbl-builder.spec
12-
/nmbl.uki
1310
/root.log
1411
/state.log
1512
/temp/

99grub2-emu/grub2-emu.service

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Start GRUB emu
2+
#
3+
4+
[Unit]
5+
Description=Start GRUB emu
6+
DefaultDependencies=no
7+
After=grub2-emu.target sysroot.mount systemd-vconsole-setup.service
8+
Conflicts=shutdown.target emergency.target
9+
10+
[Service]
11+
ExecStart=-/bin/grub2-emu --kexec
12+
ExecStop=-/sbin/reboot
13+
StandardInput=tty
14+
StandardOutput=tty

99grub2-emu/grub2-emu.target

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: LGPL-2.1+
2+
#
3+
# systemd is free software; you can redistribute it and/or modify it
4+
# under the terms of the GNU Lesser General Public License as published by
5+
# the Free Software Foundation; either version 2.1 of the License, or
6+
# (at your option) any later version.
7+
8+
[Unit]
9+
Description=Start GRUB emulator
10+
Documentation=man:grub-emu(1)
11+
OnFailure=emergency.target
12+
OnFailureJobMode=replace-irreversibly
13+
ConditionPathExists=/etc/initrd-release
14+
Requires=basic.target
15+
Wants=initrd-root-fs.target initrd-root-device.target initrd-fs.target initrd-parse-etc.service
16+
After=initrd-root-fs.target initrd-root-device.target initrd-fs.target basic.target rescue.service rescue.target
17+
AllowIsolate=yes

99grub2-emu/grub2-mount-boot.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/bash
2+
3+
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
4+
5+
boot=$(getarg boot=)
6+
case "$boot" in
7+
LABEL=*)
8+
boot="$(echo $boot | sed 's,/,\\x2f,g')"
9+
boot="block:/dev/disk/by-label/${boot#LABEL=}"
10+
;;
11+
UUID=*)
12+
boot="/dev/disk/by-uuid/${boot#UUID=}"
13+
;;
14+
PARTUUID=*)
15+
boot="/dev/disk/by-partuuid/${boot#PARTUUID=}"
16+
;;
17+
PARTLABEL=*)
18+
boot="/dev/disk/by-partlabel/${boot#PARTLABEL=}"
19+
;;
20+
/dev/*)
21+
;;
22+
*)
23+
die "You have to specify boot=<boot device> as a boot option for grub2-emu"
24+
;;
25+
esac
26+
27+
if ! [ -e "$boot" ]; then
28+
udevadm trigger --action=add >/dev/null 2>&1
29+
[ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version)
30+
i=0
31+
while ! [ -e $boot ]; do
32+
if [ $UDEVVERSION -ge 143 ]; then
33+
udevadm settle --exit-if-exists=$boot
34+
else
35+
udevadm settle --timeout=30
36+
fi
37+
[ -e $boot ] && break
38+
sleep 0.5
39+
i=$(($i+1))
40+
[ $i -gt 40 ] && break
41+
done
42+
fi
43+
44+
[ -e "$boot" ] || return 1
45+
46+
# This doesn't handle /boot being the same fs as /
47+
[ -d "/boot" ] || mkdir -p -m 0755 "/boot"
48+
info "Mounting $boot as /boot"
49+
mount "$boot" /boot || return 1
50+
51+
exit 0

99grub2-emu/module-setup.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/bash
2+
3+
check() {
4+
if ! dracut_module_included "systemd-initrd"; then
5+
derror "grub2-emu needs systemd-initrd in the initramfs"
6+
return 1
7+
fi
8+
9+
return 0
10+
}
11+
12+
depends() {
13+
echo "systemd-initrd"
14+
return 0
15+
}
16+
17+
install() {
18+
local _dir
19+
inst_binary grub2-emu
20+
inst_hook pre-mount 01 "${moddir}/grub2-mount-boot.sh"
21+
22+
for i in \
23+
grub2-emu.service \
24+
grub2-emu.target \
25+
; do
26+
inst_simple "${moddir}/${i}" "${systemdsystemunitdir}/${i}"
27+
done
28+
29+
# Running here is too early, but we also need dracut-mount to not run
30+
ln_r "/dev/null" "${systemdsystemunitdir}/dracut-mount.service"
31+
32+
mkdir -p "${initdir}${systemdsystemunitdir}/grub2-emu.target.wants"
33+
for i in \
34+
dracut-cmdline.service \
35+
dracut-initqueue.service \
36+
dracut-pre-mount.service \
37+
dracut-pre-trigger.service \
38+
dracut-pre-udev.service \
39+
; do
40+
ln_r "${systemdsystemunitdir}/${i}" "${systemdsystemunitdir}/grub2-emu.target.wants/${i}"
41+
done
42+
43+
# For now, we override initrd-switch-root, which we don't want to
44+
# run. It would be nicer if we were the default target instead.
45+
ln_r "${systemdsystemunitdir}/grub2-emu.service" "${systemdsystemunitdir}/initrd-switch-root.service"
46+
# ln_r "${systemdsystemunitdir}/grub2-emu.target" "${systemdsystemunitdir}/default.target"
47+
}

Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-License-Identifier: GPLv3
2+
#
3+
# Makefile
4+
# Copyright Peter Jones <[email protected]>
5+
#
6+
7+
TOPDIR ?= .
8+
DESTDIR ?= temp
9+
VERSION ?= 0
10+
11+
include $(TOPDIR)/utils.mk
12+
13+
all:
14+
15+
install :
16+
install -m 0755 -d "$(DESTDIR)/usr/lib/dracut/modules.d/99grub2-emu"
17+
install -m 0644 -t "$(DESTDIR)/usr/lib/dracut/modules.d/99grub2-emu" $(wildcard 99grub2-emu/*)
18+
install -m 0755 -d "$(DESTDIR)/etc/dracut.conf.d"
19+
install -m 0644 -t "$(DESTDIR)/etc/dracut.conf.d" etc/dracut.conf.d/grub2-emu.conf
20+
21+
dracut-nmbl-$(VERSION).tar.xz : Makefile
22+
@git archive --format=tar --prefix=dracut-nmbl-$(VERSION)/ HEAD -- \
23+
99grub2-emu/ \
24+
etc/ \
25+
Makefile \
26+
| xz > $@
27+
28+
tarball : dracut-nmbl-$(VERSION).tar.xz
29+
30+
clean :
31+
@rm -vf dracut-nmbl-$(VERSION).tar.xz
32+
33+
.PHONY: all install clean tarball
34+
35+
# vim:ft=make

dracut-nmbl.spec.in

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
%global debug_package %{nil}
2+
%global kver %{expand:%(rpm -q kernel-core --qf '%%{VERSION}' | tail -n 1)}
3+
%global krel %{expand:%(rpm -q kernel-core --qf '%%{RELEASE}' | tail -n 1)}
4+
5+
Summary: nmbl proof of concept as a dracut module
6+
Name: dracut-nmbl
7+
BuildArch: noarch
8+
Version: @@VERSION@@
9+
Release: @@RELEASE@@%{?dist}
10+
Group: System Environment/Base
11+
License: GPLv3
12+
URL: https://github.com/rhboot/nmbl-poc
13+
14+
BuildRequires: git
15+
BuildRequires: make
16+
17+
Source0: dracut-nmbl-%{version}.tar.xz
18+
19+
%description
20+
nmbl-poc is a proof of concept for a bootloader for UEFI machines based on
21+
the linux kernel and grub-emu, using either switchroot or kexec.
22+
23+
%prep
24+
%autosetup -S git_am
25+
26+
%build
27+
make all
28+
29+
%install
30+
%make_install
31+
32+
%files
33+
%defattr(-,root,root,-)
34+
%{_sysconfdir}/dracut.conf.d/grub2-emu.conf
35+
%dir /usr/lib/dracut/modules.d/99grub2-emu
36+
/usr/lib/dracut/modules.d/99grub2-emu/*
37+
38+
%changelog
39+
* Fri Mar 17 2023 Peter Jones <[email protected]> - 0-0
40+
- Yeet a spec file into the world

etc/dracut.conf.d/grub2-emu.conf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
omit_dracutmodules+=" grub2-emu "

utils.mk

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-License-Identifier: GPLv3
2+
#
3+
# utils.mk - make utilities
4+
# Copyright Peter Jones <[email protected]>
5+
#
6+
7+
VERSION = 0
8+
RELEASE = 1
9+
10+
DESTDIR := temp
11+
DATE=$(shell date "+%Y%m%d")
12+
ESPDIR := /boot/efi/EFI/BOOT
13+
KVRA := $(shell rpm -q kernel-core --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | tail -n 1)
14+
ARCH := $(shell rpm --eval '%{_build_arch}')
15+
EFI_ARCH := $(shell rpm --eval '%{efi_arch}')
16+
OS_NAME := $(shell grep '^ID=' /etc/os-release | sed 's/ID=//')
17+
OS_VERSION := $(shell grep '^VERSION_ID=' /etc/os-release | sed 's/VERSION_ID=//')
18+
OS_DIST := $(shell rpm --eval '%{dist}')
19+
VR := $(VERSION)-$(RELEASE)$(OS_DIST)
20+
21+
ifeq ($(.DEFAULT_GOAL),)
22+
.DEFAULT_GOAL := all
23+
endif
24+
25+
RPMBUILD_ARGS := -D "_topdir $(TOPDIR)" \
26+
-D '_builddir %{_topdir}' \
27+
-D '_rpmdir %{_topdir}' \
28+
-D '_sourcedir %{_topdir}' \
29+
-D '_specdir %{_topdir}' \
30+
-D '_srcrpmdir %{_topdir}' \
31+
-D 'dist $(OS_DIST)'
32+
33+
.EXPORT_ALL_VARIABLES:
34+
35+
% : %.in
36+
@sed \
37+
-e 's,@@VERSION@@,$(VERSION),g' \
38+
-e 's,@@RELEASE@@,$(RELEASE),g' \
39+
$< > $@
40+
41+
# vim:ft=make

0 commit comments

Comments
 (0)