creation of differencing media

Discussion about using the VirtualBox API, Tutorials, Samples.

creation of differencing media

Postby rshaw » 7. Jun 2013, 17:32

I am using iSCSI targets as the format of my IMedium and have a question regarding mounting ISO images at runtime.

The IMediums are pointing to a read only iSCSI target but that presents a problem when the disks do not have differencing mediums (VirtualBox will not allow a IMedium to a read only target with no differencing medium)

In our application, we have a function that allows changing the currently mounted ISO image, both when the guest is powered on, and powered off.

I have set the medium type of this ISO to MediumType.MultiAttach, but VirtualBox only seems to generate a differencing medium when the medium is attached when the guest is poweredoff with IMachine#attachDevice. When I swap the mounted ISO when the machine is powered on with IMachine#mountMedium, I do not get a differencing medium. Any assistance would be appreciated.

Code: Select all   Expand viewCollapse view
if (state.equals(MachineState.PoweredOff) || state.equals(MachineState.Aborted)){
            iMachine.detachDevice(MAIN_CONTROLLER, controllerPort, deviceSlot);
            iMachine.attachDevice(MAIN_CONTROLLER, controllerPort, deviceSlot, DeviceType.DVD, dvd);
            iMachine.saveSettings();
         }else if (state.equals(MachineState.Running)){
            iMachine.mountMedium(MAIN_CONTROLLER, controllerPort, deviceSlot, dvd, false);
            iMachine.saveSettings();
}
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04

Re: creation of differencing media

Postby noteirak » 8. Jun 2013, 09:43

I would rather think that getting a diff image of an ISO is not the intended use, so I find it normal that at runtime, you do not get a diff image. It's just like poping a CD/DVD in your drive. It's read-only.
So I don't think Virtualbox actually checks the Medium type if you attach an ISO. It just sees an ISO and that stops there.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: creation of differencing media

Postby rshaw » 10. Jun 2013, 21:15

Well the problem is that the iscsi target is readonly and VirtualBox does not allow mounting the medium if it does not have a differencing medium. Perhaps this is a bug, or an uninteded feature, but it makes the ability to change ISOs at runtime impossible
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04

Re: creation of differencing media

Postby noteirak » 10. Jun 2013, 22:55

Yes I understand that, but why would you make it MultiAttach?
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: creation of differencing media

Postby rshaw » 11. Jun 2013, 18:41

You cannot make a CD/DVD medium readonly through the API, unless I am doing something incorrectly. I don't see any other way to instantiate an ISO image (no other call exists, except createHardDisk such as below)

Code: Select all   Expand viewCollapse view
iscsi = vbox.createHardDisk(ISCSI_FORMAT, mediumName);
         iscsi.setProperty(MEDIUM_TARGET_NAME, request.getTargetIQN());
         iscsi.setProperty(MEDIUM_TARGET_ADDRESS, request.getTargetIP());
         iscsi.setProperty(MEDIUM_LUN, String.valueOf(request.getLunId()));
         if (request.getMediaType().equals(SCSITargetRequest.CD)){
            iscsi.setType(MediumType.Readonly);
         }else if (request.getMediaType().equals(SCSITargetRequest.HD)){
            iscsi.setType(MediumType.MultiAttach);
         }


The readonly line throws an error:

VBoxManage: error: Cannot change type for medium 'xxx' to 'Readonly' since it is a hard disk
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04

Re: creation of differencing media

Postby rshaw » 11. Jun 2013, 18:59

This also seemingly cannot be done by vboxmanage either, which in my understanding, does most everyhing!

Code: Select all   Expand viewCollapse view
VBoxManage storageattach "NewPasswordWindowsReadOnly2" --storagectl "MyStorageController" --port 1 --device 0 --type dvddrive --medium iscsi --mtype readonly --server localhost --target "iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b" --lun 1 --tport 3260
iSCSI disk created. UUID: b69755c7-3b75-427b-b9f2-4fd8dbab1a83
VBoxManage: error: Cannot change type for medium 'localhost|iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b|1' to 'Readonly' since it is a hard disk
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Medium, interface IMedium, callee nsISupports
VBoxManage: error: Context: "COMSETTER(Type)(mediumType)" at line 678 of file VBoxManageStorageController.cpp
VBoxManage: error: Failed to set the medium type
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04

Re: creation of differencing media

Postby noteirak » 11. Jun 2013, 20:00

Any ISO mounted in a CD/DVD drive in Virtualbox is already read-only! Regardless of where it is stored. But that is implemented via the fact that it's appear in a CD/DVD drive, just like a regular physical PC.
Could you put a real CD/DVD into several players? No, so it only make sense that here you can't either.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: creation of differencing media

Postby rshaw » 11. Jun 2013, 20:37

I believe I was communicating my intentions poorly in my prior posts. I was telling you what I was doing rather than why. The reason I was doing multiattach is because either:

-VirtualBox does not in fact make DVD's readonly when using iscsi
-There is a bug that prevents readonly DVD's from working when using iscsi

In the following code I am creating and mounting a dvd from a readonly iscsi target (note I have ommmited the readonly mtype flag as above, and left vbox to its own thing)

Code: Select all   Expand viewCollapse view

VBoxManage storageattach "NewPasswordWindowsReadOnly2" --storagectl "MyController" --port 1 --device 0 --type dvddrive --medium iscsi --server localhost --target "iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b" --lun 1 --tport 3260




Let's check to make sure it was added correctly:

Code: Select all   Expand viewCollapse view

vboxmanage list hdds

...
UUID:        2d4790e0-678b-4fc0-b529-32aebfec6f97
Parent UUID: base
Format:      iSCSI
Location:    localhost|iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b|1
State:       created
Type:        normal
Usage:       NewPasswordWindowsReadOnly2 (UUID: e86ffe75-2412-4aa6-9b36-3a0c0f3e4780)
...




Notice the "type" is normal, instead of readonly? We'll ignore it for the time being, and try to boot the machine up anyways.

Code: Select all   Expand viewCollapse view

Failed to open a session for the virtual machine NewPasswordWindowsReadOnly2.
VD: error VERR_VD_IMAGE_READ_ONLY opening image file 'localhost|iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b|1' (VERR_VD_IMAGE_READ_ONLY).
Failed to open image 'localhost|iqn.2001-04.com.TehDualLinux-2260f94a-90f3-4147-9e32-39c773f7095b|1' in read-write mode rc=VERR_VD_IMAGE_READ_ONLY (VERR_VD_IMAGE_READ_ONLY).
Failed to attach driver below us! Image is read-only. (VERR_VD_IMAGE_READ_ONLY).
AHCI: Failed to attach drive to Port1 (VERR_VD_IMAGE_READ_ONLY).



-If you remove the readonly flag on the iscsi target everything works perfectly
- If you take a snapshot (thus a differencing medium is created), everything works perfectly
- If you add the DVD as multiattach instead of "normal", it creates a differencing medium, and everything works perfectly.
-You cannot specify to make it readonly with mtype, and supplying nothing defaults it to "normal", which doesn't work.
-According to http://www.virtualbox.org/manual/ch05.h ... magewrites you are correct in that dvd drives should be mounted readonly, but this is obviously not working in practice, at least with iscsi.

This is sounding more a more like a bug, the more we discuss the issue. What are your thoughts? If you need assistance trying to reproduce it I can help, but it's extremely easy. Make a readonly iscsi target and try to use an ISO as a Medium in a dvddrive like I have above.
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04

Re: creation of differencing media

Postby noteirak » 12. Jun 2013, 13:42

You are fully right, except that the readonly flag is not actually set on the ISO, but internally in VB while the VM is running.
Actually, the normal emulated CD/DVD drive is only capable of reading, so it doesn't matter what type the ISO is registered under, it will always be readonly.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: creation of differencing media

Postby rshaw » 30. Sep 2013, 20:36

Just as an FYI to all, I filed this as a bug.

https://www.virtualbox.org/ticket/11857
rshaw
 
Posts: 15
Joined: 11. Feb 2013, 17:04


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 1 guest