1747 Commits

Author SHA1 Message Date
Ben Hutchings
f740273bb0 Merge branch 'avoid-double-generation' into 'debian/latest'
Avoid updating the initramfs twice for some cases

See merge request kernel-team/initramfs-tools!157
2025-03-25 23:53:49 +00:00
Benjamin Drung
7f2ed354cc Avoid updating the initramfs twice for some cases
When installing/upgrading packages (e. g. a kernel and initramfs-tools),
the same initrd is generated twice:

```
$ apt-get install --no-install-recommends -y zstd initramfs-tools linux-image-generic
[...]
Setting up initramfs-tools-core (0.146) ...
Setting up initramfs-tools (0.146) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-6.12.20-amd64 (6.12.20-1) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-6.12.20-amd64
I: /initrd.img.old is now a symlink to boot/initrd.img-6.12.20-amd64
I: /vmlinuz is now a symlink to boot/vmlinuz-6.12.20-amd64
I: /initrd.img is now a symlink to boot/initrd.img-6.12.20-amd64
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-6.12.20-amd64
Setting up linux-image-amd64 (6.12.20-1) ...
Processing triggers for initramfs-tools (0.146) ...
update-initramfs: Generating /boot/initrd.img-6.12.20-amd64
```

Remember the timestamp when the dpkg trigger is set in the file
`/run/update-initramfs.dpkg-trigger`. Then only update the initramfs if
it is not newer than the time the trigger was created.

This will solve the example given above:

```
$ apt-get install --no-install-recommends -y zstd initramfs-tools linux-image-generic
[...]
Setting up initramfs-tools-core (0.146) ...
Setting up initramfs-tools (0.146) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-6.12.20-amd64 (6.12.20-1) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-6.12.20-amd64
I: /initrd.img.old is now a symlink to boot/initrd.img-6.12.20-amd64
I: /vmlinuz is now a symlink to boot/vmlinuz-6.12.20-amd64
I: /initrd.img is now a symlink to boot/initrd.img-6.12.20-amd64
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-6.12.20-amd64
Setting up linux-image-amd64 (6.12.20-1) ...
Processing triggers for libc-bin (2.41-6) ...
Processing triggers for initramfs-tools (0.146) ...
update-initramfs: /boot/initrd.img-6.12.20-amd64 has already been updated since Tue Mar 25 11:48:49 2025.
```

