Sharing a CDROM over the network with Ubuntu 14.04

My home network server: mother

My home network server: mother

It’s been a couple of years since any of my computers at home had an internal CDROM (or optical drive, or DVD reader/writer, or what you want to call it – I’m old so I allow myself to keep calling it a CDROM). I’ve used an external USB-connected CDROM instead, but when I recently built my new home network server, “mother”, I decided to fit it with an internal CDROM that I could share to the other computers on the network.

Yesterday, I finally got around to setting up the share, and that turned out to be a bit trickier than I had anticipated. Not that it’s difficult once you learn how to do it, but the help that I found on the Internet wasn’t really much help at all to me. At least it gave me enough clues to keep searching, and eventually I got it to work. So I thought that I should share what I learned.

The basics

There are different ways to share a CDROM from Linux. You can for example use NFS or SMB to share the file contents of an inserted disk, but we will use NBD (Network Block Device) to share the CDROM device itself.

To be able to use NBD, we will install the NBD server package (nbd-server) on the computer exporting the physical CDROM, and the NBD client package (nbd-client) on any computer that wants to access the remote CDROM.

The device name of my physical CDROM is /dev/cdrom. I suppose there is a chance that yours is something else, so you might want to check that (and adjust the instructions below accordingly).

About access rights to the CDROM; If you look at the device file /dev/cdrom, you will see that everyone has read and write access to it. But if you look closer, you’ll see that this is just a link to the actual CDROM device file (/dev/sr0 in my case), which has a much stricter access list. More specifically, only the root user and the cdrom group can even read it. This is why we change the group parameter for the NBD server to cdrom, and let the nbd user join the cdrom group (see the next section).

On the computer with the physical CDROM

First we need to install the NBD server package:

sudo apt-get install nbd-server

You will get a warning about that the NBD server is quitting since there are no configured exports. Don’t worry about it – we’ll fix that soon.

The NBD server will by default run as the user nbd which was created automatically when you installed the package above. However, nbd does not currently have access to the CDROM device – only the root user and the cdrom user group have that. We don’t want to change the access list for the CDROM, and we don’t want the NBD server to run as root. Instead we will let nbd join the cdrom group. Use the adduser utility to do that:

sudo adduser nbd cdrom

Now it’s time to configure the NBD server. Open the file /etc/nbd-server/config for editing

sudo nano -Bw /etc/nbd-server/config

There are a couple of things we want to do in this configuration file:

  1. Export the CDROM by adding an export section for it. I want the name of the exported CDROM to be cdrom, so the export section tag will be [cdrom]. The only parameters we’ll set here are exportname (the device name of the CDROM, which is /dev/cdrom on my system), and readonly which we will set to true to avoid warnings (I don’t expect to use the CDROM to write anything, but if you do you should skip this parameter or set it to false).
  2. Above we joined the nbd user to the cdrom group. This allows nbd to use that group’s privileges, but the NBD server will not do that unless we explicitly tell it to. So we will set the group parameter in the [generic] section to the value cdrom.
  3. Optional: If you want to be able to get a list of the exported devices from a client, you need to tell the server to allow that. If so, add a line where you set the allowlist parameter to true.

So – add the following lines (assuming the device name for your CDROM is /dev/cdrom) at the bottom of the file:

Then find (in the [generic] section at the top of the file) the line for the group parameter, and change its value to cdrom. Also, if you want to allow clients to list the available exports from this NBD server, add a line here (it may already exist) setting the allowlist option to true:

Now we’re done fiddling around with the settings, so save the file and then start (or re-start as the case may be) the NBD server:

sudo /etc/init.d/nbd-server restart 

On computers using the exported CDROM

Install the NBD client package:

During the installation, you will be asked what to do when the NBD client is told to stop. Answer “Yes” to the question “Disconnect all NBD devices on stop?” (unless you know what you are doing and are not satisfied with that selection).

Now that the client is installed, we can run an instance of it to import the CDROM device that we just exported from the server. The command below will do that; The first argument (mother in this case) is the hostname (or IP address) of the computer that exports the device. The -name option states that we want to import the device called cdrom, which is the name that we gave the exported CDROM in the previous section. The final argument (/dev/nbd0) is the local NBD device file that we want to use to connect the remote device:

Hopefully, you didn’t get any error messages, and then you can test that the NBD device is mounted:

The response you want to see from the command above is a single number, which will be the PID (Process ID) of the process that connected the device (you have no use for it, just be happy if you see it). If you don’t get any response at all, run this command directly after the one above ($? holds the status code for the previously executed command):

The value should be “0” if all want well, and otherwise “1” (meaning that the device you queried about is not connected or does not exist) or “2” (meaning that an error occurred). If you believe that you performed the steps above correctly and it still didn’t work, go to the server and use the dmsg command to look at the syslog and check for any error messages or warnings related to NBD.

So, now you have a local CDROM (sort of) with the device name /dev/nbd0 (or whichever one of the NBD device file names you used). In the same way as if it was an actual local CDROM, you must now mount it in order to use it. Unless you have already done so, you must first create an empty mount point directory (I chose to mount the CDROM as /mnt/cdrom):

The -t iso9660 option to the mount command tells mount that this is a CDROM. The -r option tells mount to mount the device as read-only.

That’s it. Now you can, for example, list the contents of the disk in the CDROM with:

Don’t forget to dismount the CDROM when you don’t need it anymore, and by then you should also disconnect the remote CDROM device:

Edit: I had missed the -t iso9660 option when mounting the CDROM above. Added it 2014-10-10.


Comments

Sharing a CDROM over the network with Ubuntu 14.04 — 3 Comments

  1. Hey Bosse, great write up. Like you, I’ve spent way too much time trying to get this to work in my environment, but your post is a huge push in the right direction.
    The one thing that I’m still struggling to work out is how to access this new NDB from a Win7 machine; did you try this, and have you had any success?
    Thanks, and best regards,
    a.

    • Thanks, Andrew. I use Win7 and Win8 (dual-boot with Ubuntu) on two of my computers, so I too would very much like to get this to work on Windows. I started looking into it yesterday, and was surprised to find that there doesn’t seem to be any NBD clients for Windows at all (there are servers, but not clients).

      I had more pressing issues to attend to so I didn’t spend much time on the search, but it doesn’t look good :( I haven’t given up yet though, and I’ll post here if I find a solution that works.

      How close did you get? Any hints on where to look?

      /Bosse

      • Hello Bosse, I’m afraid to say that I gave up on NBDs for sharing resources across my environment as the Windows element was essential. However, I did come across iscsi as an alternative. I burned up two full days trying to get iscsi-target to work, only to find out – by chance – that it doesn’t actually work. So I tried a completely clean 14.04 server installation, and targetcli. This worked, and I can see my server’s DVD drive from my Windows 7 laptop. Huzzar!
        Here are the references that I used:
        http://www.wmaus.net/?p=1387
        http://linux-iscsi.org/wiki/Targetcli
        http://www.youtube.com/watch?v=BkBGTBadOO8 (parts 1 & 2, I didn’t need part 3)
        https://wiki.archlinux.org/index.php/ISCSI_Target
        and
        http://www.linuxclustering.net/2012/11/08/step-by-step-how-to-set-up-a-low-cost-san-with-the-linux-software-iscsi-target/
        For this little gem: “Now, you’ll just need to register the iSCSI initiators (client systems). To do this, you’ll need to find the initiator names of the systems. For Linux, this will usually be in /etc/iscsi/initiatorname.iscsi. For Windows, the initiator name is found in the iSCSI Initiator Properties Panel in the Configuration Tab.
        /iscsi/iqn.20…a1/tpgt1/acls> create iqn.1994-05.com.redhat:f5b312caf756 (register initiator — this IQN is the IQN of the initiator — do this for each initiator that will access the target)
        Successfully created Node ACL for iqn.1994-05.com.redhat:f5b312caf756
        Created mapped LUN 0.”
        I’ve no need to share out diskspace at the moment, but I’d use targetcli again if I did.
        Good-luck, and I hope that this helps,
        a.

Add Comment Register



Leave a Reply to Bosse Cancel reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">