From b2f35a7320e2c8efb6c25c9645c6250aa74abc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berk=20=C3=87akar?= Date: Mon, 13 Sep 2021 23:49:52 +0300 Subject: [PATCH] mkinitcpio, mkinitramfs, initrd rebuild --- kernel/tools/initrd/comar/pakhandler.py | 31 +++ kernel/tools/initrd/pspec.xml | 14 ++ kernel/tools/mkinitcpio/actions.py | 7 +- kernel/tools/mkinitcpio/comar/pakhandler.py | 30 +-- .../mkinitcpio/files/10-dm-initramfs.rules | 3 + .../mkinitcpio/files/70-dm-lvm-metad.rules | 93 ++++++++ kernel/tools/mkinitcpio/files/encrypt_hook | 144 ++++++++++++ kernel/tools/mkinitcpio/files/encrypt_install | 48 ++++ .../tools/mkinitcpio/files/gzip-default.patch | 40 ++++ kernel/tools/mkinitcpio/files/live_hook | 62 +++++ kernel/tools/mkinitcpio/files/live_install | 26 +++ kernel/tools/mkinitcpio/files/lvm2_hook | 25 ++ kernel/tools/mkinitcpio/files/lvm2_install | 43 ++++ kernel/tools/mkinitcpio/files/mdadm_hook | 49 ++++ kernel/tools/mkinitcpio/files/mdadm_install | 46 ++++ .../tools/mkinitcpio/files/mdadm_udev_install | 25 ++ kernel/tools/mkinitcpio/files/nosystemd.patch | 49 ++++ kernel/tools/mkinitcpio/files/udev_hook | 20 ++ kernel/tools/mkinitcpio/files/udev_install | 27 +++ kernel/tools/mkinitcpio/files/zfs_hook | 218 ++++++++++++++++++ kernel/tools/mkinitcpio/files/zfs_install | 102 ++++++++ kernel/tools/mkinitcpio/pspec.xml | 72 ++++-- kernel/tools/mkinitramfs/comar/pakhandler.py | 2 +- kernel/tools/mkinitramfs/pspec.xml | 7 + system/boot/busybox-mkinitcpio/actions.py | 3 +- system/boot/busybox-mkinitcpio/files/config | 2 +- system/boot/busybox-mkinitcpio/pspec.xml | 15 +- 27 files changed, 1159 insertions(+), 44 deletions(-) create mode 100644 kernel/tools/initrd/comar/pakhandler.py create mode 100644 kernel/tools/mkinitcpio/files/10-dm-initramfs.rules create mode 100644 kernel/tools/mkinitcpio/files/70-dm-lvm-metad.rules create mode 100644 kernel/tools/mkinitcpio/files/encrypt_hook create mode 100644 kernel/tools/mkinitcpio/files/encrypt_install create mode 100644 kernel/tools/mkinitcpio/files/gzip-default.patch create mode 100644 kernel/tools/mkinitcpio/files/live_hook create mode 100644 kernel/tools/mkinitcpio/files/live_install create mode 100644 kernel/tools/mkinitcpio/files/lvm2_hook create mode 100644 kernel/tools/mkinitcpio/files/lvm2_install create mode 100644 kernel/tools/mkinitcpio/files/mdadm_hook create mode 100644 kernel/tools/mkinitcpio/files/mdadm_install create mode 100644 kernel/tools/mkinitcpio/files/mdadm_udev_install create mode 100644 kernel/tools/mkinitcpio/files/nosystemd.patch create mode 100644 kernel/tools/mkinitcpio/files/udev_hook create mode 100644 kernel/tools/mkinitcpio/files/udev_install create mode 100644 kernel/tools/mkinitcpio/files/zfs_hook create mode 100644 kernel/tools/mkinitcpio/files/zfs_install diff --git a/kernel/tools/initrd/comar/pakhandler.py b/kernel/tools/initrd/comar/pakhandler.py new file mode 100644 index 00000000..88c307d7 --- /dev/null +++ b/kernel/tools/initrd/comar/pakhandler.py @@ -0,0 +1,31 @@ +#!/usr/bin/python + +import piksemel +import os + +def updateInitrd(filepath): + patterns = ("/lib/modules", "/lib/initrd", "/boot/kernel", "/bin/busybox") + parse = piksemel.parse(filepath) + for xmlfile in parse.tags("File"): + path = xmlfile.getTagData("Path") + if not path.startswith("/"): + path = "/%s" % path # Just in case + if path.startswith(patterns): + # Handle the proper case of modules + version = path.split("/")[3] + os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin' + cmd = "update-initrd KERNELVER=%s MODDIR=/lib/modules/%s OUTPUT=/boot/initramfs-%s" % (version, version, version) + os.system(cmd) + if os.path.exists("/proc/cmdline"): + os.system("/usr/bin/update-grub") + break + +def setupPackage(metapath, filepath): + updateInitrd(filepath) + +def cleanupPackage(metapath, filepath): + pass + +def postCleanupPackage(metapath, filepath): + # TODO: Remove old initramfs! + pass diff --git a/kernel/tools/initrd/pspec.xml b/kernel/tools/initrd/pspec.xml index 7fd00721..97339d92 100644 --- a/kernel/tools/initrd/pspec.xml +++ b/kernel/tools/initrd/pspec.xml @@ -25,13 +25,27 @@ btrfs-progs + + mkinitramfs + mkinitcpio + /bin/update-initrd /lib/initrd + + System.PackageHandler + + + 2020-09-11 + 1.1.4 + Rebuild + Berk Çakar + berk2238@hotmail.com + 2020-09-09 1.1.4 diff --git a/kernel/tools/mkinitcpio/actions.py b/kernel/tools/mkinitcpio/actions.py index db04af37..d72c8c22 100644 --- a/kernel/tools/mkinitcpio/actions.py +++ b/kernel/tools/mkinitcpio/actions.py @@ -8,10 +8,15 @@ from pisi.actionsapi import autotools from pisi.actionsapi import get from pisi.actionsapi import pisitools - def build(): autotools.make() def install(): autotools.rawInstall("DESTDIR=%s" % get.installDIR()) + + pisitools.removeDir("/usr/lib/kernel") + pisitools.removeDir("/usr/lib/tmpfiles.d") + pisitools.remove("/usr/lib/initcpio/install/sd-*") + pisitools.removeDir("/usr/share/libalpm") + pisitools.dodoc("LICENSE", "README") diff --git a/kernel/tools/mkinitcpio/comar/pakhandler.py b/kernel/tools/mkinitcpio/comar/pakhandler.py index d77ed1ec..476b39c9 100644 --- a/kernel/tools/mkinitcpio/comar/pakhandler.py +++ b/kernel/tools/mkinitcpio/comar/pakhandler.py @@ -3,25 +3,29 @@ import os import piksemel import subprocess +import os - -def generateinitrd(filepath): - doc = piksemel.parse(filepath) - for item in doc.tags("File"): - path = item.getTagData("Path") - if path.startswith("lib/modules/"): - kver = path.split("/")[2] - subprocess.call(["/usr/bin/mkinitcpio","-k","%s"% kver ,"-g","/boot/initramfs-%s-fallback.img"% kver,"-S","autodetect"]) - subprocess.call(["/usr/bin/mkinitcpio","-k","%s"% kver ,"-c","/etc/mkinitcpio.conf","-g","/boot/initramfs-%s.img"% kver]) - return +def updateInitrd(filepath): + patterns = ("/lib/modules", "/usr/lib/initcpio", "/boot/kernel", "/bin/busybox") + parse = piksemel.parse(filepath) + for xmlfile in parse.tags("File"): + path = xmlfile.getTagData("Path") + if not path.startswith("/"): + path = "/%s" % path + if path.startswith(patterns): + version = path.split("/")[3] + os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin' + subprocess.call(["mkinitcpio","-k","%s"% version ,"-g","/boot/initramfs-%s-fallback.img"% version,"-S","autodetect"]) + subprocess.call(["mkinitcpio","-k","%s"% version ,"-c","/etc/mkinitcpio.conf","-g","/boot/initramfs-%s.img"% version]) + if os.path.exists("/proc/cmdline"): + os.system("/usr/bin/update-grub") + break def setupPackage(metapath, filepath): - generateinitrd(filepath) + updateInitrd(filepath) def cleanupPackage(metapath, filepath): pass def postCleanupPackage(metapath, filepath): pass - - diff --git a/kernel/tools/mkinitcpio/files/10-dm-initramfs.rules b/kernel/tools/mkinitcpio/files/10-dm-initramfs.rules new file mode 100644 index 00000000..d2c16732 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/10-dm-initramfs.rules @@ -0,0 +1,3 @@ +# needed with new udev/mkinitcpio and as implemented in dracut: +# +SUBSYSTEM=="block", KERNEL=="dm-[0-9]*", ACTION=="add|change", OPTIONS="db_persist" diff --git a/kernel/tools/mkinitcpio/files/70-dm-lvm-metad.rules b/kernel/tools/mkinitcpio/files/70-dm-lvm-metad.rules new file mode 100644 index 00000000..c032108b --- /dev/null +++ b/kernel/tools/mkinitcpio/files/70-dm-lvm-metad.rules @@ -0,0 +1,93 @@ +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. +# +# This file is part of LVM2. + +# Udev rules for LVM. +# +# Scan all block devices having a PV label for LVM metadata. +# Store this information in LVMetaD (the LVM metadata daemon) and maintain LVM +# metadata state for improved performance by avoiding further scans while +# running subsequent LVM commands or while using lvm2app library. +# Also, notify LVMetaD about any relevant block device removal. +# +# This rule is essential for having the information in LVMetaD up-to-date. +# It also requires blkid to be called on block devices before so only devices +# used as LVM PVs are processed (ID_FS_TYPE="LVM2_member" or "LVM1_member"). + +SUBSYSTEM!="block", GOTO="lvm_end" + + +ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="lvm_end" + +# If the PV label got lost, inform lvmetad immediately. +# Detect the lost PV label by comparing previous ID_FS_TYPE value with current one. +ENV{.ID_FS_TYPE_NEW}="$env{ID_FS_TYPE}" +IMPORT{db}="ID_FS_TYPE" +ENV{ID_FS_TYPE}=="LVM2_member|LVM1_member", ENV{.ID_FS_TYPE_NEW}!="LVM2_member|LVM1_member", ENV{LVM_PV_GONE}="1" +ENV{ID_FS_TYPE}="$env{.ID_FS_TYPE_NEW}" +ENV{LVM_PV_GONE}=="1", GOTO="lvm_scan" + +# Only process devices already marked as a PV - this requires blkid to be called before. +ENV{ID_FS_TYPE}!="LVM2_member|LVM1_member", GOTO="lvm_end" +ENV{DM_MULTIPATH_DEVICE_PATH}=="1", GOTO="lvm_end" + +# Inform lvmetad about any PV that is gone. +ACTION=="remove", GOTO="lvm_scan" + +# Create /dev/disk/by-id/lvm-pv-uuid- symlink for each PV +ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-id/lvm-pv-uuid-$env{ID_FS_UUID_ENC}" + +# If the PV is a special device listed below, scan only if the device is +# properly activated. These devices are not usable after an ADD event, +# but they require an extra setup and they are ready after a CHANGE event. +# Also support coldplugging with ADD event but only if the device is already +# properly activated. +# This logic should be eventually moved to rules where those particular +# devices are processed primarily (MD and loop). + +# DM device: +KERNEL!="dm-[0-9]*", GOTO="next" +ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}=="1", GOTO="lvm_scan" +GOTO="lvm_end" + +# MD device: +LABEL="next" +KERNEL!="md[0-9]*", GOTO="next" +IMPORT{db}="LVM_MD_PV_ACTIVATED" +ACTION=="add", ENV{LVM_MD_PV_ACTIVATED}=="1", GOTO="lvm_scan" +ACTION=="change", ENV{LVM_MD_PV_ACTIVATED}!="1", TEST=="md/array_state", ENV{LVM_MD_PV_ACTIVATED}="1", GOTO="lvm_scan" +ACTION=="add", KERNEL=="md[0-9]*p[0-9]*", GOTO="lvm_scan" +ENV{LVM_MD_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0" +GOTO="lvm_end" + +# Loop device: +LABEL="next" +KERNEL!="loop[0-9]*", GOTO="next" +ACTION=="add", ENV{LVM_LOOP_PV_ACTIVATED}=="1", GOTO="lvm_scan" +ACTION=="change", ENV{LVM_LOOP_PV_ACTIVATED}!="1", TEST=="loop/backing_file", ENV{LVM_LOOP_PV_ACTIVATED}="1", GOTO="lvm_scan" +ENV{LVM_LOOP_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0" +GOTO="lvm_end" + +# If the PV is not a special device listed above, scan only after device addition (ADD event) +LABEL="next" +ACTION!="add", GOTO="lvm_end" + +LABEL="lvm_scan" + +# The table below summarises the situations in which we reach the LABEL="lvm_scan". +# Marked by X, X* means only if the special dev is properly set up. +# The artificial ADD is supported for coldplugging. We avoid running the pvscan +# on artificial CHANGE so there's no unexpected autoactivation when WATCH rule fires. +# N.B. MD and loop never actually reaches lvm_scan on REMOVE as the PV label is gone +# within a CHANGE event (these are caught by the "LVM_PV_GONE" rule at the beginning). +# +# | real ADD | real CHANGE | artificial ADD | artificial CHANGE | REMOVE +# ============================================================================= +# DM | | X | X* | | X +# MD | | X | X* | | +# loop | | X | X* | | +# other | X | | X | | X +ENV{SYSTEMD_READY}="1" +RUN+="/usr/bin/lvm pvscan --background --cache --activate ay --major $major --minor $minor", ENV{LVM_SCANNED}="1" + +LABEL="lvm_end" diff --git a/kernel/tools/mkinitcpio/files/encrypt_hook b/kernel/tools/mkinitcpio/files/encrypt_hook new file mode 100644 index 00000000..882d5fb4 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/encrypt_hook @@ -0,0 +1,144 @@ +#!/usr/bin/ash + +run_hook() { + modprobe -a -q dm-crypt >/dev/null 2>&1 + [ "${quiet}" = "y" ] && CSQUIET=">/dev/null" + + # Get keyfile if specified + ckeyfile="/crypto_keyfile.bin" + if [ -n "$cryptkey" ]; then + IFS=: read ckdev ckarg1 ckarg2 </dev/null 2>&1 + umount /ckey + ;; + *) + # Read raw data from the block device + # ckarg1 is numeric: ckarg1=offset, ckarg2=length + dd if="$resolved" of="$ckeyfile" bs=1 skip="$ckarg1" count="$ckarg2" >/dev/null 2>&1 + ;; + esac + fi + [ ! -f ${ckeyfile} ] && echo "Keyfile could not be opened. Reverting to passphrase." + fi + + if [ -n "${cryptdevice}" ]; then + DEPRECATED_CRYPT=0 + IFS=: read cryptdev cryptname cryptoptions <&2 + ;; + esac + done + + if resolved=$(resolve_device "${cryptdev}" ${rootdelay}); then + if cryptsetup isLuks ${resolved} >/dev/null 2>&1; then + [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated + dopassphrase=1 + # If keyfile exists, try to use that + if [ -f ${ckeyfile} ]; then + if eval cryptsetup --key-file ${ckeyfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; then + dopassphrase=0 + else + echo "Invalid keyfile. Reverting to passphrase." + fi + fi + # Ask for a passphrase + if [ ${dopassphrase} -gt 0 ]; then + echo "" + echo "A password is required to access the ${cryptname} volume:" + + #loop until we get a real password + while ! eval cryptsetup open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do + sleep 2; + done + fi + if [ -e "/dev/mapper/${cryptname}" ]; then + if [ ${DEPRECATED_CRYPT} -eq 1 ]; then + export root="/dev/mapper/root" + fi + else + err "Password succeeded, but ${cryptname} creation failed, aborting..." + return 1 + fi + elif [ -n "${crypto}" ]; then + [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated + msg "Non-LUKS encrypted device found..." + if echo "$crypto" | awk -F: '{ exit(NF == 5) }'; then + err "Verify parameter format: crypto=hash:cipher:keysize:offset:skip" + err "Non-LUKS decryption not attempted..." + return 1 + fi + exe="cryptsetup open --type plain $resolved $cryptname $cryptargs" + IFS=: read c_hash c_cipher c_keysize c_offset c_skip </dev/null; then + warning "Unable to locate compression method: %s" "$_optcompress" + _optcompress=cat +diff -ur a/mkinitcpio.conf b/mkinitcpio.conf +--- a/mkinitcpio.conf 2021-02-16 21:37:31.000000000 -0500 ++++ b/mkinitcpio.conf 2021-05-17 09:34:24.752605714 -0400 +@@ -52,7 +52,7 @@ + HOOKS=(base udev autodetect modconf block filesystems keyboard fsck) + + # COMPRESSION +-# Use this to compress the initramfs image. By default, zstd compression ++# Use this to compress the initramfs image. By default, gzip compression + # is used. Use 'cat' to create an uncompressed image. + #COMPRESSION="zstd" + #COMPRESSION="gzip" + \ No newline at end of file diff --git a/kernel/tools/mkinitcpio/files/live_hook b/kernel/tools/mkinitcpio/files/live_hook new file mode 100644 index 00000000..e53f3e87 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/live_hook @@ -0,0 +1,62 @@ +#!/usr/bin/bash +# See: https://gitlab.com/tearch-linux/applications-and-tools/mkinitcpio-teaiso + +live_mount(){ + mkdir -p /pisi/a # upper + mkdir -p /pisi/b # workdir + mkdir -p /live_root/ + mkdir -p /new_root/ + mkdir -p /source/ # lower + mount $root /new_root/ 2> /dev/null + mount /new_root/live/pisi.sfs /source/ 2> /dev/null + mount -t overlay -o lowerdir=/source/,upperdir=/pisi/a/,workdir=/pisi/b overlay /live_root + mount -t tmpfs -o size=100% none /pisi/a + mount -t tmpfs -o size=100% none /pisi/b + [ -d /source/merge/ ] && cp -prfv /source/merge/* /live_root/ + mount --bind /live_root /new_root/ + mkdir /new_root/cdrom/ 2> /dev/null + mkdir /new_root/source/ 2> /dev/null + mount $root /new_root/cdrom/ 2> /dev/null + mount /new_root/cdrom/live/pisi.sfs /new_root/source/ 2> /dev/null + [ "$home" != "" ] && mount $home /new_root/home 2>/dev/null +} + +is_file_avaiable(){ + disktmp=$(mktemp) + rm -f $disktmp + mkdir -p $disktmp || true + timeout 10 mount -t auto "$1" $disktmp &>/dev/null + [ -f "$disktmp/$2" ] && [ -b "$1" ] + status=$? + umount -lf $disktmp 2>/dev/null + return $status +} + +run_hook() { + # live-boot + if cat /proc/cmdline | grep "boot=live" >/dev/null ; then + while [ "$root" == "" ] ; do + list=$(ls /sys/class/block/ | grep ".*[0-9]$" | grep -v loop | grep -v ram | grep -v nbd | grep -v fd | sed "s|^|/dev/|g") + for part in $list + do + sleep 0.1 + echo "Looking for: $part" + if is_file_avaiable "$part" "/live/pisi.sfs" + then + export root=$part + elif is_file_avaiable "$part" "/mount-me" + then + export home=$part + fi + done + done + export mount_handler="live_mount" + fi +} + +run_latehook(){ + if ! cat /proc/cmdline | grep "init=" ; then + export init=/sbin/init + fi + sleep 0.3 +} diff --git a/kernel/tools/mkinitcpio/files/live_install b/kernel/tools/mkinitcpio/files/live_install new file mode 100644 index 00000000..794499c5 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/live_install @@ -0,0 +1,26 @@ +#!/bin/bash +# See: https://gitlab.com/tearch-linux/applications-and-tools/mkinitcpio-teaiso + +build() { + add_module "cdrom" + add_module "loop" + add_module "dm-snapshot" + add_module "overlay" + add_module "isofs" + add_module "squashfs" + add_module "hfsplus" + add_module "sr_mod" + add_module "dm_mod" + + add_runscript + + add_all_modules -f 'nls' '/kernel/fs' + add_all_modules -f 'overlayfs' '/kernel/fs' + add_all_modules -f 'squashfs' '/kernel/fs' + add_all_modules -f 'udf' '/kernel/fs' + add_all_modules -f 'ext4' '/kernel/fs' + add_all_modules -f 'hfsplus' '/kernel/fs' + add_all_modules -f 'usb-storage' '/kernel/drivers/usb' + + add_binary "timeout" +} diff --git a/kernel/tools/mkinitcpio/files/lvm2_hook b/kernel/tools/mkinitcpio/files/lvm2_hook new file mode 100644 index 00000000..3c28d67f --- /dev/null +++ b/kernel/tools/mkinitcpio/files/lvm2_hook @@ -0,0 +1,25 @@ +#!/usr/bin/ash + +run_earlyhook() { + mkdir /run/lvm + lvmetad +} + +# We are suffering a race condition in non-systemd initramfs: If lvmetad is +# killed before pvscan processes finish we have stale processes and +# uninitialized physical volumes. So wait for pvscan processes to finish. +# Break after 10 seconds (50*0.2s) to avaid infinite loop. +run_latehook() { + local i=50 + + while pgrep -f pvscan >/dev/null 2>/dev/null && [ $i -gt 0 ]; do + sleep 0.2 + i=$((i - 1)) + done +} + +run_cleanuphook() { + kill $(cat /run/lvmetad.pid) +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/kernel/tools/mkinitcpio/files/lvm2_install b/kernel/tools/mkinitcpio/files/lvm2_install new file mode 100644 index 00000000..d7a63332 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/lvm2_install @@ -0,0 +1,43 @@ +#!/usr/bin/bash + +build() { + local mod + local symlink + + # device mapper modules + for mod in dm-mod dm-snapshot dm-mirror dm-cache dm-cache-smq dm-thin-pool; do + add_module "$mod" + done + + # binaries from lvm2 + add_binary "lvm" + add_binary "lvmetad" + + # beinaries from device-mapper + add_binary "dmsetup" + + # from thin-provisioning-tools + add_binary "pdata_tools" + for symlink in cache_{check,dump,metadata_size,repair,restore} thin_{check,delta,dump,ls,metadata_size,repair,restore,rmap,trim}; do + add_symlink "/usr/bin/${symlink}" "pdata_tools" + done + + # udev rules and lvm configuration + add_file "/usr/lib/udev/rules.d/10-dm.rules" + add_file "/usr/lib/udev/rules.d/11-dm-lvm.rules" + add_file "/usr/lib/udev/rules.d/13-dm-disk.rules" + add_file "/usr/lib/udev/rules.d/95-dm-notify.rules" + add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules" + add_file "/usr/lib/initcpio/udev/69-dm-lvm-metad.rules" "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules" + add_file "/etc/lvm/lvm.conf" + + add_runscript +} + +help() { + cat </dev/null + + if [ -n "$md" ]; then + echo 'DEVICE partitions' >"$mdconfig" + for i in $(cat /proc/cmdline); do + case $i in + # raid + md=[0-9]*,/*) + device=${i%%,*} + device=${device/=/} + array=${i#*,} + echo "ARRAY /dev/$device devices=$array" + ;; + # partitionable raid + md=d[0-9]*,/*) + device=${i%%,*} + device=${device/=/_} + array=${i#*,} + echo "ARRAY /dev/$device devices=$array" + ;; + # raid UUID + md=[0-9]*,[0-9,a-fA-F]*) + device=${i%%,*} + device=${device/=/} + array=${i#*,} + echo "ARRAY /dev/$device UUID=$array" + ;; + # partitionable raid UUID + md=d[0-9]*,[0-9,a-fA-F]*) + device=${i%%,*} + device=${device/=/_} + array=${i#*,} + echo "ARRAY /dev/$device UUID=$array" + ;; + esac + done >>"$mdconfig" + fi + + # assemble everything + [ -s "$mdconfig" ] && /usr/bin/mdassemble +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/kernel/tools/mkinitcpio/files/mdadm_install b/kernel/tools/mkinitcpio/files/mdadm_install new file mode 100644 index 00000000..7390509f --- /dev/null +++ b/kernel/tools/mkinitcpio/files/mdadm_install @@ -0,0 +1,46 @@ +#!/bin/bash + +build() { + add_checked_modules -f 'dm-' 'drivers/md/*' + + # check if a custom mdadm.conf exists + if grep -q ^ARRAY /etc/mdadm.conf; then + echo "Custom /etc/mdadm.conf file will be used in initramfs for assembling arrays." + add_file "/etc/mdadm.conf" + fi + add_binary "/usr/bin/mdassemble" + add_file "/usr/lib/udev/rules.d/63-md-raid-arrays.rules" + + add_runscript +} + +help() { + cat <,dev0,dev1,...,devn + md=,uuid +- for partitionable raid arrays with persistent superblocks: + md=d,dev0,dev1,...,devn + md=d,uuid + +Parameters: +- = the number of the md device: + 0 means md0, 1 means md1, ... +- : e.g. /dev/hda1,/dev/hdc1,/dev/sda1,/dev/sdb1 + or 0900878d:f95f6057:c39a36e9:55efa60a +Examples: +- md=d0,/dev/sda3,/dev/sda4 md=d1,/dev/hda1,/dev/hdb1 + This will setup 2 md partitionable arrays. +- md=0,/dev/sda3,/dev/sda4 md=1,/dev/hda1,/dev/hdb1 + This will setup 2 md arrays with persistent superblocks. +HELPEOF +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/kernel/tools/mkinitcpio/files/mdadm_udev_install b/kernel/tools/mkinitcpio/files/mdadm_udev_install new file mode 100644 index 00000000..c01cbaf2 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/mdadm_udev_install @@ -0,0 +1,25 @@ +#!/bin/bash + +build() { + add_checked_modules -f 'dm-' 'drivers/md/*' + + # check if a custom mdadm.conf exists + if grep -qw ^ARRAY "$BASEDIR/etc/mdadm.conf"; then + echo "Custom /etc/mdadm.conf file will be used in initramfs for assembling arrays." + add_file "/etc/mdadm.conf" + fi + + add_binary "/usr/bin/mdadm" + add_file "/usr/lib/udev/rules.d/63-md-raid-arrays.rules" + add_file "/usr/lib/udev/rules.d/64-md-raid-assembly.rules" +} + +help() { + cat </dev/null)" || return 0 + [ "${encryption}" != "off" ] || return 0 + + # Make sure the dataset is locked + keystatus="$(zfs get -H -o value keystatus "${dataset}")" || return 0 + [ "${keystatus}" != "available" ] || return 0 + + # Make sure the encryptionroot is sensible + encryptionroot="$(zfs get -H -o value encryptionroot "${dataset}")" || return 0 + [ "${encryptionroot}" != "-" ] || return 0 + + # Export encryption root to be used by other hooks (SSH) + echo "${encryptionroot}" > /.encryptionroot + + # If key location is a file, determine if it can by overridden by prompt + prompt_override="" + if keylocation="$(zfs get -H -o value keylocation "${dataset}")"; then + if [ "${keylocation}" != "prompt" ]; then + if keyformat="$(zfs get -H -o value keyformat "${dataset}")"; then + [ "${keyformat}" = "passphrase" ] && prompt_override="yes" + fi + fi + fi + + # Loop until key is loaded here or by another vector (SSH, for instance) + while [ "$(zfs get -H -o value keystatus "${encryptionroot}")" != "available" ]; do + # Try the default loading mechanism + zfs load-key "${encryptionroot}" && break + + # Load failed, try a prompt if the failure was not a prompt + if [ -n "${prompt_override}" ]; then + echo "Unable to load key ${keylocation}; please type the passphrase" + echo "To retry the file, interrupt now or repeatedly input a wrong passphrase" + zfs load-key -L prompt "${encryptionroot}" && break + fi + + # Throttle retry attempts + sleep 2 + done + + if [ -f /.encryptionroot ]; then + rm /.encryptionroot + fi +} + +zfs_mount_handler () { + if [ "${ZFS_DATASET}" = "bootfs" ] ; then + if ! zfs_get_bootfs ; then + # Lets import everything and try again + zpool import ${ZPOOL_IMPORT_FLAGS} -N -a ${ZPOOL_FORCE} + if ! zfs_get_bootfs ; then + err "ZFS: Cannot find bootfs." + exit 1 + fi + fi + fi + + local pool="${ZFS_DATASET%%/*}" + local rwopt_exp="${rwopt:-rw}" + + if ! zpool list -H "${pool}" > /dev/null 2>&1; then + if [ ! "${rwopt_exp}" = "rw" ]; then + msg "ZFS: Importing pool ${pool} readonly." + ZPOOL_IMPORT_FLAGS="${ZPOOL_IMPORT_FLAGS} -o readonly=on" + else + msg "ZFS: Importing pool ${pool}." + fi + + if ! zpool import ${ZPOOL_IMPORT_FLAGS} -N "${pool}" ${ZPOOL_FORCE} ; then + err "ZFS: Unable to import pool ${pool}." + exit 1 + fi + fi + + local node="$1" + local rootmnt=$(zfs get -H -o value mountpoint "${ZFS_DATASET}") + local tab_file="${node}/etc/fstab" + local zfs_datasets="$(zfs list -H -o name -t filesystem -r ${ZFS_DATASET})" + + # Mount the root, and any child datasets + for dataset in ${zfs_datasets}; do + mountpoint=$(zfs get -H -o value mountpoint "${dataset}") + canmount=$(zfs get -H -o value canmount "${dataset}") + # skip dataset + [ ${dataset} != "${ZFS_DATASET}" -a \( ${canmount} = "off" -o ${canmount} = "noauto" -o ${mountpoint} = "none" \) ] && continue + if [ ${mountpoint} = "legacy" ]; then + if [ -f "${tab_file}" ]; then + if findmnt -snero source -F "${tab_file}" -S "${dataset}" > /dev/null 2>&1; then + opt=$(findmnt -snero options -F "${tab_file}" -S "${dataset}") + mnt=$(findmnt -snero target -F "${tab_file}" -S "${dataset}") + zfs_decrypt_fs "${dataset}" + mount -t zfs -o "${opt}" "${dataset}" "${node}${mnt}" + fi + fi + else + zfs_decrypt_fs "${dataset}" + mount -t zfs -o "zfsutil,${rwopt_exp}" "${dataset}" "${node}/${mountpoint##${rootmnt}}" + fi + done +} + +set_flags() { + # Force import the pools, useful if the pool has not properly been exported using 'zpool export ' + [ ! "${zfs_force}" = "" ] && ZPOOL_FORCE="-f" + + # Disable late hook, useful if we want to use zfs-import-cache.service instead + [ ! "${zfs_boot_only}" = "" ] && ZFS_BOOT_ONLY="1" + + # Add import directory to import command flags + [ ! "${zfs_import_dir}" = "" ] && ZPOOL_IMPORT_FLAGS="${ZPOOL_IMPORT_FLAGS} -d ${zfs_import_dir}" + [ "${zfs_import_dir}" = "" ] && [ -f /etc/zfs/zpool.cache.org ] && ZPOOL_IMPORT_FLAGS="${ZPOOL_IMPORT_FLAGS} -c /etc/zfs/zpool.cache.org" +} + +run_hook() { + set_flags + + # Wait 15 seconds for ZFS devices to show up + [ "${zfs_wait}" = "" ] && ZFS_WAIT="15" || ZFS_WAIT="${zfs_wait}" + + case ${root} in + # root=zfs + "zfs") + mount_handler="zfs_mount_handler" + ;; + # root=ZFS=... syntax (grub) + "ZFS="*) + mount_handler="zfs_mount_handler" + ZFS_DATASET="${root#*[=]}" + ;; + # root=zfs:... syntax (dracut) + "zfs:"*) + mount_handler="zfs_mount_handler" + ZFS_DATASET="${root#*[:]}" + ;; + esac + + case ${zfs} in + "") + # skip this line/dataset + ;; + auto|bootfs) + ZFS_DATASET="bootfs" + mount_handler="zfs_mount_handler" + local pool="[a-zA-Z][^ ]*" + ;; + *) + ZFS_DATASET="${zfs}" + mount_handler="zfs_mount_handler" + local pool="${ZFS_DATASET%%/*}" + ;; + esac + + # Allow at least n seconds for zfs device to show up. Especially + # when using zfs_import_dir instead of zpool.cache, the listing of + # available pools can be slow, so this loop must be top-tested to + # ensure we do one 'zpool import' pass after the timer has expired. + sleep ${ZFS_WAIT} & pid=$! + local break_after=0 + while :; do + kill -0 $pid > /dev/null 2>&1 || break_after=1 + if [ -c "/dev/zfs" ]; then + zpool import ${ZPOOL_IMPORT_FLAGS} | awk " + BEGIN { pool_found=0; online=0; unavail=0 } + /^ ${pool} .*/ { pool_found=1 } + /^\$/ { pool_found=0 } + /UNAVAIL/ { if (pool_found == 1) { unavail=1 } } + /ONLINE/ { if (pool_found == 1) { online=1 } } + END { if (online == 1 && unavail != 1) + { exit 0 } + else + { exit 1 } + }" && break + fi + [ $break_after == 1 ] && break + sleep 1 + done + kill $pid > /dev/null 2>&1 +} + +run_latehook () { + set_flags + # only run zpool import, if flags were set (cache file found / zfs_import_dir specified) and zfs_boot_only is not set + [ ! "${ZPOOL_IMPORT_FLAGS}" = "" ] && [ "${ZFS_BOOT_ONLY}" = "" ] && zpool import ${ZPOOL_IMPORT_FLAGS} -N -a ${ZPOOL_FORCE} +} + +# vim:set ts=4 sw=4 ft=sh et: diff --git a/kernel/tools/mkinitcpio/files/zfs_install b/kernel/tools/mkinitcpio/files/zfs_install new file mode 100644 index 00000000..41f2ad27 --- /dev/null +++ b/kernel/tools/mkinitcpio/files/zfs_install @@ -0,0 +1,102 @@ +#!/bin/bash + +build() { + map add_module \ + zavl \ + znvpair \ + zunicode \ + zcommon \ + zfs \ + spl + + map add_binary \ + fsck.zfs \ + mount.zfs \ + seq \ + zdb \ + zed \ + zfs \ + zhack \ + zinject \ + zpool \ + zstreamdump \ + /usr/lib/udev/vdev_id \ + /usr/lib/udev/zvol_id \ + findmnt + + map add_file \ + /usr/lib/udev/rules.d/60-zvol.rules \ + /usr/lib/udev/rules.d/69-vdev.rules \ + /usr/lib/udev/rules.d/90-zfs.rules \ + /usr/lib/libgcc_s.so.1 + + map add_dir \ + /etc/zfs/zed.d + + add_runscript + + # allow mount(8) to "autodetect" ZFS + echo 'zfs' >>"${BUILDROOT}/etc/filesystems" + + [[ -f /etc/hostid ]] && add_file "/etc/hostid" + [[ -f /etc/zfs/zpool.cache ]] && cp "/etc/zfs/zpool.cache" "${BUILDROOT}/etc/zfs/zpool.cache.org" + [[ -f /etc/modprobe.d/zfs.conf ]] && add_file "/etc/modprobe.d/zfs.conf" +} + +help() { + cat< + + To force importing of a ZFS pool: + + zfs_force=1 + + If set to 1, this will use "zpool import -f" when attempting to import + pools. + + To change the seconds of time to wait for ZFS devices to show up at boot: + + zfs_wait=30 + + To search for devices in a directory other than "/dev": + + zfs_import_dir=/dev/disk/by-uuid + or + zfs_import_dir=/dev/disk/by-partuuid + or + zfs_import_dir=/dev/disk/by-path + etc. + + Following initcpio convention, the 'rw' option must be specified to load the + pool as read/write. Pools are loaded as read only by default. + +Examples: + + To use bootfs on your pool, use + + zfs=bootfs rw + + This will setup your root using tank/root zfs pool. + + zfs=tank/root rw + +If you want to set properties for zfs-on-linux module, you should add them to +/etc/modprobe.d/zfs.conf and then rebuild initcpio. + +HELPEOF +} + +# vim: set ts=4 sw=4 ft=sh et: diff --git a/kernel/tools/mkinitcpio/pspec.xml b/kernel/tools/mkinitcpio/pspec.xml index b10e4137..34dcd371 100644 --- a/kernel/tools/mkinitcpio/pspec.xml +++ b/kernel/tools/mkinitcpio/pspec.xml @@ -3,69 +3,91 @@ mkinitcpio - https://projects.archlinux.org/mkinitcpio.git/ + https://github.com/archlinux/mkinitcpio Pisi Linux Admins admin@pisilinux.org - GPL + GPLv2 Modular initramfs image creation utility mkinitcpio is a generic, modular, cross-distribution initramfs generation tool. - https://github.com/bferturk/mkinitcpio/archive/19.1.tar.gz + https://github.com/archlinux/mkinitcpio/archive/refs/tags/v30.tar.gz - libkmod-devel - kmod asciidoc libxslt-devel - man-pages - man-db + + nosystemd.patch + gzip-default.patch + - + mkinitcpio - xz - bzip2 - libarchive - kmod - libkmod busybox-mkinitcpio - - mkinitramfs - + mkinitramfs + initrd + + /etc/initcpio + /etc/mkinitcpio.conf + /etc/mkinitcpio.d /usr/bin - /usr/lib - /usr/share + /usr/lib/initcpio + /usr/share/bash-completion /usr/share/doc - /etc + /usr/share/man + /usr/share/mkinitcpio + /usr/share/zsh + + udev_hook + udev_install + lvm2_hook + lvm2_install + encrypt_hook + encrypt_install + mdadm_hook + mdadm_install + mdadm_udev_install + zfs_hook + zfs_install + live_hook + live_install + 10-dm-initramfs.rules + 70-dm-lvm-metad.rules + System.PackageHandler - + - + + 2021-09-13 + 30 + Version bump + Berk Çakar + berk2238@hotmail.com + + 2021-06-09 19.1 Rebuild Mustafa Cinasal muscnslp@gmail.com - + 2020-12-26 19.1 Rebuild Mustafa Cinasal muscnslp@gmail.com - + 2019-12-27 19.1 Rebuild diff --git a/kernel/tools/mkinitramfs/comar/pakhandler.py b/kernel/tools/mkinitramfs/comar/pakhandler.py index 39a202f9..1ac747a7 100644 --- a/kernel/tools/mkinitramfs/comar/pakhandler.py +++ b/kernel/tools/mkinitramfs/comar/pakhandler.py @@ -21,4 +21,4 @@ def cleanupPackage(metapath, filepath): pass def postCleanupPackage(metapath, filepath): - generate_initramfs(filepath) + pass diff --git a/kernel/tools/mkinitramfs/pspec.xml b/kernel/tools/mkinitramfs/pspec.xml index 02d8e807..d50e4426 100644 --- a/kernel/tools/mkinitramfs/pspec.xml +++ b/kernel/tools/mkinitramfs/pspec.xml @@ -48,6 +48,13 @@ + + 2020-09-11 + 1.0.7 + Rebuild + Berk Çakar + berk2238@hotmail.com + 2020-01-18 1.0.7 diff --git a/system/boot/busybox-mkinitcpio/actions.py b/system/boot/busybox-mkinitcpio/actions.py index e630d141..0c21e70e 100644 --- a/system/boot/busybox-mkinitcpio/actions.py +++ b/system/boot/busybox-mkinitcpio/actions.py @@ -6,10 +6,11 @@ from pisi.actionsapi import autotools from pisi.actionsapi import pisitools +from pisi.actionsapi import shelltools def build(): + shelltools.export("KCONFIG_NOTIMESTAMP", "1") autotools.make() - def install(): pisitools.insinto("/usr/lib/initcpio", "busybox") diff --git a/system/boot/busybox-mkinitcpio/files/config b/system/boot/busybox-mkinitcpio/files/config index c53d6a4b..17411f84 100644 --- a/system/boot/busybox-mkinitcpio/files/config +++ b/system/boot/busybox-mkinitcpio/files/config @@ -49,7 +49,7 @@ CONFIG_PIE=y # CONFIG_FEATURE_SHARED_BUSYBOX is not set CONFIG_CROSS_COMPILER_PREFIX="" CONFIG_SYSROOT="" -CONFIG_EXTRA_CFLAGS="" +CONFIG_EXTRA_CFLAGS="-march=x86-64 -mtune=generic -Os -pipe -fno-strict-aliasing" CONFIG_EXTRA_LDFLAGS="" CONFIG_EXTRA_LDLIBS="" # CONFIG_USE_PORTABLE_CODE is not set diff --git a/system/boot/busybox-mkinitcpio/pspec.xml b/system/boot/busybox-mkinitcpio/pspec.xml index 3bb71052..a7f0e3a3 100644 --- a/system/boot/busybox-mkinitcpio/pspec.xml +++ b/system/boot/busybox-mkinitcpio/pspec.xml @@ -18,19 +18,30 @@ config - + busybox-mkinitcpio + + glibc + libxcrypt + /usr/lib/initcpio/busybox - + + 2021-09-13 + 1.33.0 + Rebuild. + Berk Çakar + berk2238@hotmail.com + + 2021-06-09 1.33.0 Rebuild.