Centos – Installing yum packages on airgapped (offline) CentOS 6 system

centoscentos6offline-filesrepositoryyum

I have a CentOS 6 system which, for security reasons, is airgapped. It may have never been connected to the internet, and if it has, it hasn't been updated in a long time.

I want to put all the .rpm packages on a drive so that they can be installed offline without querying the internet. However, the issue I am running into on my test VM is that yum keeps hanging and trying to update from an online repository, even though the local path is specified.

Also, is there a way to easily grab a package and all dependencies for that package using yum-utils/yumdownloader? At the moment, it still misses some dependencies (e.g. when I pull the gcc-c++ rpm, it'll grab cpp and gcc but it won't pull cloog-ppl, mpfr or ppl)

I have already tried a solution like this, but I cannot assume there will already be a dependency tree, or that yum will be up to date.

On a fresh install of the docker image, the first time I try to run yum (with internet disabled), I get
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

Best Answer

If you are concerned about compatibility between installed release and latest stable, you may want to determine your centos version in /etc/redhat-release and to use packages from http://vault.centos.org/, however bear in mind that they won't contain any security updates or bug fixes.

To download packages - use official redhat instrucions: https://access.redhat.com/solutions/10154

yum install yum-plugin-downloadonly
yum install --downloadonly --downloaddir=<directory> <package>

or

yum install yum-utils
yumdownloader --resolve

You may also look at replicating yum history on vm where you want to download rpms to with techniques from this answer: https://unix.stackexchange.com/a/83115

The easiest way, and it's worked for a long time is:

yum-debug-dump => gives file.
yum-debug-restore <file-from-debug-dump>

...which works much like the get/set selections dpkg command, AIUI. Also note that if you are replaying history you can use:

yum history addon-info last saved_tx => gives file
yum load-tx <file-from-addon-info>

...instead of having to parse it yourself.

Edit:

To install all rpms from directory, cd to it and simply use rpm -ivh *.rpm if you want to install them, or rpm -Uvh *.rpm if some downloaded files are newer than already present ones, and you are okay with updating them.