Moving a drive between VMs
Moving a drive between VMs
Is there an operation in the API that can be used to move a drive between different virtual machines? In particular it is critical that when a machine is destroyed the drive persists.
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Moving a drive between VMs
You do not specify the VirtualBox API you are using nor the language you want to use as asked in the API Posting Guidelines, so I will assume API 5.0, Java and Web Services.
About moving a drive from one VM to another, here is a sample code to show how to do it.
This does not move the file itself from one directory to another! This only change the VM configurations so the old VM is not using it anymore and the new VM is.
Also, beware of snapshot. This will not just work if you are using them. The example is out of scope for that.
If you need the actual file to move, you need to use regular file system operations.
You can get the path of the disk file using IMedium::getLocation() and then you can move it into the destination VM directory which you can get using IMachine::getSettingsFilePath() and resolving the directory containing it.
About moving a drive from one VM to another, here is a sample code to show how to do it.
This does not move the file itself from one directory to another! This only change the VM configurations so the old VM is not using it anymore and the new VM is.
Also, beware of snapshot. This will not just work if you are using them. The example is out of scope for that.
If you need the actual file to move, you need to use regular file system operations.
You can get the path of the disk file using IMedium::getLocation() and then you can move it into the destination VM directory which you can get using IMachine::getSettingsFilePath() and resolving the directory containing it.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!