Page 1 of 1
CreateHD file path same as VM - How?
Posted: 1. Jul 2013, 18:31
by steelej
I want to create a new vm from Vboxmanage. That part is easy. It creates the xml file in a folder of the same name
I not want to create the vdi image file in the same folder as the xml file in the same way as it would if I used the GUI to create the VM.
I have not been able to find a way of doing this. I am using a script (on Windows at the moment) to create the VM. I need to be able to create the appropriate file path for the vdi file.
How can I do this please
Re: CreateHD file path same as VM - How?
Posted: 2. Jul 2013, 11:30
by mpack
There is no way to do that, as far as I know. The VirtualBox VM has a certain folder structure, and consists of a certain set of files. I also can't think of a good reason to deviate from that structure. Note that while the VDI is always inside the VM folder, the VM folder need not be placed in default location - you can override the default machine folder using either the GUI or "VBoxManage setproperty machinefolder".
Re: CreateHD file path same as VM - How?
Posted: 2. Jul 2013, 14:50
by steelej
To be more specific.
If I create a VM using the GUI I define a VM machine name. When I create a virtual disc it defaults to use the same name as the VM name and is stored in the same folder as the *.vbox file.
I am using Windows batch file and using environment variables to set the relevant parameters e.g. %VM% is set to the new VM name, %vmexe% is set to the full path to the vboxmanage executable
When I create the VM using the Windows batch file I can set the name for the VM with the command below. It creates the folder %VM% and the %VDI%.vbox file within the folder
Code: Select all
%vmexe% createvm --name "%VM%" --ostype WindowsXP --register
When I create the HD with the following command however it is created in the root of the current path (e.g. the folder wher the batch file is run from)
Code: Select all
%vmexe% createhd --filename "%VM%.vdi" --size 476940 --format VDI
I want the file to be in the same folder as the %VM%.vbox file in exeactly the same way as it would be if I used the GUI. To do this I seem to require the full path to the folder containing the %VM%.vbox file. I thought this would be easy but I have failed to find a way to do it. Everythin else works - this is the final hurdle.
Please note that I have changed the default loction on one of my computers to locate my VMs on a separate partition. I would like the batch file to be generic and to be able to find the configured path to the VMs or to the created VM so that I can automate this process.
Re: CreateHD file path same as VM - How?
Posted: 2. Jul 2013, 15:58
by ChipMcK
is %VM% fully qualified?
Re: CreateHD file path same as VM - How?
Posted: 2. Jul 2013, 16:06
by mpack
Oh, I see. See
this part of the user manual for what is IMHO a pretty good example of what you are trying to do. Basically you create and register the VM in one step, create and add the VDI in a second step, assigning the VDI to the VM. The VDI filename should be unqualified so that VBox decides where it will go (which is inside the VM folder).
Beware: I've just noticed that the "VBoxManage createvm" part of the user manual is badly out of date. Since v4.x the settings file will have a ".vbox" extension, and it will be created (by default) in your <userdoc>\"VirtualBox VMs" folder.
Re: CreateHD file path same as VM - How?
Posted: 2. Jul 2013, 23:35
by steelej
I changed the batch file as suggested. This time I have copied in the full echoed command session. I used a SATA controller rather than an IDE controller but I have also tried it with an IDE controller with an identical result.
My default VM folder is on the V drive. The VM image is created in the folder containing the batch file. See the directory listing at the end of the code section
Code: Select all
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>set /P VM= "Enter virtual machine name: "
Enter virtual machine name: XP Clone
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>set vmexe="C:\Program Files\Oracle\VirtualBox\VBoxManage"
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>set vmbios="VBoxInternal/Devices/pcbios/0/Config"
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>set vmdisk="VBoxInternal/Devices/ahci/0/Config/Port0"
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>set VBOX_MachinePath=V:\Vbox Machines
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>prompt=$G
>echo "XP Clone.vdi"
"XP Clone.vdi"
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" createvm --name "XP Clone" --os type WindowsXP --register
Virtual machine 'XP Clone' is created and registered.
UUID: b81efa57-4cf0-4185-a718-d51e86b2ff1c
Settings file: 'V:\Vbox Machines\XP Clone\XP Clone.vbox'
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --memory 10 24
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --vram 26
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --accelerate3d on
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --accelerate2dvideo on
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --acpi on --ioapic on
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --nic1 bridged --bridgeadapter1 eth0
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --audio dsound
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --audiocontroller ac97
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyvm "XP Clone" --usb on -- usbehci on
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" createhd --filename "XP Clone.vdi" --size 476940 --format VDI
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: 630a7a5e-f8b1-4993-a1d5-f5ea43471f14
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" storagectl "XP Clone" --name "SATA Controller" --add sata --controller IntelAHCI
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" storageattach "XP Clone" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "XP Clone.vdi"
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" storagectl "XP Clone" --name "IDE Controller" --add ide
>IF NOT 0 == 0 GOTO END
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" storageattach "XP Clone" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium emptydrive
>IF NOT 0 == 0 GOTO END
-------
Directory of U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script
02/07/2013 21:51 <DIR> .
02/07/2013 21:51 <DIR> ..
02/07/2013 21:50 6,473 WinScript.bat
02/07/2013 21:51 1,912,832 XP Clone.vdi
2 File(s) 1,919,305 bytes
2 Dir(s) 366,222,180,352 bytes free
U:\Users\John.soro-lap06\Documents\Spaces\WorkShare\Computer Migration\Dell Convert\script>
The Windows batch file is automatically generated from a Python script run in a Linux Live CD and automatically reads all the BIOS and disk parameters and generates all of the settings required to migrate a physical machine to a virtual only part of it is shown). That is why I need to be able to set the HDD path automatically as I will not know whether the settings have been changed.
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 11:16
by mpack
When you say "identical result", what other result are you telling me to compare it with? What you've done looks all right so far.
Except, why the switch to SATA? XP does not have native support for SATA.
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 16:21
by ChipMcK
I believe his issue is that the 'XP Clone.vdi' is not located in folder 'V:\Vbox Machines\XP Clone\', with the 'XP Clone.vbox' file.
Of course, there is no attempt to place it there as that is not the curent working directory/folder.
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 16:30
by mpack
Yep. I skimmed the createhd topic before and had a notion that this would be done within the context of a current VM, hence files would be automatically located. It looks like this whole feature is badly outdated and there is no alternative but to move/copy the VDI outside of VirtualBox, before registering it in the VM. It looks like there needs to be a "--createhd" argument of the "createvm" command, or else an optional "--vmid=xxxxx" argument for the "createhd" command.
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 16:42
by ChipMcK
An easy workaround is
to fully qualify the name of the vdi file, as in 'V:\Vbox Machines\XP Clone\XP Clone.vdi'

Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 17:03
by steelej
The XP machine I am trying to clone has always had a SATA drive but I have tried configuring using IDE and SATA drives. The VDI file is placed in the current working directory and not in the correct virtual machine folder in both cases. I believe I followed the approach described by mpack using an unqualified name and this did not work. The vdi file is created on a different location on a different drive, the path where the batch file is run from.
I am looking for an automatic way of placing the VDI into the VM folder as it would be if I used the GUI interface. I cannot rely on the Virtual Box installation default as this can be changed. I just need to get the VM.vbox folder name or the parent virtual machine folder drive/path into my script.
The only rather convoluted way I can think of is to search the hard drives on the host computer for the .vbox file that has just been created, discover the file path, and then use that to create the fully qualified path to the vdi file. Doing this with the Windows command shell seems to be quite tricky. There should be an easier way!
I don't know the fully qualified path on YOUR computer. You may have changed the default. I have on one of my machines. My generator script is an automatic way of taking an existing machine, using a standard Linux Live CD and running a standard Python script to extract all of the BIOS settings etc and then generate the Windows Commands to create and configure the VM on a host machine. The only thing you have to do on the Windows machine is to type in the VM name. I have most of this working now.
I am aiming for my generator script to also be able to generate a Linux script so that either plaftorm could be used as the host. By design this should just require the creation of a new class in Python. generating a valid path for the target host however is much more complex than I originally envisaged.
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 17:11
by ChipMcK
Preferences specifies the
default folder for the virtual machines for creating.
Code: Select all
>"C:\Program Files\Oracle\VirtualBox\VBoxManage" createvm --name "XP Clone" --os type WindowsXP --register
Virtual machine 'XP Clone' is created and registered.
UUID: b81efa57-4cf0-4185-a718-d51e86b2ff1c
Settings file: 'V:\Vbox Machines\XP Clone\XP Clone.vbox'
'V:\Vbox Machines\XP Clone\XP Clone.vbox'
Re: CreateHD file path same as VM - How?
Posted: 3. Jul 2013, 17:13
by mpack
ChipMcK wrote:An easy workaround is to fully qualify the name of the vdi file, as in 'V:\Vbox Machines\XP Clone\XP Clone.vdi'
Yep, creating it in the right place to begin with would probably work too.
