VBOX: Only add the guest additions ISO to the VM if the file has actually been detected on the file system.

Some Linux systems separate the VirtualBox packages so that the guest additions ISO is in a separate package.  We were attempting to add a DVD device for a file that did not exist.
This commit is contained in:
Rom Walton 2015-04-02 16:55:57 -04:00
parent 4bd02fef0d
commit f7df3c380a
2 changed files with 74 additions and 56 deletions

View File

@ -605,25 +605,27 @@ int VBOX_VM::create_vm() {
// Add guest additions to the VM
//
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
CComPtr<IMedium> pGuestAdditionsImage;
rc = m_pPrivate->m_pVirtualBox->OpenMedium(
CComBSTR(virtualbox_guest_additions.c_str()),
DeviceType_DVD,
AccessMode_ReadOnly,
FALSE,
&pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
if (virtualbox_guest_additions.size()) {
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
CComPtr<IMedium> pGuestAdditionsImage;
rc = m_pPrivate->m_pVirtualBox->OpenMedium(
CComBSTR(virtualbox_guest_additions.c_str()),
DeviceType_DVD,
AccessMode_ReadOnly,
FALSE,
&pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
rc = pMachine->AttachDevice(
CComBSTR("Hard Disk Controller"),
2,
0,
DeviceType_DVD,
pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
rc = pMachine->AttachDevice(
CComBSTR("Hard Disk Controller"),
2,
0,
DeviceType_DVD,
pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
}
// Add a virtual cache disk drive to VM
//
@ -673,25 +675,27 @@ int VBOX_VM::create_vm() {
// Add guest additions to the VM
//
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
CComPtr<IMedium> pGuestAdditionsImage;
rc = m_pPrivate->m_pVirtualBox->OpenMedium(
CComBSTR(virtualbox_guest_additions.c_str()),
DeviceType_DVD,
AccessMode_ReadOnly,
FALSE,
&pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
if (virtualbox_guest_additions.size()) {
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
CComPtr<IMedium> pGuestAdditionsImage;
rc = m_pPrivate->m_pVirtualBox->OpenMedium(
CComBSTR(virtualbox_guest_additions.c_str()),
DeviceType_DVD,
AccessMode_ReadOnly,
FALSE,
&pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
rc = pMachine->AttachDevice(
CComBSTR("Hard Disk Controller"),
1,
0,
DeviceType_DVD,
pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
rc = pMachine->AttachDevice(
CComBSTR("Hard Disk Controller"),
1,
0,
DeviceType_DVD,
pGuestAdditionsImage
);
if (CHECK_ERROR(rc)) goto CLEANUP;
}
}
// Adding virtual floppy disk drive to VM
@ -1935,7 +1939,7 @@ int VBOX_VM::get_version_information(string& version) {
}
int VBOX_VM::get_guest_additions(string& guest_additions) {
int retval = ERR_EXEC;
int retval = ERR_NOT_FOUND;
HRESULT rc;
CComPtr<ISystemProperties> properties;
CComBSTR tmp;
@ -1945,7 +1949,11 @@ int VBOX_VM::get_guest_additions(string& guest_additions) {
rc = properties->get_DefaultAdditionsISO(&tmp);
if (SUCCEEDED(rc)) {
guest_additions = CW2A(tmp);
retval = BOINC_SUCCESS;
if (!boinc_file_exists(guest_additions.c_str())) {
guest_additions.clear();
} else {
retval = BOINC_SUCCESS;
}
}
}

View File

@ -448,16 +448,18 @@ int VBOX_VM::create_vm() {
// Add guest additions to the VM
//
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
command = "storageattach \"" + vm_name + "\" ";
command += "--storagectl \"Hard Disk Controller\" ";
command += "--port 2 ";
command += "--device 0 ";
command += "--type dvddrive ";
command += "--medium \"" + virtualbox_guest_additions + "\" ";
if (virtualbox_guest_additions.size()) {
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
command = "storageattach \"" + vm_name + "\" ";
command += "--storagectl \"Hard Disk Controller\" ";
command += "--port 2 ";
command += "--device 0 ";
command += "--type dvddrive ";
command += "--medium \"" + virtualbox_guest_additions + "\" ";
retval = vbm_popen(command, output, "storage attach (guest additions image)");
if (retval) return retval;
retval = vbm_popen(command, output, "storage attach (guest additions image)");
if (retval) return retval;
}
// Add a virtual cache disk drive to VM
//
@ -493,16 +495,18 @@ int VBOX_VM::create_vm() {
// Add guest additions to the VM
//
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
command = "storageattach \"" + vm_name + "\" ";
command += "--storagectl \"Hard Disk Controller\" ";
command += "--port 1 ";
command += "--device 0 ";
command += "--type dvddrive ";
command += "--medium \"" + virtualbox_guest_additions + "\" ";
if (virtualbox_guest_additions.size()) {
vboxlog_msg("Adding VirtualBox Guest Additions to VM.");
command = "storageattach \"" + vm_name + "\" ";
command += "--storagectl \"Hard Disk Controller\" ";
command += "--port 1 ";
command += "--device 0 ";
command += "--type dvddrive ";
command += "--medium \"" + virtualbox_guest_additions + "\" ";
retval = vbm_popen(command, output, "storage attach (guest additions image)");
if (retval) return retval;
retval = vbm_popen(command, output, "storage attach (guest additions image)");
if (retval) return retval;
}
}
@ -1514,10 +1518,16 @@ int VBOX_VM::get_guest_additions(string& guest_additions) {
ga_end = output.find("\n", ga_start);
guest_additions = output.substr(ga_start, ga_end - ga_start);
strip_whitespace(guest_additions);
if (guest_additions.size() <= 0) {
return ERR_NOT_FOUND;
}
if (!boinc_file_exists(guest_additions.c_str())) {
guest_additions.clear();
return ERR_NOT_FOUND;
}
return retval;
}