Apr 10
APT Bandwidth Diet
In this post ill cover how to sync your Ubuntu installation without sacrificing a large amount of bandwidth,
its commons to have a number of machines with the same packages installed the question is how we sync them all up
(especially clean installs) without using up bandwidth.
One could setup a proxy if the machines share the same local network however for distributed scenario's
(multiple networks) this won't do.
apt-move - move cache of Debian packages into a mirror hierarchy.
apt-move enables us to create a mirror from our local apt cache, we can then distribute the mirror on a removable drive using an iso format, the target machines will add the iso image by using apt-cdrom to the sources list, using the local filesystem instead the web.
The first thing is to make sure that apt-move won't delete any thing from the cache:
$ sudo aptitude install apt-move # within /etc/apt-move.conf make sure to set COPYONLY to yes => COPYONLY=yesNow lets create the mirror:
# clearing old packages $ sudo aptitude autoclean # clearing the apt-move target $ sudo rm -rf /mirrors/debian # this dumps packages from /var/cache/apt/archives into /mirrors/debian $ sudo apt-move -d karmic update $ cd /mirrors/debian # this isn't created by apt-move, a possible bug? $ sudo mkdir -p dists/karmic/non-free/binary-i386 # this solves permission issues $ sudo chmod 777 . -R $ sudo apt-ftparchive packages pool/main/ | gzip -9c > dists/karmic/main/binary-i386/Packages.gz $ sudo apt-ftparchive packages pool/non-free/ | gzip -9c > dists/karmic/non-free/binary-i386/Packages.gzTake a look into /mirrors/debian/pool folder, youll be able to see all the packages that the mirror contains, note that packages which are not within the cache folder will be missing even if you installed them before (we will see later how to bypass this), lets create the ~/Release.dummy file (the mirror Release file):
APT::FTPArchive::Release {
Origin "APT-Move";
Label "APT-Move";
Suite "karmic";
Codename "karmic";
Architectures "i386";
Components "main restricted";
Description "Ubuntu Updates CD";
};
Place the Release file within the mirror folder:
$ cd /mirrors/debian $ rm dists/karmic/Release $ apt-ftparchive -c ~/Release.dummy release dists/karmic/ > Release $ mv Release dists/karmic/Now will need a gpg key in order to sign our Release file, in this stage we will also create the iso:
$ gpg --gen-key $ gpg -bao dists/karmic/Release.gpg dists/karmic/Release # no need for this folder $ rm -rf .apt-move # creating the name of the iso $ mkdir .disk $ echo Ubuntu-Updates `date +%Y-%m-%d` > .disk/info # will need the public key within the iso $ gpg --export -a "Your Name" > public.key # creates the iso file $ mkisofs -r -A "Ubuntu Updates `date +%Y%m%d`" -o ~/ubuntu-updates.iso /mirrors/debianNow copy this iso to your favorit portable media in order to use it on the target machine:
$ sudo mount -o loop /path/to/iso/ubuntu-updates.iso /cdrom $ sudo apt-key add /cdrom/public.key # during the issue of this command the /cdrom gets unmounted, mount -o loop again before pressing enter $ sudo apt-cdrom add -d=/cdrom # mount the iso again due to the last commandWe can now install packages from the iso, lets intall java (assuming you had it in you cache):
$ sudo apt-get install sun-java6-jdk # the install should point to local filesystem & not the web (note from section). Selecting previously deselected package sun-java6-jre. (Reading database ... 146576 files and directories currently installed.) Unpacking sun-java6-jre (from .../sun-java6-jre_6-15-1_all.deb) ... sun-dlj-v1-1 license has already been accepted Selecting previously deselected package sun-java6-bin. Unpacking sun-java6-bin (from .../sun-java6-bin_6-15-1_i386.deb) ... sun-dlj-v1-1 license has already been accepted ...
In the case that you had a package that was cleared from the cache you can restore is by using:
# re-install with only download flag $ sudo apt-get install -d package-name --reinstallI hope that this will save you time post the near 10.04 release ;)

Follow me online