What is debootstrap --second-stage for
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.
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.