Bug#826709: Doesn't mention --foreign in help output
On Mon, Apr 02, 2018 at 03:27:58PM +0200, Adam Borowski wrote:
> On Sun, Apr 01, 2018 at 11:24:14AM +0800, Paul Wise wrote:
> >
> > > + if [ "$HOST_ARCH" = "amd64" ] && [ "$ARCH" = "i386" ] ; then
> > > + # i386 binary can be run on amd64 host
> >
> > It is a bad idea to hard-code this and hard-code it for only two
> > arches
>
> Especially that amd64 hosts only _usually_ can run i386.
> Thus, a hard-coded list would do more harm than good. Sure, most of the
> time it'd work, but it's the unusual cases when you need accurate error
> messages.
>
>
> > using arch-test and falling back to a more comprehensive list
> > would be much better
>
> Indeed, making arch-test a Recommends for debootstrap would be a good idea:
> it's a small package, systems that act as hosts are big enough that giving
> the user helpful error messages is worth it.
Patch implementing this attached.
> There is one caveat: binfmt uses interpreters relative to the current
> process' root directory, thus testing outside the chroot doesn't imply you
> have an interpreter in the right place inside.
Implemented in arch-test 0.11, via -c $CHROOT. There are rumours incoming
qemu has some other magic that makes this dance not required, too.
> > I prefer the message I wrote in my initial bug report:
> >
> > This machine cannot run binaries for architecture armhf
> > There are two options to work around this:
> >
> > Use qemu-debootstrap instead of debootstrap
> >
> > Use debootstrap --foreign here and
> > use debootstrap --second-stage on armhf
My stab at the patch gives only a terse error message, it's obvious how to
extend it.
> As an author of a hammer, I'm probably biased towards using it. But,
> there's at least one possibility: before calling any complex tool inside the
> chroot, you can run something dead simple like /bin/true. If that fails,
> then either you have a non-executable arch, glibc is broken or missing, or
> something else went bad while debootstrapping. These alternatives can't be
> distinguished between (this is where arch-test would be better), but at
> least we'd isolate that whole class of problems from other reasons mount can
> fail.
As it takes only a single line to implement this fallback, it's a no-brainer
to include it.
Thus, I'm attaching three patches:
1. run in_target /bin/true before anything else in the second stage
2. check arch-test if installed
3. Recommend: arch-test
(Dropped #693219 from CC, it's about improving the prose of error messages,
thus these patches don't belong there.)
Meow!
--
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢰⠒⠀⣿⡁
⢿⡄⠘⠷⠚⠋⠀ ... what's the frequency of that 5V DC?
⠈⠳⣄⠀⠀⠀⠀
>From 6a0f9d144c71d3450094faf031f604ce3c1a12a6 Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilobyte@angband.pl>
Date: Thu, 5 Apr 2018 19:45:11 +0200
Subject: [PATCH 1/3] Check if in-target /bin/true works before more complex
stuff.
The first command of second stage used to be mount /proc, which has plenty
of other reasons to fail, and people tend to try those. Instead, check
first if in-target binaries are executable at all. They can fail because
of arch unsupported by the machine (and no qemu), missing or borked libc,
borked ld-linux -- so let's separate those from mount fails.
---
scripts/debian-common | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/debian-common b/scripts/debian-common
index 36989a2..4ab1fe8 100644
--- a/scripts/debian-common
+++ b/scripts/debian-common
@@ -59,6 +59,8 @@ first_stage_install () {
}
second_stage_install () {
+ in_target /bin/true
+
setup_dynamic_devices
x_feign_install () {
--
2.17.0
>From 744feab59f0a794e373a575844a9ec78de18c0b2 Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilobyte@angband.pl>
Date: Thu, 5 Apr 2018 23:28:30 +0200
Subject: [PATCH 2/3] Use arch-test if installed to check whether second stage
is possible.
---
debootstrap | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/debootstrap b/debootstrap
index 9b547ad..772e443 100755
--- a/debootstrap
+++ b/debootstrap
@@ -526,6 +526,22 @@ fi
###########################################################################
+if [ -x /usr/bin/arch-test ] && am_doing_phase second_stage; then
+ if doing_variant fakechroot; then
+ ret=0; arch-test "$ARCH" || ret=$?
+ else
+ ret=0; arch-test -c "$TARGET" "$ARCH" || ret=$?
+ fi
+
+ case $ret in
+ 0) info ARCHEXEC "Target architecture can be executed" ;;
+ 1) error 1 ARCHNOTEXEC "Unable to execute target architecture" ;;
+ *) info ARCHEXECUNKNOWN "Can't verify that target arch works" ;;
+ esac
+fi
+
+###########################################################################
+
if [ "$UNPACK_TARBALL" ]; then
if [ "${UNPACK_TARBALL#/}" = "$UNPACK_TARBALL" ]; then
error 1 TARPATH "Tarball must be given a complete path"
--
2.17.0
>From 13a0c56a642cc94c4c5cb95f7b96dc817dbd3859 Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilobyte@angband.pl>
Date: Fri, 6 Apr 2018 01:11:38 +0200
Subject: [PATCH 3/3] Recommend arch-test.
Machines that run debootstrap in non-d-i scenarios do this for a chroot or
lxc or similar guest, thus can be assumed to have abundant storage, making
accurate error messages worth a small extra package.
---
debian/control | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/debian/control b/debian/control
index 612eaa5..ce0fc0b 100644
--- a/debian/control
+++ b/debian/control
@@ -12,7 +12,7 @@ Vcs-Git: https://anonscm.debian.org/git/d-i/debootstrap.git
Package: debootstrap
Architecture: all
Depends: ${misc:Depends}, wget
-Recommends: gnupg, ${keyring}
+Recommends: gnupg, ${keyring}, arch-test (>= 0.11~)
Suggests: ubuntu-archive-keyring
Description: Bootstrap a basic Debian system
debootstrap is used to create a Debian base system from scratch,
--
2.17.0
Reply to: