How can I share an optical drive in a way that fools the client into thinking it's a local drive?

I think you might be able to accomplish what you want using network block devices (NBD). Looking at the wikipedia page on the subject there is mention of a tool called nbd. It's comprised of a client and server component.

Example

In this scenario I'm setting up a CDROM on my Fedora 19 laptop (server) and I'm sharing it out to an Ubuntu 12.10 system (client).

installing
$ apt-cache search ^nbd-
nbd-client - Network Block Device protocol - client
nbd-server - Network Block Device protocol - server

$ sudo apt-get install nbd-server nbd-client
sharing a CD

Now back on the server (Fedodra 19) I do a similar thing using its package manager YUM. Once complete I pop a CD in and run this command to share it out as a block device:

$ sudo nbd-server 2000 /dev/sr0

** (process:29516): WARNING **: Specifying an export on the command line is deprecated.

** (process:29516): WARNING **: Please use a configuration file instead.
$

A quick check to see if it's running:

$ ps -eaf | grep nbd
root     29517     1  0 12:02 ?        00:00:00 nbd-server 2000 /dev/sr0
root     29519 29071  0 12:02 pts/6    00:00:00 grep --color=auto nbd
Mounting the CD

Now back on the Ubuntu client we need to connect to the nbd-server using nbd-client like so:

$ sudo nbd-client greeneggs 2000 /dev/nbd0
Negotiation: ..size = 643MB
bs=1024, sz=674983936 bytes

We can confirm that there's now a block device on the Ubuntu system using lsblk:

$ sudo lsblk -l
NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 465.8G  0 disk 
sda1                   8:1    0   243M  0 part /boot
sda2                   8:2    0     1K  0 part 
sda5                   8:5    0 465.5G  0 part 
ubuntu-root (dm-0)   252:0    0 461.7G  0 lvm  /
ubuntu-swap_1 (dm-1) 252:1    0   3.8G  0 lvm  [SWAP]
sr0                   11:0    1 654.8M  0 rom  
nbd0                  43:0    0   643M  1 disk 
nbd0p1                43:1    0   643M  1 part 

And now we mount it:

$ sudo mount /dev/nbd0p1 /mnt/
mount: block device /dev/nbd0p1 is write-protected, mounting read-only
$
did it work?

The suspense is killing me, and we have liftoff:

$ sudo ls /mnt/
EFI  GPL  isolinux  LiveOS

There's the contents of a LiveCD of CentOS that I mounted in the Fedora 19 laptop and was able to mount it as a block device of the network on Ubuntu.

Autoplaying & Automounting?

In the above setup I had to manually mount the DVD.

In investigating the plausibility of whether this approach would work with autoplaying and automounting, out of the box, Ubuntu's autoplay doesn't work but the nbd-client and nbd-server stayed up when I ejected the disk. When I put the DVD back in I was able to run the mount command on Ubuntu, which remounted the DVD just fine.

So I would assume you could stick a UDEV rule in on Ubuntu to detect this change and do the automount/autoplay automatically. I'm not gonna try it all out but I don't see anything that would lead me to think that it won't work.


This method also uses NBD but uses the new style configuration instead. The only advantages are that you don't have to start the server manually and you don't get an ugly deprecation warning.

After installing the nbd-server and nbd-client packages proceed to edit the configuration file on the server (/etc/nbd-server/config) and make sure it looks something like this:

[generic]
# If you want to run everything as root rather than the nbd user, you
# may either say "root" in the two following lines, or remove them
# altogether. Do not remove the [generic] section, however.
    user = nbd
    group = cdrom
    includedir = /etc/nbd-server/conf.d
    allowlist = true

# What follows are export definitions. You may create as much of them as
# you want, but the section header has to be unique.

[dvd]
    exportname = /dev/sr0
    readonly = true

Note: The [dvd] label above is a section header and it can be any word you want enclosed in square brackets. It's used to identify that particular share so make sure you use a name that is easy to use and obvious.

After saving the changes to the configuration file, either start or restart the nbd-server (example of restarting):

sudo service nbd-server restart

Then, back on the client machine connect to the server using the command:

sudo nbd-client -N dvd hostname /dev/nbd0

Note: Replace dvd with the name you used in the server configuration above, and hostname with the host name of the server machine.

Finally it's just a matter of mounting the new shared block device:

sudo mount /dev/nbd0 /mnt/