PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

How to use an ISO file as offline repository in Debian

Updated - May 14, 2020 by Arnab Satapathi

No internet connection ? still you can install packages on Debian or Ubuntu from the installer CD/DVD ISO file. This trick is very useful in case of downgrading a package, which is no longer available, also saves a lot of valuable data.

Debian installer CD/DVD ISO files suits the best for this purpose, as Debian live CD contains much less packages. Ubuntu, Linux Mint installer ISO files could be used in exactly same way, but they also have few packages.

KNOW THE RISK

If you are not an expert, do not try to mix up different Debian or Ubuntu version ISOs,  i.e. install packages from Debian testing ISO on a Debian stable system. This could render your system beyond repair very easily.

So, lest do it ..

Contents

    • 1. Create the folders (mountpoint) to mount the ISO files
    • 2. mount the ISO files
    • 3. edit the /etc/apt/sources.list file to add the repository
    • 4. now run sudo apt-get update
  • The Debian offline repository script
  • Conclusion

1. Create the folders (mountpoint) to mount the ISO files

sudo mkdir -p /media/repo_1
sudo mkdir -p /media/repo_2
sudo mkdir -p /media/repo_3

2. mount the ISO files

Assuming you have all the three Debian 8.0.0 installer DVD ISO files on your ~/Downloads folder, mount them one by one.

sudo mount -o loop /home/$USER/Downloads/debian-8.0.0-amd64-DVD-1.iso /media/repo_1/

sudo mount -o loop /home/$USER/Downloads/debian-8.0.0-amd64-DVD-2.iso /media/repo_2/

sudo mount -o loop /home/$USER/Downloads/debian-8.0.0-amd64-DVD-3.iso /media/repo_3/

replace $USER with your user name, or change the path of ISO files to where you Downloaded them .

3. edit the /etc/apt/sources.list file to add the repository

edit the /etc/apt/sources.list file with text editor of your choice, like gedit or nano and add those lines bellow.

deb file:///media/repo_1/  jessie main contrib

deb file:///media/repo_2/  jessie main contrib

deb file:///media/repo_3/  jessie main contrib

4. now run sudo apt-get update

Done, now you can install packages from this offline repository by running

sudo apt-get install your_package_name     # example

Wrapping up everything in a simple shell script

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.

To avoid repeated typing , save the script bellow as mount_ISO_repo , change the path of ISO files and run it when needed like this

sudo ./mount_ISO_repo mount        # to mount the repo

sudo ./mount_ISO_repo umount       # to un mount the repo

The Debian offline repository script

#!/bin/bash

# Debian offline repository mounting or unmounting script.
# By:~ www.pcsuggest.com

# check for root access
if [ $(id -u) -ne 0 ];then
echo 'run this scripts as root user or use sudo'
exit 1
fi

# create mount points

mkdir -p /media/repo_1
mkdir -p /media/repo_2
mkdir -p /media/repo_3

# mount or unmount

case "$1" in
mount)

# mount Debian DVD ISO images
# must change the path of ISO files according to yours

if  $(mountpoint -q /media/repo_1);then
echo 'ISO file already mounted'
else
echo 'mounting ISO file 1'
mount -o loop /home/$USER/debian-8.0.0-amd64-DVD-1.iso /media/repo_1/
fi

if  $(mountpoint -q /media/repo_2);then
echo 'ISO file already mounted'
else
echo 'mounting ISO file 2'
mount -o loop /home/$USER/debian-8.0.0-amd64-DVD-2.iso /media/repo_2/
fi

if  $(mountpoint -q /media/repo_3);then
echo 'ISO file already mounted'
else
echo 'mounting ISO file 3'
mount -o loop /home/$USER/debian-8.0.0-amd64-DVD-3.iso /media/repo_3/
fi
;;

umount)

# unmount ISO images

if ! $(mountpoint  -q /media/repo_1/);then
echo 'repo 1 not mounted'
else umount /media/repo_1
fi

if ! $(mountpoint  -q /media/repo_2/);then
echo 'repo 2 not mounted'
else umount /media/repo_2
fi

if ! $(mountpoint  -q /media/repo_3/);then
echo 'repo 3 not mounted'
else umount /media/repo_3
fi
;;

*)
echo 'use sudo mount_CD_repo mount/umount to mount or unmount ISO files'
;;

esac

Conclusion

Do you have any question ? just drop a comment, we’d be happy to assist you.
Feel free to share this tutorial with your friends.

Filed Under: featured, how to Tagged With: apt, dpkg, offline install

Your comments
  1. mrnobody says

    March 24, 2019

    it dont works
    i tried but no package can be download by code:apt-get install

    Reply
  2. Pepe says

    December 20, 2018

    NO FUNCIONA LA HUEÁ SHUSHETUMARE

    Reply
  3. edemko says

    November 19, 2018

    hi
    thank you much
    https://drive.google.com/open?id=17-gdkUg4MVT6BGpadysMOYAqEjCNe3PM

    Reply
  4. genetix says

    October 21, 2018

    beautiful work

    Reply
  5. user says

    January 3, 2018

    works very well, much appreciated.

    Reply
  6. Yosef Peretz says

    July 7, 2017

    me again , did some search and this solved the issue :

    deb [trusted=yes] file:///media/repo_1/ stretch main contrib

    Thanks

    Reply
    • Arnab Satapathi says

      July 7, 2017

      Thanks buddy, it's really helpfull, I'll include your suggestion on the article.

      Reply
    • torino says

      October 17, 2019

      Thank you

      I've had some problems with gpg keys ,
      I guess this will solve it.

      Reply
  7. Yosef Peretz says

    July 7, 2017

    it doestnt work aptget ended with "the repository is not signed" error

    Reply
  8. Anon says

    June 12, 2017

    Hi, thank you for the nice tutorial.
    You are really helping me a lot 😉

    How can we include ISOs with different architecture in Debian using this trick?

    There are amd64 packages like Wine for example, which relies on i386 packages, after i added "dpkg --add-architecture i386" command and i did the same method as above for the i386 isos, but apt-get update and upgrade doesn't show success.

    Can you help me figure this out?

    Reply
    • Arnab Satapathi says

      June 13, 2017

      That's a really interesting attemp to use ISO files as repo.
      Though I've never done that before, but I can say few words about this issue.

      First, you should'nt have other http repo enabled on your /etc/apt/sources.list file.

      Then modify the 32 bit repo enries a bit like below,
      deb [arch=i386] file:///media/repo_1/ jessie main contrib

      Then update and try again to install wine.

      Reply
  9. CN says

    June 1, 2017

    hi,
    Thank for the guide on setting up offline repository using ISOs files but i got error on finding the packages for KVM like qemu-kvm, libvirt-bin and virt-manager.
    Please help.

    Reply
    • Arnab Satapathi says

      June 1, 2017

      I don't have any debian ISO now to test exactly whats wrong.
      Perhaps these packages are not in the ISO file.

      Reply
  10. Aybars says

    March 24, 2017

    Hello,
    After all, typing the "sudo apt-get update" command and Terminal window gives the following error:

    W: Failed to fetch file:/media/repo_1/dists/jessie/contrib/binary-amd64/Packages File not found
    W: Failed to fetch file:/media/repo_2/dists/jessie/contrib/binary-amd64/Packages File not found
    W: Failed to fetch file:/media/repo_3/dists/jessie/contrib/binary-amd64/Packages File not found

    E: Some index files failed to download. They have been ignored, or old ones used instead.

    I've installed Debian 8.7.1 by using netinst. (debian-8.7.1-amd64-netinst.iso)
    Now I am trying to update/install other packages in the .iso files: "debian-8.7.1-amd64-CD-1.iso" up to ...CD-8.iso

    Regards

    Reply
    • Arnab Satapathi says

      March 24, 2017

      Are you sure there's no error in your apt sources path ? I mean in the /media/repo_3/dists/jessie/contrib/ line ? any spelling mistake will make the whole thing unusable.
      Also use file:/// instead of file:/ , that may cause problems.

      Reply
  11. Hadi says

    November 6, 2016

    It works very well. Just, there is a typo in mount section (you duplicated /media/repo_2. The last one should be /media/repo_3).
    Thanks.

    Reply
    • Arnab says

      November 7, 2016

      Thanks man for pointing that out ! Fixed it.

      Reply
  12. Chittatosh Pal says

    August 30, 2015

    Enormous Topic !

    Reply
    • Arnab says

      August 30, 2015

      If you have any further question, don't hesitate to leave comments here.

      Reply
  13. Koushik says

    July 14, 2015

    Wonderful !

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap