initramfs/klibc-utils contains identical binaries

Bug #2028571 reported by Benjamin Drung
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
initramfs-tools (Ubuntu)
Triaged
Medium
Unassigned
klibc (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

```
$ jdupes -r /usr/lib/klibc/bin
Scanning: 38 files, 1 items (in 1 specified)
/usr/lib/klibc/bin/gunzip
/usr/lib/klibc/bin/gzip
/usr/lib/klibc/bin/zcat

/usr/lib/klibc/bin/halt
/usr/lib/klibc/bin/poweroff
/usr/lib/klibc/bin/reboot
```

Please replace these binaries with symlinks to reduce the size of the uncompressed initramfs.

ProblemType: Bug
DistroRelease: Ubuntu 23.04
Package: klibc-utils 2.0.12-1
ProcVersionSignature: Ubuntu 6.2.0-25.25-generic 6.2.13
Uname: Linux 6.2.0-25-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
ApportVersion: 2.26.1-0ubuntu2
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: Unity:Unity7:ubuntu
Date: Mon Jul 24 21:14:36 2023
Dependencies: libklibc 2.0.12-1
InstallationDate: Installed on 2022-03-20 (491 days ago)
InstallationMedia: Ubuntu 21.10 "Impish Indri" - Release amd64 (20211012)
SourcePackage: klibc
UpgradeStatus: Upgraded to lunar on 2023-04-20 (95 days ago)

Revision history for this message
Benjamin Drung (bdrung) wrote :
Revision history for this message
Adrien Nader (adrien) wrote :

These are actually hardlinks I think and "cpio -H newc" handles hardlinks properly: they don't result in extra space being used.

(yes, I had also thought they did)

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

jdupes normally considers hardlinks as one.

And, indeed, on my Debian system, I see:

-rwxr-xr-x 1 root root 36656 May 27 2021 gunzip*
-rwxr-xr-x 1 root root 36656 May 27 2021 gzip*

These aren’t hardlinks.

And indeed they aren’t hardlinks in the Debian binary package either:

$ paxtar -xOf klibc-utils_2.0.8-6.1_amd64.deb data.tar.xz | xz -d | paxtar -tvf - | fgrep zip
-rwxr-xr-x 1 root root 36656 May 27 2021 ./usr/lib/klibc/bin/gunzip
-rwxr-xr-x 1 root root 36656 May 27 2021 ./usr/lib/klibc/bin/gzip

debian/klibc-utils.install just has:

usr/lib/klibc/bin/*

These get placed there by:

override_dh_auto_install:
        $(MAKE) install $(KLIBC_MAKEFLAGS)

Upstream usr/gzip/Kbuild does hardlink them in the build directory:

$(obj)/gunzip $(obj)/zcat: $(obj)/gzip
        $(call cmd,ln)

The upstream “make install” call causes execution of:

  install -m 755 usr/gzip/gzip usr/gzip/gunzip usr/gzip/zcat ../tmp/usr/lib/klibc/bin

And, indeed, this breaks up the hardlink.

I see two actions arising from this:

① The Debian packaging probably should run something like…

for pkgtopdir in debian/*/; do jdupes -rL "$pkgtopdir"; done

… after installing all the files.

@maximilian attems, are you reading?

② Upstream should probably not use install(1) to install hardlinked files; perhaps recreate the hardlinks in the destination like the BSDs do?

I’ll forward this to the upstream mailing list.

Changed in klibc (Ubuntu):
status: New → Confirmed
Revision history for this message
Ben Hutchings (benh-debian) wrote :

This is fixed upstream with:
https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=d16525038612be94cf2573c02eac8c7f76321f62

It's about time to make a new upstream release, so I will aim to do that and the Debian update this week.

Revision history for this message
Benjamin Drung (bdrung) wrote :

Thanks for addressing it so quickly.

I marked initramfs-tools as affect. We need to test if the hardlinked files will end up hardlinked in the initramfs.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package klibc - 2.0.13-1

---------------
klibc (2.0.13-1) unstable; urgency=medium

  * New upstream version:
    - time: Use clock_* system calls for time-of-day and sleep
      (Closes: #923098)
    - Install command links as appropriate (LP: #2028571)

 -- Ben Hutchings <email address hidden> Mon, 31 Jul 2023 15:04:13 +0200

Changed in klibc (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Benjamin Drung (bdrung) wrote :

Tested initramfs generated with it:

```
$ schroot-wrapper -c mantic -u root -p initramfs-tools,linux-image-generic,fdupes
(mantic)root@host:~# unmkinitramfs /boot/initrd.img initrd
(mantic)root@host:~# jdupes -r /usr/lib/klibc/bin
Scanning: 38 files, 1 items (in 1 specified)
No duplicates found.
(mantic)root@host:~# jdupes -r initrd/
Scanning: 1760 files, 462 items (in 1 specified)
initrd/main/etc/modprobe.d/amd64-microcode-blacklist.conf
initrd/main/etc/modprobe.d/intel-microcode-blacklist.conf

initrd/main/usr/bin/halt
initrd/main/usr/bin/poweroff
```

So the hard-linked files get de-duplicated in the initramfs.

Changed in initramfs-tools (Ubuntu):
importance: Undecided → Low
status: New → Triaged
importance: Low → Medium
summary: - klibc-utils contains identical binaries
+ initramfs/klibc-utils contains identical binaries
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.