RSS Feed
Oct 23

HowTo: Setup your own local Ubuntu repository mirror.

Posted on Thursday, October 23, 2008 in Tutorials

While Ubuntu’s updates are nowhere near as bad as dealing with Windows updates, it can still be annoying to do a fresh install of Ubuntu and then have to download 300MB’s worth of updates, especially if you have a slow connection, or perhaps you’re in a remote location and don’t have an Internet connection. How do you update machines then??

Why not setup your own personal local Ubuntu Repository? Here’s how to make one to use either on a personal web server or carry with you on a portable USB (or similar) hard-drive.

In this example, we’re going to make a repository using a great little tool called apt-mirror and use it to mirror the 32-bit (x86) and 64-bit (AMD64) versions of Ubuntu 8.04.1 Hardy Heron and 8.10 Intrepid Ibex ONLY from an existing source mirror (thus ignoring any other architectures we’re not interested in). Our source mirror will be the Australian Ubuntu Mirror at Internode, but you can use any mirror you like.

  1. On your Ubuntu desktop or server, get into a terminal and type in the following:

    $ sudo apt-get install apt-mirror
  2. Once installed, edit the config file with:
    $ sudo nano /etc/apt/mirror.list
    

    ...here’s my config file that I use on my own file server:

    ############# config ###################
    # set base_path    /var/spool/apt-mirror
    #
    # if you change the base path you must create the directories below with write privlages
    #
    # set mirror_path  $base_path/mirror
    # set skel_path    $base_path/skel
    # set var_path     $base_path/var
    # set cleanscript $var_path/clean.sh
    # set defaultarch  <running host architecture>
    set nthreads     3
    set _tilde 0
    ############## end config ##############
    
    # Ubuntu 8.04.1 Hardy Heron 32-bit
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-updates main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-backports main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-security main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-proposed main restricted universe multiverse
    
    # Ubuntu 8.04.1 Hardy Heron 64-bit
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-updates main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-backports main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-security main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu hardy-proposed main restricted universe multiverse
    
    # Ubuntu 8.10 Intrepid Ibex 32-bit
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-updates main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-backports main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-security main restricted universe multiverse
    deb-i386 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-proposed main restricted universe multiverse
    
    # Ubuntu 8.10 Intrepid Ibex 64-bit
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-updates main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-backports main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-security main restricted universe multiverse
    deb-amd64 http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-proposed main restricted universe multiverse
    
    # Ubuntu source
    #deb-src http://archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse
    
    clean http://mirror.internode.on.net/pub/ubuntu/ubuntu
  3. The above config sets you up to download both the 32-bit and 64-bit repos for both Hardy and Intrepid only – nothing else. If you like, you can also add other repos such as Medibuntu, Virtualbox, etc – anyone who has a standard Apt repository.Note the commented out deb-src lines. I don’t use source, but if you want it, just uncomment them and point them to Internode.

    If you wish to use a different source mirror, simply substitute the URL as appropriate.

  4. Save and exit. You then kick it off with:
    $ sudo /usr/bin/apt-mirror

    …and go and order several pizzas, because this will take a good while to finish. To update your repo with anything new since last run, just re-run the apt-mirror command. Alternatively, configure cron to execute the command for you. I have mine set to run at 2am every night.

    Here’s my log from this morning’s run:

    Downloading 222 index files using 3 threads...
    Begin time: Thu Oct 23 02:00:01 2008
    [3]... [2]... [1]... [0]...
    End time: Thu Oct 23 02:01:27 2008
    
    Proceed indexes: [PPPPPPPPPPPPPPPPPPPPPPPP]
    
    276.4 MiB will be downloaded into archive.
    Downloading 111 archive files using 3 threads...
    Begin time: Thu Oct 23 02:01:51 2008
    [3]... [2]... [1]... [0]...
    End time: Thu Oct 23 02:07:16 2008
    
    318.5 MiB in 108 files and 0 directories can be freed.
    Run /var/spool/apt-mirror/var/clean.sh for this purpose.

    …which tells me 276.4MB of new files were downloaded and 318.5MB of old files are now redundant and should be deleted. Again, I have a cron job setup to run that advised cleanup script for me.

  5. To view the downloaded files. just go to /var/spool/apt-mirror/mirror and you will see a new directory there called mirror.internode.on.net and within that will be your parent mirror’s directory structure, in this case, exactly how Internode have their structure setup.
    .
  6. Once that’s all done, just setup a virtual website with Apache to allow you to see the downloaded data via a browser and then on your desktop go:
    $ sudo nano /etc/apt/sources.list.d/mylocalrepo.list

    …and enter the appropriate URL’s to your local website (note you can call the custom sources file whatever you want as long as it ends in “.list”). If you setup a virtual server called http://localhost and point its root to /var/spool/apt-mirror/mirror/mirror.internode.on.net/ then you would enter the following into your sources.list:

    # My personal Ubuntu mirror
    deb http://localhost/pub/ubuntu/ubuntu hardy main multiverse restricted universe
    deb http://localhost/pub/ubuntu/ubuntu hardy-backports main multiverse restricted universe
    deb http://localhost/pub/ubuntu/ubuntu hardy-security main multiverse restricted universe
    deb http://localhost/pub/ubuntu/ubuntu hardy-updates main multiverse restricted universe

    …OR if you’re not using a web server, then set it up to use local files instead, eg:

    # My personal Ubuntu mirror
    deb file:/var/spool/apt-mirror/mirror/mirror.internode.on.net/pub/ubuntu/ubuntu hardy main multiverse restricted universe
    deb file:/var/spool/apt-mirror/mirror/mirror.internode.on.net/pub/ubuntu/ubuntu hardy-backports main multiverse restricted universe
    deb file:/var/spool/apt-mirror/mirror/mirror.internode.on.net/pub/ubuntu/ubuntu hardy-security main multiverse restricted universe
    deb file:/var/spool/apt-mirror/mirror/mirror.internode.on.net/pub/ubuntu/ubuntu hardy-updates main multiverse restricted universe

    If you’re using Intrepid, then change all above references to “hardy” with “intrepid”.

  7. Don’t forget to then edit /etc/apt/sources.list and comment out all the standard deb lines out. Additionally, if you don’t want to use a particular section of the repository, such as Backports or Proposed, comment out that line in your custom mylocalrepo.list too by placing a hash at the start of the line.
    .
  8. Save and exit and then update your system with your new repo list with:
    $ sudo apt-get update

    …and all subsequent updates to your system will now come from your local repository. If you’re using a 32-bit system, it will automatically use the 32-bit data you downloaded, ditto 64-bit.

  9. Pat yourself on the back. Job well done!

Bring on the comments!

  1. [...] to setting up your favourite Ubuntu mirror yourself be it your local ISP’s mirror or even your own mirror at home. Just replace the URL in the source list with the new [...]

  2. [...] you’ve gone and created your very own local Ubuntu mirror using Apt-Mirror, and you’ve come across a situation similar [...]

  3. Michael Fisher says:

    “To view the downloaded files. just go to /var/spool/apt-mirror/mirror and you will see a new directory there called mirror.internode.on.net”

    No, I don’t:

    instructor@utility:/var/spool/apt-mirror/mirror$ ls -a
    . .. archive.ubuntu.com

    “Pat yourself on the back. Job well done!”

    It does….not….work

    What I get is:

    /var/spool/apt-mirror/mirror/archive.ubuntu.com/ubuntu/pool/

    and then subdirectories:

    main/
    multiverse/
    restricted/
    universe/

    and a but load of error messages if I configure the sources.list per any instructions I have found anywhere on the web if I try to run updates.

    I’m beginning to think everyone is lying about working mirrors.

  4. HyRax says:

    Hi Michael,

    Sorry that you experiencing trouble, but believe me, it works and works well.

    What component is not working as you expect? The mirroring or the using of the mirror as your repository source?

    What errors are you getting? Remember you can’t setup the sources.list to point to your mirror until you have a successful local mirror in the first place.

    When you run Apt-Mirror, is it actually confirming that it is downloading data via a progress meter? Is there actual downloaded data in your /var/spool/apt-mirror/mirror directory?

Leave a Reply

Spam Protection by WP-SpamFree