You may build and test your live image with QEMU many times. Here are two ways you can save time and bandwidth by reusing cached deb package files instead of repeatedly downloading them.

Reuse the packages cached in cache/*

The simplest way to build the initial live ISO image is by using the commands lh_config and lh_build. They are issued in the directory you have chosen for the build root.

# cd {build root}
{build root}# lh_config

(Make optional configuration changes to {build root}/config)

{build root}# lh_build

After the first build, downloaded deb packages remain in these directories:

{build root}/cache/packages_bootstrap
{build root}/cache/packages_chroot
{build root}/cache/packages_binary

Also, a copy of the bootstrap, which is the base for your chroot, is cached here:

{build root}/cache/stages_bootstrap

You can reuse these packages in subsequent builds. Just perform an "lh_clean" before running lh_build again to clean up the image file, the binary directory and chroot directory.

{build root}# lh_clean
{build root}# lh_build

If you only want to clean up an individual stage, e.g. you have just built an iso and want to reuse the workspace to create a usb-hdd image, just clean that stage before rebuilding:

{build root}# lh_clean --binary
{build root}# lh_config --binary-images usb-hdd
{build root}# lh_build

If you for some reason do not trust the integrity of your cache, you may start over completely clean by purging it:

{build root}# lh_clean --purge
{build root}# lh_build

Cache package downloads with apt-cacher

If you are likely to build from scratch repeatedly, or do builds from different build roots or on different systems in your LAN, you may wish to set up apt caching on your computer. Install apt-cacher and configure live-helper to fetch deb files from the apt-cacher cache. If the file does not exist in its cache, apt-cacher will download it from the mirror you normally use and store it in the cache for future use. If you encounter problems while caching keyrings from non-official Debian repositories, you can use instead apt-cacher-ng, which seems to handle the issue in a better way.

Install apt-cacher

# aptitude install apt-cacher

Configure apt-cacher by editing "/etc/default/apt-cacher"

# nano /etc/default/apt-cacher

Enable apt-cacher by setting the daemon to start at boot time (AUTOSTART=1). You can change the port or leave it as the default (3142).

The location of the cache is set in /etc/apt-cacher/apt-cacher.conf. The default is "cache_dir=/var/cache/apt-cacher"

Start the apt-cacher daemon

# /etc/init.d/apt-cacher start

Apt cacher will now be used whenever you fetch a package from the new local mirror http://localhost:3142/{debian mirror}. For example, http://localhost:3142/ftp.debian.org/debian/.

Configure live-helper to use apt-cacher

Set up a new build directory.

# cd {build root}
{build root}# lh_config

Set the build environment's main mirror and the mirror for security updates to use apt-cacher by inserting localhost:3142/ after http://.

{build root}# lh_config --mirror-bootstrap "http://localhost:3142/ftp.debian.org/debian/"
{build root}# lh_config --mirror-bootstrap-security "http://localhost:3142/security.debian.org/"

You can do the same for the binary image's mirrors. These are the mirrors that end up in the image's /etc/apt/sources.list. This will save you the few minutes needed to download the "Release" and "Packages" files from the repository while you are building the image. However, these mirrors will not be available to the final live ISO image. If you wish to have a usable /etc/apt/source.list in the final live image, remove "localhost:3142/" from these two entries before the final build.

{build root}# lh_config --mirror-binary "http://localhost:3142/ftp.debian.org/debian/"
{build root}# lh_config --mirror-binary-security "http://localhost:3142/security.debian.org/"

Try a new build

{build root}# lh_build

Check that the screen messages show files being downloaded from the "localhost" mirror.

As this is the first time it will take as long as usual, but the debs are being cached. The next time you repeat the process ("configure live-helper to use apt-cacher" and "try a new build") it will take much less time.