This approach will not help, when the update-initramfs trigger is set by
another package (e. g. clevis-initramfs). That would need support from
the dpkg trigger (see Debian bug #1099136).

LP: #1466965
2025-03-25 12:49:23 +01:00
Benjamin Drung
40694280ef update-initramfs: add -s parameter
When installing/upgrading packages (e. g. a kernel and initramfs-tools),
the same initrd is generated twice:

```
$ apt-get install --no-install-recommends -y zstd initramfs-tools linux-image-generic
[...]
Setting up initramfs-tools-core (0.145) ...
Setting up initramfs-tools (0.145) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-6.12.16-amd64 (6.12.16-1) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-6.12.16-amd64
I: /initrd.img.old is now a symlink to boot/initrd.img-6.12.16-amd64
I: /vmlinuz is now a symlink to boot/vmlinuz-6.12.16-amd64
I: /initrd.img is now a symlink to boot/initrd.img-6.12.16-amd64
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-6.12.16-amd64
Setting up linux-image-amd64 (6.12.16-1) ...
Processing triggers for libc-bin (2.40-7) ...
Processing triggers for initramfs-tools (0.145) ...
update-initramfs: Generating /boot/initrd.img-6.12.16-amd64
```

Add a `-s` parameter to `update-initramfs` to set a Unix time stamp
(seconds since 1970) for the update mode. An existing initramfs will
only be updated if it is not newer than the specified Unix time stamp.

This feature is the first step to avoid generating the initrd twice.

LP: #1466965
2025-03-25 12:40:14 +01:00
Benjamin Drung
19b85a5685 Filter block kernel modules by symbol regex from dracut
dracut-install can filter modules by symbol (`--mod-filter-symbol`) to
select modules more fine-grain. Harmonize the set of modules that
initramfs-tools and dracut install.

The modules mptfc, mptsas, mptscsih, mptspi, and zfcp are covered by
including `=drivers/message/fusion` to the block devices.

LP: #2031841
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
2025-03-25 11:55:34 +01:00
Benjamin Drung
3ed407721c hook-functions: Move UFS storage drivers to block class
Including only UFS storage drivers that match the symbol regexp
`${blockfuncs}|iscsi_register_transport` is not enough.

Move UFS storage drivers to the `block` class instead of the more
specific `scsi`.

LP: #2081020
2025-03-25 11:49:28 +01:00
Benjamin Drung
7ef47552c1 Fix spelling mistakes in d/changelog
lintian complains:

```
W: initramfs-tools: spelling-error-in-changelog depency dependency [usr/share/doc/initramfs-tools/changelog.gz]
W: initramfs-tools: spelling-error-in-changelog plaforms platforms [usr/share/doc/initramfs-tools/changelog.gz]
W: initramfs-tools-core: spelling-error-in-changelog depency dependency [usr/share/doc/initramfs-tools-core/changelog.gz]
W: initramfs-tools-core: spelling-error-in-changelog plaforms platforms [usr/share/doc/initramfs-tools-core/changelog.gz]
```
2025-03-25 11:38:49 +01:00
Ben Hutchings
8722bb830a Merge branch 'unmk-regression' into 'debian/latest'
unmkinitramfs: Restore split to "early" and "main" subdirectories

See merge request kernel-team/initramfs-tools!162
2025-03-24 23:50:00 +00:00
Ben Hutchings
f48fbc6e86 Merge branch 'iscsi' into 'debian/latest'
Add qemu-net-iscsi autopkgtest

See merge request kernel-team/initramfs-tools!154
2025-03-24 23:48:28 +00:00
Ben Hutchings
a781aa7924 Merge branch 'update-initramfs' into 'debian/latest'
kernel/postinst.d: check for correct update-initramfs provider

See merge request kernel-team/initramfs-tools!159
2025-03-24 23:39:50 +00:00
Benjamin Drung
2334de30e4 kernel/postinst.d: check for correct update-initramfs provider
Ubuntu's dracut package ships an `update-initramfs` command with the
same interface as initramfs-tools'. The difference is that it calls
dracut instead of mkinitramfs.

When installing dracut without purging initramfs-tools,
`/etc/kernel/postinst.d/initramfs-tools` will still execute
`update-initramfs` (in addition to dracut's kernel postinst hook).

So query the newly add `--version` parameter to determine which package
provided the `update-initramfs` script. Only run the kernel postinst
hook when the provider matches.
2025-03-24 11:31:13 +01:00
Benjamin Drung
65166a6ff3 update-initramfs: add --version parameter 2025-03-24 11:30:45 +01:00
Benjamin Drung
716491a8ce mkinitramfs: add --version parameter 2025-03-24 11:30:24 +01:00
Benjamin Drung
20c564a90b Add qemu-net-iscsi autopkgtest
Add an autopkgtest for iSCSI similar to TEST-70-ISCSI from dracut.

LP: #2091904
2025-03-24 11:06:05 +01:00
Benjamin Drung
ab1fe4e20d test-common: introduce intermediate _run_qemu_default_devices
Introduce an intermediate function `_run_qemu_default_devices` to allow
reusing `_run_qemu` for cases where block or network devices are not
wanted.
2025-03-24 10:55:12 +01:00
Benjamin Drung
5401bf3528 test: support setting a disk label in build_fs_ext2 2025-03-24 10:47:10 +01:00
Benjamin Drung
a6884dc1ad test: let run_qemu* take extra kernel parameters as single parameter
Let the run_qemu* functions take extra kernel parameters as one single
parameter. This allows taking additional parameters later.
2025-03-24 10:42:56 +01:00
Ben Hutchings
bab0ea332f Merge branch 'squashfs' into 'debian/latest'
hook-functions: add squashfs driver

See merge request kernel-team/initramfs-tools!151
2025-03-23 18:48:32 +00:00
Ben Hutchings
bbbe1d37b3 unmkinitramfs.8: Update and expand description of multi-archive handling
The current behaviour of creating sub-directories for multi-archive
initramfs images was never documented.  Document what we do now, with
a note that we may stop creating sub-directories in future.

Signed-off-by: Ben Hutchings <benh@debian.org>
2025-03-20 02:40:42 +01:00
Scott Moser
cec12d7d80 hook-functions: add squashfs driver
Add squashfs support by default.

LP: #1501834
2025-03-17 10:16:30 +01:00
Ben Hutchings
736391d3ea Merge branch 'dep-add-reset' into 'debian/latest'
hook-functions: Add reset drivers when MODULES=dep

See merge request kernel-team/initramfs-tools!158
2025-03-16 21:54:16 +00:00
Ben Hutchings
2aa5542019 Merge branch 'devpts' into 'debian/latest'
Tighten /dev/pts permissions

See merge request kernel-team/initramfs-tools!161
2025-03-16 18:26:19 +00:00
Ben Hutchings
ca1a68b2c9 unmkinitramfs: Restore split to "early" and "main" subdirectories
unmkinitramfs used to assume that any uncompressed cpio archives at
the beginning of an initramfs image belonged to the early initramfs
and only a final compressed archive belonged to the the main
initramfs.  If it found any uncompressed archives it extracted them
into "early", "early2", etc. subdirectories and the compressed archive
into a "main" subdirectory.

The reason for using a separate subdirectory for each archive is to
guard against a symlink traversal attack from an untrusted initramfs,
e.g. the extraction of "link" as a symlink to "/etc" followed by
"link/shadow" which overwrites "/etc/shadow".  cpio itself protects
against this if we extract a single archive into an empty directory,
but not if we extract multiple archives successively into the same
directory.

mkinitramfs now splits the main initramfs files between uncompressed
and compressed archives.  unmkinitramfs was changed to use
subdirectory names "cpio1", "cpio2", etc. since the previous
distinction was no longer valid.

Several packages that integrate with initramfs-tools have autopkgtests
that run unmkinitramfs and were broken by this new behaviour.  It's
also quite possible that there are also user scripts that would also
be broken.

Therefore, try to restore the old behaviour in unmkinitramfs:

1. Distinguish whether uncompressed archives are "early" or "main"
   by checking for a kernel/ subdirectory.  Currently all filenames
   the kernel looks for in an early initramfs are in this
   subdirectory, but we should never create this in the main
   initramfs.

2. Extract early archives as before, but concatenate any "main"
   uncompressed archives to a temporary file.  Exclude the trailer
   from them so that cpio won't stop early when reading them.

3. Pass both the "main" uncompressed archives and the compressed
   archive to xcpio, and make it concatenate the uncompressed and
   decompressed archives as input to cpio.

The concatenation in steps 2 and 3 is done to preserve the protection
against symlink traversal.

Fixes: 81fd41f72dd8 ("Put compressed kernel modules and firmware in an uncompressed cpio")
Fixes: cb0618177b26 ("unmkinitramfs: use directory names 'cpio1', 'cpio2', etc.")
Closes: #1100008
Signed-off-by: Ben Hutchings <benh@debian.org>
2025-03-16 18:35:09 +01:00
Ben Hutchings
25b0c6164b unmkinitramfs: Fix detection of EOF marker
We currently split the initramfs when we see zero padding after an
file rather than a new file header.  However, the real EOF marker in a
cpio archive is a file header with the name "TRAILER!!!".  Look for
that first, then skip zero padding after it.

Signed-off-by: Ben Hutchings <benh@debian.org>
2025-03-16 17:52:59 +01:00
Ben Hutchings
025ce79bed unmkinitramfs: Create temporary directory for initramfs parts
Currently we extract the compressed archive from the initramfs to a
temporary file, but in future we will need to extract multiple
archives.  Create a temporary directory at the top level of the
script, and put the compressed archive inside that.

Signed-off-by: Ben Hutchings <benh@debian.org>
2025-03-16 17:52:01 +01:00
Chris Hofstaedtler
319cdc98f1 Tighten /dev/pts permissions
Apply a fuller fix for CVE-2024-28085 and remove g+w from
pseudo-terminals by default.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2025-03-06 22:44:05 +01:00
Benjamin Drung
81f2063c45 Merge branch 'bug1099461' into 'debian/latest'
hook-functions: avoid aborting in chroots

See merge request kernel-team/initramfs-tools!160
2025-03-06 18:11:29 +00:00
Chris Hofstaedtler
297a9e292a hook-functions: avoid aborting in chroots
chroots and other build environments often do not have /sys mounted.
Nevertheless they want to build initrds. As a complication, live-boot
calls these functions from a hook that has "set -e" turned on, turning
the ignored error from "read" into an abort of update-initramfs.

Fixes: b3e8cc4011334b6f39ba915149d5518b1644f87b
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1099461
Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2025-03-04 13:15:19 +01:00
Ben Hutchings
571db506ce Releasing version 0.146.
Signed-off-by: Ben Hutchings <benh@debian.org>
v0.146
2025-03-02 17:48:24 +01:00
Ben Hutchings
34f9acde87 hook-functions: Add reset drivers when MODULES=dep
Reset drivers are currently included when MODULES=most but not when
MODULES=dep.  Since they are outside the device model, match them by
module name not by driver class.

Closes: #1027458
Signed-off-by: Ben Hutchings <benh@debian.org>
2025-03-02 16:05:01 +01:00
Ben Hutchings
af25dc3ff4 Merge branch 'shellcheck-tests' into 'debian/latest'
fix shellcheck complaints in tests

See merge request kernel-team/initramfs-tools!144
2025-02-25 01:23:59 +00:00
Benjamin Drung
3ad3f72e63 d/salsa-ci.yml: include tests in shellcheck
Check shell scripts in `debian/tests` and `tests` with shellcheck as
well.
2025-02-24 17:40:05 +01:00
Benjamin Drung
a83ddc24ff test: fix checking output / initrd content
shellcheck correctly complains:

```
In debian/tests/qemu-klibc line 13:
! lsinitramfs "${INITRAMFS}" | grep -qw busybox
^-- SC2251 (info): This ! is not on a condition and skips errexit. Use `&& exit 1` instead, or make sure $? is checked.

Did you mean:
 lsinitramfs "${INITRAMFS}" | grep -qw busybox && exit 1

In debian/tests/qemu-panic-shell line 30:
! grep -qF "(initramfs) " "${OUTPUT}"
^-- SC2251 (info): This ! is not on a condition and skips errexit. Use `&& exit 1` instead, or make sure $? is checked.

Did you mean:
 grep -qF "(initramfs) " "${OUTPUT}" && exit 1

For more information:
  https://www.shellcheck.net/wiki/SC2251 -- This ! is not on a condition and ...
```

So the result oft those checks were just ignored. Fix that and add error
messages for the failure case. Otherwise there would be no output
explaining the exit code.

Note: The recommendation from https://www.shellcheck.net/wiki/SC2251
would cause qemu-panic-shell to always fail:
https://github.com/koalaman/shellcheck/issues/3121
2025-02-24 17:40:05 +01:00
Benjamin Drung
84115f9118 test: silence incorrect shellcheck SC2119
shellcheck complains:

```
In debian/tests/qemu-klibc line 17:
run_qemu
^------^ SC2119 (info): Use run_qemu "$@" if function's $1 should mean script's $1.

In debian/tests/qemu-separate-usr line 32:
run_qemu
^------^ SC2119 (info): Use run_qemu "$@" if function's $1 should mean script's $1.

In debian/tests/qemu-ata-only line 23:
run_qemu
^------^ SC2119 (info): Use run_qemu "$@" if function's $1 should mean script's $1.

In debian/tests/qemu-virtio-only line 22:
run_qemu
^------^ SC2119 (info): Use run_qemu "$@" if function's $1 should mean script's $1.

In debian/tests/qemu-busybox line 17:
run_qemu
^------^ SC2119 (info): Use run_qemu "$@" if function's $1 should mean script's $1.

For more information:
  https://www.shellcheck.net/wiki/SC2119 -- Use prepare_network_dumping_rootf...
```

To silence this shellcheck info since `run_qemu` should be called
without arguments in those cases.
2025-02-24 17:40:05 +01:00
Benjamin Drung
2c746f129d test: make prepare_network_dumping_rootfs take no parameters
```
In debian/tests/qemu-net line 39:
prepare_network_dumping_rootfs
^----------------------------^ SC2119 (info): Use prepare_network_dumping_rootfs "$@" if function's $1 should mean script's $1.

For more information:
  https://www.shellcheck.net/wiki/SC2119 -- Use prepare_network_dumping_rootf...
```

`prepare_network_dumping_rootfs` is never called with a parameter.
2025-02-24 17:40:05 +01:00
Benjamin Drung
32630e9bc5 tests: fix shellcheck info "read without -r will mangle backslashes"
```
In debian/tests/test-common line 21:
| while read fw_file; do
        ^--^ SC2162 (info): read without -r will mangle backslashes.

For more information:
  https://www.shellcheck.net/wiki/SC2162 -- read without -r will mangle backs...
```
2025-02-24 17:40:05 +01:00
Benjamin Drung
08ec63cc2a tests: fix shellcheck warning "variable appears unused"
```
In debian/tests/test-common line 137:
	verbose=y
        ^-----^ SC2034 (warning): verbose appears unused. Verify use (or export if used externally).

In debian/tests/test-common line 138:
	DESTDIR="$root_dir"
        ^-----^ SC2034 (warning): DESTDIR appears unused. Verify use (or export if used externally).
```
2025-02-24 17:40:05 +01:00
Benjamin Drung
db53479a2a tests: Replace 'echo -n' by printf
```
In debian/tests/copy-file line 9:
echo -n 1 >"${SOURCEDIR}/dir1/file1"
     ^-- SC3037 (warning): In POSIX sh, echo flags are undefined.

In debian/tests/copy-file line 11:
echo -n 22 >"${SOURCEDIR}/file2"
     ^-- SC3037 (warning): In POSIX sh, echo flags are undefined.

In debian/tests/copy-file line 12:
echo -n 333 >"${SOURCEDIR}/file3"
     ^-- SC3037 (warning): In POSIX sh, echo flags are undefined.
```
2025-02-24 17:40:05 +01:00
Benjamin Drung
933311181b tests: fix shellcheck warning "Declare and assign separately to ..."
```
In debian/tests/test-common line 154:
	local blocks="$(du --summarize "${dir}" | cut -f 1)"
              ^----^ SC2155 (warning): Declare and assign separately to avoid masking return values.

In debian/tests/test-common line 155:
	local inodes="$(du --summarize --inodes "${dir}" | cut -f 1)"
              ^----^ SC2155 (warning): Declare and assign separately to avoid masking return values.

For more information:
  https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
```
2025-02-24 17:40:05 +01:00
Benjamin Drung
ddec7a3f76 Mark debian/tests/test-common as sh script
`debian/tests/test-common` is sourced by the test script in debian/tests
which are /bin/sh scripts.
2025-02-24 17:40:05 +01:00
Ben Hutchings
b2d18950e6 Merge branch 'tests-install-e2fsprogs' into 'debian/latest'
tests: Add e2fsprogs to dependencies

See merge request kernel-team/initramfs-tools!156
2025-02-24 00:31:55 +00:00
Ben Hutchings
10bcd21e92 tests: Add e2fsprogs to dependencies
Until recently, e2fsprogs was installed by default in autopkgtest
testbeds on both ci.debian.net and Salsa CI.  This is no longer
the case in Salsa CI, so we need to explicitly depend on it.

Signed-off-by: Ben Hutchings <benh@debian.org>
2025-02-24 01:02:06 +01:00
Ben Hutchings
76e7679653 Merge branch 'libgcc' into 'debian/latest'
hook-functions: make copy_libgcc to not take any parameters

See merge request kernel-team/initramfs-tools!139
2025-02-23 22:26:27 +00:00
Ben Hutchings
792ee0d462 Merge branch 'log-commands-with-output' into 'debian/latest'
test: log commands that produce output on stdout

See merge request kernel-team/initramfs-tools!155
2025-02-23 22:22:44 +00:00
Ben Hutchings
5af35d8c9e Merge branch 'local-net_file' into 'debian/latest'
netinfo_to_resolv_conf: add net_file to local variables

See merge request kernel-team/initramfs-tools!148
2025-02-23 22:21:16 +00:00
Ben Hutchings
6261e6afcb Merge branch 'reset-vars-before-sourcing' into 'debian/latest'
netinfo_to_resolv_conf: clear variables between sourcing

See merge request kernel-team/initramfs-tools!147
2025-02-23 22:20:50 +00:00
Ben Hutchings
fcb333a7fe Merge branch 'set-e' into 'debian/latest'
Explicitly call "set -e" instead of specifying on shebang

See merge request kernel-team/initramfs-tools!146
2025-02-23 22:18:14 +00:00
Benjamin Drung
370b4338fa test: log commands that produce output on stdout
To ease reading the autopkgtest logs, log commands that produce output
on stdout.
2025-02-06 19:42:40 +01:00
Benjamin Drung
df2b4b3828 hook-functions: make copy_libgcc to not take any parameters
The initramfs-tools hook from multipath-tools 0.9.4-9 and newer calls
`copy_libgcc` without any arguments. This will fail:

```
mkinitramfs: copy_file: binary '/libgcc_s.so.[1-9]' not found
```

Instead of relying on multipath-tools to figure out the correct library
path, make `copy_libgcc` to not take any parameters.

LP: #2085157
2025-01-20 11:46:15 +01:00
Benjamin Drung
b55854dcef netinfo_to_resolv_conf: add net_file to local variables
`net_file` is a local variable in `netinfo_to_resolv_conf`.
2025-01-20 11:28:54 +01:00
Benjamin Drung
5eda205fb0 netinfo_to_resolv_conf: clear variables between sourcing
The function `netinfo_to_resolv_conf` does not clear the variables
between reading multiples files. This can lead to duplicate entries in
the resolv.conf in case the files do not specify the same variables.

Distilled problem:

```sh
#!/bin/sh

sourcing() {
    for file in "$@"; do
        local A B C
        . "./$file"
        echo "A: ${A-}"
        echo "B: ${B-}"
        echo "C: ${C-}"
        echo
    done
}

printf "A=1\nB=2\n" > first
printf "A=a\nC=c\n" > second
sourcing first second
```

`B` is only defined in the first file and will still contain this value
after sourcing the second file:

```
A: 1
B: 2
C:

A: a
B: 2
C: c
```

So set the local variables to empty strings to clear them before
sourcing the next configuration file.
2025-01-20 11:28:23 +01:00