How to manage packages on an off-line Debian system

There are plenty of off-line Debian systems just waiting to update index files, upgrade or install additional packages. This can be easily achieved by using apt-offline utility. I will shortly describe common usage scenario as it is very handy application.

Preparations

Visit Debian packages web-site and download apt-offline utility.

Use lsb_release command to confirm release/codename information.

$ lsb_release  -d
Description:	Debian GNU/Linux 7.3 (wheezy)

Installation

Move apt-offline package to the off-line Debian system and install it.

off-line$ sudo dpkg -i apt-offline_1.2_all.deb
(Reading database ... 24586 files and directories currently installed.)
Unpacking apt-offline (from apt-offline_1.2_all.deb) ...
Setting up apt-offline (1.2) ...
Processing triggers for man-db ...

Important notice

apt-offline uses /etc/apt/trusted.gpg file as keyring instead of files in the /etc/apt/trusted.gpg.d/ directory.

You can easily identify this problem as will you see similar program output:

$ sudo apt-offline install bundle.zip 
[...]
gpgv: Signature made Sat Dec 14 11:52:03 2013 CET using RSA key ID 46925553
gpgv: Can't check signature: public key not found
gpgv: Signature made Sat Dec 14 12:01:01 2013 CET using RSA key ID 65FFB764
gpgv: Can't check signature: public key not found
ERROR: /var/lib/apt/lists/partial/ftp.icm.edu.pl_pub_Linux_debian_dists_wheezy_Release.gpg bad signature. Not syncing because in strict mode.
[...]

Solution is very simple as you need to alter /etc/apt/trusted.gpg file to import missing keys.

$ sudo apt-key exportall | sudo gpg --no-default-keyring --import --keyring /etc/apt/trusted.gpg
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: key 473041FA: public key "Debian Archive Automatic Signing Key (6.0/squeeze) <ftpmaster@debian.org>" imported
gpg: key B98321F9: public key "Squeeze Stable Release Key <debian-release@lists.debian.org>" imported
gpg: key 46925553: public key "Debian Archive Automatic Signing Key (7.0/wheezy) <ftpmaster@debian.org>" imported
gpg: key 65FFB764: public key "Wheezy Stable Release Key <debian-release@lists.debian.org>" imported
gpg: Total number processed: 4
gpg:               imported: 4  (RSA: 4)
gpg: no ultimately trusted keys found

Package index synchronization

Define action on the off-line system

To update package index you need to issue update action and specify signature file that will be used later on the on-line Debian system.

off-line$ sudo apt-offline set debian-update.sig --update
Generating database of files that are needed for an update.	

Execute download action on the on-line system

Move generated signature file debian-update.sig to the on-line system.

Fetch required APT data described in the signature file (using two threads in the example below) and store it as debian-update.zip file.

on-line$ apt-offline get debian-update.sig --bundle debian-update.zip --threads 2

Fetching APT Data

Downloading http://security.debian.org/dists/wheezy/updates/main/source/Sources.bz2.
http://security.debian.org/dists/wheezy/updates/main/source/Sources.bz2 done.
Downloading http://security.debian.org/dists/wheezy/updates/main/binary-i386/Packages.bz2.
http://security.debian.org/dists/wheezy/updates/main/binary-i386/Packages.bz2 done.
[...]
Downloading http://ftp.icm.edu.pl/pub/Linux/debian/dists/wheezy-updates/Release.
http://ftp.icm.edu.pl/pub/Linux/debian/dists/wheezy-updates/Release done.
Downloading http://ftp.icm.edu.pl/pub/Linux/debian/dists/wheezy-updates/Release.gpg.
http://ftp.icm.edu.pl/pub/Linux/debian/dists/wheezy-updates/Release.gpg done.

Downloaded data to /home/milosz/debian-update.zip	

Execute install process on the off-line system

Move debian-update.zip file to the off-line system and finish package index update process.

off-line$ sudo apt-offline install 1.zip 
gpgv: Signature made Tue Jan 28 15:56:35 2014 CET using RSA key ID 46925553
gpgv: Good signature from "Debian Archive Automatic Signing Key (7.0/wheezy) $lt;ftpmaster@debian.org>"
[...]
/var/lib/apt/lists/partial/security.debian.org_dists_wheezy_updates_Release synced.
/var/lib/apt/lists/partial/security.debian.org_dists_wheezy_updates_Release.gpg synced.
/var/lib/apt/lists/partial/security.debian.org_dists_wheezy_updates_main_binary-i386_Packages synced.
/var/lib/apt/lists/partial/security.debian.org_dists_wheezy_updates_main_i18n_Translation-en synced.
/var/lib/apt/lists/partial/security.debian.org_dists_wheezy_updates_main_source_Sources synced.	
[...]

System upgrade

Define action on the off-line system

To upgrade off-line Debian system execute upgrade action and define signature file.

