Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm in the frankly ludicrous situation where my desktop has two optical drives and my media centre has none (nor space for one). Before I consider something as extreme as buying an external optical drive, I would like to see if there's a way of tethering my drives across the network.

Both machines are Ubuntu and they already have NFS sharing in place to access media from the desktop.

The reason I'm asking (rather than just exporting /media/cdrom) is that a mounted NFS share doesn't look like a CDROM-style device to the remote machine. This is significant to me because I need XBMC to recognise the drive as such in order for it to handle the discs automatically and appropriately.

Now I don't know what makes an optical drive look like an optical drive to Ubuntu. If I knew that, I'd probably know what I needed to do. I'm guessing there's some hot udev action in there at some point.

Is there some way of sharing a block-level device (eg /dev/sr0) in so allowing both computers to mount it separately... I feel like I'm tumbling down the rabbit hole and I can see all these massively over-engineered solutions like iSCSI and passthrough virtualisation popping up in front of me... Surely there's a simple way of sharing a few drive modes between two Ubuntu computers!

share|improve this question
    
I do not know if this is sufficient: thegeekstuff.com/2009/02/… --- I do not know if it exports the special ioctl needed for the DVD. I used it years ago for a bad-thought idea of swapping over net, and then forgot till now... (better link: linux-mag.com/id/7118) –  Rmano Mar 12 at 14:28
    
The 2 methods I've used successfully to do similar things are to use NFS and Samba, but given your rep I'm assuming you know about NFS for sure, and possibly doing this via Samba. LMK if you need more help with it. –  slm Mar 12 at 15:10
    
@slm Yeah there's already NFS between the two computers. I added the CD /media/cdrom to nfs and mounted it at the other end as /media/cdrom (and I can see the files) but XBMC isn't detecting a change of media (it doesn't think the mountpoint is a DVD). Am I doing something stupid? –  Oli Mar 12 at 15:56
    
@Oli - OK, see my A and let me know if that's what you're looking for. Incidentally the other method I've used is to make an ISO of the DVD, share that over NFS, and then mount -o loop locally on other computers. –  slm Mar 12 at 16:36
    

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.