Compare commits

...

8 commits

5 changed files with 73 additions and 22 deletions

View file

@ -1,3 +1,8 @@
1.4.3 (2024-02-01)
------------------
- take hard links into account when computing disk usage
1.4.2 (2024-01-29) 1.4.2 (2024-01-29)
------------------ ------------------

View file

@ -365,11 +365,11 @@ Variants: custom
Modes: chrootless Modes: chrootless
Needs-APT-Config: true Needs-APT-Config: true
Test: install-libmagic-mgc-on-arm64 Test: install-libmagic-mgc-on-foreign
Variants: custom Variants: custom
Modes: chrootless Modes: chrootless
Skip-If: Skip-If:
hostarch != "amd64" hostarch not in ["amd64", "arm64"]
not have_binfmt not have_binfmt
Test: install-busybox-based-sub-essential-system Test: install-busybox-based-sub-essential-system
@ -380,6 +380,7 @@ Modes: root unshare fakechroot
Skip-If: Skip-If:
hostarch not in ["amd64", "arm64"] hostarch not in ["amd64", "arm64"]
mode == "fakechroot" and not run_ma_same_tests mode == "fakechroot" and not run_ma_same_tests
mode == "fakechroot" and hostarch == "arm64" # usrmerge postinst under fakechroot wants to copy /lib/ld-linux-x86-64.so.2 (which does not exist) instead of /lib64/ld-linux-x86-64.so.2
not have_binfmt not have_binfmt
Test: no-sbin-in-path Test: no-sbin-in-path

View file

@ -23,7 +23,7 @@
use strict; use strict;
use warnings; use warnings;
our $VERSION = '1.4.2'; our $VERSION = '1.4.3';
use English; use English;
use Getopt::Long; use Getopt::Long;
@ -1551,34 +1551,41 @@ sub setup_mounts {
if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) { if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
info "skipping chroot/start-stop-daemon as requested"; info "skipping chroot/start-stop-daemon as requested";
} else { } else {
# $options->{root} must not be part of $ssdloc but must instead be
# evaluated at the time the cleanup is run or otherwise, when
# performing a pivot-root, the ssd location will still be prefixed
# with the chroot path even though we changed root
my $ssdloc; my $ssdloc;
if (-f "$options->{root}/sbin/start-stop-daemon") { if (-f "$options->{root}/sbin/start-stop-daemon") {
$ssdloc = "$options->{root}/sbin/start-stop-daemon"; $ssdloc = "/sbin/start-stop-daemon";
} elsif (-f "$options->{root}/usr/sbin/start-stop-daemon") { } elsif (-f "$options->{root}/usr/sbin/start-stop-daemon") {
$ssdloc = "$options->{root}/usr/sbin/start-stop-daemon"; $ssdloc = "/usr/sbin/start-stop-daemon";
} }
push @cleanup_tasks, sub { push @cleanup_tasks, sub {
return unless length $ssdloc; return unless length $ssdloc;
if (-e "$ssdloc.REAL") { if (-e "$options->{root}/$ssdloc.REAL") {
move("$ssdloc.REAL", "$ssdloc") move(
or error "cannot move start-stop-daemon: $!"; "$options->{root}/$ssdloc.REAL",
warning "/sbin/start-stop-daemon fake replaced with real"; "$options->{root}/$ssdloc"
) or error "cannot move start-stop-daemon: $!";
} }
}; };
if (length $ssdloc) { if (length $ssdloc) {
if (-e "$ssdloc.REAL") { if (-e "$options->{root}/$ssdloc.REAL") {
error "$ssdloc.REAL already exists"; error "$options->{root}/$ssdloc.REAL already exists";
} }
move("$ssdloc", "$ssdloc.REAL") move(
or error "cannot move start-stop-daemon: $!"; "$options->{root}/$ssdloc",
open my $fh, '>', $ssdloc "$options->{root}/$ssdloc.REAL"
) or error "cannot move start-stop-daemon: $!";
open my $fh, '>', "$options->{root}/$ssdloc"
or error "cannot open start-stop-daemon: $!"; or error "cannot open start-stop-daemon: $!";
print $fh "#!/bin/sh\n"; print $fh "#!/bin/sh\n";
print $fh print $fh
"echo \"Warning: Fake start-stop-daemon called, doing" "echo \"Warning: Fake start-stop-daemon called, doing"
. " nothing\">&2\n"; . " nothing\">&2\n";
close $fh; close $fh;
chmod 0755, "$ssdloc" chmod 0755, "$options->{root}/$ssdloc"
or error "cannot chmod start-stop-daemon: $!"; or error "cannot chmod start-stop-daemon: $!";
} }
} }
@ -4386,19 +4393,27 @@ sub approx_disk_usage {
# We ignore /dev because depending on the mode, the directory might be # We ignore /dev because depending on the mode, the directory might be
# populated or not and we want consistent disk usage results independent # populated or not and we want consistent disk usage results independent
# of the mode. # of the mode.
my $installed_size = 0; my $installed_size = 0;
my %hardlink;
my $scan_installed_size = sub { my $scan_installed_size = sub {
if ($File::Find::name eq "$directory/dev") { if ($File::Find::name eq "$directory/dev") {
# add all entries of @devfiles once # add all entries of @devfiles once
$installed_size += scalar @devfiles; $installed_size += scalar @devfiles;
return;
} elsif ($File::Find::name =~ /^$directory\/dev\//) { } elsif ($File::Find::name =~ /^$directory\/dev\//) {
# ignore everything below /dev # ignore everything below /dev
} elsif (-l $File::Find::name) { return;
# -f follows symlinks, so we first check if we have a symlink }
$installed_size += 1;
} elsif (-f $File::Find::name) { lstat or error "cannot stat $File::Find::name";
if (-f _ or -l _) {
my ($dev, $ino, $nlink) = (lstat _)[0, 1, 3];
return if exists $hardlink{"$dev:$ino"};
# Track hardlinks to avoid repeated additions.
$hardlink{"$dev:$ino"} = 1 if $nlink > 1;
# add file size in 1024 byte blocks, rounded up # add file size in 1024 byte blocks, rounded up
$installed_size += int(((-s $File::Find::name) + 1024) / 1024); $installed_size += int(((-s _) + 1024) / 1024);
} else { } else {
# all other entries are assumed to only take up one block # all other entries are assumed to only take up one block
$installed_size += 1; $installed_size += 1;
@ -5212,6 +5227,12 @@ sub main() {
} }
} }
if (defined $options->{qemu} && $options->{mode} eq 'fakechroot') {
if (!can_execute 'dpkg-architecture') {
error "cannot find dpkg-architecture";
}
}
{ {
$options->{suite} = undef; $options->{suite} = undef;
if (scalar @ARGV > 0) { if (scalar @ARGV > 0) {

View file

@ -298,6 +298,16 @@ WORKDIR=$(mktemp -d)
FAT_OFFSET_SECTORS=$((1024*2)) FAT_OFFSET_SECTORS=$((1024*2))
FAT_SIZE_SECTORS=$((1024*254)) FAT_SIZE_SECTORS=$((1024*254))
# The image is raw and not in qcow2 format because:
# - faster run-time as the "qemu-image convert" step is not needed
# - image can be used independent of qemu tooling
# - modifying the image just with "mount" instead of requiring qemu-nbd
# - sparse images make the file just as small as with qcow2
# - trim support is more difficult on qcow2
# - snapshots and overlays work just as well with raw images
# - users who prefer qcow2 get to choose to run it themselves with their own
# custom options like compression
#
# Make the image writeable to the first subgid. mmdebstrap will map this gid to # Make the image writeable to the first subgid. mmdebstrap will map this gid to
# the root group. unshare instead will map the current gid to 0 and the first # the root group. unshare instead will map the current gid to 0 and the first
# subgid to 1. Therefore mmdebstrap will be able to write to the image. # subgid to 1. Therefore mmdebstrap will be able to write to the image.

View file

@ -17,13 +17,27 @@ if [ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && [ "{{ MODE }}" != "auto
prefix="runuser -u ${SUDO_USER:-user} --" prefix="runuser -u ${SUDO_USER:-user} --"
fi fi
$prefix {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} --architectures=arm64 --include=libmagic-mgc {{ DIST }} /tmp/debian-chroot {{ MIRROR }} case "$(dpkg --print-architecture)" in
arm64)
foreign_arch=amd64
;;
amd64)
foreign_arch=arm64
;;
*)
echo "unsupported native architecture" >&2
exit 1
;;
esac
$prefix {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} --architectures="$foreign_arch" --include=libmagic-mgc {{ DIST }} /tmp/debian-chroot {{ MIRROR }}
# delete contents of libmagic-mgc # delete contents of libmagic-mgc
rm /tmp/debian-chroot/usr/lib/file/magic.mgc rm /tmp/debian-chroot/usr/lib/file/magic.mgc
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/README.Debian rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/README.Debian
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.Debian.gz rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.Debian.gz
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.gz rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.gz
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/copyright rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/copyright
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/"changelog.Debian.$foreign_arch.gz"
rm /tmp/debian-chroot/usr/share/file/magic.mgc rm /tmp/debian-chroot/usr/share/file/magic.mgc
rm /tmp/debian-chroot/usr/share/misc/magic.mgc rm /tmp/debian-chroot/usr/share/misc/magic.mgc
# delete real files # delete real files