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

modularize features #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/genkernel-*.tar.xz
/ChangeLog
/arch/*/generated-config
/build
32 changes: 29 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ifeq ("$(PACKAGE_VERSION)", "")
PACKAGE_VERSION = $(shell git describe --tags |sed 's,^v,,g')
endif
distdir = genkernel-$(PACKAGE_VERSION)
MANPAGE = genkernel.8
MANPAGE := genkernel.8
# Add off-Git/generated files here that need to be shipped with releases
EXTRA_DIST = ChangeLog $(KCONF)

Expand Down Expand Up @@ -69,6 +69,14 @@ SOFTWARE = BCACHE_TOOLS \
ZLIB \
ZSTD

FEATURE_COMPONENTS = append_base_layout \
create_initramfs \
determine_real_args \
genkernel_conf \
initramfs_append_func \
longusage \
parse_cmdline

SOFTWARE_VERSION = $(foreach entry, $(SOFTWARE), "VERSION_$(entry)=${VERSION_$(entry)}\n")

PREFIX = /usr/local
Expand All @@ -80,12 +88,15 @@ else
endif
MANDIR = $(PREFIX)/share/man

FEATURE_FILES = $(addprefix $(addprefix $(BUILD_DIR)/features/, $(GK_FEATURES))/, $(FEATURE_COMPONENTS))

all: $(BUILD_DIR)/genkernel $(BUILD_DIR)/build-config man kconfig

debug:
@echo "ARCH_KCONF=$(ARCH_KCONF)"
@echo "GENERATED_KCONF=$(GENERATED_KCONF)"
@echo "PACKAGE_VERSION=$(PACKAGE_VERSION)"
@echo "FEATURE_FILES: $(FEATURE_FILES)"

kconfig: $(GENERATED_KCONF)
man: $(addprefix $(BUILD_DIR)/,$(MANPAGE))
Expand Down Expand Up @@ -186,8 +197,23 @@ $(BUILD_DIR)/software.sh:
echo -e $(SOFTWARE_VERSION) > $(BUILD_DIR)/temp/versions
cat $(BUILD_DIR)/temp/versions defaults/software.sh > $(BUILD_DIR)/software.sh

$(BUILD_DIR)/doc/genkernel.8.txt:
install -D doc/genkernel.8.txt $(BUILD_DIR)/doc/genkernel.8.txt
$(BUILD_DIR)/temp/%:
install -d $(@D)
echo > $@
ifdef GK_FEATURES
cat $(addsuffix /$(@F) <(echo), $(addprefix features/,${GK_FEATURES})) > $@
endif

$(BUILD_DIR)/doc/genkernel.8.txt: $(BUILD_DIR)/temp/man_genkernel_8
install -d $(BUILD_DIR)/doc/
cat doc/genkernel.8.txt | sed \
-e '/\/\/ BEGIN FEATURES man_genkernel_8/ r $(BUILD_DIR)/temp/man_genkernel_8' \
> $(BUILD_DIR)/doc/genkernel.8.txt

$(BUILD_DIR)/genkernel.conf: $(BUILD_DIR)/temp/genkernel_conf
cat genkernel.conf | sed \
-e '/# BEGIN FEATURES genkernel_conf/ r $(BUILD_DIR)/temp/genkernel_conf' \
> $(BUILD_DIR)/genkernel.conf

$(BUILD_DIR)/%: %
install -D $< $@
Expand Down
29 changes: 29 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ things mentioned above.
DEPENDENCIES:
- GCC and binutils
- GNU Bash
- GNU Make
- PaX Utilities
- Autoconf and Automake
- Asciidoc
- Dependencies of each feature included

INSTALLATION:
Build with ``make PREFIX=<prefix> GK_FEATURES=<features>''
<features> is a space-separated list containing files in features/ directory,
e.g. GK_FEATURES="luks, lvm, plymouth". See MODULAR FEATURES section for detail.
Optionally:
- BINDIR: defaults to "$PREFIX/bin"
- SYSCONFDIR: defaults to "/etc" for PREFIX=/usr or "$PREFIX/etc" otherwise
- MANDIR: defaults to "$PREFIX/share/man"

Then install with ``make install'', optionally with DESTDIR

USAGE:
See https://wiki.gentoo.org/wiki/Genkernel or
Expand Down Expand Up @@ -62,3 +76,18 @@ BOOTING A KERNEL WITH INITRAMFS:

NOTE: The example above uses genkernel's --symlink feature and
initramfs was built with --lvm, --luks and --ssh.

MODULAR FEATURES

It is possible to include or exclude features
It is also possible to add your own.
Each feature is contained in a subdirectory within features/
which then includes these files:
- genkernel_conf
- man_genkernel_8
- parse_cmdline
- longusage
- append_base_layout
- create_initramfs
- initramfs_append_func
- determine_real_args
121 changes: 9 additions & 112 deletions doc/genkernel.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ KERNEL CONFIGURATION
Saves, or does not save the kernel configuration to '/etc/kernels'
if the kernel is successfully compiled.

*--*[*no-*]*bcache*::
Adds, or skip adding block layer cache (bcache) support to kernel
configuration.

*--*[*no-*]*hyperv*::
Adds, or skip adding Microsoft Hyper-V support to kernel configuration.

Expand Down Expand Up @@ -186,9 +182,6 @@ specified.
Runs, or does not run, "make oldconfig" before compilation. Specifying
*--oldconfig* implies *--no-clean*.

*--*[*no-*]*splash*::
Installs, or not, framebuffer splash support into initramfs.

*--*[*no-*]*ramdisk-modules*::
Copies or does not copy configured modules to the ramdisk.

Expand Down Expand Up @@ -349,42 +342,24 @@ LOW-LEVEL COMPILATION OPTIONS

INITIALIZATION
~~~~~~~~~~~~~~
*--splash*=<theme>::
Enable framebuffer splash using <theme>.

*--splash-res*=<resolutions>::
Select gensplash resolutions to include.

*--*[*no-*]*splash*=<theme>::
If the extra argument is specified, splash is forced using
<theme> rather than the default theme specified in your splash
configuration. If *--no-splash* is specified, then splash is disabled.

*--*[*no-*]*plymouth*::
Includes or excludes Plymouth from the initramfs. If "splash" is
passed at boot, Plymouth will be activated.

*--plymouth-theme*=<theme>::
Embeds the given Plymouth theme into the initramfs.
*--*[*no-*]*busybox*::
Includes or excludes busybox in the initramfs.
When enabled, this will compile busybox for you.

*--do-keymap-auto*::
Force keymap selection at boot.

*--*[*no-*]*keymap*::
Enables or disables keymap selection at boot.

*--*[*no-*]*lvm*::
Includes or excludes LVM support.
When enabled, this will compile LVM for you.
*--*[*no-*]*nfs*::
Includes or excludes NFS support.

*--*[*no-*]*mdadm*::
Includes or excludes mdadm support.
When enabled, this will compile mdadm for you.
*--*[*no-*]*netboot*::
Creates or does not create a self-contained env in the initramfs.

*--mdadm-config*=<file>::
Use <file> as configfile for MDADM.
By default the ramdisk will be built *without* an 'mdadm.conf' and
will auto-detect arrays during boot-up.
// BEGIN FEATURES man_genkernel_8
// END FEATURES man_genkernel_8

*--*[*no-*]*microcode-initramfs*::
Prepends, or do not prepend ucode(s) to the initramfs.
Expand All @@ -394,56 +369,9 @@ INITIALIZATION
NOTE: Embedding microcode updates into initramfs is *deprecated* when
system is able to load multiple initramfs.

*--*[*no-*]*dmraid*::
Includes or excludes DMRAID support.
When enabled, this will compile dmraid for you.

*--*[*no-*]*nfs*::
Includes or excludes NFS support.

*--*[*no-*]*e2fsprogs*::
Includes or excludes e2fsprogs.
When enabled, this will compile e2fsprogs for you.

*--*[*no-*]*xfsprogs*::
Includes or excludes xfsprogs.
When enabled, this will compile xfsprogs for you.

*--*[*no-*]*zfs*::
Includes or excludes ZFS support.

*--*[*no-*]*btrfs*::
Includes or excludes Btrfs support.
When enabled, this will compile btrfs-progs for you.

*--*[*no-*]*multipath*::
Includes or excludes Multipath support.
When enabled, this will compile multipath-tools for you.

*--*[*no-*]*iscsi*::
Includes or excludes iSCSI support.
When enabled, this will compile open-iscsi for you.

*--*[*no-*]*sandbox*::
Enables or disables sandbox-ing when building initramfs.

*--*[*no-*]*ssh*::
Includes or excludes SSH (dropbear) support for remote LUKS keys.
When enabled, this will compile dropbear for you.

*--ssh-authorized-keys-file*=<file>::
Specifies a user created authorized_keys file. By default genkernel
will use '/etc/dropbear/authorized_keys'.

*--ssh-host-keys*=<create|create-from-host|runtime>::
When set to *create*, which is the default value, genkernel will embed
SSH host keys from '/etc/dropbear' and will create those keys when missing.
When set to *create-from-host*, genkernel will embed SSH host keys from
'/etc/dropbear' but will create those keys from '/etc/ssh' when missing
(not recommended for security reasons).
When set to *runtime*, genkernel will not embed any SSH host key in
initramfs and dropbear will generate needed host key at runtime (`dropbear -R`).

*--boot-font*=<current|<file>|none>::
When set to *current*, genkernel will use "setfont" to dump and embed
current active console font into initramfs.
Expand All @@ -466,37 +394,6 @@ system is able to load multiple initramfs.
*--genzimage*::
Make and install kernelz image from 'arch/powerpc/boot/zImage.initrd'.

*--*[*no-*]*luks*::
Includes or excludes LUKS support.
When enabled, this will compile cryptsetup for you.

*--*[*no-*]*gpg*::
Includes or excludes support for GnuPG 1.x, the portable standalone branch
of GnuPG. A key can be made from
`gpg --symmetric -o /path/to/LUKS-key.gpg /path/to/LUKS-key` .
After that, re-point the *root_key* argument to the new .gpg file.

*--*[*no-*]*keyctl*::
Includes or excludes support for keyutils keyctl.
This way a LUKS passphrase can be loaded into a keyring at boot time
to unlock multiple devices (root, swap, etc.) without retyping it for each
one.

*--*[*no-*]*b2sum*::
Includes or excludes b2sum in the initramfs.
When enabled, this will compile coreutils' b2sum for you.

*--*[*no-*]*busybox*::
Includes or excludes busybox in the initramfs.
When enabled, this will compile busybox for you.

*--*[*no-*]*unionfs*::
Includes or excludes support for unionfs.
When enabled, this will compile unionfs-fuse for you.

*--*[*no-*]*netboot*::
Creates or does not create a self-contained env in the initramfs.

*--real-root*=<foo>::
Specify a default for *real_root*= kernel option which will be
embedded into initramfs.
Expand Down
Empty file.
Empty file.
Empty file.
Empty file added features/-sample/genkernel_conf
Empty file.
Empty file.
Empty file added features/-sample/longusage
Empty file.
Empty file.
Empty file added features/-sample/parse_cmdline
Empty file.
1 change: 1 addition & 0 deletions features/b2sum/append_base_layout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isTrue "${B2SUM}" && build_parameters+=( --b2sum ) || build_parameters+=( --no-b2sum )
1 change: 1 addition & 0 deletions features/b2sum/create_initramfs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
append_data 'b2sum' "${B2SUM}"
1 change: 1 addition & 0 deletions features/b2sum/determine_real_args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set_config_with_override BOOL B2SUM CMD_B2SUM "no"
2 changes: 2 additions & 0 deletions features/b2sum/genkernel_conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add b2sum support
#B2SUM="no"
25 changes: 25 additions & 0 deletions features/b2sum/initramfs_append_func
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
append_b2sum() {
local PN="coreutils"
local TDIR="${TEMP}/initramfs-b2sum-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi

populate_binpkg ${PN}

mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"

unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"

cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append b2sum to cpio!"

cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
3 changes: 3 additions & 0 deletions features/b2sum/longusage
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# b2sum
echo " --b2sum Include b2sum"
echo " --no-b2sum Exclude b2sum"
3 changes: 3 additions & 0 deletions features/b2sum/man_genkernel_8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*--*[*no-*]*b2sum*::
Includes or excludes b2sum in the initramfs.
When enabled, this will compile coreutils' b2sum for you.
4 changes: 4 additions & 0 deletions features/b2sum/parse_cmdline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--b2sum|--no-b2sum)
CMD_B2SUM=$(parse_optbool "$*")
print_info 3 "CMD_B2SUM: ${CMD_B2SUM}"
;;
1 change: 1 addition & 0 deletions features/bcache/append_base_layout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isTrue "${BCACHE}" && build_parameters+=( --bcache ) || build_parameters+=( --no-bcache )
1 change: 1 addition & 0 deletions features/bcache/create_initramfs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
append_data 'bcache' "${BCACHE}"
1 change: 1 addition & 0 deletions features/bcache/determine_real_args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set_config_with_override BOOL BCACHE CMD_BCACHE "no"
2 changes: 2 additions & 0 deletions features/bcache/genkernel_conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add bcache support
#BCACHE="no"
25 changes: 25 additions & 0 deletions features/bcache/initramfs_append_func
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
append_bcache() {
local PN="bcache-tools"
local TDIR="${TEMP}/initramfs-bcache-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi

populate_binpkg ${PN}

mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"

unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"

cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append bcache to cpio!"

cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
2 changes: 2 additions & 0 deletions features/bcache/longusage
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo " --bcache Include block layer cache (bcache) support"
echo " --no-bcache Exclude block layer cache (bcache) support"
3 changes: 3 additions & 0 deletions features/bcache/man_genkernel_8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*--*[*no-*]*bcache*::
Includes or excludes block layer cache (bcache) support.
When enabled, this will compile bcache-tools for you.
4 changes: 4 additions & 0 deletions features/bcache/parse_cmdline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--bcache|--no-bcache)
CMD_BCACHE=$(parse_optbool "$*")
print_info 3 "CMD_BCACHE: ${CMD_BCACHE}"
;;
1 change: 1 addition & 0 deletions features/btrfs/append_base_layout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isTrue "${BTRFS}" && build_parameters+=( --btrfs ) || build_parameters+=( --no-btrfs )
1 change: 1 addition & 0 deletions features/btrfs/create_initramfs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
append_data 'btrfs' "${BTRFS}"
1 change: 1 addition & 0 deletions features/btrfs/determine_real_args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set_config_with_override BOOL BTRFS CMD_BTRFS "$(rootfs_type_is btrfs)"
2 changes: 2 additions & 0 deletions features/btrfs/genkernel_conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add BTRFS support
#BTRFS="no"
Loading