├── .editorconfig ├── .git-blame-ignore-revs ├── .gitignore ├── .gitlab-ci.yml ├── .mailmap ├── .shellcheckrc ├── AUTHORS ├── CHANGELOG ├── CODEOWNERS ├── CONTRIBUTING.adoc ├── LICENSE ├── Makefile ├── PKGBUILD ├── README.adoc ├── functions ├── hooks ├── consolefont ├── encrypt ├── keymap ├── memdisk ├── meson.build ├── resume ├── shutdown ├── sleep ├── udev └── usr ├── init ├── init_functions ├── install ├── acpi_override ├── autodetect ├── base ├── block ├── consolefont ├── encrypt ├── filesystems ├── fsck ├── hostdata ├── keyboard ├── keymap ├── kms ├── lvm2 ├── mdadm_udev ├── memdisk ├── meson.build ├── microcode ├── modconf ├── resume ├── sd-encrypt ├── sd-encrypt-opensc ├── sd-shutdown ├── sd-vconsole ├── shutdown ├── sleep ├── strip ├── systemd ├── udev └── usr ├── kernel-install ├── 50-mkinitcpio.install └── meson.build ├── libalpm ├── hooks │ ├── 60-mkinitcpio-remove.hook │ └── 90-mkinitcpio-install.hook ├── meson.build └── scripts │ └── mkinitcpio ├── lsinitcpio ├── man ├── lsinitcpio.1.adoc ├── meson.build ├── mkinitcpio.8.adoc └── mkinitcpio.conf.5.adoc ├── meson.build ├── meson.options ├── mkinitcpio ├── mkinitcpio.conf ├── mkinitcpio.d ├── example.preset ├── hook.preset └── meson.build ├── shell ├── bash-completion ├── meson.build └── zsh-completion ├── shutdown ├── systemd ├── meson.build └── mkinitcpio-generate-shutdown-ramfs.service ├── test ├── cases │ ├── bash-completion.bats │ ├── extglob.bats │ ├── functions.bats │ ├── mkinitcpio.bats │ ├── parse_cmdline.bats │ └── zsh-completion.bats ├── fixtures │ ├── arm-zimage │ │ ├── README.adoc │ │ ├── image.bin │ │ ├── linux4.15-armv4-le-sa1100-zbootrom-gzip.zimage.bin │ │ ├── linux4.15-armv4-le-sa1100-zbootrom-lz4.zimage.bin │ │ ├── linux4.15-armv4-le-sa1100-zbootrom-lzma.zimage.bin │ │ ├── linux4.15-armv4-le-sa1100-zbootrom-lzo.zimage.bin │ │ ├── linux4.15-armv4-le-sa1100-zbootrom-xz.zimage.bin │ │ ├── linux4.15-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin │ │ ├── linux4.15-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin │ │ ├── linux4.15-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin │ │ ├── linux4.15-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin │ │ ├── linux4.15-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin │ │ ├── linux4.15-armv5-be32-ixp4xx-gzip.zimage.bin │ │ ├── linux4.15-armv5-be32-ixp4xx-lz4.zimage.bin │ │ ├── linux4.15-armv5-be32-ixp4xx-lzma.zimage.bin │ │ ├── linux4.15-armv5-be32-ixp4xx-lzo.zimage.bin │ │ ├── linux4.15-armv5-be32-ixp4xx-xz.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-gzip.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-lz4.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-lzma.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-lzo.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-thumb2-gzip.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-thumb2-lz4.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-thumb2-lzma.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-thumb2-lzo.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-thumb2-xz.zimage.bin │ │ ├── linux4.15-armv7-be8-generic-xz.zimage.bin │ │ ├── linux4.15-armv7-le-generic-gzip.zimage.bin │ │ ├── linux4.15-armv7-le-generic-lz4.zimage.bin │ │ ├── linux4.15-armv7-le-generic-lzma.zimage.bin │ │ ├── linux4.15-armv7-le-generic-lzo.zimage.bin │ │ ├── linux4.15-armv7-le-generic-thumb2-gzip.zimage.bin │ │ ├── linux4.15-armv7-le-generic-thumb2-lz4.zimage.bin │ │ ├── linux4.15-armv7-le-generic-thumb2-lzma.zimage.bin │ │ ├── linux4.15-armv7-le-generic-thumb2-lzo.zimage.bin │ │ ├── linux4.15-armv7-le-generic-thumb2-xz.zimage.bin │ │ ├── linux4.15-armv7-le-generic-xz.zimage.bin │ │ ├── linux4.17-armv4-le-sa1100-zbootrom-gzip.zimage.bin │ │ ├── linux4.17-armv4-le-sa1100-zbootrom-lz4.zimage.bin │ │ ├── linux4.17-armv4-le-sa1100-zbootrom-lzma.zimage.bin │ │ ├── linux4.17-armv4-le-sa1100-zbootrom-lzo.zimage.bin │ │ ├── linux4.17-armv4-le-sa1100-zbootrom-xz.zimage.bin │ │ ├── linux4.17-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin │ │ ├── linux4.17-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin │ │ ├── linux4.17-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin │ │ ├── linux4.17-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin │ │ ├── linux4.17-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin │ │ ├── linux4.17-armv5-be32-ixp4xx-gzip.zimage.bin │ │ ├── linux4.17-armv5-be32-ixp4xx-lz4.zimage.bin │ │ ├── linux4.17-armv5-be32-ixp4xx-lzma.zimage.bin │ │ ├── linux4.17-armv5-be32-ixp4xx-lzo.zimage.bin │ │ ├── linux4.17-armv5-be32-ixp4xx-xz.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-gzip.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-lz4.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-lzma.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-lzo.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-thumb2-gzip.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-thumb2-lz4.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-thumb2-lzma.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-thumb2-lzo.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-thumb2-xz.zimage.bin │ │ ├── linux4.17-armv7-be8-generic-xz.zimage.bin │ │ ├── linux4.17-armv7-le-generic-gzip.zimage.bin │ │ ├── linux4.17-armv7-le-generic-lz4.zimage.bin │ │ ├── linux4.17-armv7-le-generic-lzma.zimage.bin │ │ ├── linux4.17-armv7-le-generic-lzo.zimage.bin │ │ ├── linux4.17-armv7-le-generic-thumb2-gzip.zimage.bin │ │ ├── linux4.17-armv7-le-generic-thumb2-lz4.zimage.bin │ │ ├── linux4.17-armv7-le-generic-thumb2-lzma.zimage.bin │ │ ├── linux4.17-armv7-le-generic-thumb2-lzo.zimage.bin │ │ ├── linux4.17-armv7-le-generic-thumb2-xz.zimage.bin │ │ ├── linux4.17-armv7-le-generic-xz.zimage.bin │ │ ├── linux6.8-armv4-le-sa1100-zbootrom-gzip.zimage.bin │ │ ├── linux6.8-armv4-le-sa1100-zbootrom-lz4.zimage.bin │ │ ├── linux6.8-armv4-le-sa1100-zbootrom-lzma.zimage.bin │ │ ├── linux6.8-armv4-le-sa1100-zbootrom-lzo.zimage.bin │ │ ├── linux6.8-armv4-le-sa1100-zbootrom-xz.zimage.bin │ │ ├── linux6.8-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin │ │ ├── linux6.8-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin │ │ ├── linux6.8-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin │ │ ├── linux6.8-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin │ │ ├── linux6.8-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin │ │ ├── linux6.8-armv5-be32-ixp4xx-gzip.zimage.bin │ │ ├── linux6.8-armv5-be32-ixp4xx-lz4.zimage.bin │ │ ├── linux6.8-armv5-be32-ixp4xx-lzma.zimage.bin │ │ ├── linux6.8-armv5-be32-ixp4xx-lzo.zimage.bin │ │ ├── linux6.8-armv5-be32-ixp4xx-xz.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-gzip.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-lz4.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-lzma.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-lzo.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-thumb2-gzip.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-thumb2-lz4.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-thumb2-lzma.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-thumb2-lzo.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-thumb2-xz.zimage.bin │ │ ├── linux6.8-armv7-be8-generic-xz.zimage.bin │ │ ├── linux6.8-armv7-le-generic-gzip.zimage.bin │ │ ├── linux6.8-armv7-le-generic-lz4.zimage.bin │ │ ├── linux6.8-armv7-le-generic-lzma.zimage.bin │ │ ├── linux6.8-armv7-le-generic-lzo.zimage.bin │ │ ├── linux6.8-armv7-le-generic-thumb2-gzip.zimage.bin │ │ ├── linux6.8-armv7-le-generic-thumb2-lz4.zimage.bin │ │ ├── linux6.8-armv7-le-generic-thumb2-lzma.zimage.bin │ │ ├── linux6.8-armv7-le-generic-thumb2-lzo.zimage.bin │ │ ├── linux6.8-armv7-le-generic-thumb2-xz.zimage.bin │ │ └── linux6.8-armv7-le-generic-xz.zimage.bin │ └── uki │ │ ├── README.adoc │ │ └── splash.bmp ├── helpers │ └── common.bash └── meson.build ├── tmpfiles ├── 20-mkinitcpio.conf └── meson.build ├── tools ├── dist.sh └── git-contrib.sh └── udev ├── 01-memdisk.rules └── meson.build /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig 2 | # https://editorconfig.org 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # Unix-style newlines with a newline ending every file, utf-8 charset, 4 space 8 | # indentation, remove any whitespace characters preceding newline characters. 9 | [*] 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | indent_style = space 14 | indent_size = 4 15 | charset = utf-8 16 | # for shfmt 17 | switch_case_indent = true 18 | binary_next_line = true 19 | 20 | # Tab indentation (no size specified) 21 | [Makefile] 22 | indent_style = tab 23 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | 74df59109c9cce3c831c2314b4e8b85afe0f4c25 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | mkinitcpio.8 2 | mkinitcpio.conf.5 3 | lsinitcpio.1 4 | *~ 5 | *.bak 6 | mkinitcpio-*.tar.gz 7 | coverage/ 8 | build/ 9 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | stages: 4 | - check 5 | 6 | .pacman_install: 7 | before_script: 8 | # NOTE: Install latest archlinux-keyring before upgrading system. In the 9 | # future this should not be needed anymore when we can guarantee a valid 10 | # keyring for longer: 11 | # https://gitlab.archlinux.org/archlinux/archlinux-keyring/-/issues/4 12 | - echo -e "\e[0Ksection_start:`date +%s`:pacman[collapsed=true]\r\e[0KInstalling dependencies" 13 | - pacman -Sy --needed --noconfirm archlinux-keyring 14 | - pacman --noconfirm -Syu --needed bats bats-assert bats-support diffutils git jq kcov lzop meson pkg-config shellcheck systemd-ukify 15 | - echo -e "\e[0Ksection_end:`date +%s`:pacman\r\e[0K" 16 | - echo -e "\e[0Ksection_start:`date +%s`:useradd[collapsed=true]\r\e[0KCreating non-root user..." 17 | - useradd -d /builds/${GITLAB_USER_LOGIN} -M builder 18 | - chown -R builder:builder .. 19 | - echo -e "\e[0Ksection_end:`date +%s`:useradd\r\e[0K" 20 | 21 | shellcheck: 22 | stage: check 23 | extends: .pacman_install 24 | script: 25 | - sudo -HEu builder meson setup build -Ddocs=false 26 | - sudo -HEu builder meson test -C build --suite shellcheck 27 | tags: 28 | - vm 29 | 30 | test: 31 | stage: check 32 | extends: .pacman_install 33 | script: 34 | - sudo -HEu builder meson setup build -Ddocs=false 35 | - sudo -HEu builder meson test -C build --suite bats 36 | artifacts: 37 | reports: 38 | junit: build/meson-logs/testlog.junit.xml 39 | tags: 40 | - vm 41 | 42 | coverage: 43 | stage: check 44 | extends: .pacman_install 45 | coverage: '/Percent covered\s+\d+\.\d+/' 46 | allow_failure: true 47 | script: 48 | - sudo -HEu builder meson setup build -Ddocs=false 49 | - sudo -HEu builder meson test -C build --suite coverage 50 | - jq -r '. | 51 | ["Percent covered", .percent_covered], 52 | ["Covered lines", .covered_lines], 53 | ["Total lines", .total_lines], 54 | ["Percent low", .percent_low], 55 | ["Percent high", .percent_high] | @tsv' build/coverage/kcov-merged/coverage.json 56 | artifacts: 57 | reports: 58 | coverage_report: 59 | coverage_format: cobertura 60 | path: build/coverage/kcov-merged/cobertura.xml 61 | tags: 62 | - vm 63 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Jan Alexander Steffens (heftig) Jan Alexander Steffens (heftig) via arch-projects 2 | Jan Alexander Steffens (heftig) 3 | 4 | 5 | -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- 1 | # Suggest explicitly using -n in `[ $var ]` 2 | enable=avoid-nullary-conditions 3 | 4 | # Suggest 'command -v' instead of 'which' 5 | enable=deprecate-which 6 | 7 | # Suggest quoting variables without metacharacters 8 | enable=quote-safe-variables 9 | 10 | # Require [[ and warn about [ in Bash/Ksh 11 | enable=require-double-brackets 12 | 13 | # disable warnings validating ash scripts 14 | disable=SC2187 15 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # To see the full list of contributors, see the git log 2 | 0x7F 3 | Aaron Griffin 4 | Adam Maroti 5 | Alexander Schnaidt 6 | Alexei Colin 7 | Andrew J. Hesford 8 | Arkadij Chistyj 9 | Balló György 10 | Bartłomiej Piotrowski 11 | Benjamin Richter 12 | Brian Parsons 13 | Bill Auger 14 | Chih-Hsuan Yen 15 | Chocobo1 16 | Christian Hesse 17 | Christian Heusel 18 | Damon Harris 19 | Dan McGee 20 | Dang Huynh 21 | Daniel Edgecumbe 22 | Daniel Wallace 23 | Danilo 24 | Dave Reisner 25 | Davide Depau 26 | Dāvis 27 | Emil Velikov 28 | Eric Bélanger 29 | Erik Stromdahl 30 | Eva Kurchatova 31 | Evan James 32 | Evangelos Foutras 33 | Felix Yan 34 | Florian Eitel 35 | Florian Münchbach 36 | Florian Pritz 37 | Geert Hendrickx 38 | Gene C 39 | Gerardo Exequiel Pozzi 40 | Gerhard Brauer 41 | Giancarlo Razzolini 42 | Guilherme Silva 43 | Hector Martin 44 | Hugo Osvaldo Barrera 45 | Ionut Biru 46 | Jan Alexander Steffens (heftig) 47 | Joel McBride 48 | Jonas Große Sundrup 49 | Josephine Pfeiffer 50 | Leo Pham 51 | Levente Polyak 52 | Loui Chang 53 | Luca Stefani 54 | Luke T. Shumaker 55 | Markus Weippert 56 | Matthew Monaco 57 | Maxim Mikityanskiy 58 | Michael Kopp 59 | Mike Yuan 60 | Morten Linderud 61 | Onur Ankut 62 | Philip H. 63 | Piotr Gorski 64 | Qu Wenruo 65 | Richard Kraus 66 | Robin Ebert 67 | Ron Brown 68 | Sebastian Wiesner 69 | Sebastien Luttringer 70 | Simon Boulay 71 | Simon Brand 72 | Simon Brüggen 73 | Spencer Skylar Chan 74 | Sébastien Luttringer 75 | Tcc 76 | Thomas Bächler 77 | Thomas Weißschuh 78 | Tobias Powalowski 79 | Tom Gundersen 80 | Tuomas Lähdekorpi 81 | Vladimir Kochnev 82 | WorMzy Tykashi 83 | Xiaotian Wu 84 | Yishen Miao 85 | cedric cvl 86 | classabbyamp 87 | dNhax 88 | ff0x 89 | nl6720 90 | rogueai 91 | solsTiCe d'Hiver 92 | Štěpán Němec 93 | Страхиња Радић 94 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | [kernel-install] 2 | kernel-install/ @clavelc @lobachevsky 3 | 4 | [test suite] 5 | test/ @rogueai 6 | 7 | [cryptsetup] 8 | hooks/encrypt @eworm 9 | install/encrypt @eworm 10 | install/sd-encrypt @eworm @yhndnzj 11 | 12 | [lvm2] 13 | install/lvm2 @eworm 14 | 15 | [mdadm] 16 | install/mdadm_udev @tpowa @felixonmars 17 | 18 | [systemd] 19 | hooks/udev @eworm 20 | install/sd-shutdown @eworm 21 | install/sd-vconsole @eworm 22 | install/systemd @eworm @yhndnzj 23 | install/udev @eworm 24 | 25 | [sd-encrypt PKCS11] 26 | install/sd-encrypt-opensc @vstoiakin 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.adoc: -------------------------------------------------------------------------------- 1 | :toc: preamble 2 | :sectnums: 3 | 4 | = Care and feeding of your initramfs generator 5 | 6 | This guide attempts to outline the style used in the mkinitcpio codebase. 7 | 8 | == Bash v. POSIX 9 | 10 | Never use POSIX syntax if Bash offers a construct of its own, even if the 11 | two are effectively identical. This means always using double braces over 12 | the inferior `[` and `test`. 13 | 14 | == Variable usage and naming conventions 15 | 16 | There are three classifications of variables in mkinitcpio. 17 | 18 | === Local variables 19 | 20 | All lower case, and scoped within functions. Use 21 | freely, as they are well contained. Unless you are introducing a new 22 | option, this is what you want to use. 23 | 24 | [source,bash] 25 | ---- 26 | local foo="$1" 27 | ---- 28 | 29 | === Global variables 30 | 31 | These are known to mkinitcpio internally, but are global in scope. They carry 32 | runtime configuration and data collected during the image generation process. 33 | These are always lower case, but carry a leading underscore to denote that 34 | they are global. It is helpful to prefix these variables instead with a `_f_` or 35 | `_d_` if they refer to a file or directory, respectively. 36 | 37 | [source,bash] 38 | ---- 39 | define -i _optcolor=1 40 | _d_hookdir='/etc/foo.d' 41 | _f_config='/etc/foo.conf' 42 | ---- 43 | 44 | === "API" variables 45 | 46 | Also global in scope, but exist "outside" of mkinitcpio - either drawn in from 47 | the configuration file, or "exported" to the install hooks. These are always all 48 | upper case. When introducing new variables, extreme care must be taken to pick 49 | names that will not conflict with the environment inherited by mkinitcpio. 50 | 51 | == Function naming 52 | 53 | Use all lower case with underscores where appropriate, for easy readability. 54 | Adhere to POSIX variable naming requirements for the contents of the name, 55 | that is: only alphanumerics, underscores, and the identifier must not start 56 | with a number. 57 | 58 | == Quoting 59 | 60 | Overquoting is preferred to underquoting. Prefer single quotes to double quotes 61 | if possible. Remember to quote, quote and quote some more. 62 | 63 | When quoting variables, use brace expansion if the variable is part of a larger 64 | string. 65 | 66 | [source,bash] 67 | ---- 68 | a='/test' 69 | b="/some/path${a}" 70 | c="$b" 71 | ---- 72 | 73 | == Functions and block statements 74 | 75 | Always use "top-right, lower left" for blocks of code and functions. 76 | 77 | [source,bash] 78 | ---- 79 | do_glob() { 80 | local g fn="$1"; shift 81 | 82 | for g in "$@"; do 83 | "$fn" "$g" 84 | done 85 | } 86 | ---- 87 | 88 | == Building 89 | 90 | To build with meson, run `meson setup build [options...]`. This will create 91 | `./build` and prepare mkinitcpio for installation. See `link:meson.options[]` 92 | for a list of mkinitcpio-specific options that can be passed to meson. 93 | 94 | To install, run `meson install -C build`. 95 | 96 | === Meson templating 97 | 98 | All source files are templated by meson with the following variables: 99 | 100 | * `VERSION`: mkinitcpio version 101 | * `BINDIR`: the binary installation directory (for example: `/usr/bin`) 102 | * `SYSCONFDIR`: the system configuration directory (for example: `/etc`) 103 | * `INITCPIO_LIBDIR`: the mkinitcpio library directory (for example: `/usr/lib/initcpio`) 104 | * `INITCPIO_SYSCONFDIR`: the mkinitcpio system configuration directory (for example: `/etc/initcpio`) 105 | * `VCONSOLE_CONF`: the name of the `vconsole.conf` file in `SYSCONFDIR`. On some 106 | distributions, this may be something else, like `rc.conf` 107 | * `UDEVD_PATH`: the absolute path to the udev daemon executable 108 | * `TMPFILES_PATH`: the absolute path to the systemd-tmpfiles executable 109 | 110 | Templated values can be used in source files as `@VARIABLE@`. 111 | 112 | New templated values should be added to `conf_data` in `link:meson.build[]`. 113 | 114 | == Testing 115 | 116 | === Bash Automated Testing System 117 | 118 | mkinitcpio uses bats (Bash Automated Testing System). The tests are found in 119 | the `link:test[]` directory. Use `meson test -C build --suite bats` to run 120 | the test suite. 121 | 122 | Each newly added function should also have an accompanying test. 123 | 124 | === ShellCheck 125 | 126 | All shell scripts must be validated with ShellCheck. Use `meson test -C build 127 | --suite shellcheck` and ensure it successfully passes. 128 | 129 | == EditorConfig 130 | 131 | A `link:.editorconfig[]` file is provided to ensure consistency 132 | (indenting, newlines, trailing whitespace) between text editors. 133 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for mkinitcpio 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | VERSION = $(shell ./tools/dist.sh get-version) 5 | 6 | all: 7 | @printf "mkinitcpio now requires meson to build, install, and run tests." 8 | prepare: all 9 | @echo " Use:" 10 | @echo " meson setup build" 11 | install: prepare 12 | @echo " meson install -C build" 13 | check: prepare 14 | @echo " meson test -C build --suite bats" 15 | shellcheck: prepare 16 | @echo " meson test -C build --suite shellcheck" 17 | coverage: prepare 18 | @echo " meson test -C build --suite coverage" 19 | 20 | clean: 21 | $(RM) -r build mkinitcpio-$(VERSION).tar.xz.sig mkinitcpio-$(VERSION).tar.xz 22 | 23 | dist: mkinitcpio-$(VERSION).tar.xz 24 | mkinitcpio-$(VERSION).tar.xz: 25 | meson setup build $(MESON_ARGS) 26 | meson dist -C build 27 | cp build/meson-dist/$@ $@ 28 | 29 | mkinitcpio-$(VERSION).tar.xz.sig: mkinitcpio-$(VERSION).tar.xz 30 | gpg --detach-sign $< 31 | 32 | upload: mkinitcpio-$(VERSION).tar.xz mkinitcpio-$(VERSION).tar.xz.sig 33 | scp $^ repos.archlinux.org:/srv/ftp/other/mkinitcpio 34 | 35 | .PHONY: check clean coverage dist install shellcheck prepare upload 36 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | pkgname=mkinitcpio-git 2 | pkgver=$(make version) 3 | pkgrel=1 4 | pkgdesc="Modular initramfs image creation utility" 5 | arch=(any) 6 | url="https://git.archlinux.org/mkinitcpio.git/" 7 | license=('GPL') 8 | groups=('base') 9 | conflicts=('mkinitcpio') 10 | provides=("mkinitcpio=$pkgver" "initramfs") 11 | depends=('mkinitcpio-busybox>=1.19.4-2' 'kmod' 'util-linux>=2.23' 'libarchive' 'coreutils' 12 | 'awk' 'bash' 'binutils' 'findutils' 'grep' 'filesystem>=2011.10-1' 'systemd' 'zstd') 13 | makedepends=('asciidoc' 'git' 'sed') 14 | optdepends=('gzip: Use gzip compression for the initramfs image' 15 | 'xz: Use lzma or xz compression for the initramfs image' 16 | 'bzip2: Use bzip2 compression for the initramfs image' 17 | 'lzop: Use lzo compression for the initramfs image' 18 | 'lz4: Use lz4 compression for the initramfs image' 19 | 'mkinitcpio-nfs-utils: Support for root filesystem on NFS' 20 | 'systemd-ukify: Build UKIs using ukify') 21 | backup=(etc/mkinitcpio.conf) 22 | 23 | build() { 24 | make -C "$startdir" 25 | } 26 | 27 | package() { 28 | make -C "$startdir" DESTDIR="$pkgdir" install 29 | } 30 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :toc: preamble 2 | :sectnums: 3 | 4 | = README 5 | 6 | mkinitcpio is a modular initramfs image creation utility. 🐏 7 | 8 | == Dependencies 9 | 10 | mkinitcpio has the following dependencies. 11 | 12 | .Dependencies: 13 | * GNU awk 14 | * A static build of busybox installed at `+/usr/lib/initcpio/busybox+` 15 | * kmod 16 | * util-linux 17 | * bsdtar from libarchive 18 | * GNU Coreutils 19 | * Bash 20 | * GNU Binutils 21 | * GNU Diffutils 22 | * GNU Findutils 23 | * GNU Grep 24 | * gzip (the default initramfs compressor for Linux < 5.9) 25 | * zstd (the default initramfs compressor for Linux ≥ 5.9) 26 | 27 | .Optional dependencies: 28 | * systemd: for systemd-based initramfs 29 | * xz: for `+lzma+` and `+xz+` initramfs compression/decompression 30 | * bzip2: for initramfs compression/decompression 31 | * lzop for `+lzo+` initramfs compression/decompression 32 | * lz4 for initramfs compression/decompression 33 | * systemd-ukify: build UKIs using ukify instead of objcopy 34 | 35 | .Build time dependencies: 36 | * Meson 37 | * Asciidoctor (or alternatively a2x from AsciiDoc.py) to create man pages 38 | * Bash Automated Testing System (bats) and bats-assert for tests 39 | * ShellCheck for tests 40 | 41 | Instructions for building are available in xref:CONTRIBUTING.adoc#_building[CONTRIBUTING.adoc]. 42 | 43 | == Contributing 44 | 45 | mkinitcpio development happens on the Arch Linux GitLab instance: https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio. All issues and merge request should be submitted there. 46 | 47 | Development discussion can be held in the link:ircs://irc.libera.chat/archlinux-projects[#archlinux-projects] IRC channel on https://libera.chat/[Libera Chat] and the https://lists.archlinux.org/mailman3/lists/arch-projects.lists.archlinux.org/[arch-projects mailing list]. 48 | 49 | Before contributing, make yourself familiar with the https://terms.archlinux.org/docs/code-of-conduct/[Arch Linux code of conduct] and xref:CONTRIBUTING.adoc[mkinitcpio coding style]. 50 | 51 | == User documentation 52 | 53 | Primary usage documentation is available in the xref:man/mkinitcpio.8.adoc[mkinitcpio(8)], xref:man/lsinitcpio.1.adoc[lsinitcpio(1)] and xref:man/mkinitcpio.conf.5.adoc[mkinitcpio.conf(5)] man pages. 54 | 55 | A comprehensible user guide is available in the https://wiki.archlinux.org/title/mkinitcpio[mkinitcpio article on ArchWiki]. 56 | 57 | == License 58 | 59 | This project is licensed under the terms of the *GPL-2.0-only*. See `link:LICENSE[]`. 60 | 61 | Copyright 🄯 mkinitcpio contributors. See the `link:AUTHORS[]` file or `+git log+` for the full list of authors. 62 | -------------------------------------------------------------------------------- /hooks/consolefont: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | run_hook() { 5 | if [ -e /consolefont.psfu ]; then 6 | msg -n ":: Loading console font..." 7 | # Supported in ash 8 | # shellcheck disable=SC3036 9 | echo -en "a\010 \010" 10 | setfont -C /dev/console /consolefont.psfu 11 | msg "done." 12 | elif [ -e /consolefont.psf ]; then 13 | msg -n ":: Loading console font..." 14 | # Supported in ash 15 | # shellcheck disable=SC3036 16 | echo -en "a\010 \010" 17 | setfont -C /dev/console /consolefont.psf 18 | msg "done." 19 | else 20 | msg "No consolefont found despite added hook." 21 | fi 22 | } 23 | 24 | # vim: set ft=sh ts=4 sw=4 et: 25 | -------------------------------------------------------------------------------- /hooks/encrypt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | 3 | run_hook() { 4 | local quiet rootdelay 5 | modprobe -a -q dm-crypt >/dev/null 2>&1 6 | quiet="$(getarg quiet)" 7 | [ "${quiet}" = "y" ] && CSQUIET=">/dev/null" 8 | 9 | # Get keyfile if specified 10 | ckeyfile="/crypto_keyfile.bin" 11 | if [ -n "$cryptkey" ]; then 12 | # cryptkey can contain : which needs to be escaped. 13 | # shellcheck disable=SC2162 14 | IFS=: read ckdev ckarg1 ckarg2 </dev/null 2>&1 29 | umount /ckey 30 | ;; 31 | *) 32 | # Read raw data from the block device 33 | # ckarg1 is numeric: ckarg1=offset, ckarg2=length 34 | dd if="$resolved" of="$ckeyfile" bs=1 skip="$ckarg1" count="$ckarg2" >/dev/null 2>&1 35 | ;; 36 | esac 37 | fi 38 | [ ! -f "${ckeyfile}" ] && echo "Keyfile could not be opened. Reverting to passphrase." 39 | fi 40 | 41 | if [ -n "${cryptdevice}" ]; then 42 | DEPRECATED_CRYPT=0 43 | # cryptdevice can contain : which needs to be escaped. 44 | # shellcheck disable=SC2162 45 | IFS=: read cryptdev cryptname cryptoptions <&2 83 | ;; 84 | esac 85 | done 86 | set +f 87 | IFS="$OLDIFS" 88 | unset OLDIFS 89 | 90 | if resolved=$(resolve_device "${cryptdev}" "${rootdelay}"); then 91 | if cryptsetup isLuks "${resolved}" >/dev/null 2>&1; then 92 | [ "${DEPRECATED_CRYPT}" -eq 1 ] && warn_deprecated 93 | dopassphrase=1 94 | # If keyfile exists, try to use that 95 | if [ -f "${ckeyfile}" ]; then 96 | if eval cryptsetup --key-file "${ckeyfile}" open --type luks "${resolved}" "${cryptname}" "${cryptargs}" "${CSQUIET}"; then 97 | dopassphrase=0 98 | else 99 | echo "Invalid keyfile. Reverting to passphrase." 100 | fi 101 | fi 102 | # Ask for a passphrase 103 | if [ "${dopassphrase}" -gt 0 ]; then 104 | if command -v plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then 105 | plymouth ask-for-password \ 106 | --prompt="A password is required to access the ${cryptname} volume" \ 107 | --command="cryptsetup open --type luks --key-file=- ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}" 108 | else 109 | echo "" 110 | echo "A password is required to access the ${cryptname} volume:" 111 | 112 | #loop until we get a real password 113 | while ! eval cryptsetup open --type luks "${resolved}" "${cryptname}" "${cryptargs}" "${CSQUIET}"; do 114 | sleep 2; 115 | done 116 | fi 117 | fi 118 | if [ -e "/dev/mapper/${cryptname}" ]; then 119 | if [ "${DEPRECATED_CRYPT}" -eq 1 ]; then 120 | export root="/dev/mapper/root" 121 | fi 122 | else 123 | err "Password succeeded, but ${cryptname} creation failed, aborting..." 124 | return 1 125 | fi 126 | elif [ -n "${crypto}" ]; then 127 | [ "${DEPRECATED_CRYPT}" -eq 1 ] && warn_deprecated 128 | msg "Non-LUKS encrypted device found..." 129 | if echo "$crypto" | awk -F: '{ exit(NF == 5) }'; then 130 | err "Verify parameter format: crypto=hash:cipher:keysize:offset:skip" 131 | err "Non-LUKS decryption not attempted..." 132 | return 1 133 | fi 134 | exe="cryptsetup open --type plain $resolved $cryptname $cryptargs" 135 | # c_cipher can contain : which needs to be escaped. 136 | # shellcheck disable=SC2162 137 | IFS=: read c_hash c_cipher c_keysize c_offset c_skip <>/dev/console 18 | loadkmap /sys/power/resume 35 | return 0 36 | fi 37 | 38 | err "resume: hibernation device '$resume' not found" 39 | return 1 40 | } 41 | 42 | # vim: set ft=sh ts=4 sw=4 et: 43 | -------------------------------------------------------------------------------- /hooks/shutdown: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | run_cleanuphook() { 5 | rm -rf /usr/lib/modules 6 | cp -ax /. /run/initramfs 7 | } 8 | 9 | # vim: set ft=sh ts=4 sw=4 et: 10 | -------------------------------------------------------------------------------- /hooks/sleep: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | run_hook() { 5 | if [ -z "${sleeptime}" ] || ! [ "${sleeptime}" -gt 0 ]; then 6 | sleeptime=5 7 | fi 8 | if [ -n "${sleepdevice}" ]; then 9 | poll_device "${sleepdevice}" "${sleeptime}" 10 | else 11 | msg "Sleeping for ${sleeptime} seconds." 12 | sleep "${sleeptime}" 13 | fi 14 | } 15 | 16 | # vim: set ft=sh ts=4 sw=4 et: 17 | -------------------------------------------------------------------------------- /hooks/udev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | 3 | run_earlyhook() { 4 | local quiet 5 | if command -v '@TMPFILES_PATH@' >/dev/null 2>&1; then 6 | kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf 7 | '@TMPFILES_PATH@' --prefix=/dev --create --boot 8 | fi 9 | quiet="$(getarg quiet)" 10 | if [ "${quiet}" = "y" ]; then 11 | '@UDEVD_PATH@' --daemon --resolve-names=never >/dev/null 2>&1 12 | else 13 | '@UDEVD_PATH@' --daemon --resolve-names=never 14 | fi 15 | # used externally by poll_device() 16 | # shellcheck disable=SC2034 17 | udevd_running=1 18 | } 19 | 20 | run_hook() { 21 | msg ":: Triggering uevents..." 22 | udevadm trigger --action=add --type=subsystems 23 | udevadm trigger --action=add --type=devices 24 | udevadm settle 25 | } 26 | 27 | run_cleanuphook() { 28 | udevadm control --exit 29 | udevadm info --cleanup-db 30 | } 31 | 32 | # vim: set ft=sh ts=4 sw=4 et: 33 | -------------------------------------------------------------------------------- /hooks/usr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | run_latehook() { 5 | local usr_source mountopts passno realtab=/new_root/etc/fstab 6 | 7 | if [ -f "$realtab" ]; then 8 | if usr_source="$(findmnt -snero source --tab-file="$realtab" -T /usr)"; then 9 | mountopts="$(findmnt -snero options --tab-file="$realtab" -T /usr)" 10 | 11 | # returning the passno column requires util-linux >= 2.23. for 12 | # older versions which do not support this column, always fsck. 13 | passno="$(findmnt -snero passno --tab-file="$realtab" -T /usr 2>/dev/null)" 14 | if [ -z "$passno" ] || [ "$passno" -gt 0 ]; then 15 | fsck_device "$usr_source" 16 | fi 17 | msg ":: mounting '$usr_source' on /usr" 18 | mount "$usr_source" /new_root/usr -o "$mountopts" 19 | fi 20 | fi 21 | } 22 | 23 | # vim: set ft=sh ts=4 sw=4 et: 24 | -------------------------------------------------------------------------------- /init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | export PATH='/usr/local/sbin:/usr/local/bin:/usr/bin' 5 | 6 | udevd_running=0 7 | mount_handler=default_mount_handler 8 | init=/sbin/init 9 | rd_logmask=0 10 | 11 | . /init_functions 12 | 13 | mount_setup 14 | 15 | # parse the kernel command line 16 | parse_cmdline 1 )); then 26 | # Sleep and try again to avoid a race condition with udev 27 | # NOTE: This is a best-effort workaround for what is assumed to be 28 | # a bug in `udevadm settle` where the command exits while the 29 | # devices have not yet settled. See 30 | # https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues/177 31 | # and https://bugs.archlinux.org/task/77789 for details. 32 | warning 'An error was encountered during device lookup. Retrying.' 33 | sleep 1 34 | else 35 | error 'An error was encountered during device lookup.' 36 | return 1 37 | fi 38 | done 39 | mapfile -t mods < <(sed -n 's/\(DRIVER\|MODALIAS\)=\(.\+\)/\2/p' <<<"$uevents") 40 | mapfile -t mods < <(modprobe -S "$KERNELVERSION" -qaR "${mods[@]}" | LC_ALL=C.UTF-8 sort -u) 41 | 42 | (( ${#mods[*]} )) && printf "%s\n" "${mods[@]//-/_}" 43 | } 44 | 45 | add_if_avail() { 46 | local r='' resolved=() 47 | 48 | # treat this as an alias, since ext3 might be aliased to ext4. also, as 49 | # of linux 3.9, we can find any filesystem by the alias "fs-$name" 50 | # rather than having to guess at the corresponding module name. 51 | mapfile -t resolved < <(modprobe -S "$KERNELVERSION" -qaR {fs-,}"$1") 52 | 53 | for r in "${resolved[@]}"; do 54 | _autodetect_cache["$r"]=1 55 | done 56 | } 57 | 58 | if [[ ! -d /sys/devices ]]; then 59 | error "/sys does not appear to be mounted. Unable to use autodetection" 60 | return 1 61 | fi 62 | 63 | mapfile -t mods < <(auto_modules) 64 | if (( ! ${#mods[@]} )); then 65 | error 'Cannot acquire used modules. Unable to use autodetection.' 66 | return 1 67 | fi 68 | 69 | for m in "${mods[@]}"; do 70 | _autodetect_cache["$m"]=1 71 | done 72 | 73 | # detect filesystem for root 74 | if rootfstype="$(findmnt -uno fstype -T '/')"; then 75 | if [[ "${rootfstype}" == "overlay" ]]; then 76 | warning "cannot detect type of overlayfs root filesystem" 77 | # fs_autodetect_failed is used by other hooks called after this one 78 | # shellcheck disable=SC2034 79 | fs_autodetect_failed=1 80 | else 81 | add_if_avail "$rootfstype" 82 | fi 83 | else 84 | error "failed to detect root filesystem" 85 | # fs_autodetect_failed is used by other hooks called after this one 86 | # shellcheck disable=SC2034 87 | fs_autodetect_failed=1 88 | fi 89 | 90 | # detect filesystem for separate /usr 91 | if usrfstype="$(findmnt -snero fstype -T '/usr')"; then 92 | add_if_avail "$usrfstype" 93 | fi 94 | 95 | # scan for md raid devices 96 | mapfile -t md_devs < <(compgen -G '/sys/class/block/md*/md/level') 97 | if (( ${#md_devs[@]} )); then 98 | quiet "found %d mdadm arrays to scan" "${#md_devs[*]}" 99 | mapfile -t mods < <(awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}") 100 | for m in "${mods[@]}"; do 101 | _autodetect_cache["$m"]=1 102 | done 103 | fi 104 | 105 | if (( ${#_autodetect_cache[*]} )); then 106 | quiet "caching %d modules" "${#_autodetect_cache[*]}" 107 | fi 108 | } 109 | 110 | help() { 111 | cat </dev/null; then 21 | add_binary "mount.${rootfstype}" 22 | fi 23 | if [[ -n "$usrfstype" && "$usrfstype" != "$rootfstype" ]]; then 24 | if command -v "mount.${usrfstype}" &>/dev/null; then 25 | add_binary "mount.${usrfstype}" 26 | fi 27 | fi 28 | else 29 | for mount in $(compgen -c mount.); do 30 | # skip FUSE, clustered file systems, ecryptfs, cloud storage, pam_mount and etc. 31 | case "${mount#mount.}" in 32 | *fuse*|ecryptfs*|ddi|glusterfs|moosefs|crypt{,{,o}_LUKS}|rclone|sshfs) 33 | continue 34 | ;; 35 | esac 36 | 37 | add_binary "$mount" 38 | done 39 | fi 40 | } 41 | 42 | help() { 43 | cat </dev/null; then 24 | add_binary "fsck.$1" 25 | else 26 | return 1 27 | fi 28 | ;; 29 | esac 30 | } 31 | 32 | # fs_autodetect_failed is assigned in the autodetect hook 33 | # shellcheck disable=SC2154 34 | if (( ! fs_autodetect_failed )) && [[ -n "${rootfstype}${usrfstype}" ]]; then 35 | if [[ -n "$rootfstype" ]]; then 36 | add_fsck "$rootfstype" && (( ++added )) 37 | fi 38 | if [[ -n "$usrfstype" && "$usrfstype" != "$rootfstype" ]]; then 39 | add_fsck "$usrfstype" && (( ++added )) 40 | fi 41 | else 42 | for fsck in $(compgen -c fsck.); do 43 | add_fsck "${fsck#fsck.}" && (( ++added )) 44 | done 45 | fi 46 | 47 | if (( ! added )); then 48 | warning "No fsck helpers found. fsck will not be run on boot." 49 | return 50 | fi 51 | 52 | add_binary fsck 53 | } 54 | 55 | help() { 56 | cat < 5 || (major == 5 && minor >= 17) )); then 13 | add_checked_modules_from_symbol 'drm_privacy_screen_register' '=drivers/platform' 14 | fi 15 | } 16 | 17 | help() { 18 | cat </dev/null; then 39 | add_udev_rule '69-dm-lvm.rules' 40 | else 41 | add_udev_rule '/usr/lib/initcpio/udev/69-dm-lvm.rules' 42 | fi 43 | 44 | # config file 45 | sed -e 's/^[[:space:]#]*monitoring = [[:digit:]]\+\s*$/\tmonitoring = 0/' \ 46 | -e '/^$/d' -e '/^[[:space:]]*#/d' "/etc/lvm/lvm.conf" | add_file - '/etc/lvm/lvm.conf' 644 47 | } 48 | 49 | help() { 50 | cat </dev/null; then 19 | add_systemd_unit 'mdmon@.service' 20 | fi 21 | } 22 | 23 | help() { 24 | cat </dev/null; then 6 | echo 'amd' 7 | elif grep -aiq 'vendor_id.*intel' /proc/cpuinfo 2>/dev/null; then 8 | echo 'intel' 9 | fi 10 | } 11 | 12 | get_host_ucode() { 13 | local vendor="$1" family model stepping 14 | family="$(grep -am1 'cpu family' /proc/cpuinfo | sed 's/.*: //')" 15 | model="$(grep -am1 'model[[:space:]]*:' /proc/cpuinfo | sed 's/.*: //')" 16 | stepping="$(grep -am1 'stepping' /proc/cpuinfo | sed 's/.*: //')" 17 | 18 | case "$vendor" in 19 | amd) 20 | # 21 = 15h 21 | if (( family >= 21 )); then 22 | printf 'amd-ucode/microcode_amd_fam%xh.bin' "$family" 23 | else 24 | printf 'amd-ucode/microcode_amd.bin' 25 | fi 26 | ;; 27 | intel) 28 | printf 'intel-ucode/%02x-%02x-%02x' "$family" "$model" "$stepping" 29 | ;; 30 | esac 31 | } 32 | 33 | build() { 34 | local arch vendor fwpath ucode_file 35 | local vendors=(intel amd) 36 | local ucode_dest='/kernel/x86/microcode' 37 | local -A ucode_dir=([intel]=intel-ucode [amd]=amd-ucode) 38 | local -A ucode_img=([intel]=intel-ucode.img [amd]=amd-ucode.img) 39 | local -A ucode_bin=([intel]=GenuineIntel.bin [amd]=AuthenticAMD.bin) 40 | local -A ucode_glob=([intel]='??-??-??' [amd]='*.bin') 41 | local -a ucode_files 42 | 43 | arch="$(uname -m)" 44 | if [[ "$arch" != @(i?86|x86_64) ]]; then 45 | warning "architecture '%s' not supported, skipping hook" "$arch" 46 | return 47 | fi 48 | 49 | # mkinitcpio_autodetect is assigned in install/autodetect 50 | # shellcheck disable=SC2154 51 | if (( mkinitcpio_autodetect )); then 52 | vendor="$(get_host_vendor)" 53 | ucode_file="$(get_host_ucode "$vendor")" 54 | # _d_fwpath is assigned in mkinitcpio 55 | # shellcheck disable=SC2154 56 | for fwpath in "${_d_fwpath[@]}"; do 57 | if [[ -f "${fwpath}/${ucode_file}" ]]; then 58 | quiet "adding microcode file: '%s'" "${fwpath}/${ucode_file}" 59 | add_file_early "${fwpath}/${ucode_file}" "${ucode_dest}/${ucode_bin[$vendor]}" 644 60 | return 61 | fi 62 | done 63 | # if no host-specific microcode is found, don't continue and add all microcode 64 | return 65 | fi 66 | 67 | for vendor in "${vendors[@]}"; do 68 | # find the uncompiled update files and compile them 69 | # _d_fwpath is assigned in mkinitcpio 70 | # shellcheck disable=SC2154 71 | for fwpath in "${_d_fwpath[@]}"; do 72 | if [[ -e "${EARLYROOT}/${ucode_dest}/${ucode_bin[$vendor]}" ]]; then 73 | break 74 | fi 75 | if [[ ! -d "${fwpath}/${ucode_dir[$vendor]}" ]]; then 76 | continue 77 | fi 78 | mapfile -t ucode_files < <(LC_ALL=C.UTF-8 find "${fwpath}/${ucode_dir[$vendor]}" -maxdepth 1 -name "${ucode_glob[$vendor]}") 79 | if ! (( ${#ucode_files[@]} )); then 80 | continue 81 | fi 82 | quiet "adding microcode files: '%s'" "${ucode_files[*]}" 83 | cat "${ucode_files[@]}" | add_file_early - "${ucode_dest}/${ucode_bin[$vendor]}" 644 84 | break 85 | done 86 | 87 | # as a last resort, find and extract a precompiled image in /boot 88 | if [[ ! -e "${EARLYROOT}/${ucode_dest}/${ucode_bin[$vendor]}" && -r "/boot/${ucode_img[$vendor]}" ]]; then 89 | quiet "extracting precompiled microcode image: '/boot/%s'" "${ucode_img[$vendor]}" 90 | LC_ALL=C.UTF-8 bsdtar -xOf "/boot/${ucode_img[$vendor]}" "${ucode_dest#/}/${ucode_bin[$vendor]}" | \ 91 | add_file_early - "${ucode_dest}/${ucode_bin[$vendor]}" 644 92 | fi 93 | done 94 | } 95 | 96 | help() { 97 | cat </dev/null; then 10 | IFS=' .-~^' read -r _ systemd_ver _ < <(SYSTEMD_COLORS=0 systemctl --version) 11 | if (( systemd_ver >= 255 )); then 12 | add_binary /usr/lib/systemd/systemd-hibernate-resume 13 | fi 14 | fi 15 | 16 | add_runscript 17 | } 18 | 19 | help() { 20 | cat < cryptsetup-pre.target -> systemd-cryptsetup@.service -> cryptsetup.target 31 | add_systemd_unit 'cryptsetup-pre.target' 32 | add_symlink '/usr/lib/systemd/system/cryptsetup-pre.target.wants/pcscd.socket' '/usr/lib/systemd/system/pcscd.socket' 33 | add_symlink '/usr/lib/systemd/system/cryptsetup.target.wants/cryptsetup-pre.target' '/usr/lib/systemd/system/cryptsetup-pre.target' 34 | 35 | add_file '/usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist' 36 | add_binary '/usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/libccid.so' 37 | } 38 | 39 | help() { 40 | cat </dev/null; then 8 | add_binary kexec 9 | fi 10 | } 11 | 12 | help() { 13 | cat </dev/null | while read -r -d '' bin; do 8 | case $(file -bi "$bin") in 9 | *application/x-sharedlib*) 10 | # Libraries (.so) 11 | strip --strip-unneeded "$bin" 12 | ;; 13 | *application/x-archive*) 14 | # Libraries (.a) 15 | strip --strip-debug "$bin" 16 | ;; 17 | *application/x-executable*) 18 | # Binaries 19 | strip --strip-all "$bin" 20 | ;; 21 | *application/x-pie-executable*) 22 | # Binaries 23 | strip --strip-all "$bin" 24 | ;; 25 | *application/x-object*) 26 | # Kernel objects 27 | strip --strip-debug "$bin" 28 | ;; 29 | esac 30 | done 31 | } 32 | 33 | help() { 34 | cat < tpm2-util 130 | # kmod -> systemd-shared 131 | # qrencode -> bsod 132 | for LIB in kmod tss2-{esys,rc,mu,tcti-'*'} qrencode; do 133 | LC_ALL=C.UTF-8 find /usr/lib/ -maxdepth 1 -name "lib${LIB}.so*" | while read -r FILE; do 134 | if [[ -L "${FILE}" ]]; then 135 | add_symlink "${FILE}" 136 | else 137 | add_binary "${FILE}" 138 | fi 139 | done 140 | done 141 | 142 | add_symlink "/usr/lib/systemd/system/default.target" "initrd.target" 143 | add_symlink "/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target" 144 | 145 | printf '%s\n' \ 146 | 'passwd: files' \ 147 | 'group: files' \ 148 | 'shadow: files' \ 149 | | add_file - '/etc/nsswitch.conf' 0644 150 | 151 | printf 'root:x:0:0:root:/root:/bin/sh\n' | add_file - '/etc/passwd' 0644 152 | printf 'root:*:::::::\n' | add_file - '/etc/shadow' 0400 153 | getent group root audio disk input kmem kvm lp optical render sgx storage tty systemd-journal utmp uucp video | awk -F: ' { print $1 ":x:" $3 ":" }' | add_file - '/etc/group' 0644 154 | 155 | add_dir "/etc/modules-load.d" 156 | ( 157 | # FIXME: this should be a function in mkinitcpio 158 | # shellcheck disable=SC1091,SC2154 source=mkinitcpio.conf 159 | . "$_f_config" 160 | set -f 161 | printf '%s\n' "${MODULES[@]}" | add_file - '/etc/modules-load.d/MODULES.conf' 644 162 | ) 163 | 164 | [[ -f /etc/fstab.initramfs ]] && add_file "/etc/fstab.initramfs" "/etc/fstab" 165 | 166 | # Add default systemd tmpfiles, and tmpfile to copy stuff from .extra to /run/systemd 167 | add_file "/usr/lib/tmpfiles.d/systemd.conf" 168 | add_file "/usr/lib/tmpfiles.d/20-systemd-stub.conf" 169 | } 170 | 171 | help() { 172 | cat </dev/null <"$pkgbase_path"; then 30 | preset="/etc/mkinitcpio.d/${pkgbase}.preset" 31 | install_preset "$pkgbase" "$preset" 32 | fi 33 | done 34 | } 35 | 36 | remove_preset() { 37 | if [[ -n "$pkgbase" && -e "$preset" ]]; then 38 | if ! cmp "$preset" <(sed "s|%PKGBASE%|${pkgbase}|g" /usr/share/mkinitcpio/hook.preset) &>/dev/null; then 39 | if [[ ! -e "$preset.pacsave" ]]; then 40 | # save the preset as pacsave 41 | mv -- "$preset" "$preset.pacsave" && return 0 42 | fi 43 | else 44 | # remove the preset 45 | rm -- "$preset" && return 0 46 | fi 47 | fi 48 | } 49 | 50 | # is_kernelcopy checks whether a `*_kver` value from a .preset file is a 51 | # filename that the .preset expects us to copy the kernel file to. 52 | is_kernelcopy() { 53 | local preset_kver="$1" 54 | 55 | # Check that this is a filepath (e.g. "/boot/vmlinuz-${pkgbase}") rather 56 | # than a version number (e.g. "6.5.2-arch-1"). 57 | # 58 | # mkinitcpio:resolve_kernver() does this by checking whether the string 59 | # starts with a "/", so do the same check here. 60 | if [[ "${preset_kver}" != /* ]]; then 61 | return 1 62 | fi 63 | 64 | # Check that this isn't the filepath of the original 65 | # "/usr/lib/modules/${kver}-${pkgbase}/vmlinuz" file that we'd be copying 66 | # from... or really any other file that is actually owned by a package. 67 | if pacman -Qoq -- "${preset_kver}" &>/dev/null; then 68 | return 1 69 | fi 70 | 71 | return 0 72 | } 73 | 74 | read_preset() { 75 | local pkgbase="$1" p preset_image preset_uki preset_kver 76 | local unsorted_filelist=() unsorted_kernellist=() 77 | 78 | if [[ -v PRESETS ]]; then 79 | for p in "${PRESETS[@]}"; do 80 | declare -n preset_image="${p}_image" preset_uki="${p}_uki" preset_kver="${p}_kver" 81 | 82 | if [[ -v preset_image ]]; then 83 | unsorted_filelist+=("${preset_image}") 84 | elif [[ -v ALL_image ]]; then 85 | unsorted_filelist+=("${ALL_image}") 86 | fi 87 | if [[ -v preset_uki ]]; then 88 | unsorted_filelist+=("${preset_uki}") 89 | elif [[ -v ALL_uki ]]; then 90 | unsorted_filelist+=("${ALL_uki}") 91 | fi 92 | if [[ -v preset_kver ]]; then 93 | if is_kernelcopy "${preset_kver}"; then 94 | unsorted_filelist+=("${preset_kver}") 95 | fi 96 | unsorted_kernellist+=("${preset_kver}") 97 | elif [[ -v ALL_kver ]]; then 98 | if is_kernelcopy "${ALL_kver}"; then 99 | unsorted_filelist+=("${ALL_kver}") 100 | fi 101 | unsorted_kernellist+=("${ALL_kver}") 102 | fi 103 | done 104 | else 105 | unsorted_filelist+=("/boot/vmlinuz-${pkgbase}" 106 | "/boot/initramfs-${pkgbase}.img" 107 | "/boot/initramfs-${pkgbase}-fallback.img" 108 | "/efi/EFI/Linux/arch-${pkgbase}.efi" 109 | "/efi/EFI/Linux/arch-${pkgbase}-fallback.efi") 110 | unsorted_kernellist+=("/boot/vmlinuz-${pkgbase}") 111 | fi 112 | 113 | # Deduplicate file lists 114 | filelist=() 115 | while IFS='' read -r -d '' arrayelement; do 116 | filelist+=("$arrayelement") 117 | done < <(printf '%s\0' "${unsorted_filelist[@]}" | LC_ALL=C.UTF-8 sort -uz) 118 | kernellist=() 119 | while IFS='' read -r -d '' arrayelement; do 120 | kernellist+=("$arrayelement") 121 | done < <(printf '%s\0' "${unsorted_kernellist[@]}" | LC_ALL=C.UTF-8 sort -uz) 122 | } 123 | 124 | install_kernel() { 125 | local pkgbase="$1" 126 | local kernel preset="/etc/mkinitcpio.d/${pkgbase}.preset" 127 | 128 | install_preset "$pkgbase" "$preset" 129 | ( 130 | # source the preset to get the kernel and image locations 131 | # shellcheck disable=SC1090 132 | [[ -s "$preset" ]] && . "$preset" 133 | read_preset "$pkgbase" 134 | 135 | # always install the kernel 136 | for kernel in "${kernellist[@]}"; do 137 | if is_kernelcopy "${kernel}"; then 138 | install -Dm644 -- "${line}" "${kernel}" 139 | fi 140 | done 141 | ) 142 | 143 | add_pkgbase_to_args "$pkgbase" 144 | } 145 | 146 | remove_kernel() { 147 | local pkgbase="$1" 148 | local preset="/etc/mkinitcpio.d/${pkgbase}.preset" 149 | 150 | # subshell to avoid namespace pollution 151 | ( 152 | # source the preset to get the kernel and image locations 153 | # shellcheck disable=SC1090 154 | [[ -s "$preset" ]] && . "$preset" 155 | read_preset "$pkgbase" 156 | 157 | # access all the files to trigger any potential automounts 158 | stat -- /boot/ /efi/ "${filelist[@]}" &>/dev/null || : 159 | 160 | # remove the actual kernel and images for the package being removed 161 | rm -f -- "${filelist[@]}" 162 | ) || return 163 | # remove the preset 164 | remove_preset "$pkgbase" "$preset" 165 | } 166 | 167 | add_pkgbase_to_args() { 168 | local pkgbase="$1" 169 | 170 | # do not add the same pkgbase twice 171 | # shellcheck disable=SC2076 172 | if [[ " ${args[*]} " =~ " -p ${pkgbase} " ]]; then 173 | return 0 174 | fi 175 | 176 | # compound args for each kernel 177 | args+=(-p "$pkgbase") 178 | } 179 | 180 | while read -r line; do 181 | if [[ "${line%%-git}" == "mkinitcpio" && "$1" == "install" ]]; then 182 | # generate presets for each kernel on package install 183 | generate_presets 184 | package=1 185 | continue 186 | fi 187 | 188 | if [[ "$line" != */vmlinuz && "$line" != 'usr/lib/modules/'*'/extramodules/' ]]; then 189 | # triggers when it's a change other than to the kernel and its modules 190 | package=1 191 | continue 192 | fi 193 | 194 | if [[ "$line" == 'usr/lib/modules/'*'/extramodules/' ]]; then 195 | line="${line%/extramodules/}" 196 | extramodules=1 197 | else 198 | extramodules=0 199 | fi 200 | 201 | if ! read -r pkgbase &>/dev/null <"${line%/vmlinuz}/pkgbase"; then 202 | # if the kernel has no pkgbase, we skip it 203 | continue 204 | fi 205 | 206 | case "$1" in 207 | install) 208 | if (( extramodules )); then 209 | add_pkgbase_to_args "$pkgbase" 210 | continue 211 | fi 212 | install_kernel "$pkgbase" 213 | ;; 214 | remove) remove_kernel "$pkgbase" ;; 215 | esac 216 | done 217 | 218 | if (( package )) && compgen -G /etc/mkinitcpio.d/"*.preset" > /dev/null; then 219 | case "$1" in 220 | install) 221 | # change to use all presets 222 | args=(-P) 223 | ;; 224 | remove) 225 | shopt -s nullglob 226 | for preset in /etc/mkinitcpio.d/*.preset; do 227 | pkgbase=${preset##*/} 228 | pkgbase=${pkgbase%.preset} 229 | remove_preset "$pkgbase" "$preset" 230 | done 231 | shopt -u nullglob 232 | ;; 233 | esac 234 | fi 235 | 236 | if [[ "$1" == "install" ]] && (( ${#args[@]} )); then 237 | mkinitcpio "${args[@]}" 238 | fi 239 | -------------------------------------------------------------------------------- /lsinitcpio: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | # 4 | # lsinitcpio - dump the contents of an initramfs image 5 | # 6 | 7 | shopt -s extglob 8 | 9 | _list='--list' 10 | _optcolor=1 11 | if (( MESON_TEST )); then 12 | _f_functions='./functions' 13 | else 14 | _f_functions='@INITCPIO_LIBDIR@/functions' 15 | fi 16 | 17 | declare -A bsdcpio_options=( 18 | [list]='--list' 19 | [input]='-i' 20 | [quiet]='--quiet' 21 | ) 22 | 23 | usage() { 24 | cat < 27 | 28 | Actions: 29 | -a, --analyze analyze contents of image 30 | -c, --config show configuration file image was built with 31 | -l, --list list contents of the image (default) 32 | -x, --extract extract image to disk 33 | 34 | Options: 35 | -h, --help display this help 36 | -n, --nocolor disable colorized output 37 | -V, --version display version information 38 | -v, --verbose more verbose output 39 | --cpio list or extract only the main CPIO image 40 | --early list or extract only the early CPIO image 41 | 42 | USAGE 43 | } 44 | 45 | version() { 46 | cat < 0 )); then 54 | dd if="$image" skip=$((offset / 512)) 2>/dev/null | ${_compress:-cat} ${_compress:+-cd} 55 | else 56 | ${_compress:-cat} ${_compress:+-cd} "$image" 57 | fi 58 | } 59 | 60 | unpack_uki() { 61 | local image="$1" workdir="$2" 62 | 63 | command -v objcopy &>/dev/null || die "Unable to unpack UKI: missing 'objcopy'" 64 | 65 | objcopy \ 66 | --dump-section .initrd="$workdir"/initcpio.img \ 67 | --dump-section .cmdline="$workdir"/cmdline.txt \ 68 | --dump-section .osrel="$workdir"/os-release.txt \ 69 | --dump-section .uname="$workdir"/uname.txt \ 70 | "$image" /dev/null 2>/dev/null 71 | printf '%s/initcpio.img' "$workdir" 72 | } 73 | 74 | # shellcheck source=functions 75 | . "$_f_functions" 76 | 77 | # override the die method from functions 78 | die() { 79 | error "$@" 80 | exit 1 81 | } 82 | 83 | size_to_human() { 84 | awk -v size="$1" ' 85 | BEGIN { 86 | suffix[1] = "B" 87 | suffix[2] = "KiB" 88 | suffix[3] = "MiB" 89 | suffix[4] = "GiB" 90 | suffix[5] = "TiB" 91 | count = 1 92 | 93 | while (size > 1024) { 94 | size /= 1024 95 | count++ 96 | } 97 | 98 | sizestr = sprintf("%.2f", size) 99 | sub(/\.?0+$/, "", sizestr) 100 | printf("%s %s", sizestr, suffix[count]) 101 | }' 102 | } 103 | 104 | detect_filetype() { 105 | local file="$1" offset="$2" bytes 106 | 107 | bytes="$(od -An -t x1 -N6 -j "$offset" "$file" | tr -dc '[:alnum:]')" 108 | 109 | case $bytes in 110 | '303730373031') 111 | # no compression 112 | echo 113 | return 114 | ;; 115 | esac 116 | 117 | compression="$(detect_compression "$file" "$offset")" 118 | 119 | if [[ -n "$compression" ]]; then 120 | echo "$compression" 121 | return 122 | fi 123 | 124 | # still nothing? hrmm, maybe the user goofed and it's a kernel 125 | if kver "$1" >/dev/null; then 126 | die "'%s' is a kernel image, not an initramfs image!" "$file" 127 | fi 128 | 129 | # out of ideas, we're done here. 130 | die "Unexpected file type. Are you sure '%s' is an initramfs?" "$file" 131 | } 132 | 133 | detect_uki() { 134 | local file="$1" bytes 135 | 136 | IFS='' read -r -n 2 -d '' bytes < "$file" 137 | 138 | if [[ "$bytes" = "MZ" ]]; then 139 | return 0 140 | fi 141 | return 1 142 | } 143 | 144 | detect_early_img() { 145 | local -i early=0 146 | # early cpio archives can have a file called early_cpio in them 147 | early="$(LC_ALL=C.UTF-8 bsdtar -xOf "$1" early_cpio 2>/dev/null)" 148 | if [[ -z "$early" ]]; then 149 | # but not all do 150 | if LC_ALL=C.UTF-8 bsdtar -tf "$1" 'kernel/*/microcode/*.bin' &>/dev/null; then 151 | early=1 152 | fi 153 | fi 154 | printf '%d' "$early" 155 | } 156 | 157 | skip_early_img() { 158 | local -i offset 159 | local bytes 160 | 161 | # find last entry of the early cpio archive, marked by an entry with the name TRAILER!!! 162 | offset="$(grep -Fabom1 'TRAILER!!!' "$1" | cut -d: -f1)" || return 1 163 | 164 | # skip past the TRAILER!!! (10 chars) and to the next multiple of 512 bytes 165 | # we can do this in blocks of 512 because bsdtar/bsdcpio use blocksizes that are a multiple of 512 166 | offset="$(awk -v offset="$offset" ' 167 | function ceil(v) { 168 | return (v == int(v)) ? v : int(v)+1 169 | } 170 | BEGIN { 171 | offset += 10 172 | printf "%d", ceil(offset / 512) * 512 173 | }')" 174 | 175 | 176 | # read a byte, check if it's NUL 177 | # if it's not, we've made it through the NULs 178 | # otherwise, skip ahead to the start of the next block and repeat 179 | bytes="$(od -An -t x1 -N1 -j "$offset" "$1" | tr -dc '[:alnum:]')" || return 1 180 | until [[ "$bytes" != '00' ]]; do 181 | offset=$(( offset + 512 )) 182 | bytes="$(od -An -t x1 -N1 -j "$offset" "$1" | tr -dc '[:alnum:]')" || return 1 183 | done 184 | printf '%d' "$offset" 185 | } 186 | 187 | analyze_image() { 188 | local -a binaries explicitmod modules imagename 189 | local kernver ratio columns image="$1" optimage="$2" offset="$3" workdir="$4" 190 | columns="$(tput cols)" 191 | 192 | # fallback in case tput failed us 193 | columns="${columns:-80}" 194 | 195 | # instead of reading the size from the inode, insist on reading the entire 196 | # image to ensure that it's in the cache when we decompress. This avoids 197 | # variance in timing and makes the time spent reading from storage roughly 198 | # constant. 199 | zsize="$(dd if="$image" skip=$((offset / 512)) 2>/dev/null | wc -c)" 200 | 201 | # calculate compression ratio 202 | if [[ -n "$_compress" ]]; then 203 | decomptime="$(TIMEFORMAT=%R; { time decomp "$image" "$offset" >/dev/null; } 2>&1)" 204 | fullsize="$(decomp "$image" "$offset" | wc -c)" 205 | ratio=".$(( zsize * 1000 / fullsize % 1000 ))" 206 | fi 207 | 208 | # decompress the image since we need to read from it multiple times. 209 | install -dm755 "$workdir/initcpio" 210 | if (( offset > 0 )); then 211 | bsdtar -C "$workdir/initcpio" -xf "$image" || die 'Failed to decompress early cpio' 212 | fi 213 | decomp "$image" "$offset" | bsdtar -C "$workdir/initcpio" -xf - || die 'Failed to decompress image' 214 | 215 | 216 | shopt -s globstar nullglob 217 | modules=("$workdir/initcpio/usr/lib/modules"/*/{kernel/**,extramodules}/*.ko*) 218 | IFS=/ read -r _ _ _ kernver _ <<<"${modules[0]#$workdir/initcpio/}" 219 | shopt -u globstar nullglob 220 | 221 | mapfile -t binaries < <(LC_ALL=C.UTF-8 find "$workdir/initcpio/usr/bin" -type f -printf %f\\n) 222 | 223 | read -r version <"$workdir/initcpio/VERSION" 224 | 225 | # shellcheck disable=SC1090,SC1091 226 | . "$workdir/initcpio/config" 227 | 228 | # MODULES in /config is a string 229 | # shellcheck disable=SC2128 230 | read -ra explicitmod <<<"$MODULES" 231 | 232 | # print results 233 | imagename=("$optimage") 234 | [[ -L "$optimage" ]] && imagename+=(" -> $(readlink -e "$optimage")") 235 | msg 'Image: %s%s' "${imagename[@]}" 236 | [[ -n "$version" ]] && msg 'Created with mkinitcpio %s' "$version" 237 | msg 'Kernel: %s' "${kernver:-unknown}" 238 | [[ -f "$workdir"/uname.txt ]] && msg 'uname: %s' "$(tr -d '\0' < "$workdir"/uname.txt)" 239 | if [[ -f "$workdir"/os-release.txt ]]; then 240 | ( 241 | unset -v PRETTY_NAME NAME ID VERSION_ID BUILD_ID 242 | # shellcheck disable=SC1091 243 | . "$workdir"/os-release.txt 244 | msg 'OS Release: %s (%s %s)' "${PRETTY_NAME:-${NAME:-linux}}" \ 245 | "${ID:-linux}" "${VERSION_ID:-${BUILD_ID:-rolling}}" 246 | ) 247 | fi 248 | [[ -f "$workdir"/cmdline.txt ]] && msg 'Command line: %s' "$(tr -d '\0' < "$workdir"/cmdline.txt)" 249 | if (( offset > 0 )); then 250 | # the zero-indexed offset of the main image is the same as the size of the early image 251 | msg 'Early CPIO: %s' "$(size_to_human "$offset")" 252 | else 253 | msg 'Early CPIO: none' 254 | fi 255 | msg 'Size: %s' "$(size_to_human "$zsize")" 256 | 257 | if [[ -n "$_compress" ]]; then 258 | msg 'Compressed with: %s' "$_compress" 259 | msg2 'Uncompressed size: %s (%s ratio)' "$(size_to_human "$fullsize")" "$ratio" 260 | msg2 'Estimated decompression time: %ss' "$decomptime" 261 | fi 262 | printf '\n' 263 | 264 | if (( ${#modules[@]} )); then 265 | modules=("${modules[@]##*/}") 266 | modules=("${modules[@]%.ko*}") 267 | msg 'Included modules (%d):' "${#modules[@]}" 268 | for mod in "${modules[@]}"; do 269 | printf ' %s' "$mod" 270 | in_array "${mod//_/-}" "${explicitmod[@]//_/-}" && printf ' [explicit]' 271 | printf '\n' 272 | done | LC_ALL=C.UTF-8 sort | column -c"${columns}" 273 | printf '\n' 274 | fi 275 | 276 | msg 'Included binaries (%d):' "${#binaries[@]}" 277 | printf ' %s\n' "${binaries[@]}" | LC_ALL=C.UTF-8 sort | column -c"${columns}" 278 | printf '\n' 279 | 280 | if [[ -n "$EARLYHOOKS" ]]; then 281 | msg 'Early hook run order:' 282 | printf ' %s\n' "$EARLYHOOKS" 283 | printf '\n' 284 | fi 285 | 286 | # shellcheck disable=SC2128 287 | if [[ -n "$HOOKS" ]]; then 288 | msg 'Hook run order:' 289 | printf ' %s\n' "$HOOKS" 290 | printf '\n' 291 | fi 292 | 293 | if [[ -n "$LATEHOOKS" ]]; then 294 | msg 'Late hook run order:' 295 | printf ' %s\n' "$LATEHOOKS" 296 | printf '\n' 297 | fi 298 | 299 | if [[ -n "$CLEANUPHOOKS" ]]; then 300 | msg 'Cleanup hook run order:' 301 | printf ' %s\n' "$CLEANUPHOOKS" 302 | printf '\n' 303 | fi 304 | 305 | if [[ -n "$EMERGENCYHOOKS" ]]; then 306 | msg 'Emergency hook run order:' 307 | printf ' %s\n' "$EMERGENCYHOOKS" 308 | printf '\n' 309 | fi 310 | } 311 | 312 | _opt_short='achlnVvx' 313 | _opt_long=('analyze' 'config' 'cpio' 'early' 'help' 'list' 'nocolor' 'version' 'verbose' 'extract') 314 | 315 | parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 316 | set -- "${OPTRET[@]}" 317 | unset _opt_short _opt_long OPTRET 318 | 319 | while :; do 320 | case $1 in 321 | -a | --analyze) 322 | _optanalyze=1 323 | ;; 324 | -c | --config) 325 | _optshowconfig=1 326 | ;; 327 | --cpio) 328 | _optcpio=1 329 | ;; 330 | --early) 331 | _optearly=1 332 | ;; 333 | -h | --help) 334 | usage 335 | exit 0 336 | ;; 337 | -l | --list) 338 | _optlistcontents=1 339 | ;; 340 | -n | --nocolor) 341 | _optcolor=0 342 | ;; 343 | -V | --version) 344 | version 345 | exit 0 346 | ;; 347 | -v | --verbose) 348 | bsdcpio_options['verbose']='--verbose' 349 | ;; 350 | -x | --extract) 351 | unset 'bsdcpio_options[list]' 352 | ;; 353 | --) 354 | shift 355 | break 2 356 | ;; 357 | esac 358 | shift 359 | done 360 | 361 | _optimage="$1" 362 | _image="$_optimage" 363 | 364 | if [[ -t 1 ]] && (( _optcolor )); then 365 | try_enable_color 366 | fi 367 | 368 | [[ -n "$_image" ]] || die 'No image specified (use -h for help)' 369 | [[ -f "$_image" ]] || die "No such file: '%s'" "$_image" 370 | [[ -r "$_image" ]] || die "Unable to read file: '%s'" "$_image" 371 | 372 | case $(( _optanalyze + _optlistcontents + _optshowconfig )) in 373 | 0) 374 | # default action when none specified 375 | _optlistcontents=1 376 | ;; 377 | [!1]) 378 | die "Only one action may be specified at a time" 379 | ;; 380 | esac 381 | 382 | case $(( _optearly + _optcpio )) in 383 | 0) 384 | # default to listing/extracting both images 385 | _optearly=1 386 | _optcpio=1 387 | ;; 388 | # if == 1, only early or main cpio will be extracted/listed 389 | # if >1, same as 0 390 | esac 391 | 392 | _workdir="$(mktemp -d --tmpdir lsinitcpio.XXXXXX)" 393 | trap 'rm -rf "$_workdir"' EXIT 394 | 395 | if detect_uki "$_image"; then 396 | _image="$(unpack_uki "$_image" "$_workdir")" || die "Failed to unpack file as UKI: '%s'" "$_optimage" 397 | [[ -f "$_image" ]] || die "File does not contain initcpio image: '%s'" "$_optimage" 398 | fi 399 | 400 | if (( $(detect_early_img "$_image") )); then 401 | _offset="$(skip_early_img "$_image")" 402 | else 403 | _offset=0 404 | _optearly=0 405 | fi 406 | 407 | # read compression type of the cpio image 408 | _compress="$(detect_filetype "$_image" "$_offset")" || exit 409 | 410 | if (( _optanalyze )); then 411 | analyze_image "$_image" "$_optimage" "$_offset" "$_workdir" 412 | elif (( _optshowconfig )); then 413 | decomp "$_image" "$_offset" | bsdtar xOf - buildconfig 2>/dev/null || 414 | die 'Failed to extract config from image (mkinitcpio too old?)' 415 | else 416 | if (( _optearly )); then 417 | bsdcpio "${bsdcpio_options[@]}" <"$_image" 418 | fi 419 | if (( _optcpio )); then 420 | decomp "$_image" "$_offset" | bsdcpio "${bsdcpio_options[@]}" 421 | fi 422 | fi 423 | 424 | # vim: set ft=sh ts=4 sw=4 et: 425 | -------------------------------------------------------------------------------- /man/lsinitcpio.1.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | vim:set ts=4 sw=4 syntax=asciidoc noet: 3 | SPDX-License-Identifier: GPL-2.0-only 4 | //// 5 | :doctype: manpage 6 | :manmanual: mkinitcpio manual 7 | :mansource: mkinitcpio @VERSION@ 8 | :manversion: mkinitcpio @VERSION@ 9 | 10 | = lsinitcpio(1) 11 | 12 | 13 | == Name 14 | 15 | lsinitcpio - Examine an initramfs 16 | 17 | == Synopsis 18 | 19 | _lsinitcpio_ [action] [options] _image_ 20 | 21 | == Description 22 | 23 | Examines the contents of an initcpio image. Without any options, _lsinitcpio_ 24 | simply lists the contents of an image. 25 | 26 | == Actions 27 | 28 | *-a*, *--analyze*:: 29 | Analyze the contents of the specified image and print output in human 30 | readable form. 31 | 32 | *-c*, *--config*:: 33 | Show the configuration file the given image was built with. 34 | 35 | *-l*, *--list*:: 36 | List the contents of the archive. This is the default action. Pass the *-v* 37 | flag for more detailed results. 38 | 39 | *-x*, *--extract*:: 40 | Extract the given image to the current working directory. 41 | 42 | == Options 43 | 44 | *-h*, *--help*:: 45 | Output a short overview of available command-line switches. 46 | 47 | *-n*, *--nocolor*:: 48 | Disable color output. 49 | 50 | *-V*, *--version*:: 51 | Display version information. 52 | 53 | *-v*, *--verbose*:: 54 | Be more verbose. In particular, show long style output when listing 55 | the contents of an image, and show files as they are extracted when 56 | the *-x* option is given. 57 | 58 | *--cpio*:: 59 | List or extract only the main CPIO image. 60 | 61 | *--early*:: 62 | List or extract only the early CPIO image if it exists. See *mkinitcpio(8)* 63 | for more information about early CPIO images. 64 | 65 | == Bugs 66 | 67 | Upon writing this man page, there were no noticeable bugs present. Please visit 68 | https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues for an 69 | up to date list. 70 | 71 | == See also 72 | 73 | *mkinitcpio*(8) 74 | 75 | == Authors 76 | 77 | mkinitcpio is maintained by the Arch Linux community. Refer to the _AUTHORS_ 78 | file for a full list of contributors. 79 | 80 | == Copyright 81 | 82 | Copyright 🄯 mkinitcpio contributors. GPL-2.0-only. 83 | -------------------------------------------------------------------------------- /man/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | if not want_docs 4 | subdir_done() 5 | endif 6 | 7 | fs = import('fs') 8 | 9 | manpages = [ 10 | 'lsinitcpio.1', 11 | 'mkinitcpio.conf.5', 12 | 'mkinitcpio.8', 13 | ] 14 | 15 | asciidoctor = find_program('asciidoctor', required: false) 16 | if asciidoctor.found() 17 | else 18 | a2x = find_program('a2x', required: false) 19 | endif 20 | 21 | # support pregenerated (but still with @macros@) manpages 22 | # and generating from adoc at configure-time 23 | foreach page : manpages 24 | meson.add_dist_script('../tools/dist.sh', 'gen-doc', page + '.adoc') 25 | 26 | if fs.is_file(page) 27 | mp = configure_file( 28 | configuration: conf_data, 29 | input: page, 30 | output: page, 31 | ) 32 | else 33 | adoc = configure_file( 34 | configuration: conf_data, 35 | input: page + '.adoc', 36 | output: page + '.adoc', 37 | ) 38 | if asciidoctor.found() 39 | mp = configure_file( 40 | input: adoc, 41 | output: page, 42 | command: [asciidoctor, '-b', 'manpage', adoc], 43 | ) 44 | elif a2x.found() 45 | mp = configure_file( 46 | input: adoc, 47 | output: page, 48 | command: [a2x, '-f', 'manpage', adoc], 49 | ) 50 | endif 51 | endif 52 | 53 | install_man(mp) 54 | endforeach 55 | -------------------------------------------------------------------------------- /man/mkinitcpio.conf.5.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | vim:set ts=4 sw=4 syntax=asciidoc noet: 3 | SPDX-License-Identifier: GPL-2.0-only 4 | //// 5 | :doctype: manpage 6 | :manmanual: mkinitcpio manual 7 | :mansource: mkinitcpio @VERSION@ 8 | :manversion: mkinitcpio @VERSION@ 9 | 10 | = mkinitcpio.conf(5) 11 | 12 | == Name 13 | 14 | mkinitcpio.conf - mkinitcpio configuration file 15 | 16 | == Synopsis 17 | 18 | _@SYSCONFDIR@/mkinitcpio.conf_ 19 | 20 | == Description 21 | 22 | mkinitcpio will attempt to read from a configuration file each time it is 23 | invoked, _@SYSCONFDIR@/mkinitcpio.conf_ by default. This file defines several variables 24 | which describe the contents of the image to be generated. In addition to the "main" 25 | configuration file, drop-in configuration snippets are read 26 | from _@SYSCONFDIR@/mkinitcpio.conf.d/*.conf_. These drop-ins have higher precedence and 27 | override the main configuration file. 28 | 29 | == Variables 30 | 31 | *MODULES*:: 32 | Defines an array of additional modules which should be added to the image. 33 | Dependencies (including other modules and necessary firmware), will also be 34 | added to the image. At runtime, the modules in this array which were 35 | successfully added to the image will be explicitly loaded. 36 | 37 | *FILES*:: 38 | Defines an array of additional files which should be added to the image. 39 | Files are added as is, and parent directories will be added if needed. Files 40 | specified in this variable will override previously added files of the same 41 | path. 42 | 43 | *BINARIES*:: 44 | Defines an array of additional binaries which should be added to the 45 | image. These are assumed to be dynamic ELF binaries, and necessary shared 46 | library dependencies will automatically be added. However, it is not 47 | considered an error to specify a non-ELF binary in this variable. Parent 48 | directories will be added if needed. Files specified in this variable will 49 | override previously added files of the same path. 50 | 51 | *HOOKS*:: 52 | Defines an array of hooks which will be run during the build process. 53 | Order is important, as it defines the order in which hooks will be run 54 | during bootup. Use mkinitcpio's *-L* flag to list all available hooks, 55 | and the *-H* flag to display the help text for a specific hook. 56 | 57 | *COMPRESSION*:: 58 | Defines a program to filter the generated image through. The kernel 59 | understands the compression formats yielded by the *zstd*(1), *gzip*(1), 60 | *bzip2*(1), *lz4*(1), *lzop*(1), *lzma*(1), and *xz*(1) compressors. If 61 | unspecified, this setting defaults to _zstd_ compression for Linux ≥ 5.9 and 62 | gzip compression for Linux < 5.9. In order to create an uncompressed image, 63 | define this variable as _cat_. 64 | + 65 | It is not hard to realize that a filter such as a _tac_ or _rev_ will cause 66 | *mkinitcpio* to report success but generate a useless image. Similarly, 67 | using a compression program not listed above may generate an equally useless 68 | image, despite being "valid". 69 | 70 | *COMPRESSION_OPTIONS*:: 71 | Defines an array of additional options to be passed to the compression 72 | program. This option is generally not used. It can be potentially dangerous 73 | and may cause invalid images to be generated without any sign of an error. 74 | 75 | *MODULES_DECOMPRESS*:: 76 | Switch (_yes_/_no_) to decide whether loadable kernel modules and their 77 | firmware should remain compressed or be uncompressed during initramfs 78 | creation. Disabled by default to avoid recompressing the files using a lower 79 | compression and to reduce RAM usage during early boot. Enable to allow 80 | further decreasing image size when using high compression (e.g. 81 | *xz -9e* or *zstd --long --ultra -22*) at the expense of increased RAM usage 82 | at early boot. 83 | + 84 | Note that any compressed files will be placed in the uncompressed early CPIO 85 | to avoid double compression. 86 | 87 | == See also 88 | 89 | *mkinitcpio*(8) 90 | 91 | == Authors 92 | 93 | mkinitcpio is maintained by the Arch Linux community. Refer to the _AUTHORS_ 94 | file for a full list of contributors. 95 | 96 | == Copyright 97 | 98 | Copyright 🄯 mkinitcpio contributors. GPL-2.0-only. 99 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | project( 4 | 'mkinitcpio', 5 | version: run_command('tools/dist.sh', 'get-version', check: true).stdout().strip(), 6 | license: 'GPL-2.0-only', 7 | license_files: 'LICENSE', 8 | meson_version: '>=1.4.0', 9 | default_options: [ 10 | 'prefix=/usr/local', 11 | 'sysconfdir=/etc', 12 | ] 13 | ) 14 | 15 | meson.add_dist_script('tools/dist.sh', 'dist-version', meson.project_version()) 16 | 17 | project_source_root = meson.current_source_dir() 18 | project_build_root = meson.current_build_dir() 19 | prefixdir = get_option('prefix') 20 | bindir = prefixdir / get_option('bindir') 21 | libdir = prefixdir / get_option('libdir') 22 | sysconfdir = prefixdir / get_option('sysconfdir') 23 | mandir = prefixdir / get_option('mandir') 24 | datadir = prefixdir / get_option('datadir') 25 | bashcompletiondir = datadir / 'bash-completion' / 'completions' 26 | zshcompletiondir = datadir / 'zsh' / 'site-functions' 27 | 28 | initcpio_libdir = libdir / 'initcpio' 29 | initcpio_sysconfdir = sysconfdir / 'initcpio' 30 | 31 | want_systemd = get_option('systemd') 32 | want_kernel_install = get_option('kernel_install') 33 | want_alpm = get_option('alpm') 34 | want_presets = get_option('presets') 35 | want_docs = get_option('docs') 36 | vconsole_conf = get_option('vconsole_conf') 37 | 38 | conf_data = configuration_data({ 39 | 'VERSION': meson.project_version(), 40 | 'BINDIR': bindir, 41 | 'SYSCONFDIR': sysconfdir, 42 | 'INITCPIO_LIBDIR': initcpio_libdir, 43 | 'INITCPIO_SYSCONFDIR': initcpio_sysconfdir, 44 | 'VCONSOLE_CONF': sysconfdir / vconsole_conf, 45 | }) 46 | 47 | systemd = dependency('systemd', method: 'pkg-config', required: want_systemd) 48 | 49 | if systemd.found() 50 | systemd_util_dir = systemd.get_variable('systemd_util_dir') 51 | systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir') 52 | tmpfiles_dir = systemd.get_variable('tmpfiles_dir') 53 | 54 | udevd_dirs = [systemd_util_dir] 55 | else 56 | tmpfiles_dir = libdir / 'tmpfiles.d' 57 | 58 | udevd_dirs = [] 59 | endif 60 | 61 | udevd = find_program('systemd-udevd', 'udevd', dirs: udevd_dirs, required: true) 62 | tmpfiles = find_program('systemd-tmpfiles', required: want_systemd) 63 | shellcheck = find_program('shellcheck', required: false) 64 | 65 | conf_data.set('UDEVD_PATH', udevd.full_path()) 66 | if want_systemd.enabled() 67 | conf_data.set('TMPFILES_PATH', tmpfiles.full_path()) 68 | else 69 | conf_data.set('TMPFILES_PATH', '') 70 | endif 71 | 72 | configure_file( 73 | input: 'mkinitcpio', 74 | output: 'mkinitcpio', 75 | configuration: conf_data, 76 | install_dir: bindir, 77 | install_mode: 'rwxr-xr-x', 78 | ) 79 | 80 | configure_file( 81 | input: 'lsinitcpio', 82 | output: 'lsinitcpio', 83 | configuration: conf_data, 84 | install_dir: bindir, 85 | install_mode: 'rwxr-xr-x', 86 | ) 87 | 88 | configure_file( 89 | input: 'mkinitcpio.conf', 90 | output: 'mkinitcpio.conf', 91 | configuration: conf_data, 92 | install_dir: sysconfdir, 93 | ) 94 | 95 | configure_file( 96 | input: 'functions', 97 | output: 'functions', 98 | configuration: conf_data, 99 | install_dir: initcpio_libdir, 100 | install_mode: 'rwxr-xr-x', 101 | ) 102 | 103 | init_files = [ 104 | 'init', 105 | 'init_functions', 106 | 'shutdown', 107 | ] 108 | 109 | foreach f: init_files 110 | configure_file( 111 | input: f, 112 | output: f, 113 | configuration: conf_data, 114 | install_dir: initcpio_libdir, 115 | ) 116 | endforeach 117 | 118 | empty_dirs = [ 119 | initcpio_sysconfdir / 'hooks', 120 | initcpio_sysconfdir / 'install', 121 | initcpio_sysconfdir / 'post', 122 | sysconfdir / 'mkinitcpio.conf.d', 123 | sysconfdir / 'mkinitcpio.d', 124 | initcpio_libdir / 'post', 125 | ] 126 | 127 | foreach dir: empty_dirs 128 | install_emptydir(dir) 129 | endforeach 130 | 131 | shellcheck_files = [ 132 | 'functions', 133 | 'hooks/consolefont', 134 | 'hooks/encrypt', 135 | 'hooks/keymap', 136 | 'hooks/memdisk', 137 | 'hooks/resume', 138 | 'hooks/shutdown', 139 | 'hooks/sleep', 140 | 'hooks/udev', 141 | 'hooks/usr', 142 | 'init', 143 | 'init_functions', 144 | 'install/acpi_override', 145 | 'install/autodetect', 146 | 'install/base', 147 | 'install/block', 148 | 'install/consolefont', 149 | 'install/encrypt', 150 | 'install/filesystems', 151 | 'install/fsck', 152 | 'install/hostdata', 153 | 'install/keyboard', 154 | 'install/keymap', 155 | 'install/kms', 156 | 'install/lvm2', 157 | 'install/mdadm_udev', 158 | 'install/memdisk', 159 | 'install/microcode', 160 | 'install/modconf', 161 | 'install/resume', 162 | 'install/sd-encrypt', 163 | 'install/sd-encrypt-opensc', 164 | 'install/sd-shutdown', 165 | 'install/sd-vconsole', 166 | 'install/shutdown', 167 | 'install/sleep', 168 | 'install/strip', 169 | 'install/systemd', 170 | 'install/udev', 171 | 'install/usr', 172 | 'lsinitcpio', 173 | 'mkinitcpio', 174 | 'shell/bash-completion', 175 | 'shutdown', 176 | 'test/cases/bash-completion.bats', 177 | 'test/cases/extglob.bats', 178 | 'test/cases/functions.bats', 179 | 'test/cases/mkinitcpio.bats', 180 | 'test/cases/parse_cmdline.bats', 181 | 'test/cases/zsh-completion.bats', 182 | 'test/helpers/common.bash', 183 | ] 184 | 185 | if shellcheck.found() 186 | test( 187 | 'shellcheck', 188 | shellcheck, 189 | args: ['-W', '99', '--color'] + shellcheck_files, 190 | env: {'LC_ALL': 'C.UTF-8'}, 191 | workdir: project_source_root, 192 | verbose: true, 193 | is_parallel: true, 194 | timeout: 600, 195 | suite: 'shellcheck', 196 | ) 197 | endif 198 | 199 | subdir('hooks') 200 | subdir('install') 201 | subdir('kernel-install') 202 | subdir('libalpm') 203 | subdir('man') 204 | subdir('mkinitcpio.d') 205 | subdir('shell') 206 | subdir('systemd') 207 | subdir('test') 208 | subdir('tmpfiles') 209 | subdir('udev') 210 | -------------------------------------------------------------------------------- /meson.options: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | option('systemd', type: 'feature', value: 'enabled', 4 | description: 'install systemd hooks') 5 | option('kernel_install', type: 'boolean', value: true, 6 | description: 'install kernel-install hook') 7 | option('alpm', type: 'boolean', value: true, 8 | description: 'install ALPM hooks and scripts') 9 | option('presets', type: 'boolean', value: true, 10 | description: 'install presets') 11 | option('docs', type: 'boolean', value: true, 12 | description: 'install manual pages') 13 | option('vconsole_conf', type: 'string', value: 'vconsole.conf', 14 | description: 'name of vconsole configuration file') 15 | -------------------------------------------------------------------------------- /mkinitcpio.conf: -------------------------------------------------------------------------------- 1 | # vim:set ft=sh: 2 | # MODULES 3 | # The following modules are loaded before any boot hooks are 4 | # run. Advanced users may wish to specify all system modules 5 | # in this array. For instance: 6 | # MODULES=(usbhid xhci_hcd) 7 | MODULES=() 8 | 9 | # BINARIES 10 | # This setting includes any additional binaries a given user may 11 | # wish into the CPIO image. This is run last, so it may be used to 12 | # override the actual binaries included by a given hook 13 | # BINARIES are dependency parsed, so you may safely ignore libraries 14 | BINARIES=() 15 | 16 | # FILES 17 | # This setting is similar to BINARIES above, however, files are added 18 | # as-is and are not parsed in any way. This is useful for config files. 19 | FILES=() 20 | 21 | # HOOKS 22 | # This is the most important setting in this file. The HOOKS control the 23 | # modules and scripts added to the image, and what happens at boot time. 24 | # Order is important, and it is recommended that you do not change the 25 | # order in which HOOKS are added. Run 'mkinitcpio -H ' for 26 | # help on a given hook. 27 | # 'base' is _required_ unless you know precisely what you are doing. 28 | # 'udev' is _required_ in order to automatically load modules 29 | # 'filesystems' is _required_ unless you specify your fs modules in MODULES 30 | # Examples: 31 | ## This setup specifies all modules in the MODULES setting above. 32 | ## No RAID, lvm2, or encrypted root is needed. 33 | # HOOKS=(base) 34 | # 35 | ## This setup will autodetect all modules for your system and should 36 | ## work as a sane default 37 | # HOOKS=(base udev autodetect microcode modconf block filesystems fsck) 38 | # 39 | ## This setup will generate a 'full' image which supports most systems. 40 | ## No autodetection is done. 41 | # HOOKS=(base udev microcode modconf block filesystems fsck) 42 | # 43 | ## This setup assembles a mdadm array with an encrypted root file system. 44 | ## Note: See 'mkinitcpio -H mdadm_udev' for more information on RAID devices. 45 | # HOOKS=(base udev microcode modconf keyboard keymap consolefont block mdadm_udev encrypt filesystems fsck) 46 | # 47 | ## This setup loads an lvm2 volume group. 48 | # HOOKS=(base udev microcode modconf block lvm2 filesystems fsck) 49 | # 50 | ## This will create a systemd based initramfs which loads an encrypted root filesystem. 51 | # HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole sd-encrypt block filesystems fsck) 52 | # 53 | ## NOTE: If you have /usr on a separate partition, you MUST include the 54 | # usr and fsck hooks. 55 | HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block filesystems fsck) 56 | 57 | # COMPRESSION 58 | # Use this to compress the initramfs image. By default, zstd compression 59 | # is used for Linux ≥ 5.9 and gzip compression is used for Linux < 5.9. 60 | # Use 'cat' to create an uncompressed image. 61 | #COMPRESSION="zstd" 62 | #COMPRESSION="gzip" 63 | #COMPRESSION="bzip2" 64 | #COMPRESSION="lzma" 65 | #COMPRESSION="xz" 66 | #COMPRESSION="lzop" 67 | #COMPRESSION="lz4" 68 | 69 | # COMPRESSION_OPTIONS 70 | # Additional options for the compressor 71 | #COMPRESSION_OPTIONS=() 72 | 73 | # MODULES_DECOMPRESS 74 | # Decompress loadable kernel modules and their firmware during initramfs 75 | # creation. Switch (yes/no). 76 | # Enable to allow further decreasing image size when using high compression 77 | # (e.g. xz -9e or zstd --long --ultra -22) at the expense of increased RAM usage 78 | # at early boot. 79 | # Note that any compressed files will be placed in the uncompressed early CPIO 80 | # to avoid double compression. 81 | #MODULES_DECOMPRESS="no" 82 | -------------------------------------------------------------------------------- /mkinitcpio.d/example.preset: -------------------------------------------------------------------------------- 1 | # Example mkinitcpio preset file 2 | 3 | # preset names 4 | PRESETS=('default' 'fallback') 5 | 6 | # ALL_kver is used if presetname_kver is not set 7 | # The kver can be specified as an explicit kernel version or 8 | # as the path to an kernel image. 9 | ALL_kver='/boot/vmlinuz-linux' 10 | #ALL_config='/etc/mkinitcpio.conf' 11 | 12 | # presetname_kver - the kernel version (omit if ALL_kver should be used) 13 | # presetname_config - the configuration file (omit if ALL_config should be used) 14 | # presetname_image - the filename of generated image 15 | # presetname_options - any extra options 16 | 17 | #default_kver="3.0-ARCH" 18 | #default_config="/etc/mkinitcpio.conf" 19 | default_image="/tmp/initramfs-linux.img" 20 | default_uki="/efi/EFI/Linux/arch-linux.efi" 21 | default_options="" 22 | 23 | #fallback_kver="3.0-ARCH" 24 | #fallback_config="/etc/mkinitcpio.conf" 25 | fallback_image="/tmp/initramfs-linux-fallback.img" 26 | fallback_uki="/efi/EFI/Linux/arch-linux-fallback.efi" 27 | fallback_options="-S autodetect" 28 | -------------------------------------------------------------------------------- /mkinitcpio.d/hook.preset: -------------------------------------------------------------------------------- 1 | # mkinitcpio preset file for the '%PKGBASE%' package 2 | 3 | #ALL_config="/etc/mkinitcpio.conf" 4 | ALL_kver="/boot/vmlinuz-%PKGBASE%" 5 | 6 | PRESETS=('default' 'fallback') 7 | 8 | #default_config="/etc/mkinitcpio.conf" 9 | default_image="/boot/initramfs-%PKGBASE%.img" 10 | #default_uki="/efi/EFI/Linux/arch-%PKGBASE%.efi" 11 | #default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp" 12 | 13 | #fallback_config="/etc/mkinitcpio.conf" 14 | fallback_image="/boot/initramfs-%PKGBASE%-fallback.img" 15 | #fallback_uki="/efi/EFI/Linux/arch-%PKGBASE%-fallback.efi" 16 | fallback_options="-S autodetect" 17 | -------------------------------------------------------------------------------- /mkinitcpio.d/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | presets = [ 4 | 'example.preset', 5 | 'hook.preset', 6 | ] 7 | 8 | if want_presets 9 | foreach preset: presets 10 | configure_file( 11 | input: preset, 12 | output: preset, 13 | configuration: conf_data, 14 | install_dir: datadir / 'mkinitcpio', 15 | ) 16 | endforeach 17 | endif 18 | -------------------------------------------------------------------------------- /shell/bash-completion: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | _detect_kver() { 5 | if (( MESON_TEST )); then 6 | './functions' run_mkinitcpio_func kver "$1" 2>/dev/null 7 | else 8 | '@INITCPIO_LIBDIR@/functions' run_mkinitcpio_func kver "$1" 2>/dev/null 9 | fi 10 | } 11 | 12 | _lsinitcpio() { 13 | local cur opts 14 | opts=(-a --analyze -c --config -h --help -l --list 15 | -n --nocolor -V --version -v --verbose -x --extract --cpio --early) 16 | 17 | _get_comp_words_by_ref cur 18 | 19 | case $cur in 20 | -*) mapfile -t COMPREPLY < <(compgen -W "${opts[*]}" -- "$cur") ;; 21 | *) _filedir ;; 22 | esac 23 | } 24 | 25 | _find_kernel_versions() { 26 | local -a matches 27 | local f kver 28 | 29 | for f in /boot/*; do 30 | # only match regular files which pass validation 31 | if [[ ! -L $f && -f $f ]] && kver=$(_detect_kver "$f"); then 32 | matches+=("$f" "$kver") 33 | fi 34 | done 35 | 36 | mapfile -t COMPREPLY < <(compgen -W "${matches[*]}" -- "$cur") 37 | } 38 | 39 | _files_from_dirs() { 40 | local files stripsuf d f 41 | 42 | if [[ $1 = -s ]]; then 43 | stripsuf=$2 44 | shift 2 45 | fi 46 | 47 | for d in "$@"; do 48 | for f in "$d"/*; do 49 | [[ -f $f ]] && files+=("${f##*/}") 50 | done 51 | done 52 | 53 | printf '%s\n' "${files[@]%$stripsuf}" 54 | } 55 | 56 | _mkinitcpio() { 57 | local cur prev opts 58 | opts=(-A --addhooks -c --config -D --hookdir -d --generatedir -g --generate -H --hookhelp -h --help -k --kernel 59 | -L --listhooks -M --automods -n --nocolor --nopost -P --allpresets -p --preset -R --remove -r --moduleroot 60 | -S --skiphooks -s --save -t --builddir -V --version -v --verbose -z --compress 61 | -U --cmdline --no-cmdline --kernelimage --osrelease --splash --uki --uefistub --ukiconfig --no-ukify) 62 | 63 | _get_comp_words_by_ref cur prev 64 | 65 | case $prev in 66 | -[cgU] | --cmdline | --config | --generate | --kernelimage | --osrelease | --splash | --uki | --uefistub | --ukiconfig) 67 | _filedir 68 | ;; 69 | -D | --hookdir | -d | --generatedir | -r | --moduleroot | -t | --builddir) 70 | _filedir -d 71 | ;; 72 | -k | --kernel) 73 | _find_kernel_versions 74 | ;; 75 | -p | --preset) 76 | mapfile -t COMPREPLY < <(compgen -W "$(_files_from_dirs -s .preset "@SYSCONFDIR@/mkinitcpio.d")" -- "$cur") 77 | ;; 78 | -[AHS] | --add | --hookhelp | --skiphooks) 79 | mapfile -t COMPREPLY < <(compgen -W "$(_files_from_dirs "@INITCPIO_LIBDIR@/install")" -- "$cur") 80 | ;; 81 | *) 82 | mapfile -t COMPREPLY < <(compgen -W "${opts[*]}" -- "$cur") 83 | ;; 84 | esac 85 | } 86 | 87 | complete -F _mkinitcpio mkinitcpio 88 | complete -F _lsinitcpio lsinitcpio 89 | 90 | # vim: set et ts=4 sw=4 ft=sh: 91 | -------------------------------------------------------------------------------- /shell/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | configure_file( 4 | input: 'bash-completion', 5 | output: 'mkinitcpio', 6 | configuration: conf_data, 7 | install_dir: bashcompletiondir, 8 | install_tag: 'completions', 9 | ) 10 | 11 | install_symlink( 12 | 'lsinitcpio', 13 | pointing_to: 'mkinitcpio', 14 | install_dir: bashcompletiondir, 15 | install_tag: 'completions', 16 | ) 17 | 18 | configure_file( 19 | input: 'zsh-completion', 20 | output: '_mkinitcpio', 21 | configuration: conf_data, 22 | install_dir: zshcompletiondir, 23 | install_tag: 'completions', 24 | ) 25 | -------------------------------------------------------------------------------- /shell/zsh-completion: -------------------------------------------------------------------------------- 1 | #compdef lsinitcpio mkinitcpio 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | 5 | _detect_kver() { 6 | if (( MESON_TEST )); then 7 | './functions' run_mkinitcpio_func kver "$1" 2>/dev/null 8 | else 9 | '@INITCPIO_LIBDIR@/functions' run_mkinitcpio_func kver "$1" 2>/dev/null 10 | fi 11 | } 12 | 13 | _find_kernel_versions() { 14 | local -a version 15 | local filedata 16 | 17 | for f in /boot/*; do 18 | # only match regular files which pass validation 19 | if [[ ! -L $f && -f $f ]] && kver=$(_detect_kver "$f"); then 20 | version+=("$kver" "$f") 21 | fi 22 | done 23 | 24 | compadd ${(u)version} 25 | } 26 | 27 | local -a hookdirs=("@INITCPIO_LIBDIR@/install") 28 | 29 | case $service in 30 | lsinitcpio) 31 | _arguments : \ 32 | '(-a --analyze)'{-a,--analyze}'[analyze contents of image]' \ 33 | '(-c --config)'{-c,--config}'[show configuration file image was built with]' \ 34 | '(-l --list)'{-l,--list}'[list contents of the image (default)]' \ 35 | '(-x --extract)'{-x,--extract}'[extract image to disk]' \ 36 | '(-h --help)'{-h,--help}'[display this help]' \ 37 | '(-n --nocolor)'{-n,--nocolor}'[disable colorized output]' \ 38 | '(-V --version)'{-V,--version}'[display version information]' \ 39 | '(-v --verbose)'{-v,--verbose}'[more verbose output]' \ 40 | '--cpio[list or extract only the main CPIO image]' \ 41 | '--early[list or extract only the early CPIO image]' \ 42 | ':image file:_files' 43 | ;; 44 | mkinitcpio) 45 | _arguments : \ 46 | '(-A --addhooks)'{-A,--addhooks}'[Add specified hooks, comma separated, to image]:hook(s):_sequence -s , _path_files -W hookdirs' \ 47 | '(-c --config)'{-c,--config}'[Use alternate config file (default: @SYSCONFDIR@/mkinitcpio.conf)]:config file:_files' \ 48 | '(-D --hookdir)'{-D,--hookdir}'[Specify where to look for hooks]:directory:_files -/' \ 49 | '(-d --generatedir)'{-d,--generatedir}'[Specify where to build the initramfs]:directory:_files -/' \ 50 | '(-g --generate)'{-g,--generate}'[Generate cpio image and write to specified path]:output filename:_files' \ 51 | '(-H --hookhelp)'{-H,--hookhelp}'[Display help for given hook and exit]:hook:_path_files -W hookdirs' \ 52 | '(-h --help)'{-h,--help}'[Display this message and exit]' \ 53 | '(-k --kernel)'{-k,--kernel}'[Use specified kernel version]:kernel version:_find_kernel_versions' \ 54 | '(-L --listhooks)'{-L,--listhooks}'[List all available hooks]' \ 55 | '(-M --automods)'{-M,--automods}'[Display modules found via autodetection]' \ 56 | '(-n --nocolor)'{-n,--nocolor}'[Disable colorized output messages]' \ 57 | '--nopost[Disable post hooks]' \ 58 | '(-P --allpresets)'{-P,--allpresets}'[Process all presets in @SYSCONFDIR@/mkinitcpio.d]' \ 59 | '(-p --preset)'{-p,--preset}'[Build specified preset from @SYSCONFDIR@/mkinitcpio.d]:presets:_files -g "*(\:r)" -W @SYSCONFDIR@/mkinitcpio.d' \ 60 | '--remove[Remove specified preset images]' \ 61 | '(-r --moduleroot)'{-r,--moduleroot}'[Root directory for modules (default: /)]:directory:_files -/' \ 62 | '(-S --skiphooks)'{-S,--skiphooks}'[Skip specified hooks, comma-separated, during build]:hook(s):_sequence -s , _path_files -W hookdirs' \ 63 | '(-s --save)'{-s,--save}'[Save build directory (default: no)]' \ 64 | '(-t --builddir)'{-t,--builddir}'[Use DIR as the temporary build directory]:directory:_files -/' \ 65 | '(-V --version)'{-V,--version}'[Display version information and exit]' \ 66 | '(-v --verbose)'{-v,--verbose}'[Verbose output (default: no)]' \ 67 | '(-z --compress)'{-z,--compress}'[Use an alternate compressor on the image]' \ 68 | '(-U --uki)'{-U,--uki}'[Build a unified kernel image]:path:_files' \ 69 | '--cmdline[Specify kernel cmdline for the unified kernel image]:path:_files' \ 70 | '--no-cmdline[Do not embed a cmdline in the unified kernel image]' \ 71 | '--kernelimage[Include a kernel image for the unified kernel image]:path:_files' \ 72 | '--osrelease[Include a os-release file for the unified kernel image]:path:_files' \ 73 | '--splash[Bitmap splash image to include in unified kernel image]:path:_files' \ 74 | '--uefistub[UEFI stub image used for unified kernel image generation]:path:_files' \ 75 | '--ukiconfig[Config file for ukify for unified kernel image generation]:path:_files' \ 76 | '--no-ukify[Do not use ukify for unified kernel image generation]:path:_files' \ 77 | ;; 78 | *) 79 | return 1; 80 | ;; 81 | esac 82 | 83 | # vim: set et ts=4 sw=4 ft=zsh: 84 | -------------------------------------------------------------------------------- /shutdown: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | # teardown a single device by node name 5 | # $1: device node name, e.g. md0, dm-2 6 | stop_device() { 7 | local devtype='' devname='' 8 | 9 | # the device must still be active 10 | [ -e "/sys/class/block/$1" ] || return 1 11 | 12 | # this can sometimes fail on stopped md devices, when the 13 | # sysfs node doesn't go away as quickly as i'd like it to. 14 | devtype="$(lsblk -drno TYPE "/dev/$1" 2>/dev/null)" || return 1 15 | case "$devtype" in 16 | crypt) 17 | # dmsetup could be used here, but we don't know that it 18 | # exists. 19 | read -r devname <"$1/dm/name" 20 | cryptsetup remove "$devname" 21 | ;; 22 | lvm | dm) 23 | read -r devname <"$1/dm/name" 24 | dmsetup --noudevsync remove "$devname" 25 | ;; 26 | raid*) 27 | # wait for arrays with external metadata to be marked as 28 | # clean. unfortunately, there isn't a whole lot we can do 29 | # if this fails, and the array may need a full rebuild on 30 | # the next reboot. 31 | IFS=: read -r metadata _ <"/sys/class/block/$1/md/metadata_version" 32 | if [ "$metadata" = external ]; then 33 | mdadm --wait-clean "/dev/$1" 34 | fi 35 | mdadm --stop "/dev/$1" 36 | ;; 37 | dmraid) 38 | read -r devname <"$1/dm/name" 39 | dmraid -an "$devname" 40 | ;; 41 | # silently ignore unstacked devices 42 | esac 43 | } 44 | 45 | # recursively disassemble a device chain 46 | # $1: device node name, e.g. md0, dm-2 47 | disassemble() { 48 | local holder='' 49 | 50 | for holder in "$1"/holders/*; do 51 | [ -e "$holder" ] && disassemble "${holder##*/}" 52 | stop_device "$1" 53 | done 54 | } 55 | 56 | copy_binary_from_host() { 57 | local bin="$1" 58 | 59 | # hardcode a sane PATH 60 | for p in '/usr/sbin' '/usr/bin' '/sbin' '/bin'; do 61 | if [ -e "/oldroot/$p/$bin" ]; then 62 | cp "/oldroot/$p/$bin" "/usr/bin/$1" 63 | return 0 64 | fi 65 | done 66 | 67 | return 1 68 | } 69 | 70 | # XXX: Discourage libdevmapper from thinking that udev 71 | # might be in a useful state. FS#30995. 72 | rm -rf /run/udev 73 | 74 | if [ "$1" = kexec ] && ! command -v kexec >/dev/null; then 75 | copy_binary_from_host kexec 76 | fi 77 | 78 | # chdir, so that we can avoid a lot of path chopping 79 | cd /sys/class/block || exit 80 | 81 | printf '%s\n' "Unmounting all devices." 82 | 83 | umount --recursive /oldroot 84 | 85 | printf '%s\n' 'Detaching loop devices.' 86 | 87 | for loop in loop*/loop; do 88 | [ -e "$loop" ] && losetup -d "${loop%/loop}" 89 | done 90 | 91 | printf '%s\n' "Disassembling stacked devices." 92 | 93 | # iterate over devices with holders 94 | for part in */holders/*; do 95 | [ -e "$part" ] && disassemble "${part%%/*}" 96 | done 97 | 98 | case "$1" in 99 | poweroff | shutdown | halt) 100 | "$1" -f 101 | ;; 102 | *) 103 | type kexec >/dev/null && kexec -e 104 | reboot -f 105 | ;; 106 | esac 107 | 108 | # vim: ft=sh ts=4 sw=4 109 | -------------------------------------------------------------------------------- /systemd/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | if not want_systemd.enabled() 4 | subdir_done() 5 | endif 6 | 7 | shutdown_targets = [ 8 | 'halt.target.wants', 9 | 'kexec.target.wants', 10 | 'poweroff.target.wants', 11 | 'reboot.target.wants', 12 | ] 13 | 14 | configure_file( 15 | input: 'mkinitcpio-generate-shutdown-ramfs.service', 16 | output: 'mkinitcpio-generate-shutdown-ramfs.service', 17 | configuration: conf_data, 18 | install_dir: systemd_system_unit_dir, 19 | ) 20 | foreach tgt: shutdown_targets 21 | install_symlink( 22 | 'mkinitcpio-generate-shutdown-ramfs.service', 23 | pointing_to: '../mkinitcpio-generate-shutdown-ramfs.service', 24 | install_dir: systemd_system_unit_dir / tgt, 25 | ) 26 | endforeach 27 | -------------------------------------------------------------------------------- /systemd/mkinitcpio-generate-shutdown-ramfs.service: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | [Unit] 4 | Description=Generate shutdown-ramfs 5 | DefaultDependencies=no 6 | Before=shutdown.target 7 | ConditionPathExists=/run/initramfs/mkinitcpio-shutdown.conf 8 | ConditionFileIsExecutable=!/run/initramfs/shutdown 9 | 10 | [Service] 11 | Type=oneshot 12 | # /tmp/ could be unmounted at this point 13 | # use /run/initcpio-tmp/ as temporary directory 14 | RuntimeDirectory=initcpio-tmp 15 | ExecStart=/usr/bin/mkinitcpio -c /run/initramfs/mkinitcpio-shutdown.conf -d /run/initramfs -k none -t "$RUNTIME_DIRECTORY" 16 | 17 | ProtectSystem=strict 18 | ReadWritePaths=/run/initramfs 19 | ProtectHome=yes 20 | ProtectHostname=yes 21 | ProtectClock=yes 22 | ProtectKernelTunables=yes 23 | ProtectKernelModules=yes 24 | ProtectKernelLogs=yes 25 | ProtectControlGroups=yes 26 | PrivateNetwork=yes 27 | LockPersonality=yes 28 | MemoryDenyWriteExecute=yes 29 | -------------------------------------------------------------------------------- /test/cases/bash-completion.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | shopt -s extglob 5 | 6 | bats_load_library 'bats-assert' 7 | bats_load_library 'bats-support' 8 | load "../helpers/common" 9 | 10 | setup() { 11 | # shellcheck disable=SC1091 12 | source ./shell/mkinitcpio || true 13 | } 14 | 15 | @test "_detect_kver" { 16 | local kernel_ver tmp_knl 17 | local arch 18 | arch="$(uname -m)" 19 | 20 | kernel_ver="6.0.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 16 Nov 2022 17:01:17 +0000 x86_64 GNU/Linux" 21 | 22 | # For non-i686/x86_64 platform, we rely on Linux banner for version detection. 23 | # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/version-timestamp.c?h=v6.7#n28 24 | [[ "$arch" != @(i?86|x86_64) ]] && kernel_ver="Linux version ${kernel_ver}" 25 | 26 | tmp_knl=$(__gen_test_kernel "$kernel_ver") 27 | run _detect_kver "$tmp_knl" 28 | assert_output "6.0.9-arch1-1" 29 | } 30 | -------------------------------------------------------------------------------- /test/cases/extglob.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | bats_load_library 'bats-support' 4 | 5 | @test "check for syntax errors" { 6 | local bash_scripts=(mkinitcpio lsinitcpio) 7 | for s in "${bash_scripts[@]}"; do 8 | bash -O extglob -n "${s}" 9 | done 10 | } 11 | -------------------------------------------------------------------------------- /test/cases/mkinitcpio.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | bats_load_library 'bats-assert' 5 | bats_load_library 'bats-support' 6 | load "../helpers/common" 7 | 8 | @test "test reproducible builds for initramfs" { 9 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 10 | skip "No kernel modules available" 11 | fi 12 | 13 | local tmpdir 14 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 15 | 16 | echo "HOOKS=(base)" >> "$tmpdir/mkinitcpio.conf" 17 | 18 | run ./mkinitcpio \ 19 | -D "${PWD}" \ 20 | -c "$tmpdir/mkinitcpio.conf" \ 21 | -g "$tmpdir/initramfs-1.img" 22 | 23 | run ./mkinitcpio \ 24 | -D "${PWD}" \ 25 | -c "$tmpdir/mkinitcpio.conf" \ 26 | -g "$tmpdir/initramfs-2.img" 27 | 28 | cmp "$tmpdir/initramfs-1.img" "$tmpdir/initramfs-2.img" 29 | } 30 | 31 | __validate_uki() { 32 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 33 | skip "No kernel modules available" 34 | fi 35 | 36 | local mode="$1" tmpdir kver 37 | shift 38 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 39 | kver="$(uname -r)" 40 | 41 | tmp_knl="$(__gen_test_kernel "$kver")" 42 | ln -s "$tmp_knl" "$tmpdir/linux.in" 43 | printf '%s' "$kver" > "$tmpdir/uname.in" 44 | printf 'VERSION_ID=%s\n' "$kver" > "$tmpdir/osrel.in" 45 | grep -v '^VERSION_ID=' /etc/os-release >> "$tmpdir/osrel.in" 46 | printf '%s' 'root=gpt-auto rw' > "$tmpdir/cmdline.in" 47 | ln -s "$BATS_TEST_DIRNAME/../fixtures/uki/splash.bmp" "$tmpdir/splash.in" 48 | 49 | echo 'HOOKS=(base)' > "$tmpdir/mkinitcpio.conf" 50 | run ./mkinitcpio \ 51 | -t "$tmpdir" \ 52 | -D "${PWD}" \ 53 | -c "$tmpdir/mkinitcpio.conf" \ 54 | --kernel "$tmpdir/linux.in" \ 55 | --generate "$tmpdir/initrd.in" \ 56 | --cmdline "$tmpdir/cmdline.in" \ 57 | --osrelease "$tmpdir/osrel.in" \ 58 | --splash "$tmpdir/splash.in" \ 59 | --uki "$tmpdir/uki.efi" \ 60 | --verbose "$@" 61 | assert_success 62 | assert_output --partial "Using $mode to build UKI" 63 | assert_output --partial "Assembling UKI: $mode " 64 | 65 | printf ' \n\0' >> "$tmpdir/cmdline.in" 66 | 67 | objcopy \ 68 | --dump-section ".linux=$tmpdir/linux.out" \ 69 | --dump-section ".initrd=$tmpdir/initrd.out" \ 70 | --dump-section ".uname=$tmpdir/uname.out" \ 71 | --dump-section ".osrel=$tmpdir/osrel.out" \ 72 | --dump-section ".cmdline=$tmpdir/cmdline.out" \ 73 | --dump-section ".splash=$tmpdir/splash.out" \ 74 | "$tmpdir/uki.efi" 75 | 76 | cmp "$tmpdir"/linux.{in,out} 77 | cmp "$tmpdir"/initrd.{in,out} 78 | cmp "$tmpdir"/uname.{in,out} 79 | cmp "$tmpdir"/osrel.{in,out} 80 | cmp "$tmpdir"/cmdline.{in,out} 81 | cmp "$tmpdir"/splash.{in,out} 82 | } 83 | 84 | @test "test creating UKI with ukify" { 85 | if ! command -v ukify &>/dev/null; then 86 | skip "ukify is not available" 87 | fi 88 | __validate_uki ukify --ukiconfig /dev/null 89 | } 90 | 91 | @test "test creating UKI with objcopy" { 92 | __validate_uki objcopy --no-ukify 93 | } 94 | 95 | @test "test reproducible builds for UKI" { 96 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 97 | skip "No kernel modules available" 98 | fi 99 | 100 | local tmpdir 101 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 102 | 103 | echo "HOOKS=(base)" >> "$tmpdir/mkinitcpio.conf" 104 | 105 | ./mkinitcpio \ 106 | -D "${PWD}" \ 107 | -c "$tmpdir/mkinitcpio.conf" \ 108 | --uki "$tmpdir/uki-1.efi" \ 109 | --no-ukify 110 | 111 | ./mkinitcpio \ 112 | -D "${PWD}" \ 113 | -c "$tmpdir/mkinitcpio.conf" \ 114 | --uki "$tmpdir/uki-2.efi" \ 115 | --no-ukify 116 | 117 | sha256sum "$tmpdir/uki-1.efi" "$tmpdir/uki-2.efi" 118 | cmp "$tmpdir/uki-1.efi" "$tmpdir/uki-2.efi" 119 | } 120 | 121 | @test "test creating UKI with no cmdline" { 122 | bats_require_minimum_version 1.5.0 123 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 124 | skip 'No kernel modules available' 125 | fi 126 | 127 | local tmpdir 128 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 129 | 130 | printf '%s\n' 'HOOKS=(base)' > "${tmpdir}/mkinitcpio.conf" 131 | 132 | ./mkinitcpio \ 133 | -D "${PWD}" \ 134 | -c "${tmpdir}/mkinitcpio.conf" \ 135 | --uki "${tmpdir}/uki.efi" \ 136 | --no-ukify \ 137 | --no-cmdline 138 | 139 | run objdump -h "${tmpdir}/uki.efi" 140 | assert_success 141 | refute_output --partial ' .cmdline ' 142 | assert_output --partial ' .linux ' 143 | assert_output --partial ' .initrd ' 144 | assert_output --partial ' .uname ' 145 | } 146 | 147 | @test "test early cpio creation" { 148 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 149 | skip "No kernel modules available" 150 | fi 151 | 152 | local tmpdir 153 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 154 | 155 | echo "HOOKS=(base test)" >> "$tmpdir/mkinitcpio.conf" 156 | install -dm755 "$tmpdir/install" 157 | cat << EOH >> "$tmpdir/install/test" 158 | #!/usr/bin/env bash 159 | build() { 160 | echo "this is a test" > "\${EARLYROOT}/some_file" 161 | } 162 | EOH 163 | 164 | run ./mkinitcpio \ 165 | -D "${PWD}" -D "$tmpdir" \ 166 | -c "$tmpdir/mkinitcpio.conf" \ 167 | -g "$tmpdir/initramfs.img" 168 | 169 | assert_output --partial '-> Early uncompressed CPIO image generation successful' 170 | } 171 | 172 | @test "test moving compressed files to early cpio" { 173 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 174 | skip "No kernel modules available" 175 | fi 176 | 177 | local tmpdir 178 | tmpdir="$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX")" 179 | 180 | echo "HOOKS=(test) COMPRESSION=zstd" >> "$tmpdir/mkinitcpio.conf" 181 | install -dm755 "$tmpdir/install" 182 | cat << EOH >> "$tmpdir/install/test" 183 | #!/usr/bin/env bash 184 | build() { 185 | mkdir -p "\$BUILDROOT"/test/{compressed,mixed,uncompressed} 186 | touch "\$BUILDROOT"/test/{compressed/dummy,mixed/dummy}.zst 187 | touch "\$BUILDROOT"/test/{mixed/dummy,uncompressed/dummy} 188 | } 189 | EOH 190 | 191 | ./mkinitcpio \ 192 | -D "$tmpdir" \ 193 | -c "$tmpdir/mkinitcpio.conf" \ 194 | -g "$tmpdir/initramfs.img" 195 | 196 | run ./lsinitcpio --early "$tmpdir/initramfs.img" 197 | assert_line 'test/compressed/dummy.zst' 198 | assert_line 'test/mixed/dummy.zst' 199 | refute_line 'test/uncompressed' 200 | 201 | run ./lsinitcpio --cpio "$tmpdir/initramfs.img" 202 | refute_line 'test/compressed' 203 | assert_line 'test/mixed/dummy' 204 | assert_line 'test/uncompressed/dummy' 205 | refute_output --regexp '.*\.zst$' 206 | } 207 | 208 | @test "image creation zstd" { 209 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 210 | skip "No kernel modules available" 211 | fi 212 | 213 | __gen_test_initcpio zstd 214 | } 215 | 216 | @test "image creation gzip" { 217 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 218 | skip "No kernel modules available" 219 | fi 220 | 221 | __gen_test_initcpio gzip 222 | } 223 | 224 | @test "image creation bzip2" { 225 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 226 | skip "No kernel modules available" 227 | fi 228 | 229 | __gen_test_initcpio bzip2 230 | } 231 | 232 | @test "image creation lzma" { 233 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 234 | skip "No kernel modules available" 235 | fi 236 | 237 | __gen_test_initcpio lzma 238 | } 239 | 240 | @test "image creation xz" { 241 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 242 | skip "No kernel modules available" 243 | fi 244 | 245 | __gen_test_initcpio xz 246 | } 247 | 248 | @test "image creation lzop" { 249 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 250 | skip "No kernel modules available" 251 | fi 252 | 253 | __gen_test_initcpio lzop 254 | } 255 | 256 | @test "image creation lz4" { 257 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 258 | skip "No kernel modules available" 259 | fi 260 | 261 | __gen_test_initcpio lz4 262 | } 263 | 264 | @test "image creation uncompressed" { 265 | if [[ ! -d "/lib/modules/$(uname -r)/" ]]; then 266 | skip "No kernel modules available" 267 | fi 268 | 269 | __gen_test_initcpio cat 270 | } 271 | -------------------------------------------------------------------------------- /test/cases/parse_cmdline.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | shopt -s extglob 5 | 6 | bats_load_library 'bats-assert' 7 | bats_load_library 'bats-support' 8 | load "../helpers/common" 9 | 10 | setup() { 11 | source "init_functions" 12 | } 13 | 14 | __assert() { 15 | local expect_fail key expected_value actual_value 16 | 17 | if [[ "$1" == '--expect-fail' ]]; then 18 | expect_fail=y 19 | shift 20 | fi 21 | 22 | key=$1 expected_value=$2 23 | eval actual_value=\$"$1" 24 | 25 | # shellcheck disable=SC2254 26 | case $actual_value in 27 | $expected_value) 28 | if [[ -n "$expect_fail" ]]; then 29 | echo "EXPECTED FAIL: $key: expected='$expected_value', got='$actual_value'" 30 | return 1 31 | fi 32 | ;; 33 | *) 34 | if [[ -z "$expect_fail" ]]; then 35 | echo "FAIL: $key: expected='$expected_value', got='$actual_value'" 36 | return 1 37 | fi 38 | ;; 39 | esac 40 | 41 | return 0 42 | } 43 | 44 | __test_parse() { 45 | local flag cmdline expect_fail expect_parse_fail 46 | 47 | for flag; do 48 | case $flag in 49 | --expect-fail) 50 | expect_fail='--expect-fail' 51 | shift 52 | ;; 53 | --expect-parse-fail) 54 | # shellcheck disable=SC2034 55 | expect_parse_fail=y 56 | shift 57 | ;; 58 | *) 59 | break 60 | ;; 61 | esac 62 | done 63 | 64 | cmdline=$1 65 | shift 66 | [[ -n "$V" ]] && echo "testing cmdline: $cmdline" 67 | 68 | echo "$cmdline" | { 69 | parse_cmdline 70 | 71 | result=0 72 | while (( $# )); do 73 | key=$1 expected_value=$2 74 | shift 2 75 | # Quoting expect_fail ruins the test, unsure why 76 | # shellcheck disable=SC2248 77 | __assert $expect_fail "$key" "$expected_value" || result=$e_assertion_failure 78 | done 79 | 80 | exit "$result" 81 | } 2>/dev/null 82 | 83 | } 84 | 85 | @test "parse_cmdline" { 86 | 87 | # Legacy stuff, idk man 88 | 89 | # shellcheck disable=SC2034 90 | failed=0 91 | # shellcheck disable=SC2034 92 | tests=0 93 | 94 | # shellcheck disable=SC2034 95 | e_ok=0 96 | # shellcheck disable=SC2034 97 | e_parser_failure=2 98 | # shellcheck disable=SC2034 99 | e_assertion_failure=130 100 | 101 | # bare words 102 | __test_parse 'foo' \ 103 | 'foo' 'y' 104 | __test_parse 'foo bar' \ 105 | 'foo' 'y' \ 106 | 'bar' 'y' 107 | 108 | # overwriting 109 | __test_parse 'foo=bar bar=baz foo bar="no pe"' \ 110 | 'bar' 'no pe' \ 111 | 'foo' 'y' 112 | 113 | # simple key=value assignment 114 | __test_parse 'foo=bar' \ 115 | 'foo' 'bar' 116 | __test_parse 'foo=bar bar=baz' \ 117 | 'foo' 'bar' \ 118 | 'bar' 'baz' 119 | __test_parse '_derpy=hooves' \ 120 | '_derpy' 'hooves' 121 | __test_parse 'f5=abc f_5_=abc' \ 122 | 'f5' 'abc' \ 123 | 'f_5_' 'abc' 124 | __test_parse 'v="foo bar=baz"' \ 125 | 'v' 'foo bar=baz' 126 | 127 | # double quoting 128 | __test_parse 'foo="bar"' \ 129 | 'foo' 'bar' 130 | __test_parse 'foo="bar baz"' \ 131 | 'foo' 'bar baz' 132 | 133 | # single quoting 134 | __test_parse "foo='bar'" \ 135 | 'foo' 'bar' 136 | __test_parse "foo='bar baz'" \ 137 | 'foo' 'bar baz' 138 | 139 | # dangling quotes 140 | __test_parse 'foo="bar' \ 141 | 'foo' '"bar' 142 | __test_parse 'foo=bar"' \ 143 | 'foo' 'bar"' 144 | 145 | # nested quotes 146 | __test_parse "foo='\"bar baz\"' herp='\"de\"rp'" \ 147 | 'foo' '"bar baz"' \ 148 | 'herp' '"de"rp' 149 | 150 | # escaped quotes 151 | __test_parse 'foo=bar"baz' \ 152 | 'foo' 'bar"baz' 153 | 154 | # neighboring quoted regions 155 | __test_parse --expect-fail 'foo="bar""baz"' \ 156 | 'foo' 'barbaz' 157 | __test_parse --expect-fail "foo=\"bar\"'baz'" \ 158 | 'foo' "barbaz" 159 | __test_parse --expect-fail "foo='bar'\"baz\"" \ 160 | 'foo' "barbaz" 161 | 162 | # comments 163 | __test_parse 'foo=bar # ignored content' \ 164 | 'foo' 'bar' \ 165 | 'ignored' '' \ 166 | 'content' '' 167 | __test_parse 'foo=bar #ignored content' \ 168 | 'foo' 'bar' \ 169 | 'ignored' '' \ 170 | 'content' '' 171 | __test_parse 'foo="bar #baz" parse=this' \ 172 | 'foo' 'bar #baz' \ 173 | 'parse' 'this' 174 | 175 | # shell metachars 176 | __test_parse 'foo=*' \ 177 | 'foo' '\*' 178 | __test_parse 'Make*' \ 179 | 'Makefile' '' 180 | __test_parse '[Makefile]*' \ 181 | 'Makefile' '' \ 182 | 'init' '' \ 183 | 'functions' '' 184 | 185 | # invalid names 186 | __test_parse 'in-valid=name' 187 | __test_parse '6foo=bar' 188 | __test_parse '"gar bage"' \ 189 | 'gar' '' \ 190 | 'bage' '' 191 | 192 | # special handling 193 | __test_parse 'rw' \ 194 | 'ro' '' \ 195 | 'rw' '' \ 196 | 'rwopt' 'rw' 197 | __test_parse 'ro' \ 198 | 'ro' '' \ 199 | 'rw' '' \ 200 | 'rwopt' 'ro' 201 | __test_parse 'fstype=btrfs' \ 202 | 'rootfstype' 'btrfs' 203 | __test_parse 'fsck.mode=force' \ 204 | 'forcefsck' 'y' \ 205 | 'fastboot' '' 206 | __test_parse 'fsck.mode=skip' \ 207 | 'forcefsck' '' \ 208 | 'fastboot' 'y' 209 | __test_parse 'rd.debug' \ 210 | 'rd_debug' 'y' 211 | __test_parse 'rd.log' \ 212 | 'rd_logmask' '6' 213 | __test_parse 'rd.log=all' \ 214 | 'rd_logmask' '7' 215 | __test_parse 'rd.log=console' \ 216 | 'rd_logmask' '4' 217 | __test_parse 'rd.log=kmsg' \ 218 | 'rd_logmask' '2' 219 | __test_parse 'rd.log=file' \ 220 | 'rd_logmask' '1' 221 | 222 | # a mix of stuff 223 | __test_parse 'foo=bar bareword bar="ba az"' \ 224 | 'foo' 'bar' \ 225 | 'bareword' 'y' \ 226 | 'bar' 'ba az' 227 | 228 | } 229 | 230 | __test_getarg() { 231 | local flag="$1" cmdline expect_fail key expected actual_value 232 | local cmdline_cache="${BATS_TEST_TMPDIR}/cmdline" 233 | 234 | if [[ "$flag" = '--expect-fail' ]]; then 235 | expect_fail='y' 236 | shift 237 | fi 238 | 239 | cmdline="$1" 240 | key="$2" 241 | default="$3" 242 | expected="$4" 243 | 244 | [[ -n "$V" ]] && printf 'testing cmdline: %s\n' "$cmdline" 245 | 246 | : > "$cmdline_cache" 247 | parse_cmdline "parse_cmdline_item" "$cmdline_cache" <<< "$cmdline" 248 | 249 | run getarg "$key" "$default" "$cmdline_cache" 250 | 251 | if [[ -z "$expect_fail" ]]; then 252 | assert_output "$expected" 253 | else 254 | refute_output "$expected" 255 | fi 256 | } 257 | 258 | @test "getarg" { 259 | # bare words 260 | __test_getarg 'foo' \ 261 | 'foo' '' 'y' 262 | __test_getarg 'foo bar' \ 263 | 'bar' '' 'y' 264 | 265 | # overwriting 266 | __test_getarg 'foo=bar bar=baz foo bar="no pe"' \ 267 | 'bar' '' 'no pe' 268 | __test_getarg 'foo=bar bar=baz foo bar="no pe"' \ 269 | 'foo' '' 'y' 270 | 271 | # simple key=value assignment 272 | __test_getarg 'foo=bar' \ 273 | 'foo' '' 'bar' 274 | __test_getarg 'foo=bar bar=baz' \ 275 | 'bar' '' 'baz' 276 | __test_getarg '_derpy=hooves' \ 277 | '_derpy' '' 'hooves' 278 | __test_getarg 'f5=abc f_5_=abc' \ 279 | 'f5' '' 'abc' 280 | __test_getarg 'f5=abc f_5_=abc' \ 281 | 'f_5_' '' 'abc' 282 | __test_getarg 'v="foo bar=baz"' \ 283 | 'v' '' 'foo bar=baz' 284 | 285 | # double quoting 286 | __test_getarg 'foo="bar"' \ 287 | 'foo' '' 'bar' 288 | __test_getarg 'foo="bar baz"' \ 289 | 'foo' '' 'bar baz' 290 | 291 | # single quoting 292 | __test_getarg "foo='bar'" \ 293 | 'foo' '' 'bar' 294 | __test_getarg "foo='bar baz'" \ 295 | 'foo' '' 'bar baz' 296 | 297 | # dangling quotes 298 | __test_getarg 'foo="bar' \ 299 | 'foo' '' '"bar' 300 | __test_getarg 'foo=bar"' \ 301 | 'foo' '' 'bar"' 302 | 303 | # nested quotes 304 | __test_getarg "foo='\"bar baz\"' herp='\"de\"rp'" \ 305 | 'foo' '' '"bar baz"' 306 | __test_getarg "foo='\"bar baz\"' herp='\"de\"rp'" \ 307 | 'herp' '' '"de"rp' 308 | 309 | # escaped quotes 310 | __test_getarg 'foo=bar"baz' \ 311 | 'foo' '' 'bar"baz' 312 | 313 | # neighboring quoted regions 314 | __test_getarg --expect-fail 'foo="bar""baz"' \ 315 | 'foo' '' 'barbaz' 316 | __test_getarg --expect-fail "foo=\"bar\"'baz'" \ 317 | 'foo' '' "barbaz" 318 | __test_getarg --expect-fail "foo='bar'\"baz\"" \ 319 | 'foo' '' "barbaz" 320 | 321 | # comments 322 | __test_getarg 'foo=bar # ignored content' \ 323 | 'foo' '' 'bar' 324 | __test_getarg 'foo=bar # ignored content' \ 325 | 'ignored' '' '' 326 | __test_getarg 'foo=bar # ignored content' \ 327 | 'content' '' '' 328 | __test_getarg 'foo=bar #ignored content' \ 329 | 'foo' '' 'bar' 330 | __test_getarg 'foo=bar #ignored content' \ 331 | 'ignored' '' '' 332 | __test_getarg 'foo=bar #ignored content' \ 333 | 'content' '' '' 334 | __test_getarg 'foo="bar #baz" parse=this' \ 335 | 'foo' '' 'bar #baz' 336 | __test_getarg 'foo="bar #baz" parse=this' \ 337 | 'parse' '' 'this' 338 | 339 | # shell metachars 340 | __test_getarg 'foo=*' \ 341 | 'foo' '' '*' 342 | __test_getarg 'Make*' \ 343 | 'Makefile' '' '' 344 | __test_getarg '[Makefile]*' \ 345 | 'Makefile' '' '' 346 | __test_getarg '[Makefile]*' \ 347 | 'init' '' '' 348 | __test_getarg '[Makefile]*' \ 349 | 'functions' '' '' 350 | 351 | # invalid shell variables 352 | __test_getarg 'in-valid=name' \ 353 | 'in-valid' '' 'name' 354 | __test_getarg '6foo=bar' \ 355 | '6foo' '' 'bar' 356 | __test_getarg '"gar bage"' \ 357 | 'gar' '' '' 358 | __test_getarg '"gar bage"' \ 359 | 'bage' '' '' 360 | __test_getarg 'foo.bar=bage' \ 361 | 'foo.bar' '' 'bage' 362 | 363 | # a mix of stuff 364 | __test_getarg 'foo=bar bareword bar="ba az"' \ 365 | 'foo' '' 'bar' 366 | __test_getarg 'foo=bar bareword bar="ba az"' \ 367 | 'bareword' '' 'y' 368 | __test_getarg 'foo=bar bareword bar="ba az"' \ 369 | 'bar' '' 'ba az' 370 | 371 | # defaults 372 | __test_getarg 'foo=bar' \ 373 | 'foo' 'default' 'bar' 374 | __test_getarg 'foo' \ 375 | 'foo' 'default' 'y' 376 | __test_getarg 'foo' \ 377 | 'bar' 'default' 'default' 378 | 379 | # pass through escaped characters 380 | # https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues/257 381 | __test_getarg 'foo=bar\:baz:qux' \ 382 | 'foo' '' 'bar\:baz:qux' 383 | } 384 | -------------------------------------------------------------------------------- /test/cases/zsh-completion.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | shopt -s extglob 5 | 6 | bats_load_library 'bats-assert' 7 | bats_load_library 'bats-support' 8 | load "../helpers/common" 9 | 10 | setup() { 11 | # shellcheck disable=SC1091 12 | source ./shell/_mkinitcpio || true 13 | } 14 | 15 | @test "_detect_kver" { 16 | local kernel_ver tmp_knl 17 | local arch 18 | arch="$(uname -m)" 19 | 20 | kernel_ver="6.0.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 16 Nov 2022 17:01:17 +0000 x86_64 GNU/Linux" 21 | 22 | # For non-i686/x86_64 platform, we rely on Linux banner for version detection. 23 | # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/version-timestamp.c?h=v6.7#n28 24 | [[ "$arch" != @(i?86|x86_64) ]] && kernel_ver="Linux version ${kernel_ver}" 25 | tmp_knl=$(__gen_test_kernel "$kernel_ver") 26 | run _detect_kver "$tmp_knl" 27 | assert_output "6.0.9-arch1-1" 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/README.adoc: -------------------------------------------------------------------------------- 1 | = `+image.bin+` 2 | 3 | As described in the comment in `+functions:_arm_zimage_cat()+`, we 4 | require that the image file is at least 128KiB when compressed; real 5 | kernels will obviously satisfy this, but would be bulky and present 6 | license-probems to bundle as testcases. Instead, let’s use a copy of 7 | Mary Shelly’s Frankenstein (which is in the public domain, 8 | https://www.gutenberg.org/ebooks/84.txt.utf-8[courtesy of Project 9 | Gutenberg]). This is about 440KiB uncompressed, and 140KiB when 10 | compressed with lzma or xz (the best compression ratios of all the 11 | algorithms). 12 | 13 | = `+linux-*.zimage.bin+` 14 | 15 | For the compressed versions, I used the script 16 | https://gitlab.archlinux.org/lukeshu/gen-zimage to use the Linux 17 | kernel’s build system across a variety of versions and configurations to 18 | build ARM zImage files with the above `+image.bin+` as a payload. It 19 | uses a custom `+objcopy+` that replaces all machine code with garbage 20 | (the string 0xDEADBEEF again and again), as to 21 | 22 | * avoid license infringement; the interesting thing for these tests is 23 | the shape of the file, not the code in it 24 | 25 | * make it easier to verify that nothing unsavory is being smuggled in 26 | these files. 27 | 28 | I have not included all of the zImage files that I generated (44,585), 29 | just what I feel to be a representative subset (though I did test 30 | against all 45k), a matrix of: 31 | 32 | * kernel versions: 33 | ** v4.15 (the first version we support) 34 | ** v6.8 (the most recent version at the time of this writing) 35 | ** v4.17 (because unlike v4.15 and v6.8 these have multiple 36 | sub-0x20000 values early in the GOT (except for the lz4 files)) 37 | 38 | * each compression method (gzip, lz4, lzma, lzo, xz) 39 | 40 | * a configuration that captures each of: 41 | ** zbootrom builds (for old-school ARMv4 StrongARM machines) (because 42 | they have a non-zero `+CONFIG_ZBOOT_ROM_TEXT+`) 43 | ** each endianness: 44 | *** LE (with and without thumb2) 45 | *** BE-32 46 | *** BE-8 (with and without thumb2) 47 | ** ARMv4t efistub builds that merge bootloader args with the args from 48 | device tree (because of all the kernels I built, these have the 49 | largest `+input_data_addr+`) 50 | -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4-le-sa1100-zbootrom-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv5-be32-ixp4xx-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-be8-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.15-armv7-le-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.15-armv7-le-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4-le-sa1100-zbootrom-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv5-be32-ixp4xx-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-be8-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux4.17-armv7-le-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux4.17-armv7-le-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4-le-sa1100-zbootrom-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv4t-le-generic-dtbextend-efistub-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv5-be32-ixp4xx-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-be8-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-gzip.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-gzip.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lz4.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lz4.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lzma.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lzma.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lzo.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-lzo.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-thumb2-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/arm-zimage/linux6.8-armv7-le-generic-xz.zimage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/arm-zimage/linux6.8-armv7-le-generic-xz.zimage.bin -------------------------------------------------------------------------------- /test/fixtures/uki/README.adoc: -------------------------------------------------------------------------------- 1 | `+splash.bmp+` generated with: 2 | 3 | [,sh] 4 | ---- 5 | magick montage -size 256x256 xc:magenta xc:black xc:black xc:magenta -mode Concatenate ppm:- | \ 6 | pnmdepth 4 | \ 7 | ppmtobmp > splash.bmp 8 | ---- 9 | 10 | Requires `+magick+` from imagemagick and `+pnmdepth+` and `+ppmtobmp+` from netpbm. 11 | -------------------------------------------------------------------------------- /test/fixtures/uki/splash.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archlinux/mkinitcpio/a6ef10d3f4f24029fc649686ba36f692d8575a7a/test/fixtures/uki/splash.bmp -------------------------------------------------------------------------------- /test/helpers/common.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | # Generates a temporary image with the specified compression options 5 | __gen_test_image() { 6 | local compress_opts tmp_img tmp_file 7 | compress_opts=("${@:-cat}") 8 | tmp_img="$(mktemp --tmpdir="$BATS_RUN_TMPDIR" tmp_img.XXXXXX)" 9 | tmp_file="$(mktemp --tmpdir="$BATS_RUN_TMPDIR" tmp_file.XXXXXX)" 10 | trap '{ rm -f -- "$tmp_img"; }' EXIT 11 | trap '{ rm -f -- "$tmp_file"; }' EXIT 12 | echo "this is a test file" > "$tmp_file" 13 | bsdtar -cf - "$tmp_file" | "${compress_opts[@]}" > "$tmp_img" 14 | rm -f -- "$tmp_file" 15 | echo "$tmp_img" 16 | } 17 | 18 | # Generates a temporary dummy kernel, setting the passed string as kernel version 19 | __gen_test_kernel() { 20 | local kernel_ver tmp_knl 21 | kernel_ver="$1" 22 | tmp_knl="$(mktemp --tmpdir="$BATS_RUN_TMPDIR" tmp_knl.XXXXXX)" 23 | # generate a file of 526 bytes to 0x20E 24 | dd if=/dev/zero of="$tmp_knl" count=526 bs=1 25 | # set the offset value at 0x20E to point to the very next byte at 0x210 26 | printf "%b" '\x10\x02' >>"$tmp_knl" 27 | # pad with 0x200 (512) bytes 28 | dd if=/dev/zero of="$tmp_knl" bs=1 count=512 oflag=append conv=notrunc 29 | # append kernel version 30 | echo "$kernel_ver" >>"$tmp_knl" 31 | echo "$tmp_knl" 32 | } 33 | 34 | # Generates a temporary zboot dummy kernel, with the passed string as kernel version and specified compression type 35 | __gen_test_zboot_kernel() { 36 | local kernel_ver="$1" 37 | local comp_type="$2" 38 | local tmp_img tmp_file 39 | local num count size start 40 | local compress_opts 41 | 42 | tmp_img="$(mktemp --tmpdir="$BATS_RUN_TMPDIR" tmp_img.XXXXXX)" 43 | tmp_file="$(mktemp --tmpdir="$BATS_RUN_TMPDIR" tmp_file.XXXXXX)" 44 | 45 | # generate image with random size between 256 to 1024, 4 bytes align 46 | num=$(head -n 10 /dev/urandom | cksum | awk -F ' ' '{print $1}') 47 | count=$((num%192*4+512)) 48 | dd if=/dev/zero of="$tmp_img" count="$count" bs=1 status=none 49 | 50 | trap '{ rm -f -- "$tmp_img"; }' EXIT 51 | trap '{ rm -f -- "$tmp_file"; }' EXIT 52 | 53 | case $comp_type in 54 | gzip) 55 | compress_opts=("gzip") 56 | ;; 57 | lz4) 58 | compress_opts=("lz4") 59 | ;; 60 | lzma) 61 | compress_opts=("lzma") 62 | ;; 63 | lzo) 64 | compress_opts=("lzop") 65 | ;; 66 | xzkern) 67 | compress_opts=("xz" "--check=crc32") 68 | ;; 69 | zstd22) 70 | compress_opts=("zstd" "-T0") 71 | ;; 72 | *) 73 | echo "Compress type is not supported" 74 | return 1 75 | ;; 76 | esac 77 | 78 | echo "$kernel_ver" | "${compress_opts[@]}" > "$tmp_file" 79 | cat "$tmp_file" >> "$tmp_img" 80 | size=$(stat -c %s "$tmp_file") 81 | 82 | # write "zimg" into image at 0x04 83 | printf "zimg" | dd of="$tmp_img" seek="$((0x4))" bs=1 count=4 status=none conv=notrunc 84 | 85 | # write COMP_TYPE string into image at 0x18 86 | printf '%s' "$comp_type" | dd of="$tmp_img" seek="$((0x18))" bs=1 count=36 status=none conv=notrunc 87 | 88 | # write compress data start offset at 0x08 89 | start=$(printf "%08x" "$count") 90 | echo -n -e "\\x${start:6:2}\\x${start:4:2}\\x${start:2:2}\\x${start:0:2}" | dd of="$tmp_img" seek=$((0x8)) bs=1 count=4 status=none conv=notrunc 91 | 92 | # write compress data size offset at 0x0c 93 | size=$(printf "%08x\n" "$size") 94 | echo -n -e "\\x${size:6:2}\\x${size:4:2}\\x${size:2:2}\\x${size:0:2}" | dd of="$tmp_img" seek=$((0xc)) bs=1 count=4 status=none conv=notrunc 95 | 96 | rm -f -- "$tmp_file" 97 | echo "$tmp_img" 98 | } 99 | 100 | # Generates a temporary initcpio with the specified compression options 101 | __gen_test_initcpio() { 102 | local tmpdir compression="$1" 103 | tmpdir=$(mktemp -d --tmpdir="$BATS_RUN_TMPDIR" "${BATS_TEST_NAME}.XXXXXX") 104 | 105 | cat << EOC >> "$tmpdir/mkinitcpio.conf" 106 | HOOKS=(base) 107 | COMPRESSION=$compression 108 | EOC 109 | 110 | ./mkinitcpio \ 111 | -D "${PWD}" \ 112 | -c "$tmpdir/mkinitcpio.conf" \ 113 | -g "$tmpdir/initramfs.img" 114 | } 115 | 116 | __check_binary(){ 117 | local binary="$1" 118 | if ! command -v "${binary}" &>/dev/null; then 119 | skip "${binary} not installed" 120 | fi 121 | } 122 | -------------------------------------------------------------------------------- /test/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | bats = find_program('bats', required: false) 4 | kcov = find_program('kcov', required: false) 5 | 6 | test_files = [ 7 | 'bash-completion', 8 | 'extglob', 9 | 'functions', 10 | 'mkinitcpio', 11 | 'parse_cmdline', 12 | 'zsh-completion', 13 | ] 14 | 15 | coverage_dirs = [] 16 | 17 | test_env = environment({ 18 | 'LC_ALL': 'C.UTF-8', 19 | 'MESON_TEST': '1', 20 | }) 21 | 22 | if not bats.found() 23 | subdir_done() 24 | endif 25 | 26 | foreach test: test_files 27 | test( 28 | test, 29 | bats, 30 | args: project_source_root / 'test/cases' / test + '.bats', 31 | env: test_env, 32 | workdir: project_build_root, 33 | protocol: 'tap', 34 | verbose: true, 35 | timeout: 600, 36 | suite: 'bats', 37 | ) 38 | 39 | if kcov.found() 40 | test( 41 | 'coverage-' + test, 42 | kcov, 43 | args: [ 44 | '--include-path=.', '--exclude-path=test', '--collect-only', 45 | project_build_root / 'coverage-' + test, 46 | bats.full_path(), project_source_root / 'test/cases' / test + '.bats', 47 | ], 48 | env: test_env, 49 | workdir: project_build_root, 50 | verbose: true, 51 | timeout: 600, 52 | suite: 'coverage', 53 | ) 54 | coverage_dirs += project_build_root / 'coverage-' + test 55 | endif 56 | endforeach 57 | 58 | # merge all coverage results after all other tests run 59 | if kcov.found() 60 | test( 61 | 'merge-coverage', 62 | kcov, 63 | args: [ 64 | '--merge', project_build_root / 'coverage', coverage_dirs, 65 | ], 66 | workdir: project_build_root, 67 | verbose: true, 68 | is_parallel: false, 69 | priority: -1000, 70 | timeout: 600, 71 | suite: 'coverage', 72 | ) 73 | endif 74 | -------------------------------------------------------------------------------- /tmpfiles/20-mkinitcpio.conf: -------------------------------------------------------------------------------- 1 | # Create /run/initramfs for shutdown 2 | d /run/initramfs 0755 root root 3 | 4 | # Create config for shutdown ramfs 5 | f+ /run/initramfs/mkinitcpio-shutdown.conf 0644 root root - HOOKS=(sd-shutdown)\n 6 | -------------------------------------------------------------------------------- /tmpfiles/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | if tmpfiles.found() 4 | configure_file( 5 | input: '20-mkinitcpio.conf', 6 | output: '20-mkinitcpio.conf', 7 | configuration: conf_data, 8 | install_dir: tmpfiles_dir, 9 | ) 10 | endif 11 | -------------------------------------------------------------------------------- /tools/dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0-only 3 | 4 | case "$1" in 5 | get-version) 6 | git -C "$MESON_SOURCE_ROOT" describe --abbrev=7 | sed 's/-/./g;s/^v//;' 7 | ;; 8 | dist-version) 9 | $MESONREWRITE --sourcedir="$MESON_PROJECT_DIST_ROOT" kwargs set project / version "$2" 10 | ;; 11 | gen-doc) 12 | if command -v asciidoctor &>/dev/null; then 13 | asciidoctor -b manpage "${MESON_PROJECT_DIST_ROOT}/man/$2" 14 | else 15 | a2x -f manpages "${MESON_PROJECT_DIST_ROOT}/man/$2" 16 | fi 17 | ;; 18 | *) 19 | exit 1 20 | ;; 21 | esac 22 | -------------------------------------------------------------------------------- /tools/git-contrib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: LGPL-2.1-or-later 3 | # From: https://github.com/systemd/systemd/blob/main/tools/git-contrib.sh 4 | set -eu 5 | 6 | export LC_ALL=C.UTF-8 7 | 8 | tag="$(git describe --abbrev=0 --match 'v[0-9]*')" 9 | ( 10 | # authors 11 | git log --pretty=tformat:%aN -s "${tag}.." 12 | # Co-authors (drop empty line and mail addresses) 13 | git log --pretty='tformat:%(trailers:key=Co-authored-by,valueonly)' -s "${tag}.." | sed -e '/^[[:space:]]*$/ d' | sed -e 's/ <.*@.*>$//' 14 | ) | 15 | sed 's/ / /g; s/--/-/g; s/.*/\0,/' | 16 | sort -u | tr '\n' ' ' | sed -e "s/^/Contributions from: /g" -e "s/,\s*$/\n/g" | fold -w 72 -s | 17 | sed -e "s/^/ /g" -e "s/\s*$//g" 18 | -------------------------------------------------------------------------------- /udev/01-memdisk.rules: -------------------------------------------------------------------------------- 1 | ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="mtdblock*", ATTRS{name}=="memdisk", ATTRS{type}=="ram", GOTO="memdisk_start" 2 | GOTO="memdisk_end" 3 | 4 | LABEL="memdisk_start" 5 | 6 | SYMLINK+="memdisk" 7 | IMPORT{builtin}="blkid" 8 | ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" 9 | ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" 10 | 11 | LABEL="memdisk_end" 12 | -------------------------------------------------------------------------------- /udev/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | 3 | udev_rules = [ 4 | '01-memdisk.rules', 5 | ] 6 | 7 | foreach rule: udev_rules 8 | configure_file( 9 | input: rule, 10 | output: rule, 11 | configuration: conf_data, 12 | install_dir: initcpio_libdir / 'udev', 13 | ) 14 | endforeach 15 | --------------------------------------------------------------------------------