4

I have a Windows 10 VM running headless in VirtualBox on FreeBSD 11.1. It runs without issues. I'd like to enable the VM to access physical CDs/DVDs so that I can insert real discs and open them in the VM.

When I do

VBoxManage storageattach MyVM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium host:/dev/cd0

the VM no longer starts.

$ VBoxManage startvm MyVM
--type headless Waiting for VM "MyVM" to power on...
VBoxManage: error: The VM session was aborted
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface ISession

I ensured that /etc/devfs.conf contains

perm cd* 0660
perm xpt0 0660
perm pass* 0660

and my user is in the operator group. Furthermore, the VirtualBox log contains no obvious errors or warnings. The VM just aborts without any useful diagnostic information. Removing the CD device restores the VM to functionality.

Any ideas?

Update: it looks like VBoxHeadless is shutting down due to a segmentation fault. The cause is still unclear to me. From /var/log/messages:

May 5 12:05:31 the_computer kernel: vboxdrv: XXXXXXXXXXXXXXXX VMMR0.r0
May 5 12:05:31 the_computer kernel: vboxdrv: XXXXXXXXXXXXXXXX VBoxDDR0.r0
May 5 12:05:31 the_computer kernel: pid 61621 (VBoxHeadless), uid 1001: exited on signal 11

Update 2: The point where VBoxHeadless aborts is where the VM initializes ATA devices. Without the CD device, I see the following in the log:

...
00:00:01.280311 VD#0: Cancelling all active requests
00:00:01.280468 PIIX3 ATA: LUN#0: no unit
...

but when I add it back in, I get

...
00:00:00.273730 VD#0: Cancelling all active requests
[end of file]
0
2
+150

Things to try:

According to the FreeBSD Handbook §21.6.3: VirtualBox™ Host DVD/CD Access

HAL needs to run for VirtualBox™ DVD/CD functions to work

Thus you need to…

enable it in /etc/rc.conf and start it if it is not already running

This is done by adding hald_enable="YES" to your/etc/rc.conf file and then executing

# service hald start

This is in addition to the requirement for the user needing access to /dev/xpt0, /dev/cdN, and /dev/passN, which according to the same section of the handbook is "usually achieved by making the user a member of operator", and correcting the device's permissions "by adding these lines to /etc/devfs.conf"

perm cd* 0660
perm xpt0 0660
perm pass* 0660

and (so that the system will make use of these changes) restarting the devfs service

# service devfs restart

If after all of this your VM still won't start while connected to your host CD/DVD drive, consider following this advice (taken from the same page as above):

If needed, create an empty IDE CD/DVD device first. Then choose the Host Drive from the popup menu for the virtual CD/DVD drive selection.

If you can't use the mentioned 'popup menu', I think (from reading the documentation) that the following should be the command-line equivalent:

  1. With the VM powered off: Attach an empty, virtual IDE CD/DVD device

    VBoxManage storageattach MyVM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
    
  2. Boot up your VM:

    VBoxManage startvm MyVM
    
  3. While the VM is still running: Switch to using the host drive

    VBoxManage storageattach MyVM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium host:/dev/cd0
    

Unfortunately, it still may not work:

It appears that there may be a bug in VirtualBox that's preventing this from working on your system. I suggest that the issue be reported to the VirtualBox developers on the project's Bugtracker.

Workaround:

Until this issue is fixed, I recommend working around the issue by making an ISO file from your physical disc(s) for use with VirtualBox. (Some people may prefer this anyway.)

  1. Read the block and volume size of the disc so that you can make a perfect ISO
    (this step isn't really necessary, but an ISO made without it will have a different checksum than the original ISO file used to make the CD because of "A pair of zero data blocks at the end", plus the volume size can be useful later)
    isoinfo -d -i /dev/cd0 | grep -i -E 'block size|volume size'

    You'll get output similar to this:

    Logical block size is: 2048
    Volume size is: 327867
    
  2. Use dd to copy the contents of the disc

    • dd if=/dev/cd0 of=<cd name>.iso bs=<block size from step 1> count=<volume size from step 1>
      For instance, I'll make an ISO called "MyVirtualCD.iso" from the example disc above:
      dd if=/dev/cd0 of=MyVirtualCD.iso bs=2048 count=327867
    • If you skipped step 1, just leave off bs and count, like so:
      dd if=/dev/cd0 of=MyVirtualCD.iso
      Your ISO will still work just fine, it'll just have some unnecessary "zero data blocks" at the end.
    • If you're using a new version of dd it may support showing it's status by adding status=progress to the above command line
    • If you're using an older version of dd, or want a nicer looking progress indicator, you can install pv via "The Ports Collection" or "FreshPorts", and pipe the dd output through pv to see statistics, and since we know the volume size from step 1, an accurate progress bar:
      dd if=/dev/cd0 | pv -s <volume size from step 1> | dd of=<cd name>.iso

      In our example, this would be as follows:
      dd if=/dev/cd0 of=MyVirtualCD.iso | pv -s 327867 | dd of=MyVirtualCD.iso

  3. Now you can attach the ISO to the VM and boot it:

    • VBoxManage storageattach MyVM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium /path/to/MyVirtualCD.iso
    • VBoxManage startvm MyVM
    • Also if you boot your VM with it set to use the emptydrive medium mentioned earlier, the empty virtual CD drive will be available for you to use the same storageattach command while the VM is running to swap in one of your virtual CDs whenever you like.

Sources:
FreeBSD Handbook, VBoxManage docs, Thomas-Krenn Wiki, Ask Ubuntu answer by "phoibos"

4
  • hald is already running on my machine, with exactly the same /etc/devfs you have. Good thinking, though! – Dan Barowy May 16 '18 at 0:28
  • Unfortunately, this answer did not help (I suspect a VBox bug), but it seems complete enough that hopefully it helps someone else. – Dan Barowy May 21 '18 at 17:16
  • I've edited my answer to show info on how to make ISO files from your CDs as a workaround for this issue. Since it seems to be a bug in VirtualBox, I urge you to report it via their Bugtracker. If you do, please post a link to the bug in a comment here, and I'll edit it into my answer. – 3D1T0R May 21 '18 at 20:10
  • @DanBarowy: Did you submit a bug report? – 3D1T0R May 24 '18 at 5:15
2

I think that your error is that you should define the storage as IDE Controller rather than SATA Controller.

The command should rather look like:

VBoxManage storageattach MyVM --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium host:/dev/cd0

In case of a problem, try this :

   $ VBoxManage storagectl MyVM --name "IDE Controller" --remove 
   $ VBoxManage storagectl MyVM --name "IDE Controller" --add ide
   $ VBoxManage storageattach MyVM --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium host:/dev/cd0
2
  • Good suggestion but unfortunately that produces the same error. The log now shows two PIIX3 entries instead of one (for LUN#0 and LUN#1). – Dan Barowy May 16 '18 at 0:27
  • This should have worked. Something is wrong with your VM. I suggest copying it to a computer with GUI and looking into the definition. If necessary, reconstruct it based on the hard disk. – harrymc May 16 '18 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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