off-line$ sudo apt-offline set debian-upgrade.sig --upgrade	
I strongly suggest to read manual page if you want to perform dist-upgrade action or download bug reports.

Execute download action on the on-line system

Upload debian-upgrade.sig to the on-line system and download required files.

on-line$ apt-offline get debian-upgrade.sig --bundle debian-upgrade.zip --threads 3

Execute install process on the off-line system

Upload debian-upgrade.zip bundle to the off-line system and install it using apt-offline utility to update APT database.

off-line$ sudo apt-offline install debian-upgrade.zip

Now you can start upgrade process as every required package is already downloaded.

off-line$ sudo apt-get upgrade

There are couple of exceptions to the above statement like flash player as it cannot be installed in off-line mode.

Package installation

Define action on the off-line system

To install mc and hdparm packages on the off-line Debian system execute install-packages action and define signature file.

off-line$ apt-offline set debian-install.sig --install-packages mc hdparm
Generating database of package mc, hdparm,  and its dependencies.	

Execute download action on the on-line system

Upload debian-install.sig to the on-line system and download required files.

on-line$ apt-offline get debian-install.sig --bundle debian-install.zip 

Fetching APT Data

Downloading libffi5 3.0.10-3 - 20 KiB
libffi5 3.0.10-3 done.
Downloading libglib2.0-0 2.33.12+really2.32.4-5 - 1 MiB
libglib2.0-0 2.33.12+really2.32.4-5 done. 
Downloading hdparm 9.39-1+b1 - 110 KiB  
hdparm 9.39-1+b1 done.                        
Downloading libglib2.0-data 2.33.12+really2.32.4-5 - 1 MiB
libglib2.0-data 2.33.12+really2.32.4-5 done.
Downloading mc-data 3%3a4.8.3-10 - 1 MiB 
mc-data 3%3a4.8.3-10 done.  
Downloading mc 3%3a4.8.3-10 - 460 KiB   
mc 3%3a4.8.3-10 done.     
Downloading powermgmt-base 1.31 - 11 KiB  
powermgmt-base 1.31 done.    
Downloading shared-mime-info 1.0-1+b1 - 590 KiB
shared-mime-info 1.0-1+b1 done.
Downloading unzip 6.0-8 - 182 KiB  
unzip 6.0-8 done. 

Downloaded data to /home/milosz/debian-install.zip

Execute install process on the off-line system

Upload debian-install.zip file to the off-line system, install it using apt-offline utility to update APT database.

off-line$ sudo apt-offline install debian-install.zip 
/var/cache/apt/archives/libffi5_3.0.10-3_i386.deb file synced.
/var/cache/apt/archives/libglib2.0-0_2.33.12+really2.32.4-5_i386.deb file synced.
/var/cache/apt/archives/hdparm_9.39-1+b1_i386.deb file synced.
/var/cache/apt/archives/libglib2.0-data_2.33.12+really2.32.4-5_all.deb file synced.
/var/cache/apt/archives/mc-data_3%3a4.8.3-10_all.deb file synced.
/var/cache/apt/archives/mc_3%3a4.8.3-10_i386.deb file synced.
/var/cache/apt/archives/powermgmt-base_1.31_i386.deb file synced.
/var/cache/apt/archives/shared-mime-info_1.0-1+b1_i386.deb file synced.
/var/cache/apt/archives/unzip_6.0-8_i386.deb file synced.	

Now install specified packages using regular apt-get utility.

off-line$ sudo apt-get install mc hdparm 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libffi5 libglib2.0-0 libglib2.0-data mc-data powermgmt-base 
  shared-mime-info unzip
Suggested packages:
  apmd zip arj xpdf pdf-viewer dbview odt2txt gv catdvi djvulibre-bin 
  imagemagick python-boto python-tz
The following NEW packages will be installed:
  hdparm libffi5 libglib2.0-0 libglib2.0-data mc mc-data powermgmt-base 
  shared-mime-info unzip
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/5931 kB of archives.
After this operation, 23.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? 
Selecting previously unselected package libffi5:i386.
(Reading database ... 24694 files and directories currently installed.)
[...]
Processing triggers for man-db ...
Processing triggers for mime-support ...
Setting up libffi5:i386 (3.0.10-3) ...
Setting up libglib2.0-0:i386 (2.33.12+really2.32.4-5) ...
No schema files found: doing nothing.
Setting up hdparm (9.39-1+b1) ...
Setting up libglib2.0-data (2.33.12+really2.32.4-5) ...
Setting up mc-data (3:4.8.3-10) ...
Setting up mc (3:4.8.3-10) ...
update-alternatives: using /usr/bin/mcview to provide /usr/bin/view (view) in auto mode
Setting up powermgmt-base (1.31) ...
Setting up shared-mime-info (1.0-1+b1) ...
Setting up unzip (6.0-8) ...

GUI interface

Surprisingly, there is a nice graphical user interface available in Debian package repository.

To install it execute the following command.

$ sudo apt-get install apt-offline-gui
Milosz Galazka