I want to run debootstrap multiple times for the same target.

Often I am in transit with no internet access and would like to run it offline.

How can I run the process one with internet access and then multiple times afterwards without internet access?

I am open to using wrappers/alternatives like multistrap and cache options like apt-cacher-ng or squid.

The key requirement is that I can run it completely offline.


If you want to install Linux many times with the same configuration, debootstrap the system first with the --foreign option when installing. e.g. the following bootstraps Ubuntu zesty into the directory "deboot"

sudo debootstrap --foreign zesty deboot

You can then keep the deboot dir as a reference and copy it to a new working dir each time you want to reuse it and use the second-stage option.

mkdir work
cd work
sudo cp -r ../deboot .
sudo DEBOOTSTRAP_DIR=deboot/debootstrap/ debootstrap --second-stage --second-stage-target $(readlink -f deboot)

Two things to note here are the DEBOOTSTRAP_DIR environment variable that the debootstrap script uses (but doesn't document very well) and that the second-stage-target option requires a full path.

An alternative option is to use the parameter --make-tarball=[file] which allows you to download the packages and then use --unpack-tarball=[file] to put those packages in the target dir.

If you want to reuse your cache from some other source or shared folder use apt-proxy or cp -a packages /var/cache/apt/archives/, however, this isn't fully offline as debootstrap will still try to connect to the interent to get the InRelease file from the remote repo.


You can use squid-deb-proxy as is to run offline (even the InRelease files) but you need to modify it slightly to run debootstrap offline even when you are online.

You need to modify the squid-deb-proxy.conf file so take a copy and put it in your project.

There are absolute paths in the conf file to /etc and /var so you need to modify these to be relative if you to separate it from the system.

In order to still use the proxy when you are online you need to add this to the conf file.

#Use cached values when offline
offline_mode on

You can then start it like this:

mkdir -p squid/var/log/squid-deb-proxy
mkdir -p squid/var/run/

echo "Starting an instance of squid using the working dir for caches and logs instead of the system dirs"
squid -Nf squid/squid-deb-proxy.conf

Then before you start debootstrap

#Use a caching proxy to save bandwidth
export http_proxy=

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.