zsync is a wonderful piece of software that downloads only the parts of a file that are changed, so as to avoid downloading a full copy every time.

A nice thing about the way the Ubuntu CDs are constructed is that it is quite easy to keep an up to date local install CD using zsync. Since the daily CDs generally change quite little, it can be processed quite quickly. zsync also perform a checksum comparison making it possible to change the flavour of the ISO (e.g. you have an ISO of Ubuntu and you want to change it on Kubuntu. Simply copy/paste the right line for Kubuntu and it will download just the parts that differs from the two versions).

Installing zsync

Open a terminal session:

sudo apt-get install zsync -y

You will asked to enter your password and then zsync will prompt to install.

Acquiring the ISO

All Ubuntu CD images are stored on http://cdimage.ubuntu.com.

Updating the ISO

Ubuntu archives provide .zsync files using quite similar URIs about the various flavours. For example:

zsync http://cdimage.ubuntu.com/daily-live/current/trusty-desktop-i386.iso.zsync

will sync the server's daily unstable raring (14.04) desktop image (for i386) to your local system with an older desktop image already stored on your hard drive.

Note 1: If you are using other flavours of Ubuntu don't forget to add the flavour's name in the zsync path after cdimage/, e.g.

zsync http://cdimage.ubuntu.com/kubuntu/daily-live/current/trusty-desktop-i386.iso.zsync

zsync http://cdimage.ubuntu.com/lubuntu/daily-live/current/trusty-desktop-i386.iso.zsync

Note 2: If you are using another architecture don't forget to change i386 in the zsync path with the correct architecture name, e.g.

zsync http://cdimage.ubuntu.com/daily-live/current/trusty-desktop-amd64.iso.zsync

Updating with rsync instead

Another way to update your ISO is by using rsync. rsync is another implementation of the same algorithm that zsync uses, but it requires special software at the server end and it seems to be less efficient (require more data to be downloaded) for ISO images. https://launchpad.net/products/rsync is a good resource for more information. A number of the Ubuntu servers also work as rsync servers with quite similar URIs to the websites. For example:

rsync -zhhP rsync://cdimage.ubuntu.com/cdimage/daily-live/current/trusty-desktop-i386.iso .

will sync the server's daily Trusty desktop image (for i386) to your local system with an older desktop image already stored on your hard drive. -z is compression, -hh is human readable file size (in KB or MB), and -P is a progress indicator. If you have a local Ubuntu archive mirror or cache, you can also use Jigdo, rsync is handy for finishing up Jigdo downloads that still have a few missing pieces.

Note: If you are using other flavours of Ubuntu don't forget to add the flavour's name in the rsync path after cdimage/, e.g.

rsync -zhhP rsync://cdimage.ubuntu.com/cdimage/kubuntu/daily-live/current/trusty-desktop-i386.iso .

A slightly more advanced script will automate much of the syncing process. To run this script successfully, you will need to set the DIR variable according to your needs. You can set ISO inside the script or simply pass it in on the command-line (to make it easier to sync multiple ISO images). In some cases you may need to manually set ISOPATH if you are downloading an image not automatically detected.

#    Copyright 2010 Aaditya Bhatia http://www.dragonsblaze.com/
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    See GNU General Public License at <http://www.gnu.org/licenses/>.

# This script updates individual ISO image from cdimage.ubuntu.com via rsync
# Original script written by Henrik Omma, slightly adjusted by Bert Verhaeghe,
# then a bit by Victor Van Hee. 
# Jeremy Yoder made it try to automatically pick an ISOPATH,
# adapted to karmic by Christian Bangerter.
# And then Aaditya pimped it up a little (curl, stdout text, md5 logic)

# This is how you adjust the ISOPATH, in case you need to.
# ISOPATH="cdimage.ubuntu.com/cdimage/LOCATION/current"

# If a command line argument is present, use that as ISO name
if [ -n "$1" -a $(expr "$1" : '.*\.iso$') -gt 4 ]; then
 ISO=`basename $1`;
 cd `dirname $1`;
else
 echo -e "\nUsage:\n\t$(basename $0) UBUNTU-IMAGE-FILENAME.iso\n";
 exit 1;
fi

if [ "$ISOPATH" = "" ]; then
 if [[ "$ISO" =~ "-desktop-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/daily-live/current"
 elif [[ "$ISO" =~ "-alternate-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/daily/current"
 elif [[ "$ISO" =~ "-dvd-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/dvd/current"
 elif [[ "$ISO" =~ "-netbook-remix-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-netbook-remix/daily-live/current"
 elif [[ "$ISO" =~ "-server-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-server/daily/current"
 else
 echo "Unrecognized distribution, set \$ISOPATH manually"
 exit 2;
 fi
fi

curl -sI "http://$ISOPATH/$ISO" | head -1 | grep 200 > /dev/null;

if [ $? -eq 0 ]; then
 echo "Location: rsync://$ISOPATH/$ISO";
else
 echo "Not Found: http://$ISOPATH/$ISO";
 exit 2;
fi;


echo -n "Fetching latest md5sum from the server... "
curl -s http://$ISOPATH/MD5SUMS | grep $ISO > $ISO.md5
echo "done"

echo -n "Comparing local and server MD5SUMs... "
md5sum --status -c $ISO.md5

if [ $? -eq 0 ]; then
 echo "match!"
 echo "Local copy is up to date."
 rm $ISO.md5;
 exit 0
else
 echo "mismatch!"
 echo "Performing rsync..."
 rsync -avzhhP rsync://$ISOPATH/$ISO .
fi

echo -n "Comparing local and server MD5SUMs one more time... "

md5sum --status -c $ISO.md5

if [ $? -eq 0 ]; then
 echo "match!"
 echo "Success!"
 rm $ISO.md5;
else
 echo "mismatch!"
 echo "FAILED!"
 rm $ISO.md5;
 exit 2;
fi

This script downloads MD5SUMs from the server, checks it against the local copy's MD5SUM. If they are not identical, it syncs the local ISO image to the most recent ISO image on the Ubuntu servers. Then it compares the new local MD5SUM against the server's copy again to check whether the sync process was successful displaying the result. Even though the differences between the images may be higher the total download size is very less and can be used easily.

ZsyncCdImage (last edited 2013-11-24 04:18:12 by marcobra)