Once these requirements are met you can begin configuring the apt-mirror tool. The main items that you’ll need to define are:

storage location (base_path)

number of download threads (nthreads)

release(s) and architecture(s) you want

The configuration is in the /etc/apt/mirror.list file. A default config was put in place when you installed the package, but it is generic. You’ll need to update the values mentioned above.

Below I have included a complete configuration which will mirror Ubuntu 16.04 LTS for both 32 and 64 bit installations. It will require nearly 250GB of storage space, which I will be putting on a removable drive. The drive will be mounted at /media/STORAGE/.

Once your configuration is saved you can begin to populate your mirror by running the command:

apt-mirror

In order for this repository to be available to other clients on your local area network you’ll need to share the contents over http. This is why we listed Apache2 as a requirement above. In my example configuration above I mirrored the repository on a removable drive, and mounted it at /media/STORAGE. What I need to do now is make that address available over the web. This can be done by way of a symbolic link.

The commands above will tell the filesystem to follow any requests for “ubuntu” back up to the mounted external drive, where it will find your mirrored contents. If you have any problems with this linking double-check your paths (as compared to those suggested here) and make sure your link points to the ubuntu directory, which is a subdirectory of the mirror you pulled from. If you point anywhere below this point your clients will not properly be able to find the contents.

If you get the “403 Forbidden” error then make sure the user and group of apache2 process have at least read and execute permission for every folder in the full-path to your local repository, for this article, the full-path to your local repository is:

/media/STORAGE/mirror/vn.archive.ubuntu.com/ubuntu/

shell commands that helps you check user and group of apache2 process are:

ps -ef | grep apache2#orps -aux | grep apache2

The default user and group of apache2 process are: “www-data” and “www-data”. If the “403 Forbidden” error happens, you usually can solve this error by “chmod” command. For example:

sudo chmod -R o+rx /media

The other cause for “403 Forbidden” error is wrong configurations for apache2. In Ubuntu 16.04LTS the apache2 version is usually 2.4.18. Version of apache2 can be checked with command:

apache2 -v

make sure that /etc/apache2/apache2.conf or /etc/apache2/sites-available/000-default.conf has the following line:

The additional task of keeping this newly downloaded mirror updated with the latest updates can be automated by way of a cron job. By activating the cron job your machine will automatically run the apt-mirror command on a regular daily basis, keeping your mirror up to date without any additional effort on your part.

To activate the automated cron job, edit the file /etc/cron.d/apt-mirror. There will be a sample entry in the file. Simply uncomment the line and (optionally) change the “4” to an hour more convenient for you. If left with its defaults it will run the apt-mirror command, updating and synchronizing your mirror, every morning at 4:00am.

The final step needed, now that you have your repository created, shared over http and configured to automatically update, is to configure your clients to use it. Ubuntu clients define where they should grab errata and security updates in the /etc/apt/sources.list file. This will usually point to the default or regional mirror. To update your clients to use your local mirror instead you’ll need to edit the /etc/apt/sources.list and comment the existing entries (you may want to revert to them later!)

Once you’ve commented the entries you can create new entries, this time pointing to your mirror. A sample entry pointing to a local mirror might look something like this:

Basically what you are doing is recreating your existing entries but replacing the archive.ubuntu.com with the IP of your local mirror. As long as the mirrored contents are made available over http on the mirror-server itself you should have no problems. If you do run into problems check your apache logs for details.