8

I'm doing a study about how CD-ROM can be mounted virtually and all I could find out was mounting using loop devices.

mount -o loop disk1.iso /mount-point

This is fairly easy.

I understand that /dev/sr0 is a block device and it point to some buffer in kernel and the kernel device driver puts the filesystem (ot whatever it puts i am not sure) in that buffer and when we use mount it mounts the filesystem to the specified mount-point.

But am wondering whether we can mount an ISO of our choice (e.g. disk1.iso) by using SCSI CD-ROM device /dev/sr0 (without changing anything in the kernel) as it is done in Vmware and Virtualbox, where we can specify the ISO and it automatically emulates a CD-ROM hardware and the ISO can be mounted using /dev/sr0 device?

The major problem which i see here is that how /dev/sr0/ will be linked to the iso?

9
  • 1
    How would you tell the OS that /dev/sr0 points to a particular ISO file?
    – Anthon
    Commented Oct 28, 2014 at 10:49
  • @Anthon yes that's what i am wondering how can we link/map the iso to /dev/sr0
    – Tejendra
    Commented Oct 28, 2014 at 10:50
  • That's a bad idea...let udev (or your favorite kernel helper) handle stuff in /dev; however, you could always symlink it...it is *nix after all...everything is a file.
    – SailorCire
    Commented Oct 28, 2014 at 11:03
  • Something that I just thought of...look up the OLD command mknod.
    – SailorCire
    Commented Oct 28, 2014 at 11:05
  • 1
    If you have a requirement that nothing in the kernel can be changed, and that linking /dev/sr0 to /dev/loop0 is not acceptable, then I think the only way to do this is to mount an external USB hardware device that emulates a CD-ROM drive. There are specialized pieces of hardware that can do this, such as KVM switches, as well as iLO modules on some systems that let you mount ISO images over the network, but it could conceivably be done with another computer with local disk storage containing ISO images. Commented Oct 28, 2014 at 14:50

2 Answers 2

5

The thing here is that /dev/sr0 is linked to a kernel device driver. That device driver will allow access to a physical CDROM if available through that node; VMWare and VirtualBox emulate hardware as you mention and hence the kernel and device driver think they're communicating with hardware.

The /dev/sr0 doesn't point to a certain buffer directly, it provides an interface to the block device interface that allows userspace processes to acces the contents of the hardware device.

If you want to make an image available as a block device, then your only choice (besides virtualization and emulating hardware) is to use loop devices with losetup... or to write your own replacement device driver, but I expect that's not a viable option for now.

If you want to make that image available as /dev/sr0 (are we talking about faking out some software that demands access to a CDROM at that location?) then you could move that file to e.g. /dev/sr0.moved and then symlink the appropriate /dev/loopX to /dev/sr0. Of course, if the software in question tries special commands that only apply to CDROM devices, then this won't work. Otherwise it shouldn't be a problem.

7
  • but in symbolic link it will create the target file while in our system /dev/sr0 is already present ?? And ya you are write i want to use eject command which in turn won't work as it will eventually get executed on the linked device
    – Tejendra
    Commented Oct 28, 2014 at 13:50
  • Did you miss the part about moving the device to another name (so that you can move it back afterwards)? You can't use the existing /dev/sr0 for your purposes! You need a loop device. If you insist on having the image available at /dev/sr0 then this is the only way.
    – wurtel
    Commented Oct 28, 2014 at 13:53
  • @Tejendra what do you expect to happen when you run the eject command on a device that isn't actually a disc? What good can it possibly do?
    – user41515
    Commented Oct 28, 2014 at 13:55
  • This thing looks the same as it is just another way anyway we are using loopmount, I think the only possible way out is to use loopmount as linking /dev/sr0 to loop device will just provide a feel of using /dev/sr0 but it doesn't serve the main purpose.
    – Tejendra
    Commented Oct 28, 2014 at 13:56
  • @WumpusQ.Wumbley i actually wanted to eject the cdrom only but didn't know that it will eventually try to eject the main file which is loop device
    – Tejendra
    Commented Oct 28, 2014 at 13:58
2

If you use cdemu instead of the loop mount it will give the desired effect. It emulates a cd-rom device. Where as mounting just gives access to the files. It can also be used for mounting cue/bin files and other image types. This gives the ability to mount images that have more than one track or data/music track combinations.

1
  • i need automount when i mount image on cdemu, for example when i mount an image file with cdemu, i need the /dev/sr0 used by cdemu , mount on /cdrom . for Games with Data/Music works the game need it.
    – inukaze
    Commented Feb 27, 2017 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .