1. Introduction

Package managers are tools for finding, downloading, installing, updating, and upgrading packages. Most of these features are fully automated, so the user is free from dependency and compatibility checks, manual maintenance, testing, and similar activities. However, to function correctly, a package manager needs to know where packages can be found, in other words – a repository path.

In this tutorial, we explore ways to set an ISO file as a repository when using apt. First, we go over general source and repository types. After that, we delve into ways that Debian handles the different protocols for repository data acquisition. Finally, we show two ways to set an ISO file as the main source for a given repository definition.

We tested the code in this tutorial on Debian 12 (Bookworm) with GNU Bash 5.2.15. It should work in most POSIX-compliant environments unless otherwise specified.

2. Source and Repository Types

There are two main repository types:

  • online
  • offline

Naturally, offline repositories don’t require a network connection. On the other hand, online doesn’t necessarily mean the Internet.

Let’s see some sample options:

For example, we can use local network HTTP, FTP, NFS, or CIFS (SMB) servers. Of course, we can also specify Internet sources.

Finally, local repository storage can be indicated via a local file syntax.

3. Debian Repositories

Since it’s one of the major Linux distributions, let’s check the default Debian repositories:

$ cat /etc/apt/sources.list
#deb cdrom:[Official Debian GNU/Linux Live 2023-12-22T00:06:56Z]/ bookworm main non-free-firmware

deb http://deb.debian.org/debian stable main
deb-src http://deb.debian.org/debian stable main

deb http://deb.debian.org/debian-security/ stable-security main
deb-src http://deb.debian.org/debian-security/ stable-security main

deb http://deb.debian.org/debian stable-updates main
deb-src http://deb.debian.org/debian stable-updates main

When it comes to apt, we check the /etc/apt/sources.list file for the current repository set. Still, there can also be additional repositories within files in /etc/apt/sources.list.d, but not by default.

Importantly, we can configure the relevant source and repository type via different protocol prefixes and a URI:

  • HTTP(S): http[s]://www.example.com/path/to/repository
  • FTP: ftp://ftp.example.com/path/to/repository
  • SMB: smb://path/to/repository (share should be preconfigured)
  • NFS: file:///path/to/repository (share should be preconfigured)
  • Filesystem: file:///path/to/local/directory

So, we can add a custom repository via any of these protocols.

Importantly, APT has no way or protocol for specifying paths in a filesystem within a file that holds our repository data.

4. ISO File Repository

Unlike devices specified in the CD-ROM repository format, an ISO is just a file, so APT can’t use it directly. However, since ISO files are specialized filesystem containers, we have several ways to employ their contents as repository sources.

4.1. Mount ISO

The first and perhaps most basic way to leverage an ISO file with APT sources is by mounting it.

Specifically, we mount ISO files as loop devices via the relevant –options:

$ mount --types iso9660 aptrepo1.iso /mnt/aptrepo1 --options ro,loop

In this case, we make the contents of aptrepo1.iso available at /mnt/aptrepo1.

After this operation, we can use apt-cdrom to add the respective sources.list entry:

$ apt-cdrom --cdrom=/mnt/aptrepo1 add --no-mount
Using CD-ROM mount point /mnt/aptrepo1/
Identifying... [8608a6660104005c5a720c707ef916c-2]
Scanning disc for index files...
Found 2 package indexes, 0 source indexes, 0 translation indexes and 0 signatures
Found label 'Debian GNU/Linux 12.4.0 _Bookworm_ - Official amd64 NETINST with firmware 20231222-00:06'
This disc is called:
'Debian GNU/Linux 12.4.0 _Bookworm_ - Official amd64 NETINST with firmware 20231222-00:06'
Reading Package Indexes... Done
Writing new source list
Source list entries for this disc are:
deb cdrom:[Debian GNU/Linux 12.4.0 _Bookworm_ - Official amd64 NETINST with firmware 20231222-00:06]/ bookworm main non-free-firmware
Repeat this process for the rest of the CDs in your set.

Here, we provide the mount point via –cdrom and add –no-mount since we already performed the mount.

Alternatively, we can just configure the path as a trusted local filesystem repository for the respective version:

$ cat /etc/apt/sources.list
deb [trusted=yes] file:///mnt/aptrepo1 bookworm main

Either way, we should be ready to use the new repository.

4.2. Extract ISO

Another way to expose the inside of an ISO file is to extract it.

Different applications support ISO extraction, but one of the most prevalent is 7z. If we don’t have 7z on the system, we can install it via the p7zip-full package:

$ apt-get install p7zip-full

Now, we should be able to e[x]tract the ISO file to a given [-o]utput directory at /var/repos/aptrepo1:

$ 7z x aptrepo1.iso -o/var/repos/aptrepo1

After that, we add the respective path as a trusted local filesystem entry in /etc/apt/sources.list:

$ cat /etc/apt/sources.list
deb [trusted=yes] file:///var/repos/aptrepo1 bookworm main

While this isn’t usually necessary when using a mounted ISO file, we might need to change the permissions of the extracted ISO files to allow apt to access them:

$ chown -R _apt:root /var/repos/aptrepo1
$ chmod -R 700 /var/repos/aptrepo1

This way, we ensure the special _apt user owns and has full permissions over our repository path.

At this point, we can perform an update:

$ apt-get update 
Get:1 file:/var/repos/aptrepo1 bookworm InRelease
Ign:1 file:/var/repos/aptrepo1 bookworm InRelease
Get:2 file:/var/repos/aptrepo1 bookworm Release [66.6 kB]
Get:2 file:/var/repos/aptrepo1 bookworm Release [66.6 kB]
Get:3 file:/var/repos/aptrepo1 bookworm Release.gpg
Ign:3 file:/var/repos/aptrepo1 bookworm Release.gpg
Hit:4 http://deb.debian.org/debian stable InRelease
Reading package lists... Done

Notably, there are no issues during the update, so our repository should now be fully functional to install packages.

5. Summary

In this article, we talked about APT repository types and ways to use an ISO file for package repository data.

In conclusion, although apt doesn’t directly support it, we can use the contents of ISO files as repository sources.

Comments are closed on this article!