diff --git a/conf/initramfs.conf b/conf/initramfs.conf index dd76996cc41416431b85e4c2c30fdd0a298b1477..01bdd8539f96979b725dba37f3ac9d0f6e9a60c1 100644 --- a/conf/initramfs.conf +++ b/conf/initramfs.conf @@ -38,15 +38,11 @@ BUSYBOX=auto KEYMAP=n # -# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz ] +# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ] # COMPRESS=gzip -# -# NFS Section of the config. -# - # # DEVICE: ... # @@ -70,3 +66,12 @@ NFSROOT=auto # RUNSIZE=10% + +# +# FSTYPE: ... +# +# The filesystem type(s) to support, or "auto" to use the current root +# filesystem type +# + +FSTYPE=auto diff --git a/debian/README b/debian/README index dc85c9ba6b90f590927b3b7a5d4554b17d2cd220..7fa0c6139108a578a766b0338b7d87e2740882c4 100644 --- a/debian/README +++ b/debian/README @@ -1,12 +1,37 @@ initramfs-tools =============== -This package is a work in progress towards the replacement of the initrd -system with an initramfs system. +The Linux kernel may boot using an "initramfs", an archive of files +that it unpacks into an in-memory file system at the beginning of the +boot process. This archive must contain its own init program which +the kernel will run as the first user process. In a Debian system, +the initramfs is responsible for: -The goals include using klibc for all earlyspace tools, an integrated udev -and an integrated hotplug. +* Loading essential driver modules +* Setting up a network connection, if required +* Setting up layered storage devices, if required +* Resuming from hibernation (suspend-to-disk), if possible +* Checking and mounting the root and /usr file systems +* Handing over to the main init system -See the TODO file for a current status. +initramfs-tools is designed to be extensible, and many other packages +provide these and additional features in the initramfs. -Jeff Bailey - 2005-04-24 +On x86 systems, the initramfs can also contain CPU microcode updates +that the kernel will apply at a very early stage. These are provided +by the (non-free) intel-microcode and amd64-microcode packages. + +Debian's official kernel packages require the use of an initramfs, +since drivers and filesystem code are built as modules that need to be +loaded before the file systems can be mounted. Custom kernel packages +that have this code built-in may still need an initramfs to set up +layered storage devices or to provide microcode updates. + +If initramfs-tools is installed, it will generate an initramfs +automatically whenever a kernel is installed or upgraded (and remove +it when the kernel is removed). If only initramfs-tools-core is +installed, you can run mkinitramfs to generate an initramfs. + +The initramfs-tools(7) manual page documents the supported parameters +and how to extend initramfs-tools. There are additional manual pages +for the various commands and configuration files. diff --git a/debian/changelog b/debian/changelog index 4a3132806fa5a43325ba481b168834a1af5e8bf7..d4cf274e9609a989508e0eeb3ca4bbc2a1e8a779 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,296 @@ +initramfs-tools (0.140pureos1) byzantium; urgency=medium + + * Merge in 0.140 from Debian stable, remaining change + - Depend on busybox instead of just recommending it + - Don't show "Possible missing firmware" messages unless "-v" is passed + * d/control: Remove Uploaders field + * d/control: Adjust Maintainer/Vcs to PureOS fork + * Add d/pureos-ci.yml for CI + + -- Carsten Schoenert Wed, 23 Mar 2022 07:19:15 +0100 + +initramfs-tools (0.140) unstable; urgency=medium + + [ Norbert Lange ] + * mkinitramfs: use temporary file for uncompressed cpio + + [ Michael Prokop ] + * mkinitramfs: report actually requested compress util if it's not present + + [ Ben Hutchings ] + * init: Mount /dev without the noexec option + + [ dann frazier ] + * configure_networking(): Wait for specified network device (Closes: #965935) + + [ Bastian Blank ] + * Include all PCI controller modules + * Include all reset controller modules + + -- Bastian Blank Sat, 13 Mar 2021 19:13:18 +0100 + +initramfs-tools (0.139) unstable; urgency=medium + + * [9679f0c] debian/tests: Run amd64 tests on either amd64 or generic flavour + * [0099040] debian/tests/control: Mark all amd64 tests as + skip-not-installable (Closes: #970184) + * [3616c8f] conf/initramfs.conf: Fix typo "filesytem" (Closes: #970235) + + -- Ben Hutchings Sun, 13 Sep 2020 19:28:00 +0100 + +initramfs-tools (0.138) unstable; urgency=medium + + [ Ben Hutchings ] + * [0b034b4] docs/maintainer-notes.md: Delete the horizontal rules + * [ba883cb] docs/maintainer-notes.md: Use Gitlab markup for table of contents + * [5284a00] docs/maintainer-notes.md: Use Gitlab markup for definition table + * [a469b7e] docs/maintainer-notes.md: Use archive.org URL for Daniel Baumann + doc + * [424260e] debian/control, docs/maintainer-notes.md: Use my @debian.org + address + * [181a35c] update-initramfs: Remove test for direct invocation from kernel + package + * [6ebe41b] Remove obsolete update-initramfs state in + /var/lib/initramfs-tools + * [2f2ad0d] hook-functions: copy_exec: Copy libgcc_s.so with any soversion up + to 9 (Closes: #959768) + * [0f24cc1] Add CI configuration for salsa.debian.org + * [9877542] initramfs.conf: Delete "NFS Section" comment + * [4309c3b] Add FSTYPE config parameter to allow overriding filesystem type + detection (Closes: #923400) + * [6300aa1] Change "panic" parameter handling to work more like the kernel + * [90d64bd] debian/tests: Add common test preparation code + * [3dd2984] debian/tests: Add basic test for amd64 using klibc and not + busybox + * [69240b1] debian/tests: Add basic test for amd64 using busybox + * [3d834c8] debian/tests: Add basic tests for amd64 with only ata/virtio + driver + * [c14b760] debian/tests: Add test for separate /usr device + * [6b3b361] debian/tests: Add test of the panic shell and parameter handling + + [ Vagrant Cascadian ] + * [482897b] hook-functions: Add modules needed for Pinebook LCD display. + + [ Guilherme G. Piccoli ] + * [c3cbf35] scripts/functions: Prevents printf error carry over if wrong + console is set (Closes: #960355) + + [ Unit 193 ] + * [3b82099] When overriding configured compressor, warn the user. + + [ Norbert Lange ] + * [e94f410] un-,mkinitramfs: add support for zstd (Closes: #955469) + + [ Jann Horn ] + * [a7718dc] Add firmware for built-in drivers (Closes: #857054) + + -- Ben Hutchings Fri, 11 Sep 2020 20:37:29 +0100 + +initramfs-tools (0.137) unstable; urgency=medium + + [ Ben Hutchings ] + * [1b28d25] Document copy_exec as usable for shared libraries + * [f2ac13e] hook-functions: copy_exec: Copy libgcc_s.so.1 along with + libpthread.so.* (Closes: #950254) + * [d96228a] hook-functions: copy_exec: Correct verbose log message for + symlinks + * [dd5fb36] hook-functions: Factor out device class walking into a function + * [14a00af] hook-functions: Don't add backlight modules if we have generic + fb device (Closes: #955347) + * [f6133e1] Fix new shellcheck warnings around unquoted parameter expansion + (Closes: #958851) + + [ AP ] + * [857042c] hook-functions: Search for firmware under /lib/firmware/updates + (Closes: #956663) + + -- Ben Hutchings Tue, 28 Apr 2020 04:56:17 +0100 + +initramfs-tools (0.136) unstable; urgency=medium + + [ Mathieu Malaterre ] + * [90bd459] Update to new name for kernel module therm_pm72 + + [ Alper Nebi Yasak ] + * [ded7214] hook-functions: Handle dw_mmc-rockchip hidden dependency on + rockchip-io-domain + * [da85190] hook-functions: Include modules for Chromebook Plus display + + [ Ben Hutchings ] + * [afd2668] debian/tests/control: Mark shellcheck test as superficial + * [9d8b690] mkinitramfs: Remove workaround for old udev versions + * [2b55aca] mkinitramfs: Remove special case for Arm OABI ports + * [a9e5169] mkinitramfs: Remove armhf dynamic linker hack + * [b19b6f3] debian/rules: Suppress execution of dh_installinitramfs + * [8330bcd] mkinitramfs: Use cp -p option for ld.so.conf* instead of -aZ + * [15fd713] initramfs-tools(7): Change example to use copy_exec instead of cp + * [c2d589e] Revert "mkinitramfs: check if initramfs has a shell" + * [835d584] mkinitramfs: Copy modules.builtin.bin into initramfs + (Closes: #948257) + * [0012977] init: Remove special case for kernel parameter resume=UUID=... + * [897ab77] update-initramfs: Make "-c -k all" options useful again + (Closes: #926401) + * [d6c6eec] init: Mount /dev with "exec" option if v86d is present + (Closes: #940171) + * [a9e73b5] hook-functions: Drop ext4dev from filesystem module list + * [41d9ceb] mkinitramfs: Enable multihreaded xz compression (Closes: #942144) + + [ Alexander Volkov ] + * [e34affa] Don't require build dependency on shellcheck when nocheck profile + is enabled + + [ Johannes 'josch' Schauer ] + * [e2ad678] hook-functions: preloaded libraries should not end up in the + initramfs (Closes: #944929) + + [ Debian Janitor ] + * [a1e17fc] Bump debhelper from old 9 to 12. + * [4d86d1a] Set debhelper-compat version in Build-Depends. + + [ Romain Perier ] + * [4df27e2] hook-functions: Add f2fs as base in auto_add_modules + + [ Christian Göttsche ] + * [0db5752] Do not copy SELinux context in mkinitramfs (Closes: #948365) + + [ Topi Miettinen ] + * [55afeec] Tighten permissions for /run/initramfs + + -- Ben Hutchings Sat, 18 Jan 2020 18:48:51 +0000 + +initramfs-tools (0.135) unstable; urgency=medium + + [ Topi Miettinen ] + * [eb98d2e] init: /dev can be noexec and /run nodev + + [ Alper Nebi Yasak ] + * [43488a3] hook-functions: Handle spi-rockchip hidden dependency on pl330 + + [ Ben Hutchings ] + * [116ce5c] autopkgtest: Only test hook and boot scripts from specific + packages + + -- Ben Hutchings Wed, 21 Aug 2019 23:06:28 +0100 + +initramfs-tools (0.134) unstable; urgency=medium + + [ Ben Hutchings ] + * [8aeae9f] hooks/resume: Disable resume when there are no suitable swap + devices. Thanks to Trek (Closes: #916696) + * [40f6647] hook-functions: Include all keyboard driver modules when + MODULES=most. Thanks to Alper Nebi Yasak + * [797e5fe] hook-functions: Include cros_ec_spi and SPI drivers when + MODULES=most. Thanks to Alper Nebi Yasak + * [f65627d] resume: Set plymouth status only if there is a suspend image + (Closes: #928736) + * [c31a908] hook-functions: Fix copy_file with target of "/bin" + (Closes: #928689) + * [8a29ef3] scripts/functions: Use "reboot -f" to reboot on panic. + Thanks to Michael Niewöhner (Closes: #923165) + * [da9f53e] unmkinitramfs: Work around lz4cat filename check. + Thanks to Dimitri John Ledkov (Closes: #930366) + * [cf7bb4b] initramfs-tools-core: Depend on logsave or older e2fsprogs + (Closes: #932854) + * [8570718] update-initramfs(8): Document -d option as "delete" instead of + "remove" + * [fffe514] update-initramfs(8): Update description of "-k all" option + + [ Benjamin Drung ] + * [5e94f22] autopkgtest: Check also + /usr/share/initramfs-tools/{hooks,scripts} + + [ Alper Nebi Yasak ] + * [994d698] hook-functions: Include extcon-usbc-cros-ec when MODULES=most + * [4e3496a] hook-functions: Include extcon drivers when MODULES=dep + + [ Uwe Kleine-König ] + * [37dcf3d] mkinitramfs: suppress warning when using bzip2 or lzma + (Closes: #930754) + + -- Ben Hutchings Sun, 28 Jul 2019 01:10:56 +0100 + +initramfs-tools (0.133) unstable; urgency=medium + + [ Ben Hutchings ] + * [942f1d2] unmkinitramfs, lsinitramfs: Avoid zcat compatibility issue by + running gzip (Closes: #903931) + * [94683ef] mkinitramfs: Remove check for kernel version < 2.6.38 + * [40fb032] mkinitramfs; Stop setting both compress and COMPRESS variables + * [01af757] initramfs-tools: Change trigger declaration to "interest-await" + * [2bb6a9c] update-initramfs: Remove test for working dpkg-trigger + * [1f10559] kernel hooks: Remove use of update-initramfs -t option + * [1343b68] update-initramfs: Remove undocumented -y option + * [e0d4024] mkinitramfs: Warn if the compression command is not recognised + * [bafb9d4] init: Always export the resume and noresume variables, as + documented + * [f21fdae] debian/rules: Use a more conservative "find" for shellcheck + arguments + * [9c63564] Change get_fstype to be silent on failure + * [58df6d3] scripts/functions: Abort _checkfs_once early if fs type is + unknown + * [f8ceeb9] scripts/local: Explicitly check for missing root parameter and + mount failure. Thanks to "G.raud" (Closes: #848906) + * [a5ae8a1] scripts/{local,nfs}: Remove redundant modprobe of filesystem + modules + * [4807ede] hook-functions: Avoid symlinks that conflict with usr-merge in + copy_file + * [79f49b9] {hooks,scripts}/keymap: Use setupcon --setup-dir + * [839be1b] scripts/local: Handle rootfstype=auto the same as if type is + unspecified (Closes: #908967) + * [f086b72] mkinitramfs: Use default compression level for lzop + (Closes: #916935) + * [d343f5e] README: Summarise what initramfs-tools does and point to manual + pages + * [c5dd80a] initramfs-tools(7): Document how to update the initramfs from + another package (Closes: #893897) + * [2e5e389] scripts/functions: Revert change to _log_msg and make callers + format-safe + * [49139ca] scripts/local-premount/resume: Report when we are resuming. + Thanks to Mario Limonciello + * [28b9d1d] scripts/nfs: Use "sleep" instead of /bin/sleep (Closes: #677049) + * [db394d3] Print warnings and errors in initramfs generation consistently + * [d9cf2f2] hooks/fsck: If get_fstype fails, report which file system it + failed for (Closes: #766446) + * [1ae0994] mkinitramfs: Change EXTRA_CONF to include directory names + * [34f84b4] mkinitramfs: Don't add directories to EXTRA_CONF + * [db31e7e] mkinitramfs: Use pigz if available instead of gzip + * [e4a5589] initramfs-tools-core: Recommend pigz + * [b8d3d59] Remove descriptions of removed/deprecated options from man page + synopses + * [4d57f63] mkinitramfs(8), update-initramfs(8): Fix over-indentation of + options + * [66902db] update-initramfs(8): Fix formatting of mode options in the + synopsis + * [bb9d247] Move usage function for mkinitramfs out of hook-functions + * [2380cb8] update-initramfs: Use getopt instead of getopts + * [abca193] update-initramfs: Make -h option return 0 and write usage to + stdout + * [ccf07ee] update-initramfs: Support --help option + * [c800321] Make all commands return 2 in case of a usage error + * [fc81f7f] mkinitramfs: Support -h and --help options + * [94e05dd] unmkinitramfs(8): Abbreviate synopsis to avoid wrapping + * [00809d7] Make manual pages and usage messages more consistent + * [45f4d15] unmkinitramfs: Write usage on stderr in case of error + * [908bd7d] lsinitramfs, mkinitramfs, unmkinitramfs: Show usage if getopt + fails + * [1cc6e78] lsinitramfs: Check for empty list of arguments after parsing + options + * [fb3ea62] hooks/resume: Report in excruciating detail if the -v option is + used + + [ Benjamin Drung ] + * [806c757] scripts/functions: Fix syntax error: unexpected "(" on panic + * [88b0c9b] mkinitramfs: Fix termination of gzip compression case + * [5438f31] scripts/functions: Drop render function + * [3c8b4c3] Remove trailing newline from debian/changelog + * [f277309] Fix (nearly) all issues found by shellcheck + * [2bab73b] Disable shellcheck for desired behaviour + * [3650731] Replace 'echo -n' by printf + * [9c0feb2] Run shellcheck on package build time + * [c9cb0a0] Add autopkgtest for shellcheck + + -- Ben Hutchings Wed, 06 Feb 2019 20:13:59 +0000 + initramfs-tools (0.132pureos1) green; urgency=medium * Merge with Debian unstable, remaining changes: @@ -4502,4 +4795,3 @@ initramfs-tools (0.1) unstable; urgency=low * Initial Release. -- Jeff Bailey Thu, 27 Jan 2005 15:23:52 -0500 - diff --git a/debian/compat b/debian/compat deleted file mode 100644 index ec635144f60048986bc560c5576355344005e6e7..0000000000000000000000000000000000000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/debian/control b/debian/control index 41228061365145dcc85ac317e8a04ac299626371..173dba7d03c94704a54f840191f91200334fee8b 100644 --- a/debian/control +++ b/debian/control @@ -1,13 +1,15 @@ Source: initramfs-tools Section: utils Priority: optional -Uploaders: Michael Prokop , Ben Hutchings Maintainer: PureOS Maintainers -Build-Depends: debhelper (>= 9), bash-completion +XBSC-Oiginal-Maintainer: Debian kernel team +Build-Depends: debhelper-compat (= 12), bash-completion, shellcheck Rules-Requires-Root: no Standards-Version: 4.1.5 Vcs-Browser: https://source.puri.sm/pureos/core/initramfs-tools Vcs-Git: https://source.puri.sm/pureos/core/initramfs-tools.git +XSBC-Original-Vcs-Browser: https://salsa.debian.org/kernel-team/initramfs-tools +XSBC-Original-Vcs-Git: https://salsa.debian.org/kernel-team/initramfs-tools.git Package: initramfs-tools Architecture: all @@ -25,8 +27,8 @@ Description: generic modular initramfs generator (automation) Package: initramfs-tools-core Architecture: all Multi-Arch: foreign -Recommends: ${busybox:Recommends} -Depends: klibc-utils (>= 2.0.4-8~), cpio (>= 2.12), kmod, udev, coreutils (>= 8.24), e2fsprogs, ${misc:Depends} +Recommends: pigz +Depends: klibc-utils (>= 2.0.4-8~), cpio (>= 2.12), kmod, udev, coreutils (>= 8.24), logsave | e2fsprogs (<< 1.45.3-1~), ${misc:Depends}, ${busybox:Recommends} Suggests: bash-completion Breaks: initramfs-tools (<< 0.121~), ${busybox:Breaks}, busybox-initramfs (<< 1:1.27.2-3) Replaces: initramfs-tools (<< 0.121~) diff --git a/debian/gbp.conf b/debian/gbp.conf new file mode 100644 index 0000000000000000000000000000000000000000..78ed4d96a7de5990cdd7f14f58ce1737814f0009 --- /dev/null +++ b/debian/gbp.conf @@ -0,0 +1,6 @@ +[DEFAULT] +sign-tags = True +debian-branch = pureos/latest +debian-tag = pureos/%(version)s +upstream-branch = +upstream-tag = %(version)s diff --git a/debian/initramfs-tools-core.dirs b/debian/initramfs-tools-core.dirs index 21f605c90f4ed7419e65e20eeaaac53a581a5596..8092c1b38721694074192250fe59656cbebb6363 100644 --- a/debian/initramfs-tools-core.dirs +++ b/debian/initramfs-tools-core.dirs @@ -14,4 +14,3 @@ usr/sbin usr/share/initramfs-tools/conf.d usr/share/initramfs-tools/conf-hooks.d usr/share/initramfs-tools/modules.d -/var/lib/initramfs-tools diff --git a/debian/initramfs-tools-core.postinst b/debian/initramfs-tools-core.postinst index 395e997d35a5267b6459857f9bd440744daaca74..c4d7b754ebf5776b17955d0e53d1754adcf77ede 100644 --- a/debian/initramfs-tools-core.postinst +++ b/debian/initramfs-tools-core.postinst @@ -40,4 +40,9 @@ if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.123~; then finish_mv_conffile /etc/initramfs-tools/initramfs.conf initramfs-tools-core fi +# Remove obsolete state directory +if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.138~; then + rm -rf /var/lib/initramfs-tools +fi + #DEBHELPER# diff --git a/debian/initramfs-tools.preinst b/debian/initramfs-tools.preinst index 99144bbeb02480d2634554f64aab3cdcc57394dc..3084c4aa28526e4f65a262c9f448231733dd3259 100755 --- a/debian/initramfs-tools.preinst +++ b/debian/initramfs-tools.preinst @@ -20,9 +20,10 @@ prepare_rm_conffile() { [ -e "$CONFFILE" ] || return 0 ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0 - local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')" - local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PACKAGE | \ - sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")" + local md5sum old_md5sum + md5sum="$(md5sum "$CONFFILE" | sed -e 's/ .*//')" + old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \ + sed -n -e "\\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")" if [ "$md5sum" != "$old_md5sum" ]; then mv $mvverbose -f "$CONFFILE" "$CONFFILE.dpkg-backup" else diff --git a/debian/initramfs-tools.triggers b/debian/initramfs-tools.triggers index 860c664e98294b755f66ada9305cee6f60f86ed8..c3d4146f17b7f33a132f89c40461d8c13bc964a5 100644 --- a/debian/initramfs-tools.triggers +++ b/debian/initramfs-tools.triggers @@ -1 +1 @@ -interest update-initramfs +interest-await update-initramfs diff --git a/debian/pureos-ci.yml b/debian/pureos-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..9bb8c3a688647eb26ee1ac0efe9601fac4d85487 --- /dev/null +++ b/debian/pureos-ci.yml @@ -0,0 +1,7 @@ +include: + - 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-definitions.yml' + - 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-byzantium-jobs.yml' + +stages: + - package + - test-package diff --git a/debian/rules b/debian/rules index d59095646d6c8693561a63892ad6738aa4ab9dc1..42ad0d31c2f7e02cd43354ed887a26a99176a3c0 100755 --- a/debian/rules +++ b/debian/rules @@ -19,3 +19,11 @@ override_dh_install: mkinitramfs > debian/initramfs-tools-core/usr/sbin/mkinitramfs chmod 755 debian/initramfs-tools-core/usr/sbin/mkinitramfs dh_install + +override_dh_installinitramfs: + @: + +override_dh_auto_test: +ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) + shellcheck -e SC1090,SC1091 -s dash hook-functions $$(find hooks scripts -type f) $$({ find . -maxdepth 1 -type f -executable; find debian -maxdepth 1 -type f; find docs kernel -type f; } | xargs grep -l '^#!/bin/sh') +endif diff --git a/debian/salsa-ci.yml b/debian/salsa-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac7bc44ad8f33912e0d82fe489f0f6b2d9fb7cd2 --- /dev/null +++ b/debian/salsa-ci.yml @@ -0,0 +1,6 @@ +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml + +variables: + RELEASE: 'unstable' diff --git a/debian/tests/amd64-ata-only b/debian/tests/amd64-ata-only new file mode 100755 index 0000000000000000000000000000000000000000..b91601eb4121c9097df4e31c53a5361045569d2e --- /dev/null +++ b/debian/tests/amd64-ata-only @@ -0,0 +1,22 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=ide +ROOTDISK_LINUX_NAME=sda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <>"${CONFDIR}/initramfs.conf" <>"${CONFDIR}/initramfs.conf" <>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" < "${ROOTDIR}/etc/fstab" "/dev/${USRDISK_LINUX_NAME} /usr ext2 defaults 0 2" +USRDIR="$(mktemp -d)" +mv "${ROOTDIR}/usr/"* "${USRDIR}" + +build_rootfs_ext2 +build_fs_ext2 "${USRDIR}" "${USRDISK}" + +run_qemu_amd64 + +# Check that fsck ran on both devices +grep -q "^/dev/${ROOTDISK_LINUX_NAME}: clean," "${OUTPUT}" +grep -q "^/dev/${USRDISK_LINUX_NAME}: clean," "${OUTPUT}" diff --git a/debian/tests/amd64-virtio-only b/debian/tests/amd64-virtio-only new file mode 100755 index 0000000000000000000000000000000000000000..5cca6dac021001521b3af8fe9b2d446cffc87e86 --- /dev/null +++ b/debian/tests/amd64-virtio-only @@ -0,0 +1,22 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=virtio +ROOTDISK_LINUX_NAME=vda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" < "$AUTOPKGTEST_TMP/installed-packages" + +# The packages that we're prepared to test +echo "initramfs-tools initramfs-tools-core klibc-utils kmod udev" \ + | sed 's/ /\n/g' \ + | sort -u \ + > "$AUTOPKGTEST_TMP/tested-packages" + +# Installed hook/boot scripts that we're prepared to test +join "$AUTOPKGTEST_TMP/installed-packages" "$AUTOPKGTEST_TMP/tested-packages" \ + | xargs dpkg -L \ + | grep -E '^/usr/share/initramfs-tools/(hooks|scripts)/' \ + | while read file; do test -f "$file" && printf '%s\n' "$file"; done \ + > "$AUTOPKGTEST_TMP/hook-boot-scripts" + +shellcheck -e SC1090,SC1091 -s dash /usr/bin/lsinitramfs /usr/sbin/mkinitramfs /usr/bin/unmkinitramfs /usr/share/initramfs-tools/hook-functions /usr/share/initramfs-tools/init /etc/kernel/postinst.d/initramfs-tools /etc/kernel/postrm.d/initramfs-tools /usr/sbin/update-initramfs $(cat "$AUTOPKGTEST_TMP/hook-boot-scripts") diff --git a/debian/tests/test-common b/debian/tests/test-common new file mode 100644 index 0000000000000000000000000000000000000000..d1bf67190050c66b36690dd9020ea63def94755a --- /dev/null +++ b/debian/tests/test-common @@ -0,0 +1,100 @@ +# -*- mode: sh -*- + +# Find kernel flavour and release +KVER= +for flavour in $SUPPORTED_FLAVOURS; do + KVER="$(dpkg-query -Wf '${Depends}' "linux-image-${flavour}" 2>/dev/null | tr ',' '\n' | sed -n 's/^ *linux-image-\([-a-z0-9+.]*\).*/\1/p')" + if [ "$KVER" ]; then + break + fi +done +if [ -z "$KVER" ]; then + echo >&2 "E: Test must set SUPPORTED_FLAVOURS and depend on those flavours" + exit 2 +fi + +if [ -n "${AUTOPKGTEST_TMP}" ]; then + export TMPDIR="${AUTOPKGTEST_TMP}" +fi + +# Skeleton configuration directory +CONFDIR="$(mktemp -d)" +cp conf/initramfs.conf "${CONFDIR}/initramfs.conf" +echo "RESUME=none" >>"${CONFDIR}/initramfs.conf" +touch "${CONFDIR}/modules" +mkdir "${CONFDIR}/scripts" + +# initramfs image file +INITRAMFS="$(mktemp)" + +# root disk image file +ROOTDISK="$(mktemp)" + +# root disk interface type (for qemu) and device name (for Linux) +test -n "${ROOTDISK_QEMU_IF}" || ROOTDISK_QEMU_IF=virtio +test -n "${ROOTDISK_LINUX_NAME}" || ROOTDISK_LINUX_NAME=vda + +# Create a root fs with a trivial userspace +ROOTDIR="$(mktemp -d)" +INIT_MESSAGE='root fs init system started successfully' +for subdir in bin dev lib proc run sbin sys usr usr/bin; do + mkdir "${ROOTDIR}/${subdir}" +done +cat >"${ROOTDIR}/sbin/init" <&1 -b "${blocks}" -N "${inodes}" -U -d "${dir}" "${disk}" +} + +build_rootfs_ext2() { + build_fs_ext2 "${ROOTDIR}" "${ROOTDISK}" +} + +_run_qemu_amd64() { + local extra_params="$*" + + timeout --foreground 60 qemu-system-x86_64 -m 1G -drive "file=${ROOTDISK},if=${ROOTDISK_QEMU_IF},media=disk,format=raw" ${USRDISK:+-drive "file=${USRDISK},if=${USRDISK_QEMU_IF},media=disk,format=raw"} -nographic -no-reboot -kernel "/boot/vmlinuz-${KVER}" -initrd "${INITRAMFS}" -append "root=/dev/${ROOTDISK_LINUX_NAME} ro console=ttyS0,115200 ${extra_params}" | tee "${OUTPUT}" +} + +run_qemu_nocheck_amd64() { + # hide error messages from autopkgtest + _run_qemu_amd64 2>&1 "$@" +} + +run_qemu_amd64() { + _run_qemu_amd64 "panic=-1" + grep -qF "${INIT_MESSAGE}" "${OUTPUT}" +} diff --git a/docs/framebuffer b/docs/framebuffer index 47d8302fcff854e7ba6f936d518c70faa12c3756..81ba77f802eb026072d009aa0bd80d5a2ec4ceb0 100644 --- a/docs/framebuffer +++ b/docs/framebuffer @@ -44,19 +44,19 @@ parse_video_opts() for opt in ${OPTS}; do # Already in the "=" form if [ "${opt}" != "${opt#*=}" ]; then - echo -n "$opt " + printf "%s" "$opt " # In the ":" form elif [ "${opt}" != "${opt#*:}" ]; then - echo -n "${opt%:*}=${opt#*:} " + printf "%s" "${opt%:*}=${opt#*:} " # Presumably a modevalue without the "mode=" prefix elif [ "${opt}" != "${opt#[0-9]*x[0-9]}" ]; then # Adjust: mode= option? - echo -n "mode=$opt " + printf "%s" "mode=$opt " # ... or mode_option= option? - # echo -n "mode_option=$opt " + # printf "%s" "mode_option=$opt " # Presumably a boolean else - echo -n "${opt}=1 " + printf "%s" "${opt}=1 " fi done } @@ -64,6 +64,7 @@ parse_video_opts() FB="" OPTS="" +# shellcheck disable=SC2013 for x in $(cat /proc/cmdline); do case ${x} in vga=*) @@ -99,13 +100,15 @@ esac if [ -n "${FB}" ]; then unset MODPROBE_OPTIONS modprobe -q fbcon + # shellcheck disable=SC2086 modprobe -q ${FB} ${OPTS} fi if [ -e /proc/fb ]; then - while read fbno desc; do - if [ $(($fbno < 32)) ]; then - mknod -m 0640 /dev/fb${fbno} c 29 ${fbno} + # shellcheck disable=SC2034 + while read -r fbno desc; do + if [ $((fbno < 32)) ]; then + mknod -m 0640 "/dev/fb${fbno}" c 29 "${fbno}" fi done < /proc/fb else diff --git a/docs/maintainer-notes.md b/docs/maintainer-notes.md index 0f961adfa2b7d1f358bc13456bae2c4dfde9f2b1..380c865619ea270bc8bb0d9516fd46b36260328d 100644 --- a/docs/maintainer-notes.md +++ b/docs/maintainer-notes.md @@ -1,42 +1,19 @@ -*** - # Maintainer documentation for initramfs-tools -*** - -## Table of Contents - -* [1. Definitions](#definitions) -* [2. Preparations](#preparations) -* [3. Workflow for daily work](#workflow) - * [3.1 Implement new features](#newfeature) - * [3.2 Merge branches](#merge) - * [3.3 Test specific branch](#test) - * [3.4 Build snapshot version](#snapshot) -* [4. Contribute](#contribute) -* [5. Release new version](#release) -* [6. Resources](#resources) -* [7. Credits](#credits) -* [8. License](#license) - -*** +[[_TOC_]] **NOTE:** The most recent version of this document is available at docs/maintainer-notes.md in the [the git repository](#checkout) or online at [salsa.debian.org](https://salsa.debian.org/kernel-team/initramfs-tools/blob/master/docs/maintainer-notes.md). -*** - ## 1. Definitions - - - - - -
$mailaddress:mailaddress of the user
$username:name of the Salsa account
$version:version string
$yourname:your fullname
- -*** +| Name | Meaning | +| --- | --- | +| **`$mailaddress`** | mailaddress of the user | +| **`$username`** | name of the Salsa account | +| **`$version`** | version string | +| **`$yourname`** | your fullname | ## 2. Preparations @@ -64,8 +41,6 @@ or online at [salsa.debian.org](https://salsa.debian.org/kernel-team/initramfs-t % git clone ssh://git@salsa.debian.org/kernel-team/initramfs-tools.git % cd initramfs-tools -*** - ## 3. Workflow for daily work ### 3.1 Implement new features @@ -137,8 +112,6 @@ any stale remote branches locally by executing: % gbp buildpackage --git-ignore-new --git-debian-branch="$(git branch | awk -F\*\ '/^* / { print $2}' )" --post-clean -*** - ### 3.4 Build snapshot version 1. Adjust debian/changelog accordingly: @@ -150,8 +123,6 @@ any stale remote branches locally by executing: % gbp buildpackage --git-debian-branch="$(git branch | awk -F\*\ '/^* / { print $2}' )" --post-clean [-us -uc] -*** - ## 4. Contribute 1. Create patch: @@ -167,8 +138,6 @@ any stale remote branches locally by executing: Discussion of features, bugs and patches are more than welcome on one of these lists. -*** - ## 5. Release new version 1. Creating changelog: @@ -202,8 +171,6 @@ any stale remote branches locally by executing: debian-kernel@lists.debian.org + kernel-team@lists.ubuntu.com - including a shortlog (generated through "git shortlog $TAG.."). -*** - ## 6. Resources * [initramfs-tools git web interface](https://salsa.debian.org/kernel-team/initramfs-tools) @@ -214,21 +181,14 @@ any stale remote branches locally by executing: * [bugreports @ ubuntu](https://bugs.launchpad.net/ubuntu/+source/initramfs-tools) * [qa page @ ubuntu](http://status.qa.ubuntu.com/qapkgstatus/initramfs-tools) -*** - ## 7. Credits -* Thanks to Daniel Baumann for his "[Debian Packaging with Git](http://documentation.debian-projects.org/other/debian-packaging-git/)" which inspired this document. - -*** +* Thanks to Daniel Baumann for his "[Debian Packaging with Git](https://web.archive.org/web/20110528125600/http://documentation.debian-projects.org/other/debian-packaging-git/)" which inspired this document. ## 8. License * This document is licensed under GPL v2 or any later version. -*** - *-- Michael Prokop <[mika@debian.org](mailto:mika@debian.org)>, -Ben Hutchings <[ben@decadent.org.uk](mailto:ben@decadent.org.uk)>* +Ben Hutchings <[benh@debian.org](mailto:benh@debian.org)>* -*** diff --git a/hook-functions b/hook-functions index 9f5690ea0378f5d03916167a5eea021e0de1137e..cc7e07ff5768729989553fa0d28835c5d4535b4c 100644 --- a/hook-functions +++ b/hook-functions @@ -44,12 +44,44 @@ add_modules_from_file() return fi - grep '^[^#]' ${1} | while read module args; do + grep '^[^#]' "${1}" | while read -r module args; do [ -n "$module" ] || continue force_load "${module}" "${args}" done } +# Locate a firmware file with the given name and copy it into DESTDIR, unless +# DESTDIR already contains such a file. +# Returns an error if no such firmware file can be located and DESTDIR doesn't +# already contain any matching file. (It is up to the caller to figure out +# whether a warning should be printed in that case.) +add_firmware() +{ + local firmware fwloc + + firmware="${1}" + + if [ -e "${DESTDIR}/lib/firmware/updates/${version?}/${firmware}" ] \ + || [ -e "${DESTDIR}/lib/firmware/updates/${firmware}" ] \ + || [ -e "${DESTDIR}/lib/firmware/${version}/${firmware}" ] \ + || [ -e "${DESTDIR}/lib/firmware/${firmware}" ]; then + return 0 + fi + + for fwloc in "/lib/firmware/updates/${version}/${firmware}" \ + "/lib/firmware/updates/${firmware}" \ + "/lib/firmware/${version}/${firmware}" \ + "/lib/firmware/${firmware}"; do + if [ -e "$fwloc" ]; then + copy_file firmware "$fwloc" + return 0 + fi + done + + # We can't figure out where to get that firmware from. + return 1 +} + # Add dependent modules + eventual firmware manual_add_modules() { @@ -64,9 +96,10 @@ manual_add_modules() # module.ko' as we want. However it also means that 'softdep' # configuration lines and embedded softdep information is not # processed. So we run twice, with and without this option. - { modprobe --all --set-version="${version}" --ignore-install --quiet --show-depends "$@"; + # shellcheck disable=SC2034 + { modprobe --all --set-version="${version?}" --ignore-install --quiet --show-depends "$@"; modprobe --all --set-version="${version}" --quiet --show-depends "$@"; } | - while read prefix kmod options ; do + while read -r prefix kmod options ; do if [ "${prefix}" != "insmod" ]; then continue fi @@ -75,20 +108,15 @@ manual_add_modules() # Add required firmware for firmware in $(modinfo -k "${version}" -F firmware "${kmod}"); do - if [ -e "${DESTDIR}/lib/firmware/${firmware}" ] \ - || [ -e "${DESTDIR}/lib/firmware/${version}/${firmware}" ]; then - continue - fi - # Only print warning for missing fw of loaded module # or forced loaded module - if [ ! -e "/lib/firmware/${firmware}" ] \ - && [ ! -e "/lib/firmware/${version}/${firmware}" ] ; then + if ! add_firmware "$firmware"; then # Only warn about missing firmware if # /proc/modules exists if [ ! -e /proc/modules ] ; then continue fi + # shellcheck disable=SC2154 if [ "${verbose}" != "y" ]; then continue fi @@ -100,17 +128,35 @@ manual_add_modules() fi continue fi - - if [ -e "/lib/firmware/${version}/${firmware}" ]; then - copy_file firmware \ - "/lib/firmware/${version}/${firmware}" - else - copy_file firmware "/lib/firmware/${firmware}" - fi done done } +# manual_add_modules() takes care of adding firmware for things that were built +# as modules; but drivers can also be built into the kernel itself. To cover +# that case, we have to look at modules.builtin.modinfo instead. +# This file is generated by the kernel's build process since commit 898490c010b5 +# ("moduleparam: Save information about built-in modules in separate file"), +# which was added in Linux 5.2. +add_builtin_firmware() +{ + local builtin_modinfo_path builtin_modname firmware + + builtin_modinfo_path="/lib/modules/${version?}/modules.builtin.modinfo" + if [ ! -e "$builtin_modinfo_path" ]; then + if linux-version compare "${version}" ge 5.2; then + echo "W: Can't find modules.builtin.modinfo (for locating built-in drivers' firmware, supported in Linux >=5.2)" >&2 + fi + return + fi + + tr '\0' '\n' < "$builtin_modinfo_path" | grep -E '^[^=]*\.firmware=' | sed -n 's/\.firmware=/\t/p' | while read -r builtin_modname firmware; do + if ! add_firmware "$firmware"; then + echo "W: Possible missing firmware /lib/firmware/${firmware} for built-in driver ${builtin_modname}" >&2 + fi + done +} + # $1 = file type (for logging) # $2 = file to copy to initramfs # $3 (optional) Name for the file on the initramfs @@ -130,10 +176,14 @@ copy_file() { target="${target}/${src##*/}" fi + # Canonicalise usr-merged target directories + case "${target}" in + /bin/* | /lib* | /sbin/*) target="/usr${target}" ;; + esac + # check if already copied [ -e "${DESTDIR}/${target}" ] && return 1 - #FIXME: inst_dir mkdir -p "${DESTDIR}/${target%/*}" if [ -h "${src}" ]; then @@ -141,8 +191,16 @@ copy_file() { # just link directly to the ultimate target link_target="$(readlink -f "${src}")" || return $(($? + 1)) + # Update source for the copy + src="${link_target}" + + # Canonicalise usr-merged target directories + case "${link_target}" in + /bin/* | /lib* | /sbin/*) link_target="/usr${link_target}" ;; + esac + if [ "${link_target}" != "${target}" ]; then - [ "${verbose}" = "y" ] && echo "Adding ${type}-link ${src}" + [ "${verbose?}" = "y" ] && echo "Adding ${type}-link ${target}" # Create a relative link so it always points # to the right place @@ -150,7 +208,6 @@ copy_file() { fi # Copy the link target if it doesn't already exist - src="${link_target}" target="${link_target}" [ -e "${DESTDIR}/${target}" ] && return 0 mkdir -p "${DESTDIR}/${target%/*}" @@ -161,7 +218,7 @@ copy_file() { cp -pP "${src}" "${DESTDIR}/${target}" || return $(($? + 1)) } -# $1 = executable to copy to initramfs, with library dependencies +# $1 = executable/shared library to copy to initramfs, with dependencies # $2 (optional) Name for the file on the initramfs # Location of the image dir is assumed to be $DESTDIR # We never overwrite the target if it exists. @@ -174,7 +231,7 @@ copy_exec() { copy_file binary "${src}" "${target}" || return $(($? - 1)) # Copy the dependant libraries - for x in $(ldd "${src}" 2>/dev/null | sed -e ' + for x in $(env --unset=LD_PRELOAD ldd "${src}" 2>/dev/null | sed -e ' /\//!d; /linux-gate/d; /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/}; @@ -190,13 +247,29 @@ copy_exec() { x="${nonoptlib}" fi - copy_file library "${x}" || { + # Handle common dlopen() dependency (Debian bug #950254) + case "${x}" in + */libpthread.so.*) + copy_libgcc "${x%/*}" || return + ;; + esac + + copy_file binary "${x}" || { ret=$? [ ${ret} = 1 ] || return $((ret - 1)) } done } +copy_libgcc() { + local libdir library + + libdir="$1" + for library in "${libdir}"/libgcc_s.so.[1-9]; do + copy_exec "${library}" || return + done +} + # Copy entire subtrees to the initramfs copy_modules_dir() { @@ -227,9 +300,11 @@ copy_modules_dir() first=false done + # shellcheck disable=SC2044 for kmod in $(find "${MODULESDIR}/${dir}" "$@" -name '*.ko*' -printf '%f\n'); do modules="$modules ${kmod%%.*}" done + # shellcheck disable=SC2086 manual_add_modules $modules } @@ -249,15 +324,15 @@ sys_walk_mod_add() fi # current driver module - driver_path="$(readlink -f ${device_path}/driver/module)" + driver_path="$(readlink -f "${device_path}/driver/module")" if [ -e "$driver_path" ]; then - module="$(basename $(readlink -f $driver_path))" + module="$(basename "$(readlink -f "$driver_path")")" if [ -n "${module}" ]; then manual_add_modules "${module}" fi fi - device_path="$(dirname ${device_path})" + device_path="$(dirname "${device_path}")" done } @@ -276,11 +351,11 @@ block_dev_sys_walk_mod_add() fi # Iterate over component of a layered device - ls -1 "$disk_sys_path/slaves" | while read component; do - block_dev_sys_walk_mod_add "$disk_sys_path/slaves/$component" + find "$disk_sys_path/slaves" -mindepth 1 -maxdepth 1 | while read -r component; do + block_dev_sys_walk_mod_add "$component" done - sys_walk_mod_add ${dev_sys_path} + sys_walk_mod_add "${dev_sys_path}" } block_dev_mod_add() @@ -311,22 +386,22 @@ block_dev_mod_add() add_loaded_modules() { local pattern="$1" - local module - local builtin=/lib/modules/$(uname -r)/modules.builtin + local module builtin + builtin="/lib/modules/$(uname -r)/modules.builtin" for module in /sys/module/$pattern; do if [ -d "$module" ]; then - manual_add_modules $(basename $module) + manual_add_modules "$(basename "$module")" fi done - if [ -f $builtin ]; then - while read module; do + if [ -f "$builtin" ]; then + while read -r module; do case "$module" in */$pattern.ko) - manual_add_modules $(basename $module .ko) + manual_add_modules "$(basename "$module" .ko)" ;; esac - done < $builtin + done < "$builtin" fi } @@ -344,9 +419,10 @@ dep_add_modules_mount() fi # find out block device + fstype - eval "$(while read dev mp fs opts rest ; do \ + # shellcheck disable=SC2034 + eval "$(while read -r dev mp fs opts rest ; do \ [ "$mp" = "$dir" ] && [ "$fs" != "rootfs" ] \ - && printf "dev_node=$dev\nFSTYPE=$fs"\ + && printf "dev_node=%s\\nFSTYPE=%s" "$dev" "$fs"\ && break; done < /proc/mounts)" # Only the root mountpoint has to exist; do nothing if any other @@ -365,11 +441,12 @@ dep_add_modules_mount() if [ "$dir" = / ] && [ "${dev_node}" = "/dev/root" ] ; then if [ -b "${dev_node}" ]; then # Match it to the canonical device name by UUID - dev_node="/dev/disk/by-uuid/"$(blkid -o value -s UUID ${dev_node}) 2>/dev/null + dev_node="/dev/disk/by-uuid/"$(blkid -o value -s UUID "${dev_node}") 2>/dev/null else # Does not exist in our namespace, so look at the # kernel command line dev_node= + # shellcheck disable=SC2013 for arg in $(cat /proc/cmdline); do case "$arg" in root=*) @@ -389,7 +466,7 @@ dep_add_modules_mount() fi # recheck device - if [ -z "$dev_node" ] || ! dev_node="$(readlink -f ${dev_node})" \ + if [ -z "$dev_node" ] || ! dev_node="$(readlink -f "${dev_node}")" \ || ! [ -b "$dev_node" ]; then echo "mkinitramfs: failed to determine device for $dir" >&2 echo "mkinitramfs: workaround is MODULES=most, check:" >&2 @@ -401,7 +478,7 @@ dep_add_modules_mount() fi # do not trust mount, check superblock - eval "$(/usr/lib/klibc/bin/fstype ${dev_node})" + eval "$(/usr/lib/klibc/bin/fstype "${dev_node}")" # check that fstype fs recognition if [ "${FSTYPE}" = "unknown" ]; then @@ -415,11 +492,21 @@ dep_add_modules_mount() fi # Add filesystem - manual_add_modules ${FSTYPE} + manual_add_modules "${FSTYPE}" block_dev_mod_add "$dev_node" } +class_add_modules() +{ + local device + + for device in "/sys/class/$1"/*; do + device="$(readlink -f "$device")" \ + && sys_walk_mod_add "$device" + done +} + dep_add_modules() { local device dev_node @@ -436,11 +523,8 @@ dep_add_modules() fi # sys walk some important device classes - for class in gpio phy regulator rtc; do - for device in /sys/class/$class/*; do - device="$(readlink -f "$device")" \ - && sys_walk_mod_add "$device" - done + for class in extcon gpio phy pwm regulator rtc; do + class_add_modules "$class" done # clk, USB-PHY and pinctrl devices are outside the device model (!) so @@ -460,6 +544,24 @@ dep_add_modules() fi done + # Sys walk graphics for machines that don't have a generic framebuffer + # device and wouldn't have a working video console otherwise. + walk_graphics=yes + for device in /sys/bus/platform/drivers/efi-framebuffer/* \ + /sys/bus/platform/drivers/platform-framebuffer/* \ + /sys/bus/platform/drivers/simple-framebuffer/* \ + /sys/bus/platform/drivers/vesa-framebuffer/*; do + if [ -d "$device" ]; then + walk_graphics=no + break + fi + done + + if [ "$walk_graphics" = "yes" ]; then + class_add_modules backlight + class_add_modules graphics + fi + # catch old-style IDE if [ -e /sys/bus/ide/devices/ ]; then modules="$modules ide-gd_mod ide-cd" @@ -490,6 +592,11 @@ dep_add_modules() modules="$modules sunvnet sunvdc" fi + if [ -e /sys/devices/platform/edp-panel ]; then + sys_walk_mod_add /sys/devices/platform/edp-panel + fi + + # shellcheck disable=SC2086 manual_add_modules $modules } @@ -500,13 +607,13 @@ auto_add_modules() local modules= if [ "$#" -eq 0 ] ; then - set -- base net ide scsi block ata i2o dasd ieee1394 firewire mmc usb_storage + set -- base net ide scsi block ata i2o dasd ieee1394 firewire mmc usb_storage fb fi for arg in "$@" ; do case "$arg" in base) - modules="$modules btrfs ext2 ext3 ext4 ext4dev " + modules="$modules btrfs ext2 ext3 ext4 f2fs" modules="$modules isofs jfs reiserfs udf xfs" modules="$modules nfs nfsv2 nfsv3 nfsv4" modules="$modules af_packet atkbd i8042 psmouse" @@ -524,15 +631,17 @@ auto_add_modules() copy_modules_dir kernel/drivers/usb/musb copy_modules_dir kernel/drivers/usb/renesas_usbhs # and any extcon drivers for USB - modules="$modules extcon-usb-gpio" + modules="$modules extcon-usb-gpio extcon-usbc-cros-ec" # Add the axp20x_usb_power power supply driver, # required to initialize the USB host controllers # on a number of armhf systems modules="$modules axp20x_usb_power" - # Include all HID drivers unless we're sure they - # don't support keyboards. hid-*ff covers various - # game controllers with force feedback. + # Include all keyboard drivers and all HID drivers + # unless we're sure they don't support keyboards. + # hid-*ff covers various game controllers with + # force feedback. + copy_modules_dir kernel/drivers/input/keyboard copy_modules_dir kernel/drivers/hid \ 'hid-*ff.ko' hid-a4tech.ko hid-cypress.ko \ hid-dr.ko hid-elecom.ko hid-gyration.ko \ @@ -546,6 +655,8 @@ auto_add_modules() hid-speedlink.ko hid-tivo.ko hid-twinhan.ko \ hid-uclogic.ko hid-wacom.ko hid-waltop.ko \ hid-wiimote.ko hid-zydacron.ko + # needed to access keyboard on some ChromeOS devices + modules="$modules cros_ec_spi" # Any of these might be needed by other drivers copy_modules_dir kernel/drivers/bus @@ -554,9 +665,12 @@ auto_add_modules() copy_modules_dir kernel/drivers/i2c/busses copy_modules_dir kernel/drivers/i2c/muxes copy_modules_dir kernel/drivers/mfd + copy_modules_dir kernel/drivers/pci/controller copy_modules_dir kernel/drivers/phy copy_modules_dir kernel/drivers/pinctrl copy_modules_dir kernel/drivers/regulator + copy_modules_dir kernel/drivers/reset + copy_modules_dir kernel/drivers/spi copy_modules_dir kernel/drivers/usb/phy # Needed for periodic fsck @@ -606,9 +720,15 @@ auto_add_modules() usb_storage) copy_modules_dir kernel/drivers/usb/storage ;; + fb) + # For machines that don't have a generic framebuffer device. + modules="$modules rockchipdrm pwm-cros-ec pwm_bl panel-simple" + modules="$modules analogix-anx6345 pwm-sun4i sun4i-drm sun8i-mixer" + ;; esac done + # shellcheck disable=SC2086 manual_add_modules $modules } @@ -619,12 +739,13 @@ auto_add_modules() # hidden dependencies. hidden_dep_add_modules() { + # shellcheck disable=SC2046 manual_add_modules $( { cat "${DESTDIR}/lib/modules/${version}/modules.builtin" find "${DESTDIR}/lib/modules/${version}/kernel" -name '*.ko*' } | - while read module; do + while read -r module; do module="${module##*/}" module="${module%%.*}" case "$module" in @@ -637,6 +758,9 @@ hidden_dep_add_modules() btrfs) echo crc32c ;; + f2fs) + echo crc32 + ;; mlx4_core) echo mlx4_ib ;; @@ -649,31 +773,17 @@ hidden_dep_add_modules() nvme) echo vmd ;; + spi-rockchip) + echo pl330 + ;; + dw_mmc-rockchip) + echo rockchip-io-domain + ;; esac done ) } -# mkinitramfs help message -usage() -{ - cat >&2 << EOF - -Usage: ${0} [OPTION]... -o outfile [version] - -Options: - -c compress Override COMPRESS setting in initramfs.conf. - -d confdir Specify an alternative configuration directory. - -k Keep temporary directory used to make the image. - -o outfile Write to outfile. - -r root Override ROOT setting in initramfs.conf. - -See mkinitramfs(8) for further details. -EOF - exit 1 - -} - # Find the source for a script file. This is needed to work around # temporary directories mounted with the noexec option. The source # will be on / or /usr which must be executable. @@ -691,7 +801,7 @@ get_source() set_initlist() { unset initlist - for si_x in ${initdir}/*; do + for si_x in "${initdir}"/*; do # skip empty dirs without warning [ "${si_x}" = "${initdir}/*" ] && return @@ -705,7 +815,7 @@ set_initlist() esac # skip directories - if [ -d ${si_x} ]; then + if [ -d "${si_x}" ]; then [ "${verbose}" = "y" ] \ && echo "$si_x ignored: a directory" >&2 continue @@ -714,14 +824,14 @@ set_initlist() si_x="$(get_source "${si_x#${initdir}/}")" # skip non executable scripts - if [ ! -x ${si_x} ]; then + if [ ! -x "${si_x}" ]; then [ "${verbose}" = "y" ] \ && echo "$si_x ignored: not executable" >&2 continue fi # skip bad syntax - if ! sh -n ${si_x} ; then + if ! sh -n "${si_x}" ; then [ "${verbose}" = "y" ] \ && echo "$si_x ignored: bad syntax" >&2 continue @@ -735,11 +845,11 @@ get_prereq_pairs() { set_initlist for gp_x in ${initlist:-}; do - echo ${gp_x} ${gp_x} - gp_src="$(get_source $gp_x)" + echo "${gp_x} ${gp_x}" + gp_src="$(get_source "$gp_x")" prereqs=$("${gp_src}" prereqs) for prereq in ${prereqs}; do - echo ${prereq} ${gp_x} + echo "${prereq} ${gp_x}" done done } @@ -750,14 +860,14 @@ cache_run_scripts() DESTDIR=${1} scriptdir=${2} initdir=${DESTDIR}${scriptdir} - [ ! -d ${initdir} ] && return + [ ! -d "${initdir}" ] && return - > ${initdir}/ORDER + true > "${initdir}/ORDER" runlist=$(get_prereq_pairs | tsort) for crs_x in ${runlist}; do - [ -f ${initdir}/${crs_x} ] || continue - echo "${scriptdir}/${crs_x} \"\$@\"" >> ${initdir}/ORDER - echo "[ -e /conf/param.conf ] && . /conf/param.conf" >> ${initdir}/ORDER + [ -f "${initdir}/${crs_x}" ] || continue + echo "${scriptdir}/${crs_x} \"\$@\"" >> "${initdir}/ORDER" + echo "[ -e /conf/param.conf ] && . /conf/param.conf" >> "${initdir}/ORDER" done } @@ -765,15 +875,15 @@ call_scripts() { set -e for cs_x in ${runlist}; do - [ -f ${initdir}/${cs_x} ] || continue + [ -f "${initdir}/${cs_x}" ] || continue # mkinitramfs verbose output if [ "${verbose}" = "y" ]; then echo "Calling hook ${cs_x}" fi - ${initdir}/${cs_x} && ec=$? || ec=$? + "${initdir}/${cs_x}" && ec=$? || ec=$? # allow hooks to abort build: if [ "$ec" -ne 0 ]; then - echo "E: ${initdir}/${cs_x} failed with return $ec." + echo "E: ${initdir}/${cs_x} failed with return $ec." >&2 # only errexit on mkinitramfs [ -n "${version}" ] && exit $ec fi @@ -789,8 +899,8 @@ run_scripts() { scriptdir=${2:-} initdir=${1} - [ ! -d ${initdir} ] && return + [ ! -d "${initdir}" ] && return runlist=$(get_prereq_pairs | tsort) - call_scripts $scriptdir + call_scripts "$scriptdir" } diff --git a/hooks/fsck b/hooks/fsck index e4779fc80f7a2cd0dff8bf50cc9a1dd64e19d6c1..15127ddc1cc22c8cccdd7ff68be32a416e9ccd41 100755 --- a/hooks/fsck +++ b/hooks/fsck @@ -7,14 +7,6 @@ prereqs() echo "$PREREQ" } -fstab_files() -{ - echo /etc/fstab - if [ -d /etc/fstab.d ]; then - ls -1 /etc/fstab.d | grep '\.fstab$' | sed -e 's;^;/etc/fstab.d/;' - fi -} - # Find a specific fstab entry # $1=mountpoint # $2=fstype (optional) @@ -24,9 +16,10 @@ _read_fstab_entry () { echo "MNT_DIR=" echo "MNT_TYPE=" - fstab_files | while read file; do + for file in /etc/fstab /etc/fstab.d/*.fstab; do if [ -f "$file" ]; then - while read MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do + # shellcheck disable=SC2034 + while read -r MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do case "$MNT_FSNAME" in ""|\#*) continue; @@ -60,7 +53,9 @@ get_fsck_type_fstab () { if [ "${MNT_DIR}" = "/" ] || [ "${MNT_TYPE}" = "auto" ]; then MNT_FSNAME="$(resolve_device "${MNT_FSNAME}")" fstype() { "/usr/lib/klibc/bin/fstype" "$@"; } - get_fstype "${MNT_FSNAME}" + if ! get_fstype "${MNT_FSNAME}"; then + echo "W: Couldn't identify type of $2 file system for fsck hook" >&2 + fi unset -f fstype else echo "${MNT_TYPE}" @@ -69,8 +64,18 @@ get_fsck_type_fstab () { } get_fsck_types() { - get_fsck_type_fstab / - get_fsck_type_fstab /usr + if [ "${FSTYPE:-auto}" = auto ]; then + get_fsck_type_fstab / root + get_fsck_type_fstab /usr usr + else + local IFS=, + local fstype + set -f + for fstype in $FSTYPE; do + echo "$fstype" + done + set +f + fi } case $1 in @@ -97,14 +102,9 @@ copy_exec /sbin/fsck copy_exec /sbin/logsave for type in $fsck_types; do - if [ "$type" = "unknown" ] ; then - echo "Warning: couldn't identify filesystem type for fsck hook, ignoring." - continue - fi - - if prog="$(command -v fsck.${type})"; then + if prog="$(command -v "fsck.${type}")"; then copy_exec "$prog" else - echo "Warning: /sbin/fsck.${type} doesn't exist, can't install to initramfs, ignoring." + echo "W: /sbin/fsck.${type} doesn't exist, can't install to initramfs" >&2 fi done diff --git a/hooks/keymap b/hooks/keymap index b88d95c7960df7525fa49701935aaf48f81c7fd2..64f8e6d167abe25c9a76a7c396763f2b5cb07d57 100755 --- a/hooks/keymap +++ b/hooks/keymap @@ -20,47 +20,21 @@ if [ "$KEYMAP" != "y" ] && [ "$KEYMAP" != "Y" ]; then exit 0 fi -# Step 1 - Basic tools -if [ ! -x /bin/loadkeys ]; then - echo "loadkeys is missing. Please install the 'kbd' package." - exit 0 -fi - if [ ! -x /bin/setupcon ]; then echo "setupcon is missing. Please install the 'console-setup' package." exit 0 fi . /usr/share/initramfs-tools/hook-functions -copy_exec /bin/loadkeys /bin -if ! setupcon --save-keyboard ${DESTDIR}/etc/boottime.kmap.gz ; then - echo "Warning: error while trying to store keymap file - ignoring request to install /etc/boottime.kmap.gz" - rm -f ${DESTDIR}/etc/boottime.kmap.gz - exit 0 -fi +# Tell setupcon to copy/create the files it needs. +setupcon --setup-dir "$DESTDIR" -# Step 2 - Check for UTF8 console -if [ ! -x /usr/bin/kbd_mode ]; then - exit 0 -fi +# Copy additional files that setupcon needs. We assume they are +# executables. +while read -r file; do + copy_exec "$file" +done < "$DESTDIR/morefiles" +rm -f "$DESTDIR/morefiles" -if [ -r /etc/environment ]; then - env="/etc/environment" -elif [ -r /etc/default/locale ]; then - env="/etc/default/locale" -else - exit 0 -fi - -for var in LANG LC_ALL LC_CTYPE; do - value=$(egrep "^[^#]*${var}=" $env | tail -n1 | cut -d= -f2) - eval $var=$value -done - -charmap=$(LANG=$LANG LC_ALL=$LC_ALL LC_CTYPE=$LC_CTYPE locale charmap) -if [ "$charmap" = "UTF-8" ]; then - copy_exec /usr/bin/kbd_mode /bin -fi exit 0 - diff --git a/hooks/resume b/hooks/resume index df6cde89375c15558336cc8388a7669a7b47deb1..0cd78fefa2ae5e6dc9296adce528fa20caa0b855 100755 --- a/hooks/resume +++ b/hooks/resume @@ -32,25 +32,39 @@ if [ -n "$RESUME" ] && [ "$RESUME" != auto ]; then echo >&2 "W: but no matching swap device is available." fi -# If we were not explicitly requested to select a device, report that we -# are doing so +# If we were not explicitly requested to select a device, or the -v +# option is used, report that we are doing so report_auto() { - test "$RESUME" = auto || echo >&2 "I: $*" + test "${verbose?}" != y && test "$RESUME" = auto || echo "I: $*" } +# Report in excruciating detail if the -v option is used +report_verbose() +{ + test "${verbose?}" != y || echo "I: $*" +} + +report_verbose "Configuration sets RESUME=$RESUME" + # Try to autodetect the RESUME partition, using biggest swap device that # is not ephemeral. We need to be able to read the listed swap partitions. resume_auto= if ! ischroot && [ -r /proc/swaps ]; then + # shellcheck disable=SC2013 for resume_auto in $(grep ^/dev/ /proc/swaps | sort -rnk3 | cut -d " " -f 1); do + report_verbose "Checking swap device $resume_auto" ephemeral=false dm_name="$(dmsetup info -c --noheadings -o name "$resume_auto" 2>/dev/null)" # dm-crypt is ephemeral if the key file is /dev/urandom if [ -n "$dm_name" ] && [ -e /etc/crypttab ]; then - while read cryptdev srcdev keyfile junk; do + report_verbose "$resume_auto has device-mapper name $dm_name; checking crypttab" + # shellcheck disable=SC2034 + while read -r cryptdev srcdev keyfile junk; do + report_verbose "Found cryptdev=$cryptdev keyfile=$keyfile" if [ "$cryptdev" = "$dm_name" ] && [ "$keyfile" = /dev/urandom ]; then + report_verbose "Rejecting $resume_auto since it has no permanent key" ephemeral=true fi done < /etc/crypttab @@ -59,6 +73,7 @@ if ! ischroot && [ -r /proc/swaps ]; then # zram is ephemeral case "$resume_auto" in /dev/zram*) + report_verbose "Rejecting $resume_auto since it is zram" ephemeral=true ;; esac @@ -66,7 +81,10 @@ if ! ischroot && [ -r /proc/swaps ]; then $ephemeral || break done - if [ -n "$resume_auto" ] && ! $ephemeral; then + if $ephemeral; then + resume_auto= + fi + if [ -n "$resume_auto" ]; then if [ -n "$dm_name" ]; then resume_auto_canon="/dev/mapper/$dm_name" elif UUID=$(blkid -s UUID -o value "$resume_auto"); then @@ -90,5 +108,5 @@ if [ "$RESUME" = auto ] || [ -n "$resume_auto" ]; then if [ -z "$resume_auto" ]; then echo >&2 "W: initramfs-tools failed to select a resume device" fi - echo "RESUME=${resume_auto}" > ${DESTDIR}/conf/conf.d/zz-resume-auto + echo "RESUME=${resume_auto}" > "${DESTDIR}/conf/conf.d/zz-resume-auto" fi diff --git a/hooks/thermal b/hooks/thermal index 93f510019ebc48cc7ef6df05ce84ed5f87f2ee91..0a42c123499eba87f1f0d6f6796d6033892c5904 100755 --- a/hooks/thermal +++ b/hooks/thermal @@ -24,16 +24,19 @@ case "$DPKG_ARCH" in powerpc|ppc64) # Only G5 Mac machines need to load - # therm_pm72 or one of the windfarm_pm* modules. + # windfarm_core or one of the windfarm_pm* modules. [ -r /proc/cpuinfo ] || exit 0 - MODEL="`grep model /proc/cpuinfo`" + MODEL="$(grep model /proc/cpuinfo)" MODEL="${MODEL##*: }" case "$MODEL" in - RackMac3,1|PowerMac7,2|PowerMac7,3) - force_load therm_pm72 + RackMac3,1) + force_load windfarm_rm31 + ;; + PowerMac7,2|PowerMac7,3) + force_load windfarm_pm72 ;; PowerMac8,1|PowerMac8,2) force_load windfarm_pm81 diff --git a/init b/init index 5d10622c9424e676f394f9b1cea50eb330307f78..b7f1cc7e115ecc0380f98e589749e1a9c7eae3f0 100755 --- a/init +++ b/init @@ -13,6 +13,7 @@ mkdir -p /var/lock mount -t sysfs -o nodev,noexec,nosuid sysfs /sys mount -t proc -o nodev,noexec,nosuid proc /proc +# shellcheck disable=SC2013 for x in $(cat /proc/cmdline); do case $x in initramfs.clear) @@ -62,6 +63,7 @@ export panic= export blacklist= export resume= export resume_offset= +export noresume= export drop_caps= export fastboot=n export forcefsck=n @@ -76,6 +78,7 @@ done . /scripts/functions # Parse command line options +# shellcheck disable=SC2013 for x in $(cat /proc/cmdline); do case $x in init=*) @@ -102,6 +105,7 @@ for x in $(cat /proc/cmdline); do esac ;; nfsroot=*) + # shellcheck disable=SC2034 NFSROOT="${x#nfsroot=}" ;; initramfs.runsize=*) @@ -118,10 +122,6 @@ for x in $(cat /proc/cmdline); do ;; resume=*) RESUME="${x#resume=}" - case $RESUME in - UUID=*) - RESUME="/dev/disk/by-uuid/${RESUME#UUID=}" - esac ;; resume_offset=*) resume_offset="${x#resume_offset=}" @@ -134,11 +134,6 @@ for x in $(cat /proc/cmdline); do ;; panic=*) panic="${x#panic=}" - case ${panic} in - *[![:digit:].]*) - panic= - ;; - esac ;; ro) readonly=y @@ -198,14 +193,13 @@ if [ -z "${BOOT}" ]; then fi if [ -n "${noresume}" ] || [ "$RESUME" = none ]; then - export noresume=y - unset resume + noresume=y else resume=${RESUME:-} fi -mount -t tmpfs -o "noexec,nosuid,size=${RUNSIZE:-10%},mode=0755" tmpfs /run -mkdir -m 0755 /run/initramfs +mount -t tmpfs -o "nodev,noexec,nosuid,size=${RUNSIZE:-10%},mode=0755" tmpfs /run +mkdir -m 0700 /run/initramfs if [ -n "$log_output" ]; then exec >$log_output 2>&1 @@ -223,8 +217,12 @@ maybe_break modules load_modules [ "$quiet" != "y" ] && log_end_msg +starttime="$(_uptime)" +starttime=$((starttime + 1)) # round up +export starttime + if [ "$ROOTDELAY" ]; then - sleep $ROOTDELAY + sleep "$ROOTDELAY" fi maybe_break premount @@ -311,15 +309,18 @@ unset quiet unset readonly unset resume unset resume_offset +unset noresume unset fastboot unset forcefsck unset fsckfix +unset starttime # Move virtual filesystems over to the real filesystem mount -n -o move /sys ${rootmnt}/sys mount -n -o move /proc ${rootmnt}/proc # Chain to real filesystem -exec run-init ${drop_caps} "${rootmnt}" "${init}" "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1 +# shellcheck disable=SC2086,SC2094 +exec run-init ${drop_caps} "${rootmnt}" "${init}" "$@" <"${rootmnt}/dev/console" >"${rootmnt}/dev/console" 2>&1 echo "Something went badly wrong in the initramfs." panic "Please file a bug on initramfs-tools." diff --git a/initramfs-tools.7 b/initramfs-tools.7 index 271c7aa885c63eba78261b2d6c3703a5ab29315d..2d5d2d2bd469c3240aeb9031319eb77bc311b298 100644 --- a/initramfs-tools.7 +++ b/initramfs-tools.7 @@ -267,14 +267,14 @@ copy_modules_dir kernel/drivers/ata .RE .SS Including binaries -If you need to copy binaries to the initramfs module, a command like this -should be used: +If you need to copy an executable or shared library to the initramfs +module, use a command like this: .PP .RS copy_exec /sbin/mdadm /sbin .RE -mkinitramfs will automatically detect which libraries the executable depends on +mkinitramfs will automatically detect which libraries it depends on and copy them to the initramfs. This means that most executables, unless compiled with klibc, will automatically include glibc in the image which will increase its size by several hundred kilobytes. @@ -516,7 +516,7 @@ if [ ! \-x "/sbin/frobnicate" ]; then fi force_load frobnicator interval=10 -cp /sbin/frobnicate "${DESTDIR}/sbin" +copy_exec /sbin/frobnicate /sbin exit 0 .fi .RE @@ -601,6 +601,28 @@ is the path where root gets mounted usually /root. indicates that a debug log is captured for further investigation. +.SH UPDATING THE INITRAMFS FROM ANOTHER PACKAGE +Package maintainer scripts should not run \fBupdate-initramfs\fR +directly. A package that installs hooks for initramfs-tools should +include a triggers file containing: +.RS +.nf +activate\-noawait update\-initramfs +.fi +.RE + +Kernel packages must call the kernel hooks as documented in the +Debian Kernel Handbook. + +A package that requires an initramfs to function, but is not a kernel +package, should include a triggers file containing: +.RS +.nf +activate\-await update\-initramfs +.fi +.RE + + .SH KERNEL HOOKS initramfs-tools includes hook scripts that are called by kernel packages on installation and removal, so that an initramfs is diff --git a/initramfs.conf.5 b/initramfs.conf.5 index e2271518530077a3cf57c13be0af2ca439e42fdc..4615892cc12349a8fd32dff98c28b73c30b36b5c 100644 --- a/initramfs.conf.5 +++ b/initramfs.conf.5 @@ -93,6 +93,12 @@ or is set to \fIauto\fP, will automatically select the largest available swap partition. Set it to \fInone\fP to disable resume from disk. +.TP +\fB FSTYPE +Specifies the filesystem type(s) to support, separated by commas. If +this is not defined or is set to \fIauto\fP, \fBmkinitramfs\fP will +automatically detect the current root and \fI/usr\fP filesystem types. + .SH VARIABLES FOR NFS BOOT .TP \fB DEVICE diff --git a/kernel/postinst.d/initramfs-tools b/kernel/postinst.d/initramfs-tools index 0d463f4031296d114e8f00d3f3c979316c6a1baf..6b6fef39bcb412f9ea8cb65618d6e6ce9c6d431e 100755 --- a/kernel/postinst.d/initramfs-tools +++ b/kernel/postinst.d/initramfs-tools @@ -32,4 +32,5 @@ if [ -n "$DEB_MAINT_PARAMS" ]; then fi # we're good - create initramfs. update runs do_bootloader -INITRAMFS_TOOLS_KERNEL_HOOK=1 update-initramfs -c -t -k "${version}" ${bootopt} >&2 +# shellcheck disable=SC2086 +update-initramfs -c -k "${version}" ${bootopt} >&2 diff --git a/kernel/postrm.d/initramfs-tools b/kernel/postrm.d/initramfs-tools index d58fa6117de27c335965e8c5a57ec98ae30aca69..c340beb1e211262c76aa55f387d2c763d92164e0 100755 --- a/kernel/postrm.d/initramfs-tools +++ b/kernel/postrm.d/initramfs-tools @@ -32,4 +32,5 @@ if [ -n "$DEB_MAINT_PARAMS" ]; then fi # delete initramfs -INITRAMFS_TOOLS_KERNEL_HOOK=1 update-initramfs -d -t -k "${version}" ${bootopt} >&2 +# shellcheck disable=SC2086 +update-initramfs -d -k "${version}" ${bootopt} >&2 diff --git a/lsinitramfs b/lsinitramfs index a96308da277b2f587276978c0e28d026eedb8710..5b3315fb61a17e50d90f9880c720449f7eaa70b2 100755 --- a/lsinitramfs +++ b/lsinitramfs @@ -4,19 +4,27 @@ set -eu usage() { - echo "Usage: $(basename $0) [-l] " + cat << EOF + +Usage: lsinitramfs [-l] initramfs-file... + +Options: + -l Display long and more verbose listing of initramfs content + +See lsinitramfs(8) for further details. + +EOF } -if [ "$#" -eq 0 ] ; then +usage_error() +{ usage >&2 - exit 1 -fi + exit 2 +} umi_opts="--list" -OPTIONS=`getopt -o hl --long help,long -n "$0" -- "$@"` -# Check for non-GNU getopt -if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi +OPTIONS=$(getopt -o hl --long help,long -n "$0" -- "$@") || usage_error eval set -- "$OPTIONS" @@ -40,6 +48,10 @@ while true; do esac done +if [ "$#" -eq 0 ] ; then + usage_error +fi + for initramfs in "$@" ; do unmkinitramfs $umi_opts -- "$initramfs" done diff --git a/lsinitramfs.8 b/lsinitramfs.8 index eb07fa69c3da8b51b815f6f5b582ffa3c696c5a5..c5715525ec72cc65de9144a2db9f8790247cd87a 100644 --- a/lsinitramfs.8 +++ b/lsinitramfs.8 @@ -5,8 +5,10 @@ lsinitramfs \- list content of an initramfs image .SH SYNOPSIS .B lsinitramfs -.RI [ options ] " " [ ] +.RB [ -l ] +.IR initramfs-file ... .br +.BR lsinitramfs " " -h .SH DESCRIPTION The diff --git a/mkinitramfs b/mkinitramfs index 4394a3c9a10216ea0411af6e752a8dc8617f43d2..95169926b1c5a9d86d5c49860c3229c406e956bd 100755 --- a/mkinitramfs +++ b/mkinitramfs @@ -11,10 +11,31 @@ verbose="n" BUSYBOXDIR= export BUSYBOXDIR -OPTIONS=`getopt -o c:d:ko:r:v -n "$0" -- "$@"` +usage() +{ + cat << EOF -# Check for non-GNU getopt -if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi +Usage: mkinitramfs [option]... -o outfile [version] + +Options: + -c compress Override COMPRESS setting in initramfs.conf. + -d confdir Specify an alternative configuration directory. + -k Keep temporary directory used to make the image. + -o outfile Write to outfile. + -r root Override ROOT setting in initramfs.conf. + +See mkinitramfs(8) for further details. + +EOF +} + +usage_error() +{ + usage >&2 + exit 2 +} + +OPTIONS=$(getopt -o c:d:hko:r:v --long help -n "$0" -- "$@") || usage_error eval set -- "$OPTIONS" @@ -32,6 +53,10 @@ while true; do exit 1 fi ;; + -h|--help) + usage + exit 0 + ;; -o) outfile="$2" shift 2 @@ -64,27 +89,35 @@ done . /usr/share/initramfs-tools/hook-functions . "${CONFDIR}/initramfs.conf" + EXTRA_CONF='' -for i in /usr/share/initramfs-tools/conf.d/* ${CONFDIR}/conf.d/*; do - [ -e $i ] && EXTRA_CONF="${EXTRA_CONF} $(basename $i \ - | grep '^[[:alnum:]][[:alnum:]\._-]*$' | grep -v '\.dpkg-.*$')"; -done -# FIXME: deprecated those settings on mkinitramfs run -# these conf dirs are for boot scripts and land on initramfs -for i in ${EXTRA_CONF}; do - if [ -d ${CONFDIR}/conf.d/${i} ]; then - echo "Warning: ${CONFDIR}/conf.d/${i} is a directory instead of file, ignoring." - elif [ -e ${CONFDIR}/conf.d/${i} ]; then - . ${CONFDIR}/conf.d/${i} - elif [ -e /usr/share/initramfs-tools/conf.d/${i} ]; then - . /usr/share/initramfs-tools/conf.d/${i} +maybe_add_conf() { + if [ -e "$1" ] && \ + basename "$1" \ + | grep '^[[:alnum:]][[:alnum:]\._-]*$' \ + | grep -qv '\.dpkg-.*$'; then + if [ -d "$1" ]; then + echo "W: $1 is a directory instead of file" >&2 + else + EXTRA_CONF="${EXTRA_CONF} $1" + . "$1" + fi + fi +} +for i in /usr/share/initramfs-tools/conf.d/*; do + # Configuration files in /etc mask those in /usr/share + if ! [ -e "${CONFDIR}"/conf.d/"$(basename "${i}")" ]; then + maybe_add_conf "${i}" fi done +for i in "${CONFDIR}"/conf.d/*; do + maybe_add_conf "${i}" +done # source package confs for i in /usr/share/initramfs-tools/conf-hooks.d/*; do if [ -d "${i}" ]; then - echo "Warning: ${i} is a directory instead of file, ignoring." + echo "W: ${i} is a directory instead of file." >&2 elif [ -e "${i}" ]; then . "${i}" fi @@ -101,7 +134,7 @@ if [ -n "${UMASK:-}" ]; then fi if [ -z "${outfile}" ]; then - usage + usage_error fi touch "$outfile" @@ -127,34 +160,40 @@ esac case "${version}" in */*) echo "$PROG: ${version} is not a valid kernel version" >&2 - exit 1 + exit 2 ;; esac -# Check userspace and kernel support for compressed initramfs images if [ -z "${compress:-}" ]; then - compress=${COMPRESS} -else - COMPRESS=${compress} + compress=${COMPRESS?} fi +unset COMPRESS if ! command -v "${compress}" >/dev/null 2>&1; then + echo "No ${compress} in ${PATH}, using gzip" compress=gzip - [ "${verbose}" = y ] && \ - echo "No ${COMPRESS} in ${PATH}, using gzip" - COMPRESS=gzip fi -if dpkg --compare-versions "${version}" lt "2.6.38" 2>/dev/null; then - compress=gzip - [ "${verbose}" = y ] && \ - echo "linux-2.6 likely misses ${COMPRESS} support, using gzip" -fi - -[ "${compress}" = gzip ] && [ -n "${SOURCE_DATE_EPOCH}" ] && compress="gzip -n" -[ "${compress}" = lz4 ] && compress="lz4 -9 -l" -[ "${compress}" = lzop ] && compress="lzop -9" -[ "${compress}" = xz ] && compress="xz --check=crc32" +case "${compress}" in +gzip) # If we're doing a reproducible build, use gzip -n + if [ -n "${SOURCE_DATE_EPOCH}" ]; then + compress="gzip -n" + # Otherwise, substitute pigz if it's available + elif command -v pigz >/dev/null; then + compress=pigz + fi + ;; +lz4) compress="lz4 -9 -l" ;; +zstd) compress="zstd -q -19 -T0" ;; +xz) compress="xz --check=crc32" + # If we're not doing a reproducible build, enable multithreading + test -z "${SOURCE_DATE_EPOCH}" && compress="$compress --threads=0" + ;; +bzip2|lzma|lzop) + # no parameters needed + ;; +*) echo "W: Unknown compression command ${compress}" >&2 ;; +esac if [ -d "${outfile}" ]; then echo "${outfile} is a directory" >&2 @@ -164,22 +203,26 @@ fi MODULESDIR="/lib/modules/${version}" if [ ! -e "${MODULESDIR}" ]; then - echo "WARNING: missing ${MODULESDIR}" - echo "Ensure all necessary drivers are built into the linux image!" + echo "W: missing ${MODULESDIR}" >&2 + echo "W: Ensure all necessary drivers are built into the linux image!" >&2 fi if [ ! -e "${MODULESDIR}/modules.dep" ]; then - depmod ${version} + depmod "${version}" fi # Prepare to clean up temporary files on exit DESTDIR= __TMPCPIOGZ= +__TMPMAINCPIO= __TMPEARLYCPIO= clean_on_exit() { if [ "${keep}" = "y" ]; then - echo "Working files in ${DESTDIR:-}, early initramfs in ${__TMPEARLYCPIO:-} and overlay in ${__TMPCPIOGZ:-}" + echo "Working files in ${DESTDIR:-}," \ + "early initramfs in ${__TMPEARLYCPIO:-}," \ + "main initramfs in ${__TMPMAINCPIO:-} and" \ + "overlay in ${__TMPCPIOGZ:-}" else - for path in "${DESTDIR}" "${__TMPCPIOGZ}" "${__TMPEARLYCPIO}"; do + for path in "${DESTDIR}" "${__TMPCPIOGZ}" "${__TMPMAINCPIO}" "${__TMPEARLYCPIO}"; do test -z "${path}" || rm -rf "${path}" done fi @@ -189,12 +232,13 @@ trap "exit 1" INT TERM # makes the EXIT trap effective even when killed # Create temporary directory and files for initramfs contents [ -n "${TMPDIR}" ] && [ ! -w "${TMPDIR}" ] && unset TMPDIR -DESTDIR="$(mktemp -d ${TMPDIR:-/var/tmp}/mkinitramfs_XXXXXX)" || exit 1 +DESTDIR="$(mktemp -d "${TMPDIR:-/var/tmp}/mkinitramfs_XXXXXX")" || exit 1 chmod 755 "${DESTDIR}" -__TMPCPIOGZ="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-OL_XXXXXX)" || exit 1 -__TMPEARLYCPIO="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-FW_XXXXXX)" || exit 1 +__TMPCPIOGZ="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-OL_XXXXXX")" || exit 1 +__TMPMAINCPIO="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-MAIN_XXXXXX")" || exit 1 +__TMPEARLYCPIO="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-FW_XXXXXX")" || exit 1 -DPKG_ARCH=`dpkg --print-architecture` +DPKG_ARCH=$(dpkg --print-architecture) # Export environment for hook scripts. # @@ -208,6 +252,7 @@ export KEYMAP export MODULES export BUSYBOX export RESUME +export FSTYPE # Private, used by 'catenate_cpiogz'. export __TMPCPIOGZ @@ -226,7 +271,9 @@ for d in conf/conf.d etc run scripts ${MODULESDIR}; do done # Copy in modules.builtin and modules.order (not generated by depmod) -for x in modules.builtin modules.order; do +# and modules.builtin.bin (generated by depmod, but too late to avoid +# error messages as in #948257) +for x in modules.builtin modules.builtin.bin modules.order; do if [ -f "${MODULESDIR}/${x}" ]; then cp -p "${MODULESDIR}/${x}" "${DESTDIR}${MODULESDIR}/${x}" fi @@ -255,8 +302,8 @@ list) # nothing to add ;; *) - echo "W: mkinitramfs: unsupported MODULES setting: ${MODULES}." - echo "W: mkinitramfs: Falling back to MODULES=most." + echo "W: mkinitramfs: unsupported MODULES setting: ${MODULES}." >&2 + echo "W: mkinitramfs: Falling back to MODULES=most." >&2 auto_add_modules ;; esac @@ -264,8 +311,11 @@ esac # Resolve hidden dependencies hidden_dep_add_modules +# Add firmware for built-in code +add_builtin_firmware + # First file executed by linux -cp -p /usr/share/initramfs-tools/init ${DESTDIR}/init +cp -p /usr/share/initramfs-tools/init "${DESTDIR}/init" # add existant boot scripts for b in $(cd /usr/share/initramfs-tools/scripts/ && find . \ @@ -283,24 +333,19 @@ for b in $(cd "${CONFDIR}/scripts" && find . -maxdepth 2 -name '.?*' -prune -o \ cp -p "${CONFDIR}/scripts/${b}" "${DESTDIR}/scripts/$(dirname "${b}")/" done -echo "DPKG_ARCH=${DPKG_ARCH}" > ${DESTDIR}/conf/arch.conf -cp -p "${CONFDIR}/initramfs.conf" ${DESTDIR}/conf +echo "DPKG_ARCH=${DPKG_ARCH}" > "${DESTDIR}/conf/arch.conf" +cp -p "${CONFDIR}/initramfs.conf" "${DESTDIR}/conf" for i in ${EXTRA_CONF}; do - if [ -e "${CONFDIR}/conf.d/${i}" ]; then - copy_file config "${CONFDIR}/conf.d/${i}" /conf/conf.d - elif [ -e "/usr/share/initramfs-tools/conf.d/${i}" ]; then - copy_file config "/usr/share/initramfs-tools/conf.d/${i}" \ - /conf/conf.d - fi + copy_file config "${i}" /conf/conf.d done # ROOT hardcoding if [ -n "${ROOT:-}" ]; then - echo "ROOT=${ROOT}" > ${DESTDIR}/conf/conf.d/root + echo "ROOT=${ROOT}" > "${DESTDIR}/conf/conf.d/root" fi if ! command -v ldd >/dev/null 2>&1 ; then - echo "WARNING: no ldd around - install libc-bin" >&2 + echo "E: no ldd around - install libc-bin" >&2 exit 1 fi @@ -318,30 +363,22 @@ for file in /etc/modprobe.d/*.conf /lib/modprobe.d/*.conf ; do fi done -# workaround: libgcc always needed on old-abi arm -if [ "$DPKG_ARCH" = arm ] || [ "$DPKG_ARCH" = armeb ]; then - cp -a /lib/libgcc_s.so.1 "${DESTDIR}/lib/" -fi - run_scripts /usr/share/initramfs-tools/hooks run_scripts "${CONFDIR}"/hooks -# Avoid double sleep when using older udev scripts -sed -i 's/^\s*sleep \$ROOTDELAY$/:/' "${DESTDIR}/scripts/init-top/udev" - # cache boot run order for b in $(cd "${DESTDIR}/scripts" && find . -mindepth 1 -type d); do cache_run_scripts "${DESTDIR}" "/scripts/${b#./}" done # generate module deps -depmod -a -b "${DESTDIR}" ${version} +depmod -a -b "${DESTDIR}" "${version}" rm -f "${DESTDIR}/lib/modules/${version}"/modules.*map # make sure that library search path is up to date -cp -ar /etc/ld.so.conf* "$DESTDIR"/etc/ +cp -pPr /etc/ld.so.conf* "$DESTDIR"/etc/ if ! ldconfig -r "$DESTDIR" ; then - [ $(id -u) != "0" ] \ + [ "$(id -u)" != "0" ] \ && echo "ldconfig might need uid=0 (root) for chroot()" >&2 fi # The auxiliary cache is not reproducible and is always invalid at boot @@ -356,32 +393,8 @@ if [ -e "${CONFDIR}/DSDT.aml" ]; then copy_file DSDT "${CONFDIR}/DSDT.aml" fi -# Make sure there is a final sh in initramfs -if [ ! -e "${DESTDIR}/bin/sh" ]; then - copy_exec /bin/sh "${DESTDIR}/bin/" -fi - -# dirty hack for armhf's double-linker situation; if we have one of -# the two known eglibc linkers, nuke both and re-create sanity -if [ "$DPKG_ARCH" = armhf ]; then - if [ -e "${DESTDIR}/lib/arm-linux-gnueabihf/ld-linux.so.3" ] || \ - [ -e "${DESTDIR}/lib/ld-linux-armhf.so.3" ]; then - rm -f "${DESTDIR}/lib/arm-linux-gnueabihf/ld-linux.so.3" - rm -f "${DESTDIR}/lib/ld-linux-armhf.so.3" - cp -aL /lib/ld-linux-armhf.so.3 "${DESTDIR}/lib/" - ln -sf /lib/ld-linux-armhf.so.3 "${DESTDIR}/lib/arm-linux-gnueabihf/ld-linux.so.3" - fi -fi - [ "${verbose}" = y ] && echo "Building cpio ${outfile} initramfs" -if [ -s "${__TMPEARLYCPIO}" ]; then - cat "${__TMPEARLYCPIO}" >"${outfile}" || exit 1 -else - # truncate - > "${outfile}" -fi - ( # preserve permissions if root builds the image, see #633582 [ "$(id -ru)" != 0 ] && cpio_owner_root="-R 0:0" @@ -397,9 +410,11 @@ if [ -n "${SOURCE_DATE_EPOCH}" ]; then fi # work around lack of "set -o pipefail" for the following pipe: -# cd "${DESTDIR}" && find . | LC_ALL=C sort | cpio --quiet $cpio_owner_root $cpio_reproducible -o -H newc | gzip >>"${outfile}" || exit 1 +# cd "${DESTDIR}" && find . | LC_ALL=C sort | cpio --quiet $cpio_owner_root $cpio_reproducible -o -H newc >>"${outfile}" || exit 1 +ec1=1 +ec2=1 exec 3>&1 -eval ` +eval "$( # http://cfaj.freeshell.org/shell/cus-faq-2.html exec 4>&1 >&3 3>&- cd "${DESTDIR}" @@ -408,26 +423,32 @@ eval ` } | { LC_ALL=C sort } | { - cpio --quiet $cpio_owner_root $cpio_reproducible -o -H newc 4>&-; echo "ec2=$?;" >&4 - } | ${compress} >>"${outfile}" - echo "ec3=$?;" >&4 -` + # shellcheck disable=SC2086 + cpio --quiet $cpio_owner_root $cpio_reproducible -o -H newc 4>&- >"${__TMPMAINCPIO}" + echo "ec2=$?;" >&4 + } +)" if [ "$ec1" -ne 0 ]; then - echo "E: mkinitramfs failure find $ec1 cpio $ec2 $compress $ec3" + echo "E: mkinitramfs failure find $ec1 cpio $ec2" >&2 exit "$ec1" fi if [ "$ec2" -ne 0 ]; then - echo "E: mkinitramfs failure cpio $ec2 $compress $ec3" + echo "E: mkinitramfs failure cpio $ec2" >&2 exit "$ec2" fi -if [ "$ec3" -ne 0 ]; then - echo "E: mkinitramfs failure $compress $ec3" - exit "$ec3" -fi ) || exit 1 +{ +if [ -s "${__TMPEARLYCPIO}" ]; then + cat "${__TMPEARLYCPIO}" || exit 1 +fi + +$compress -c "${__TMPMAINCPIO}" || + { echo "E: mkinitramfs failure $compress $?" >&2; exit 1; } + if [ -s "${__TMPCPIOGZ}" ]; then - cat "${__TMPCPIOGZ}" >>"${outfile}" || exit 1 + cat "${__TMPCPIOGZ}" || exit 1 fi +} >"${outfile}" || exit 1 exit 0 diff --git a/mkinitramfs.8 b/mkinitramfs.8 index 241ab7d23cfa0ee3e624b70eef118c4b0b61e3c9..3267ad45e1ff769e82e92f8b4b17616de2b5438c 100644 --- a/mkinitramfs.8 +++ b/mkinitramfs.8 @@ -5,25 +5,12 @@ mkinitramfs \- low-level tool for generating an initramfs image .SH SYNOPSIS .B mkinitramfs -.RB [ \-c -.IR compress ] -.RB [ \-d -.IR confdir ] -.RB [ \-k ] -.RB \-o +.RI [ option ]... +.B \-o .IR outfile -.RB [ \-r -.IR root ] -.RB [ \-v ] .RI [ version ] - -.B mkinitramfs -.RB [ \-\-supported-host-version= -.IR hversion ] - -.B mkinitramfs -.RB [ \-\-supported-target-version= -.IR tversion ] +.br +.BR mkinitramfs " " -h .SH DESCRIPTION The @@ -47,41 +34,45 @@ happens in this early userspace. .SH OPTIONS .TP -\fB \-c \fI compress +\fB\-c \fI compress Override the .B COMPRESS setting in .IR initramfs.conf . .TP -\fB \-d \fI confdir +\fB\-d \fI confdir Set an alternate configuration directory. .TP -\fB \-k +\fB\-k Keep the temporary directory used to make the image. .TP -\fB \-o \fI outfile +\fB\-o \fI outfile Write the image to .IR outfile . .TP -\fB \-r \fI root +\fB\-r \fI root Override the .B ROOT setting in .IR initramfs.conf . .TP -\fB \-v +\fB\-v Set the verbose mode output. .TP -\fI version +\fIversion Set the kernel version of the initramfs image (defaults to the running kernel). +.TP +\fB\-h\fR, \fB\-\-help\fR +Display usage information and exit. + .SH ENVIRONMENT .B mkinitramfs honours the diff --git a/scripts/functions b/scripts/functions index 7c6f8aaa7d6ba3f007aabe2375bebc04ccc23676..54290f80005b8c7e23f3107cdc792e1499434d62 100644 --- a/scripts/functions +++ b/scripts/functions @@ -2,49 +2,70 @@ _log_msg() { - if [ "$quiet" = "y" ]; then return; fi + if [ "${quiet?}" = "y" ]; then return; fi + # shellcheck disable=SC2059 printf "$@" + return 0 # Prevents error carry over in case of unavailable console } log_success_msg() { - _log_msg "Success: $@\n" + _log_msg "Success: %s\\n" "$*" } log_failure_msg() { - _log_msg "Failure: $@\n" + _log_msg "Failure: %s\\n" "$*" } log_warning_msg() { - _log_msg "Warning: $@\n" + _log_msg "Warning: %s\\n" "$*" } log_begin_msg() { - _log_msg "Begin: $@ ... " + _log_msg "Begin: %s ... " "$*" } log_end_msg() { - _log_msg "done.\n" + _log_msg "done.\\n" } panic() { - local console rest + local console rest IFS if command -v chvt >/dev/null 2>&1; then chvt 1 fi echo "$@" - # Disallow console access - if [ -n "${panic}" ]; then - echo "Rebooting automatically due to panic= boot argument" - sleep ${panic} - reboot + + # The panic= parameter implies we should disallow console access + if [ -n "${panic?}" ]; then + delay= + case "${panic?}" in + -*[![:digit:].]*) # invalid: wait forever + ;; + -*) # timeout < 0: reboot immediately + delay=0 + ;; + 0 | *[![:digit:].]*) # timeout = 0 or invalid: wait forever + ;; + *) # timeout > 0: seconds before rebooting + delay="${panic}" + ;; + esac + if [ -n "${delay}" ]; then + echo "Rebooting automatically due to panic= boot argument" + sleep "${delay}" + reboot -f + else + echo "Halting automatically due to panic= boot argument" + halt -f + fi exit # in case reboot fails, force kernel panic fi @@ -53,22 +74,23 @@ panic() # Try to use setsid, which will enable job control in the shell # and paging in more if command -v setsid >/dev/null 2>&1; then - read console rest /dev/${console} 1>&0 2>&1" + REASON="$*" PS1='(initramfs) ' setsid sh -c "exec sh -i <>/dev/${console} 1>&0 2>&1" else - REASON="$@" PS1='(initramfs) ' sh -i /dev/console 2>&1 + REASON="$*" PS1='(initramfs) ' sh -i /dev/console 2>&1 fi } maybe_break() { - case ",$break," in + case ",${break?}," in *,$1,*) if [ "$1" = "top" ]; then # udev is not yet running, so load keyboard drivers @@ -83,7 +105,7 @@ maybe_break() sleep 2 for modalias in /sys/bus/hid/devices/*/modalias; do if [ -f "${modalias}" ]; then - modprobe ${opts} -b "$(cat ${modalias})" + modprobe ${opts} -b "$(cat "${modalias}")" fi done fi @@ -92,26 +114,21 @@ maybe_break() esac } -render() -{ - eval "echo -n \${$@}" -} - # For boot time only; this is overridden at build time in hook-functions run_scripts() { initdir=${1} - [ ! -d ${initdir} ] && return + [ ! -d "${initdir}" ] && return shift - . ${initdir}/ORDER + . "${initdir}/ORDER" } # Load custom modules first load_modules() { if [ -e /conf/modules ]; then - cat /conf/modules | while read m; do + while read -r m; do # Skip empty lines if [ -z "$m" ]; then continue @@ -121,9 +138,29 @@ load_modules() if [ "$com" = "#" ]; then continue fi + # shellcheck disable=SC2086 modprobe $m - done + done < /conf/modules + fi +} + +_uptime() { + local uptime + uptime="$(cat /proc/uptime)" + uptime="${uptime%%[. ]*}" + echo "$uptime" +} + +time_elapsed() { + # shellcheck disable=SC2154 + if [ -z "$starttime" ]; then + log_failure_msg "time_elapsed() called before \$starttime initialized" + echo 0 fi + local delta + delta="$(_uptime)" + delta=$((delta - starttime)) + echo "$delta" } # lilo compatibility @@ -147,11 +184,12 @@ parse_numeric() { *) # [A-Fa-f0-9]* value=$(( 0x${1} )) - minor=$(( (${value} & 0xff) | (${value} >> 12) & 0xfff00 )) - major=$(( (${value} >> 8) & 0xfff )) + minor=$(( (value & 0xff) | (value >> 12) & 0xfff00 )) + major=$(( (value >> 8) & 0xfff )) ;; esac + # shellcheck disable=SC2034 ROOT="/dev/block/${major}:${minor}" } @@ -160,24 +198,18 @@ parse_numeric() { # Return value: indicates if an fs could be recognized get_fstype () { - local FS FSTYPE FSSIZE RET + local FS FSTYPE FS="${1}" # blkid has a more complete list of file systems, # but fstype is more robust FSTYPE="unknown" - eval $(fstype "${FS}" 2> /dev/null) + eval "$(fstype "${FS}" 2> /dev/null)" if [ "$FSTYPE" = "unknown" ]; then - FSTYPE=$(blkid -o value -s TYPE "${FS}") - fi - RET=$? - - if [ -z "${FSTYPE}" ]; then - FSTYPE="unknown" + FSTYPE=$(blkid -o value -s TYPE "${FS}") || return fi - echo "${FSTYPE}" - return ${RET} + return 0 } _handle_device_vs_ip() @@ -189,6 +221,7 @@ _handle_device_vs_ip() # - Otherwise, substitute in any device name we already have local IFS=: set -f + # shellcheck disable=SC2086 set -- ${IP} set +f if [ -n "$6" ]; then @@ -243,6 +276,21 @@ configure_networking() # networking already configured thus bail out [ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ] && return 0 + if [ -n "${DEVICE}" ]; then + local netdevwait=180 + log_begin_msg "Waiting up to ${netdevwait} secs for ${DEVICE} to become available" + while [ "$(time_elapsed)" -lt "$netdevwait" ]; do + if [ -e "/sys/class/net/${DEVICE}" ]; then + break + fi + sleep 1 + done + if [ ! -e "/sys/class/net/${DEVICE}" ]; then + log_failure_msg "Interface ${DEVICE} did not appear in time" + fi + log_end_msg + fi + wait_for_udev 10 # support ip options see linux sources @@ -267,10 +315,10 @@ configure_networking() ipconfig -t ${ROUNDTTT} "${DEVICE}" ;; dhcp|bootp|rarp|both) - ipconfig -t ${ROUNDTTT} -c ${IP} -d "${DEVICE}" + ipconfig -t ${ROUNDTTT} -c "${IP}" -d "${DEVICE}" ;; *) - ipconfig -t ${ROUNDTTT} -d $IP + ipconfig -t ${ROUNDTTT} -d "$IP" ;; esac done @@ -278,7 +326,7 @@ configure_networking() # source ipconfig output if [ -n "${DEVICE}" ]; then # source specific bootdevice - . /run/net-${DEVICE}.conf + . "/run/net-${DEVICE}.conf" else # source any interface... # ipconfig should have quit after first response @@ -301,9 +349,10 @@ read_fstab_entry() { # Not found by default. found=1 - for file in ${rootmnt}/etc/fstab; do + for file in ${rootmnt?}/etc/fstab; do if [ -f "$file" ]; then - while read MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do + # shellcheck disable=SC2034 + while read -r MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do case "$MNT_FSNAME" in ""|\#*) continue; @@ -357,26 +406,30 @@ _checkfs_once() fi FSCKCODE=0 + if [ -z "${TYPE}" ]; then + log_warning_msg "Type of $NAME file system is unknown, so skipping check." + return + fi if ! command -v fsck >/dev/null 2>&1; then log_warning_msg "fsck not present, so skipping $NAME file system" return fi - if [ "$fastboot" = "y" ] ; then + if [ "${fastboot?}" = "y" ] ; then log_warning_msg "Fast boot enabled, so skipping $NAME file system check." return fi - if [ "$forcefsck" = "y" ] + if [ "${forcefsck?}" = "y" ] then force="-f" else force="" fi - if [ "$fsckfix" = "y" ] + if [ "${fsckfix?}" = "y" ] then fix="-y" - elif [ "$fsckfix" = "n" ] + elif [ "${fsckfix?}" = "n" ] then fix="-n" else @@ -384,19 +437,21 @@ _checkfs_once() fi spinner="" - if [ -z "${debug}" ]; then + if [ -z "${debug?}" ]; then spinner="-C" fi if [ "${quiet}" = n ] then log_begin_msg "Will now check $NAME file system" - logsave -a -s $FSCK_LOGFILE fsck $spinner $force $fix -V -t $TYPE $DEV + # shellcheck disable=SC2086 + logsave -a -s $FSCK_LOGFILE fsck $spinner $force $fix -V -t "$TYPE" "$DEV" FSCKCODE=$? log_end_msg else log_begin_msg "Checking $NAME file system" - logsave -a -s $FSCK_LOGFILE fsck $spinner $force $fix -T -t $TYPE $DEV + # shellcheck disable=SC2086 + logsave -a -s $FSCK_LOGFILE fsck $spinner $force $fix -T -t "$TYPE" "$DEV" FSCKCODE=$? log_end_msg fi @@ -418,7 +473,7 @@ _checkfs_once() log_warning_msg "File system check failed but did not detect errors" sleep 5 else - > $FSCK_STAMPFILE + true > $FSCK_STAMPFILE fi return 0 } diff --git a/scripts/init-top/all_generic_ide b/scripts/init-top/all_generic_ide index e9539d8207c22c482728814d5b6be97e6f674075..0f408d0fb26481539aeeedb11ff5156a17fd4282 100755 --- a/scripts/init-top/all_generic_ide +++ b/scripts/init-top/all_generic_ide @@ -13,13 +13,14 @@ prereqs) ;; esac +# shellcheck disable=SC2013 for x in $(cat /proc/cmdline); do case ${x} in all_generic_ide) modprobe ata_generic all_generic_ide=1 ;; all_generic_ide=*) - if [ ${x#all_generic_ide=} ]; then + if [ -n "${x#all_generic_ide=}" ]; then modprobe ata_generic all_generic_ide=1 fi ;; diff --git a/scripts/init-top/blacklist b/scripts/init-top/blacklist index 216490660617f35d99ffda69976f56b5b9a82212..d86060304fd96ac5c4c7288a31bfbebdc6ef0c13 100755 --- a/scripts/init-top/blacklist +++ b/scripts/init-top/blacklist @@ -16,7 +16,7 @@ prereqs) esac # sanity check -[ -z "${blacklist}" ] && exit 0 +[ -z "${blacklist?}" ] && exit 0 # write blacklist to modprobe.d IFS=',' diff --git a/scripts/init-top/keymap b/scripts/init-top/keymap index f011abf595583ba65a868629551d38759729744b..1c6b2dce781e441e99cbf31411a563c28a81a4ad 100755 --- a/scripts/init-top/keymap +++ b/scripts/init-top/keymap @@ -13,15 +13,6 @@ prereqs) ;; esac -OPTS="-q" - -# Should terminal be in UTF8 mode? -if [ -x /bin/kbd_mode ]; then - /bin/kbd_mode -u - OPTS="${OPTS} -u" -fi - -# Load custom keymap -if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]; then - loadkeys ${OPTS} /etc/boottime.kmap.gz +if [ -x /bin/setupcon ]; then + /bin/setupcon fi diff --git a/scripts/local b/scripts/local index 4ec926cae6cb5edb251e2e3b9b09f0784f142936..becb79807c6f7875588a59666802229c81aefb18 100644 --- a/scripts/local +++ b/scripts/local @@ -3,24 +3,16 @@ local_top() { if [ "${local_top_used}" != "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/local-top" run_scripts /scripts/local-top [ "$quiet" != "y" ] && log_end_msg fi local_top_used=yes - - # Start time for measuring elapsed time in local_device_setup - if [ -z "${local_top_time}" ]; then - local_top_time="$(cat /proc/uptime)" - local_top_time="${local_top_time%%[. ]*}" - local_top_time=$((local_top_time + 1)) # round up - export local_top_time - fi } local_block() { - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-block" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/local-block" run_scripts /scripts/local-block "$@" [ "$quiet" != "y" ] && log_end_msg } @@ -28,7 +20,7 @@ local_block() local_premount() { if [ "${local_premount_used}" != "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/local-premount" run_scripts /scripts/local-premount [ "$quiet" != "y" ] && log_end_msg fi @@ -38,13 +30,12 @@ local_premount() local_bottom() { if [ "${local_premount_used}" = "yes" ] || [ "${local_top_used}" = "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/local-bottom" run_scripts /scripts/local-bottom [ "$quiet" != "y" ] && log_end_msg fi local_premount_used=no local_top_used=no - unset local_top_time } # $1=device ID to mount @@ -65,7 +56,7 @@ local_device_setup() # Load ubi with the correct MTD partition and return since fstype # doesn't work with a char device like ubi. if [ -n "$UBIMTD" ]; then - modprobe ubi mtd=$UBIMTD + modprobe ubi "mtd=$UBIMTD" DEV="${dev_id}" return fi @@ -88,15 +79,13 @@ local_device_setup() # Timeout is max(30, rootdelay) seconds (approximately) slumber=30 - if [ ${ROOTDELAY:-0} -gt $slumber ]; then + if [ "${ROOTDELAY:-0}" -gt $slumber ]; then slumber=$ROOTDELAY fi while true; do sleep 1 - time_elapsed="$(cat /proc/uptime)" - time_elapsed="${time_elapsed%%[. ]*}" - time_elapsed=$((time_elapsed - local_top_time)) + time_elapsed="$(time_elapsed)" local_block "${dev_id}" @@ -113,7 +102,7 @@ local_device_setup() else break fi - if [ ${count} -ge ${time_elapsed} ]; then + if [ "${count}" -ge "${time_elapsed}" ]; then break; fi /scripts/local-block/mdadm "${dev_id}" @@ -125,7 +114,7 @@ local_device_setup() log_end_msg 0 break fi - if [ ${time_elapsed} -ge ${slumber} ]; then + if [ "${time_elapsed}" -ge "${slumber}" ]; then log_end_msg 1 || true break fi @@ -155,11 +144,14 @@ local_device_setup() local_mount_root() { local_top + if [ -z "${ROOT}" ]; then + panic "No root device specified. Boot arguments must include a root= parameter." + fi local_device_setup "${ROOT}" "root file system" ROOT="${DEV}" # Get the root filesystem type if not set - if [ -z "${ROOTFSTYPE}" ]; then + if [ -z "${ROOTFSTYPE}" ] || [ "${ROOTFSTYPE}" = auto ]; then FSTYPE=$(get_fstype "${ROOT}") else FSTYPE=${ROOTFSTYPE} @@ -167,23 +159,18 @@ local_mount_root() local_premount - if [ "${readonly}" = "y" ]; then + if [ "${readonly?}" = "y" ]; then roflag=-r else roflag=-w fi - # FIXME This has no error checking - modprobe ${FSTYPE} + checkfs "${ROOT}" root "${FSTYPE}" - checkfs ${ROOT} root "${FSTYPE}" - - # FIXME This has no error checking # Mount root - if [ "${FSTYPE}" != "unknown" ]; then - mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} - else - mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt} + # shellcheck disable=SC2086 + if ! mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then + panic "Failed to mount ${ROOT} as root file system." fi } @@ -202,16 +189,14 @@ local_mount_fs() roflag=-w fi - # FIXME This has no error checking - modprobe "${MNT_TYPE}" - if [ "$MNT_PASS" != 0 ]; then checkfs "$MNT_FSNAME" "$MNT_DIR" "${MNT_TYPE}" fi - # FIXME This has no error checking # Mount filesystem - mount ${roflag} -t "${MNT_TYPE}" -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}" + if ! mount ${roflag} -t "${MNT_TYPE}" -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}"; then + panic "Failed to mount ${MNT_FSNAME} as $MNT_DIR file system." + fi } mountroot() diff --git a/scripts/local-premount/resume b/scripts/local-premount/resume index 4cafcaafb0fa157e625c120b6e091cb712acd79e..63dcc4961695a3bff33b3423c6b5fb7470b9073b 100755 --- a/scripts/local-premount/resume +++ b/scripts/local-premount/resume @@ -15,20 +15,32 @@ prereqs) ;; esac -if [ -z "${resume}" ] || [ ! -e /sys/power/resume ]; then +if [ -z "${resume?}" ] || [ ! -e /sys/power/resume ]; then exit 0 fi . /scripts/functions . /scripts/local -if ! local_device_setup ${resume} "suspend/resume device" false; then +if ! local_device_setup "${resume}" "suspend/resume device" false; then exit 0 fi +if [ "$(get_fstype "${DEV}")" = suspend ] && + command -v plymouth >/dev/null && + plymouth --ping; then + plymouth display-message --text="Resuming from hibernation" + + # The above command does not wait for a framebuffer update to + # complete, so the kernel can freeze the framebuffer before + # the message is even visible. Wait just a moment to make + # that less likely. + sleep 0.1 +fi + # hardcode path, uswsusp ships an resume binary too -if [ -n "${resume_offset}" ]; then - /bin/resume ${DEV} ${resume_offset} +if [ -n "${resume_offset?}" ]; then + /bin/resume "${DEV}" "${resume_offset}" else - /bin/resume ${DEV} + /bin/resume "${DEV}" fi diff --git a/scripts/nfs b/scripts/nfs index 359bd466f4735d12fcb0fea383945b0736c04ea3..40c92c763dda1e1f4857f79310505b39abf95536 100644 --- a/scripts/nfs +++ b/scripts/nfs @@ -5,7 +5,7 @@ nfs_top() { if [ "${nfs_top_used}" != "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-top" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-top" run_scripts /scripts/nfs-top [ "$quiet" != "y" ] && log_end_msg fi @@ -15,7 +15,7 @@ nfs_top() nfs_premount() { if [ "${nfs_premount_used}" != "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-premount" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-premount" run_scripts /scripts/nfs-premount [ "$quiet" != "y" ] && log_end_msg fi @@ -25,7 +25,7 @@ nfs_premount() nfs_bottom() { if [ "${nfs_premount_used}" = "yes" ] || [ "${nfs_top_used}" = "yes" ]; then - [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom" + [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom" run_scripts /scripts/nfs-bottom [ "$quiet" != "y" ] && log_end_msg fi @@ -65,13 +65,14 @@ nfs_mount_root_impl() nfs_premount - if [ ${readonly} = y ]; then + if [ "${readonly?}" = y ]; then roflag="-o ro" else roflag="-o rw" fi - nfsmount -o nolock ${roflag} ${NFSOPTS} ${NFSROOT} ${rootmnt} + # shellcheck disable=SC2086 + nfsmount -o nolock ${roflag} ${NFSOPTS} "${NFSROOT}" "${rootmnt?}" } # NFS root mounting @@ -79,7 +80,6 @@ nfs_mount_root() { nfs_top - modprobe nfs # For DHCP modprobe af_packet @@ -92,13 +92,13 @@ nfs_mount_root() nfs_mount_root_impl ret=$? nfs_retry_count=0 - while [ ${nfs_retry_count} -lt ${delay} ] \ + while [ ${nfs_retry_count} -lt "${delay}" ] \ && [ $ret -ne 0 ] ; do [ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount" - /bin/sleep 1 + sleep 1 nfs_mount_root_impl ret=$? - nfs_retry_count=$(( ${nfs_retry_count} + 1 )) + nfs_retry_count=$(( nfs_retry_count + 1 )) [ "$quiet" != "y" ] && log_end_msg done } @@ -113,7 +113,7 @@ nfs_mount_fs_impl() nfs_premount - if [ ${readonly} = y ]; then + if [ "${readonly}" = y ]; then roflag="-o ro" else roflag="-o rw" @@ -121,6 +121,7 @@ nfs_mount_fs_impl() read_fstab_entry "$1" + # shellcheck disable=SC2086 nfsmount ${roflag} ${NFSOPTS} -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}" } @@ -128,7 +129,6 @@ nfs_mount_fs() { nfs_top - modprobe nfs # For DHCP modprobe af_packet diff --git a/unmkinitramfs b/unmkinitramfs index bd7bacf0b8f03525df29d33b69832c6cebebfe52..d1226c323dcb8a57cbfcb3bc1e7eb8f6da43926b 100755 --- a/unmkinitramfs +++ b/unmkinitramfs @@ -4,7 +4,22 @@ set -eu usage() { - echo "Usage: $(basename "$0") [-v] " + cat << EOF + +Usage: unmkinitramfs [-v] initramfs-file directory + +Options: + -v Display verbose messages about extraction + +See unmkinitramfs(8) for further details. + +EOF +} + +usage_error() +{ + usage >&2 + exit 2 } # Extract a compressed cpio archive @@ -14,11 +29,13 @@ xcpio() dir="$2" shift 2 - if zcat -t "$archive" >/dev/null 2>&1 ; then - zcat "$archive" + if gzip -t "$archive" >/dev/null 2>&1 ; then + gzip -c -d "$archive" + elif zstd -q -c -t "$archive" >/dev/null 2>&1 ; then + zstd -q -c -d "$archive" elif xzcat -t "$archive" >/dev/null 2>&1 ; then xzcat "$archive" - elif lz4cat -t "$archive" >/dev/null 2>&1 ; then + elif lz4cat -t < "$archive" >/dev/null 2>&1 ; then lz4cat "$archive" elif bzip2 -t "$archive" >/dev/null 2>&1 ; then bzip2 -c -d "$archive" @@ -75,12 +92,12 @@ splitinitramfs() break fi magic="$(readhex "$initramfs" $end 6)" || break - test $magic = 070701 || test $magic = 070702 || break + test "$magic" = 070701 || test "$magic" = 070702 || break namesize=0x$(readhex "$initramfs" $((end + 94)) 8) filesize=0x$(readhex "$initramfs" $((end + 54)) 8) end=$(((end + 110))) - end=$(((end + $namesize + 3) & ~3)) - end=$(((end + $filesize + 3) & ~3)) + end=$(((end + namesize + 3) & ~3)) + end=$(((end + filesize + 3) & ~3)) done if [ $end -eq $start ]; then break @@ -106,10 +123,10 @@ splitinitramfs() if [ $end -gt 0 ]; then # Extract to main subdirectory - subarchive=$(mktemp ${TMPDIR:-/var/tmp}/unmkinitramfs_XXXXXX) - trap "rm -f '$subarchive'" EXIT + subarchive=$(mktemp "${TMPDIR:-/var/tmp}/unmkinitramfs_XXXXXX") + trap 'rm -f "$subarchive"' EXIT dd < "$initramfs" skip=$end iflag=skip_bytes 2> /dev/null \ - > $subarchive + > "$subarchive" xcpio "$subarchive" "${dir:+$dir/main}" -i "$@" else # Don't use subdirectories (for backward compatibility) @@ -117,9 +134,7 @@ splitinitramfs() fi } -OPTIONS=`getopt -o hv --long help,list,verbose -n "$0" -- "$@"` -# Check for non-GNU getopt -if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi +OPTIONS=$(getopt -o hv --long help,list,verbose -n "$0" -- "$@") || usage_error cpio_opts="--preserve-modification-time --no-absolute-filenames --quiet" expected_args=2 @@ -152,8 +167,8 @@ while true; do done if [ $# -ne $expected_args ]; then - usage - exit 2 + usage_error fi +# shellcheck disable=SC2086 splitinitramfs "$1" "${2:-}" $cpio_opts diff --git a/unmkinitramfs.8 b/unmkinitramfs.8 index 45ffd40fca0b71b02d4538f81a6f35a72b9fcab0..ae9252de8b6812734df234361bc93ab553118ec6 100644 --- a/unmkinitramfs.8 +++ b/unmkinitramfs.8 @@ -5,8 +5,10 @@ unmkinitramfs \- extract content from an initramfs image .SH SYNOPSIS .B unmkinitramfs -.RI [ options ] " " +.RB [ -v ] +.IR initramfs-file " " directory .br +.BR unmkinitramfs " " -h .SH DESCRIPTION The diff --git a/update-initramfs b/update-initramfs index e3136dc06a121a0ccd62f1f73e2d0837a70e2a2e..dbd7ed67cf093b00c47eeef17a152166088bb7da 100755 --- a/update-initramfs +++ b/update-initramfs @@ -1,6 +1,5 @@ #!/bin/sh -STATEDIR=/var/lib/initramfs-tools BOOTDIR=/boot CONF=/etc/initramfs-tools/update-initramfs.conf mode="" @@ -12,35 +11,18 @@ set -e [ -r ${CONF} ] && . ${CONF} -case "$DPKG_MAINTSCRIPT_PACKAGE" in -linux-image-*) - if [ -z "$INITRAMFS_TOOLS_KERNEL_HOOK" ]; then - # kernel maintainer script called us directly; ignore - # it and let the hook script handle it instead - echo "update-initramfs: deferring update (hook will be called later)" +if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] && [ $# = 1 ] && [ x"$1" = x-u ]; then + if dpkg-trigger --no-await update-initramfs; then + echo "update-initramfs: deferring update (trigger activated)" exit 0 fi - ;; -?*) - if [ $# = 1 ] \ - && [ x"$1" = x-u ] \ - && dpkg-trigger --check-supported 2>/dev/null - then - if dpkg-trigger --no-await update-initramfs; then - echo "update-initramfs: deferring update (trigger activated)" - exit 0 - fi - fi - ;; -esac +fi usage() { - if [ -n "${1:-}" ]; then - printf "${*}\n\n" >&2 - fi - cat >&2 << EOF -Usage: ${0} [OPTION]... + cat << EOF + +Usage: update-initramfs {-c|-d|-u} [-k version] [-v] [-b directory] Options: -k version Specify kernel version or 'all' @@ -49,16 +31,25 @@ Options: -d Remove an existing initramfs -b directory Set alternate boot directory -v Be verbose - -h This message + +See update-initramfs(8) for further details. EOF - exit 1 +} + +usage_error() +{ + if [ -n "${1:-}" ]; then + printf "%s\\n\\n" "${*}" >&2 + fi + usage >&2 + exit 2 } mild_panic() { if [ -n "${1:-}" ]; then - printf "${*}\n" >&2 + printf "%s\\n" "${*}" >&2 fi exit 0 } @@ -66,7 +57,7 @@ mild_panic() panic() { if [ -n "${1:-}" ]; then - printf "${*}\n" >&2 + printf "%s\\n" "${*}" >&2 fi exit 1 } @@ -74,7 +65,7 @@ panic() verbose() { if [ "${verbose}" = 1 ]; then - printf "${*}\n" + printf "%s\\n" "${*}" fi } @@ -120,7 +111,7 @@ backup_booted_initramfs() boot_initramfs= uptime_days=$(awk '{printf "%d", $1 / 3600 / 24}' /proc/uptime) if [ -n "$uptime_days" ]; then - boot_initramfs=$(find "${initramfs}.bak" -mtime +${uptime_days}) + boot_initramfs=$(find "${initramfs}.bak" -mtime "+${uptime_days}") fi if [ -n "${boot_initramfs}" ]; then mv -f "${initramfs_bak}" "${initramfs}.bak" @@ -147,9 +138,9 @@ generate_initramfs() if [ "${verbose}" = 1 ]; then OPTS="-v ${OPTS}" fi + # shellcheck disable=SC2086 if mkinitramfs ${OPTS} "${initramfs}.new" "${version}"; then mv -f "${initramfs}.new" "${initramfs}" - set_sha1 # Guard against an unclean shutdown sync -f "${initramfs}" else @@ -166,23 +157,12 @@ run_bootloader() { # invoke policy conformant bootloader hooks if [ -d /etc/initramfs/post-update.d/ ]; then - run-parts --arg=${version} --arg=${initramfs} \ + run-parts --arg="${version}" --arg="${initramfs}" \ /etc/initramfs/post-update.d/ return 0 fi } -# Note that this must overwrite so that updates work. -set_sha1() -{ - sha1sum "${initramfs}" > "${STATEDIR}/${version}" -} - -delete_sha1() -{ - rm -f "${STATEDIR}/${version}" -} - # ro /boot is not modified ro_boot_check() { @@ -191,11 +171,12 @@ ro_boot_check() return 0 fi + # shellcheck disable=SC1004 boot_opts=$(awk '/boot/{if ((match($4, /^ro/) || match($4, /,ro/)) \ && $2 == "/boot") print "ro"}' /proc/mounts) if [ -n "${boot_opts}" ]; then - echo "WARNING: /boot is ro mounted." - echo "update-initramfs: Not updating ${initramfs}" + echo "W: /boot is ro mounted." >&2 + echo "W: update-initramfs: Not updating ${initramfs}" >&2 exit 0 fi } @@ -204,7 +185,7 @@ get_sorted_versions() { version_list="$( linux-version list | - while read version; do + while read -r version; do test -e "${BOOTDIR}/initrd.img-$version" && echo "$version" done | linux-version sort --reverse @@ -214,8 +195,8 @@ get_sorted_versions() set_current_version() { - if [ -f /boot/initrd.img-`uname -r` ]; then - version=`uname -r` + if [ -f "/boot/initrd.img-$(uname -r)" ]; then + version=$(uname -r) fi } @@ -244,6 +225,7 @@ set_highest_version() version= return fi + # shellcheck disable=SC2086 set -- ${version_list} version=${1} } @@ -251,7 +233,7 @@ set_highest_version() create() { if [ -z "${version}" ]; then - usage "Create mode requires a version argument" + usage_error "Create mode requires a version argument" fi set_initramfs @@ -301,76 +283,90 @@ update() delete() { if [ -z "${version}" ]; then - usage "Delete mode requires a version argument" + usage_error "Delete mode requires a version argument" fi set_initramfs echo "update-initramfs: Deleting ${initramfs}" - delete_sha1 - rm -f "${initramfs}" "${initramfs}.bak" } # Defaults verbose=0 -yes=0 ## -while getopts "k:cudyvtb:h?" flag; do - case "${flag}" in - k) - version="${OPTARG}" +OPTIONS=$(getopt -o "k:cudvtb:h?" --long help -n "$0" -- "$@") || usage_error + +eval set -- "$OPTIONS" + +while true; do + case "$1" in + -k) + version="$2" + shift 2 ;; - c) + -c) mode="c" + shift ;; - d) + -d) mode="d" + shift ;; - u) + -u) mode="u" + shift ;; - v) + -v) verbose="1" + shift ;; - y) - yes="1" - ;; - t) + -t) # accepted for compatibility, but ignored + shift ;; - b) - BOOTDIR="${OPTARG}" + -b) + BOOTDIR="$2" if [ ! -d "${BOOTDIR}" ]; then - echo "Error: ${BOOTDIR} is not a directory." >&2 + echo "E: ${BOOTDIR} is not a directory." >&2 exit 1 fi + shift 2 ;; - h|?) + -h|-\?|--help) usage + exit 0 + ;; + --) + shift + break ;; esac done -shift $((${OPTIND} - 1)) - if [ $# -ne 0 ]; then - printf "Extra argument '%s'\n\n" "$1" >&2 - usage + printf "Extra argument '%s'\\n\\n" "$1" >&2 + usage_error fi # Validate arguments if [ -z "${mode}" ]; then - usage "You must specify at least one of -c, -u, or -d." + usage_error "You must specify at least one of -c, -u, or -d." fi if [ "${version}" = "all" ] \ - || ( [ "${update_initramfs}" = "all" ] && [ -z "${version}" ] ); then - : FIXME check for --yes, and if not ask are you sure - get_sorted_versions + || { [ "${update_initramfs}" = "all" ] && [ -z "${version}" ]; }; then + case "${mode}" in + c) + version_list="$(linux-version list)" + ;; + d | u) + get_sorted_versions + ;; + esac if [ -z "${version_list}" ]; then verbose "Nothing to do, exiting." exit 0 @@ -380,11 +376,9 @@ if [ "${version}" = "all" ] \ if [ "${verbose}" = "1" ]; then OPTS="${OPTS} -v" fi - if [ "${yes}" = "1" ]; then - OPTS="${OPTS} -y" - fi for u_version in ${version_list}; do verbose "Execute: ${0} -${mode} -k \"${u_version}\" ${OPTS}" + # shellcheck disable=SC2086 "${0}" -${mode} -k "${u_version}" ${OPTS} done exit 0 diff --git a/update-initramfs.8 b/update-initramfs.8 index bb88499804ff2c84c59a27882306f82b86f4ce56..b36fc5726d4ed842a5014a2ae954d2392f63bb4a 100644 --- a/update-initramfs.8 +++ b/update-initramfs.8 @@ -5,14 +5,14 @@ update\-initramfs \- generate an initramfs image .SH SYNOPSIS .B update\-initramfs -.RB \-c | \-d | \-u +.RB { \-c | \-d | \-u } .RB [ \-k .IR version ] -.RB [ \-t ] .RB [ \-v ] .RB [ \-b .IR directory ] -.RB [ \-h ] +.br +.BR update\-initramfs " " \-h .SH DESCRIPTION The .B update\-initramfs @@ -28,42 +28,42 @@ happens in this early userspace. .SH OPTIONS .TP -\fB \-k \fI version +\fB\-k \fI version Set the specific kernel version for whom the initramfs will be generated. For example the output of uname \-r for your currently running kernel. This argument is optional for update. The default is the latest kernel version. The use of "all" for the .I version -string specifies +string specifies that .B update\-initramfs -to execute the chosen action for all kernel versions, that are already known -to -.B update\-initramfs. +should operate on all installed kernel versions (with \fB\-c\fR), or +on all installed kernel versions that already have an initramfs +(with \fB\-d\fR or \fB\-u\fR). .TP -\fB \-c +\fB\-c This mode creates a new initramfs. .TP -\fB \-u +\fB\-u This mode updates an existing initramfs. .TP -\fB \-d -This mode removes an existing initramfs. +\fB\-d +This mode deletes an existing initramfs. .TP -\fB \-v +\fB\-v This option increases the amount of information you are given during the chosen action. .TP -\fB \-b \fI directory +\fB\-b \fI directory Set an different bootdir for the image creation. .TP -\fB \-h +\fB\-h\fR, \fB--help\fR Print a short help page describing the available options in .B update\-initramfs.