Hello boys and girls!
Today I'm gonna tell you about how to create your own Ubuntu repository just in a couple of minutes. For most Linux users this is not quite a difficult task, but I will create my Ubuntu repository in local network... and this makes a difference.
Why should you use your own repo? The answer may vary, regarding different factors. For example, if you need to update several desktops, but you don't want to do this separately for each machine (slow Internet connection). Instead, you can create your own local mirror of the repository and let your desktops pull necessary updates from it. This will save both your time and traffic. There are some other technical reasons to use local repo, but I was mostly driven by curiosity about how it works (although, this was also the main reason for writing about 80% of my tips&tricks articles in the Russian section of the blog :-D ).
I decided to create my repository on my e-TRAYz NAS, which automatically added some level of complexity to my plan. However, all the tutorials I have found on the Internet were even more strange and complicated. The most common workaround was to attach NAS repository via a web server using apache. For me it was a stumbling-stone - I only need to mount a network folder, why should I use apache? Too dully to be a perfect solution. The idea of how to get things done appeared after several google searches that pushed me in the right direction.
After a while, Xubuntu 15.04 was installed on my second hard drive and I started my experiments. To bring simplicity, this tutorial is divided into several sections.
Prerequisites: Internet connection, Terminal, 100+ GB of free space on your hard drive and a bit of patience.
Part 1: cifs-utils.
- Install cifs-utils. Open Terminal and type the following command:
sudo apt-get install cifs-utils
- Configure system mounting options. Type the following command in Terminal:
sudo mousepad /etc/fstab
This command will open the configuration file that lists all available disks, partitions and mount points. Add the following line at the end of the file:
//192.168.26.126/public/repo /media/repo cifs guest,uid=1000,iocharset=utf8 0 0
- 192.168.26.126 - server's (NAS) IP address
- /public/repo - which folder should be mounted (destination folder for Ubuntu repository)
- /media/repo - the place where /public/repo will be mounted
- guest - username (guest account doesn't require password to access shares)
- uid=1000 - the owner of the mounted share
After saving and closing /etc/fstab file, type the following command in Terminal:
sudo mount -a
It will remount all the volumes specified in the /etc/fstab file and new folder should appear on the desktop and/or in the Thunar:
If you are using password-protected share, then you need to do the following:
- type the following command in Terminal:
- in the mousepad window, enter username and password to access network share:
Save changes and close mousepad.
- change access permissions for the .smb file:
chmod 600 ~/.smb
- update the line in the /etc/fstab file accordingly:
//192.168.26.126/public/repo /media/repo cifs credentials=/home/antonio/.smb,iocharset=utf8,sec=ntlm 0 0
There are two aspects to note:
- credentials - a path to the previously created .smb file
- sec - security mode that determines how password is encrypted
Save changes and close mousepad. Remount existing volumes again:
sudo mount -a
Note that if you choose the password-protected mode, you can perform different actions in the mounted folder (e.g. create/delete files) only with sudo privileges.
My NAS Xtreamer e-TRAYz supports both CIFS modes, however, I prefer to use unprotected share to simplify files transferring and accessing the storage.
Part 2: apt-mirror.
- Install apt-mirror. Open Terminal and type the following command:
sudo apt-get install apt-mirror
- Configure apt-mirror. Type the following command in Terminal:
sudo mousepad /etc/apt/mirror.list
It will open the main configuration file of apt-mirror with a list of repositories. After some changes my mirror.list looked as follows:
############# config ################## # set base_path /media/repo # # 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 amd64 # set postmirror_script $var_path/postmirror.sh # set run_postmirror 0 set nthreads 35 set _tilde 0 # ############# end config ############## deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse #deb http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse #deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse #deb http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse #deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse clean http://archive.ubuntu.com/ubuntu
The most important parameters here are:
- set base_path - the place where all the downloaded packages will be stored.
- set defaultarch - defines packages for a particular architecture (i386 or amd64) that will be downloaded.
- set nthreads - the number of threads that will be used by apt-mirror.
I DO NOT recommend using the same configuration as mine. The local repository will not be fully functional (especially in resolving dependencies while installing packages) because only one branch is downloaded.
- Run apt-mirror using the following command:
sudo -u apt-mirror apt-mirror
After downloading indexes and translations, apt-mirror will process them and show an approximate size of the repository to be downloaded. In my case, it was 66.1 Gb (note, that apt-mirror was configured to download only main branch).
When 66.1 Gb will be downloaded, your local repository should look something like that:
Apt-mirror can be executed automatically according to cron schedule. To do so, edit /etc/cron.d/apt-mirror file and uncomment the last line:
0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log
0 4 means that apt-mirror will be executed at 4:00AM each day and logs will be saved to cron.log file. However, in my case it is more comfortable to update apt-mirror manually.
Part 3: Attaching local repository.
The most important part is how to link the local repository with the current system. This is where I understood why different tutorials recommended to install apache or nginx. As original (online) repositories are attached via http, the mirrored (local) repository is suggested to be included in the same way. This approach is used in vast majority of cases even if it is not necessary. However, few know that a repository can be attached directly without any web manipulations. That was my case.
- Type the following command in Terminal:
sudo mousepad /etc/apt/sources.list
This command will open the file with a list of repositories that are used by the system. Add the following line at the end of the file:
deb file:///media/repo/mirror/archive.ubuntu.com/ubuntu/ trusty main
Here we mount the local "identity" of the network folder where our repository is located. Save and close the file.
As an alternative, you can open any appropriate GUI (Synaptic, Software and Updates, Ubuntu Software Center) and add new repository manually.
This is how the new repository appeared in Synaptic:
Now, you can type in Terminal
sudo apt-get update
When refreshing index, you may receive the following error (if you have downloaded just one main repository):
Failed to fetch file:/media/repo/mirror/archive.ubuntu.com/ubuntu/dists/trusty/main/binary-i386/Packages
File not found
Some index files failed to download. They have been ignored, or old ones used instead.
The error means that downloading a single repository just for amd64 architecture was a bad idea :-) However, this error can be partially ignored, as some packages are installed normally. For example, git:
After installation, git worked as intended:
As the result, my local repository is located on my e-TRAYz NAS, packages are installed normally, so the main goal is achieved. The only thing is to download the rest of repositories for trusty release and have fun! :-)
That's it! See you in new articles!
Интересна ли для вас была статья? Осталось ли что-то неясным? Напишите в комментариях ниже.