10

I just played around with debootstrap and schroot. I'm setting up my environments with debootstrap. I'm not using --second-stage option of debootstrap.

When and how do I need to use this option. What does debootstrap do in the second stage?

10

Separating the two stages is only needed if you are bootstrapping a distribution for a foreign architecture (CrossDebootstrap). Ssee the description of the --foreign option on the man page. For example, using a x86 machine to create a Debian/Ubuntu installation for an embedded ARM or PowerPC system.

The first stage downloads the needed .deb files and unpacks them into the directory you specify. The second stage runs all of the package configuration scripts, which must be done using the target architecture (or by using qemu-user-static to emulate the target architecture).

If you're not building an install for a foreign architecture, the stages are combined and you can ignore the --second-stage option.

  • 1
    This post on the Unix Stack Exchange also has good information about the --foreign and --second-stage options. – GDP2 Mar 11 '18 at 21:57
1

Example of how to use debootstrap --second-stage

If you want to debootstrap an arm64 Ubuntu 18.04 image from an Ubuntu 18.04 amd64 host, you would do:

sudo apt-get install \
  debootstrap \
  qemu-user-static \
;
debootstrap_dir=debootstrap
sudo debootstrap \
  --arch arm64 \
  --foreign \
  bionic \
  "$debootstrap_dir" \
  http://ports.ubuntu.com/ubuntu-ports \
;
sudo mkdir -p "${debootstrap_dir}/usr/bin"
sudo cp "$(which qemu-aarch64-static)" "${debootstrap_dir}/usr/bin"
sudo chroot "$debootstrap_dir" /debootstrap/debootstrap --second-stage
sudo rm -f "$root_filesystem"

The qemu-user-static package in Ubuntu 18.04 also comes with a qemu-debootstrap script that does basically the same thing as we did, but generalized to all archs. It is not in the QEMU main source tree however.

Here is my full setup to run the generated system on QEMU full system emulation: Is there any prebuilt QEMU Ubuntu image(32bit) online?

Tested on Ubuntu 18.04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.