Using a Debian ISO instead of a CD-ROM in your sources.list

I recently purchased a home server (Lenovo ThinkServer TS140 with Intel Xeon E3-1225). My goal with this purchase is to learn a little bit more about Linux, play around with Xen a bit, and eventually create a home-base for all my media and files.

I’ve been documenting every single step of the process in my personal wiki, but I want to take select pieces from that and turn them into mini tutorials. This is one of those pieces.

The sources.list file

Linux is designed to be installed from a CD-ROM, which feels so old-school to me. I haven’t owned a CD or DVD player or burner in years — none of my laptops have them, I have no gaming systems, and I stream all my media to an Amazon Fire TV running Kodi. So installing Linux from a CD just felt wrong.

I chose to work with Debian, specifically because that’s one of the Linux flavors we use at work. I downloaded the ISO (or CD image file) from the official website, “burned” it onto a USB stick, and installed.

However, when I tried to use the apt-get command to install some software, specifically lvm2, I got this error:

Media change: please insert the disc labeled
 'Debian GNU/Linux 8.2.0 _Jessie_ - Official i386 CD Binary-1 20150906-10:02'
 in the drive '/media/cdrom/' and press enter

Even though I installed Debian from a USB stick, it was still looking for a CD in the CD drive. I needed some way to tell the system to look somewhere else.

Alternate options

There are two main solutions to this problem:

  1. Tell Debian to look at the USB stick instead of the CD-ROM
  2. Tell Debian to look at a local Debian ISO file instead of the CD-ROM

I chose option number two, mainly because I didn’t want to keep a USB stick plugged into my server. This could be limiting, especially if I’m remotely accessing my server, need to access the Debian install image, and don’t have the USB stick plugged in.

Instead, I chose to download a copy of the ISO image file to my server, and then tell Debian to look at that file instead of a CD-ROM or USB stick. The file will always live on my server, so it’ll be accessible any time.

The Process

Using an ISO image, rather than a CD-ROM, requires a few steps:

  1. Download the ISO file to a specified directory
  2. Create the directory where we want to ISO to mount
  3. Tell our system to mount the ISO file every time we boot the server
  4. Tell Debian to look at our mount point directory instead of a CD-ROM
  5. Mount the image and refresh these changes

We’re going to do all of this from the command line, since I didn’t install any desktop environment.

Let’s get started.

Download the ISO file to a specified directory

The first thing we want to do is create a directory for our ISO file to live. I chose to create a directory called storage inside the /mnt directory.

Within the Linux file directory structure, /mnt is the folder used for temporary mounting, including CD and USB images. Since the Debian ISO file is a CD-ROM image, it makes sense to store it inside the /mnt directory, in a new directory called storage.

Next, I navigated into that new directory (cd command) and ran:

wget http://cdimage.debian.org/debian-cd/8.2.0/i386/iso-cd/debian-8.2.0-i386-CD-1.iso

The wget command downloads a file from the internet, and I got the file’s URL from the official Debian website. It’s the i386 version, as that’s the version needed for my Lenovo server.

Once the download was complete, it was time to move on to the next step.

Create the directory where we want to ISO to mount

Debian can’t just read the ISO file directly. It needs to be mounted, which means it needs a specific directory in which to mount. Let’s create one inside the /mnt directory:

mkdir /mnt/debian-cd

Simple as that.

Tell our system to mount the ISO file every time we boot the server

Now we need to make sure that the ISO file is mounted into the correct directory on boot. We do this by editing the fstab file inside the /etc directory. We’re going to use a command line text editor called Nano to do this (note: you can also use Vim if you want):

nano /etc/fstab

Scroll to the bottom of that file and add the following line:

/mnt/storage/debian-8.2.0-i386-CD-1.iso /mnt/debian-cd/ udf,iso9660 loop 0 0

Note: if you’ve downloaded a different version of Debian, make sure that you’ve replaced “debian-8.2.0-i386-CD-1.iso” with the full name of the file you downloaded.

Save those changes by clicking Ctrl+O, press enter to keep the same file name, then press Ctrl+X to exit Nano.

Tell Debian to look at our mount point directory instead of a CD-ROM

Now, we need to tell Debian to look at this new mount point instead of searching for a nonexistent CD-ROM. We do this by editing the sources.list file inside the /etc/apt directory, which tells Debian where to search for application packages when using the apt-get command.

Again, we’re going to use Nano to open and edit this file:

nano /etc/apt/sources.list

First, we want to comment out the line telling Debian to look for a CD. Add a hash (#) to the beginning of this line:

deb cdrom:[Debian GNU/Linux 8.2.0 _Jessie_ - Official i386 CD Binary-1 20150906-10:02]/ jessie main

The hash comments out that line, which tells the computer not to read it. Next, we’re going to tell Debian exactly where to look instead. Add this line right underneath the line we just commented out:

deb file:/mnt/debian-cd/ jessie main contrib

I’m using the version of Debian called Jessie, which is why you see jessie in the above line. If you’re using a different version of Debian, you’ll need to replace jessie with the version that you’re using.

Press Ctrl+O to save these files, enter to keep the same file name, and Ctrl+X to exit Nano.

Mount the image and refresh these changes

We’re almost done! All that’s left is to mount the ISO file to the directory we created:

mount /mnt/debian-dvd/

Then refresh the changes:

apt-get update

If everything works as it should, you’re now using an ISO file in lieu of a CD-ROM!

3 Comments Using a Debian ISO instead of a CD-ROM in your sources.list

  1. anon

    Hello,
    first you create a directory:
    mkdir /mnt/debian-cd

    then you mount something with a similar name :
    mount /mnt/debian-dvd/

    is this a mistake?

    Reply
  2. IK

    I have an error /mnt/debian-cd can’t find in /etc/fstab maybe entries in fstab are not correct?

    Reply

Share what you think