VirtualBox: How can I add (mount) a ISO image file from command-line?

Manage the IDE controller

In case the VM doesn't have an IDE controller you can use the storagectl command to add one:

VBoxManage.exe storagectl "<uuid|vmname>" --name IDE --add ide

Attach a disk image file

Here's a sample syntax you can use to attach a CD/DVD image file:

VBoxManage.exe storageattach "<uuid|vmname>" --storagectl IDE --port 0 --device 0 --type dvddrive --medium "X:\Folder\containing\the.iso"

Detach a disk image file

To detach an image file the syntax is similar: you just need to replace the file path with "none". The --type parameter can be omitted:

VBoxManage.exe storageattach "<uuid|vmname>" --storagectl IDE --port 0 --device 0 --medium "none"

Further reading

  • VBoxManage

First of all, check if you have any CD/DVD drive installed, whether empty or not (note the use of the find command to filter results):

1.- Is there any empty CD/DVD drive?

C:\Oracle\VirtualBox>vboxmanage showvminfo "Windows 7 SP1 - SandBox 01" | find "empty" /i
SATA (1, 0): Empty

Congratulations, you have found a possible empty CD/DVD drive. So you can attach your ISO to it, but...

... in order to face the worst scenario, lets show another way to find your CD/DVD drive, if installed:

2.- Locate the name of your VM:

C:\Oracle\VirtualBox>VBoxManage.exe list vms
"Windows 7 SP1 - SandBox 01" {e016fcf2-9b6e-4b8e-b89b-49a3c8ba0898}

3.- List its storage controllers (note the find command to filter too much output data) (*):

C:\Oracle\VirtualBox>vboxmanage showvminfo "Windows 7 SP1 - SandBox 01" | find "storage controller name" /i
Storage Controller Name (0):            IDE
Storage Controller Name (1):            SATA

4.- Show its attached devices:

C:\Oracle\VirtualBox>vboxmanage showvminfo "Windows 7 SP1 - SandBox 01" | find "IDE"
Storage Controller Name (0):            IDE

(this one is empty, so there are no device controllers, whether hard disks or CD/DVD drives)

C:\Oracle\VirtualBox>vboxmanage showvminfo "Windows 7 SP1 - SandBox 01" | find "SATA"
Storage Controller Name (1):            SATA
SATA (0, 0): d:\VirtualBox VMs\Windows 7 SP1 - SandBox 01\SnapShots/{71b8bf72-dca1-4816-89ff-feba271ec262}.vmdk (UUID: 71b8bf72-dca1-4816-89ff-feba271ec262)
SATA (1, 0): Empty

SATA(0,0) has a(the) virtual disk, and SATA(1,0) is empty (first number between parentheses is known as type, second one is device), so it should be the CD/DVD drive.

5.- Lets attach an ISO image file (Office 2013, for example) to it:

C:\Oracle\VirtualBox>vboxmanage storageattach "Windows 7 SP1 - SandBox 01" --storagectl "SATA" --port 1 --device 0 --type dvddrive --medium "Office2013-VL-SP1.iso"

(no results on screen means OK).

$- To remove the ISO keeping the CD/DVD drive controller:

C:\Oracle\VirtualBox>vboxmanage storageattach "Windows 7 SP1 - SandBox 01" --storagectl "SATA" --port 1 --device 0 --type dvddrive --medium "emptydrive"

$- For the case there is no "empty" CD/DVD drive controller installed, VirtualBox should add a new one to an existing controller, assumed we choose a not-occupied port/device, for example for the SATA controller:

C:\Oracle\VirtualBox>vboxmanage storageattach "Windows 7 SP1 - SandBox 01" --storagectl "SATA" --port 5 --device 0 --type dvddrive --medium "Office2013-VL-SP1.iso"

(note we used port 5)
And for the IDE controller:

C:\Oracle\VirtualBox>vboxmanage storageattach "Windows 7 SP1 - SandBox 01" --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "Office2013-VL-SP1.iso"

(note we used (0,0), this is, the first port and first device)

$- If we want to remove (destroy) (any of) the devices (example for the last IDE one):

C:\Oracle\VirtualBox>vboxmanage storageattach "Windows 7 SP1 - SandBox 01" --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "emptydrive"

(the ISO image gets umounted at the same time of executing this command).

$- Finally, if we wanna create a new controller instead of using the existing(s) one(s) (example for a SATA controller that we will name SATA3):

C:\Oracle\VirtualBox>vboxmanage storagectl "Windows 7 SP1 - SandBox 01" --name SATA3 --add sata

$- And maybe removing it later:

C:\Oracle\VirtualBox>vboxmanage storagectl "Windows 7 SP1 - SandBox 01" --name SATA3 --remove

(*) If the name is not enough (could have been changed) to figure out what kind of controller is it, try:

C:\Oracle\VirtualBox>vboxmanage showvminfo "Windows 7 SP1 - SandBox 01" | find "storage controller" /i
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SATA
Storage Controller Type (1):            IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  30
Storage Controller Port Count (1):      2

As we can see, controller named IDE (#0) is a PIIX4 device (IDE) and the one named SATA (#1) is an IntelAhci (SATA).

NOTE: IDE controllers accept possible image files at 4 configurations: (0,0), (0,1), (1,0) and (1,1). Choose the one that is not occupied. SATA controllers accept 30. These parameters can be configured on VM properties. Remember that, in both cases, count starts at 0, not 1.

NOTE2: Some devices can be created during VM execution (running), depending on the operating system and device. For example, SATA devices can be created on runtime for Windows 7 VMs. Anyway, an ISO CD/DVD image file can always be inserted on runtime in any empty medium. You can check running vms by doing:

C:\Oracle\VirtualBox>vboxmanage list runningvms

Thanks to @and31415 and @DanielB for their comments and info.