Ceci est une ancienne révision du document !
VirtualBox en environnement serveur
VirtualBox fourni VBoxManage, qui permet la création, suppression ou modification de machines virtuelles en lignes de commandes.
Avec VBoxManage, il est possible, via ssh, de contrôler à distance son parc de machines virtuelles.
Ce tutoriel reprend, étape par étape, les commandes permettant de créer et configurer une machine virtuelle.
Pré-requis
- Disposer des droits d'administration.
- VirtualBox est installé sur une installation d'ubuntu serveur.
Création
Nous allons créer une machine virtuelle, que nous nommerons SRV1, destinée à accueillir un OS Ubuntu.
$ VBoxManage createvm --name SRV1 --ostype Ubuntu --register Oracle VM VirtualBox Command Line Management Interface Version 3.2.4 (C) 2005-2010 Oracle Corporation All rights reserved. Virtual machine 'SRV1' is created and registered. UUID: d1ff6a5d-9859-4df7-ab72-ad1766525ba6 Settings file: '/home/test/.VirtualBox/Machines/SRV1/SRV1.xml'
Modification
Pour modifier la mémoire vive de cette machine virtuelle et lui attribuer 256 Mo:
$ VBoxManage modifyvm SRV1 --memory 256
Pour modifier l'interface réseau : (par exemple basculer la carte réseau en mode pont)
Attention –nic1 correspond à la première carte, –nic2 à la seconde, etc.
$ VBoxManage modifyvm SRV1 --nic1 bridged $ VBoxManage modifyvm SRV1 --bridgeadapter1 eth0
Permettre un contrôle à distance via VRDP (attention, dans ce cas, VirtualBox devient payant)
$ VBoxManage modifyvm SRV1 --vrdp on --vrdpport 3395
Désactiver certaines options si elles sont inutiles :
$ VBoxManage modifyvm SRV1 --usb off --audio none
Créer un disque dur :
$ VBoxManage createhd --filename SRV1 --size 15000 Oracle VM VirtualBox Command Line Management Interface Version 3.2.4 (C) 2005-2010 Oracle Corporation All rights reserved. 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Disk image created. UUID: 4a5a8819-35f0-40de-a8e3-6dd3113d1746
Créer le controleur :
$ VBoxManage storagectl SRV1 --name SATA1 --add sata
Attacher le disque au controleur :
$ VBoxManage storageattach SRV1 --storagectl SATA1 --port 0 --device 0 --type hdd --medium SRV1.vdi
Créer un controleur IDE et son lecteur de dvd-rom associé :
$ VBoxManage storagectl SRV1 --name IDE1 --add ide $ VBoxManage storageattach SRV1 --storagectl IDE1 --port 0 --device 0 --type dvddrive --medium emptydrive
On peut aussi attacher une image iso d'ubuntu-serveur :
$ VBoxManage storageattach SRV1 --storagectl IDE1 --port 0 --device 0 --type dvddrive --medium /home/test/ubuntu-10.04.1-server-i386.iso
Récapitulatif :
$ VBoxManage showvminfo SRV1 Oracle VM VirtualBox Command Line Management Interface Version 3.2.4 (C) 2005-2010 Oracle Corporation All rights reserved. Name: SRV1 Guest OS: Ubuntu UUID: 7fe28aa4-e28d-4a27-a216-f20b47a6cce9 Config file: /home/test/.VirtualBox/Machines/SRV1/SRV1.xml Hardware UUID: 7fe28aa4-e28d-4a27-a216-f20b47a6cce9 Memory size: 256MB Page Fusion: off VRAM size: 8MB HPET: off Number of CPUs: 1 Synthetic Cpu: off CPUID overrides: None Boot menu mode: message and menu Boot Device (1): Floppy Boot Device (2): DVD Boot Device (3): HardDisk Boot Device (4): Not Assigned ACPI: on IOAPIC: off PAE: off Time offset: 0 ms RTC: local time Hardw. virt.ext: on Hardw. virt.ext exclusive: on Nested Paging: on Large Pages: off VT-x VPID: on State: running (since 2010-12-02T18:49:04.102000000) Monitor count: 1 3D Acceleration: off 2D Video Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: Teleporter Password: Storage Controller Name (0): SATA1 Storage Controller Type (0): IntelAhci Storage Controller Instance Number (0): 0 Storage Controller Max Port Count (0): 30 Storage Controller Port Count (0): 30 Storage Controller Name (1): IDE1 Storage Controller Type (1): PIIX4 Storage Controller Instance Number (1): 0 Storage Controller Max Port Count (1): 2 Storage Controller Port Count (1): 2 SATA1 (0, 0): /home/test/.VirtualBox/HardDisks/SRV1.vdi (UUID: 4a5a8819-35f0-40de-a8e3-6dd3113d1746) IDE1 (0, 0): /home/test/ubuntu-10.04.1-server-i386.iso (UUID: 3b57f58d-72b7-435d-a30a-2b8a5acfb580) NIC 1: MAC: 0800273BB884, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0 NIC 2: disabled NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: PS/2 Mouse Keyboard Device: PS/2 Keyboard UART 1: disabled UART 2: disabled Audio: disabled Clipboard Mode: Bidirectional Video mode: 640x480x0 VRDP: enabled (Address 0.0.0.0, Ports 3395, MultiConn: off, ReuseSingleConn: off, Authentication type: null) VRDP port: 3395 Video redirection: disabled USB: disabled USB Device Filters: <none> Available remote USB devices: <none> Currently Attached USB Devices: <none> Shared folders: <none>
Lancement de la machine
On peut lancer la machine avec la commande suivante :
$ VBoxManage startvm SRV1 –type vrdp
Oracle VM VirtualBox Command Line Management Interface Version 3.2.4 (C) 2005-2010 Oracle Corporation All rights reserved. Waiting for the VM to power on... VM has been successfully started.
et prendre le contrôle de la machine via le Terminal Server Client.
Aller plus loin...
La commande VBoxManage renvoi les options possibles à utiliser avec la commande.
$ VBoxManage Oracle VM VirtualBox Command Line Management Interface Version 3.2.4 (C) 2005-2010 Oracle Corporation All rights reserved. Usage: VBoxManage [-v|--version] print version number and exit VBoxManage [-q|--nologo] ... suppress the logo VBoxManage list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies| bridgedifs|hostonlyifs|dhcpservers|hostinfo| hostcpuids|hddbackends|hdds|dvds|floppies| usbhost|usbfilters|systemproperties VBoxManage showvminfo <uuid>|<name> [--details] [--statistics] [--machinereadable] VBoxManage showvminfo <uuid>|<name> --log <idx> VBoxManage registervm <filename> VBoxManage unregistervm <uuid>|<name> [--delete] VBoxManage createvm --name <name> [--ostype <ostype>] [--register] [--basefolder <path> | --settingsfile <path>] [--uuid <uuid>] VBoxManage modifyvm <uuid|name> [--name <name>] [--ostype <ostype>] [--memory <memorysize in MB>] [--pagefusion on|off] [--vram <vramsize in MB>] [--acpi on|off] [--ioapic on|off] [--pae on|off] [--hpet on|off] [--hwvirtex on|off] [--nestedpaging on|off] [--largepages on|off] [--vtxvpid on|off] [--synthcpu on|off] [--cpuidset <leaf> <eax> <ebx> <ecx> <edx>] [--cpuidremove <leaf>] [--cpuidremoveall] [--hardwareuuid <uuid>] [--cpus <number>] [--cpuhotplug on|off] [--plugcpu <id>] [--unplugcpu <id>] [--rtcuseutc on|off] [--monitorcount <number>] [--accelerate3d on|off] [--accelerate2dvideo on|off] [--firmware bios|efi|efi32|efi64] [--bioslogofadein on|off] [--bioslogofadeout on|off] [--bioslogodisplaytime <msec>] [--bioslogoimagepath <imagepath>] [--biosbootmenu disabled|menuonly|messageandmenu] [--biossystemtimeoffset <msec>] [--biospxedebug on|off] [--boot<1-4> none|floppy|dvd|disk|net>] [--nic<1-N> none|null|nat|bridged|intnet|hostonly| vde] [--nictype<1-N> Am79C970A|Am79C973| 82540EM|82543GC|82545EM| virtio] [--cableconnected<1-N> on|off] [--nictrace<1-N> on|off] [--nictracefile<1-N> <filename>] [--nicspeed<1-N> <kbps>] [--nicbootprio<1-N> <priority>] [--bridgeadapter<1-N> none|<devicename>] [--hostonlyadapter<1-N> none|<devicename>] [--intnet<1-N> <network name>] [--natnet<1-N> <network>|default] [--vdenet<1-N> <network>|default] [--natsettings<1-N> [<mtu>],[<socksnd>], [<sockrcv>],[<tcpsnd>], [<tcprcv>]] [--natpf<1-N> [<rulename>],tcp|udp,[<hostip>], <hostport>,[<guestip>],<guestport>] [--natpf<1-N> delete <rulename>] [--nattftpprefix<1-N> <prefix>] [--nattftpfile<1-N> <file>] [--nattftpserver<1-N> <ip>] [--natdnspassdomain<1-N> on|off] [--natdnsproxy<1-N> on|off] [--natdnshostresolver<1-N> on|off] [--nataliasmode<1-N> default|[log],[proxyonly], [sameports]] [--macaddress<1-N> auto|<mac>] [--mouse ps2|usb|usbtablet [--keyboard ps2|usb [--uart<1-N> off|<I/O base> <IRQ>] [--uartmode<1-N> disconnected| server <pipe>| client <pipe>| file <file>| <devicename>] [--guestmemoryballoon <balloonsize in MB>] [--gueststatisticsinterval <seconds>] [--audio none|null|oss|alsa|pulse] [--audiocontroller ac97|sb16] [--clipboard disabled|hosttoguest|guesttohost| bidirectional] [--vrdp on|off] [--vrdpport default|<ports>] [--vrdpaddress <host>] [--vrdpauthtype null|external|guest] [--vrdpmulticon on|off] [--vrdpreusecon on|off] [--vrdpvideochannel on|off] [--vrdpvideochannelquality <percent>] [--usb on|off] [--usbehci on|off] [--snapshotfolder default|<path>] [--teleporter on|off] [--teleporterport <port>] [--teleporteraddress <address|empty> [--teleporterpassword <password>] VBoxManage import <ovf> [--dry-run|-n] [more options] (run with -n to have options displayed for a particular OVF) VBoxManage export <machines> --output|-o <ovf> [--legacy09] [--vsys <number of virtual system>] [--product <product name>] [--producturl <product url>] [--vendor <vendor name>] [--vendorurl <vendor url>] [--version <version info>] [--eula <license text>] [--eulafile <filename>] VBoxManage startvm <uuid>|<name> [--type gui|sdl|vrdp|headless] VBoxManage controlvm <uuid>|<name> pause|resume|reset|poweroff|savestate| acpipowerbutton|acpisleepbutton| keyboardputscancode <hex> [<hex> ...]| injectnmi| setlinkstate<1-N> on|off | nic<1-N> null|nat|bridged|intnet|hostonly [<devicename>] | nictrace<1-N> on|off nictracefile<1-N> <filename> guestmemoryballoon <balloonsize in MB>] gueststatisticsinterval <seconds>] usbattach <uuid>|<address> | usbdetach <uuid>|<address> | vrdp on|off | vrdpport default|<ports> | vrdpvideochannelquality <percent> setvideomodehint <xres> <yres> <bpp> [display] | setcredentials <username> <password> <domain> [--allowlocallogon <yes|no>] | teleport --host <name> --port <port> [--maxdowntime <msec>] [--password password] plugcpu <id> unplugcpu <id> VBoxManage discardstate <uuid>|<name> VBoxManage adoptstate <uuid>|<name> <state_file> VBoxManage snapshot <uuid>|<name> take <name> [--description <desc>] [--pause] | delete <uuid>|<name> | restore <uuid>|<name> | restorecurrent | edit <uuid>|<name>|--current [--name <name>] [--description <desc>] | showvminfo <uuid>|<name> VBoxManage openmedium disk|dvd|floppy <filename> [--type normal|immutable|writethrough] (disk only) [--uuid <uuid>] [--parentuuid <uuid>] (disk only) VBoxManage closemedium disk|dvd|floppy <uuid>|<filename> [--delete] VBoxManage storageattach <uuid|vmname> --storagectl <name> --port <number> --device <number> [--type dvddrive|hdd|fdd] [--medium none|emptydrive| <uuid>|<filename>|host:<drive>] [--passthrough on|off] [--forceunmount] VBoxManage storagectl <uuid|vmname> --name <name> [--add ide|sata|scsi|floppy|sas] [--controller LSILogic|LSILogicSAS|BusLogic| IntelAHCI|PIIX3|PIIX4|ICH6|I82078] [--sataideemulation<1-4> <1-30>] [--sataportcount <1-30>] [--hostiocache on|off] [--remove] VBoxManage showhdinfo <uuid>|<filename> VBoxManage createhd --filename <filename> --size <megabytes> [--format VDI|VMDK|VHD] (default: VDI) [--variant Standard,Fixed,Split2G,Stream,ESX] [--type normal|writethrough] (default: normal) [--comment <comment>] [--remember] VBoxManage modifyhd <uuid>|<filename> [--type normal|writethrough|immutable] [--autoreset on|off] [--compact] VBoxManage clonehd <uuid>|<filename> <outputfile> [--format VDI|VMDK|VHD|RAW|<other>] [--variant Standard,Fixed,Split2G,Stream,ESX] [--type normal|writethrough|immutable] [--remember] [--existing] VBoxManage convertfromraw <filename> <outputfile> [--format VDI|VMDK|VHD] [--variant Standard,Fixed,Split2G,Stream,ESX] VBoxManage convertfromraw stdin <outputfile> <bytes> [--format VDI|VMDK|VHD] [--variant Standard,Fixed,Split2G,Stream,ESX] VBoxManage addiscsidisk --server <name>|<ip> --target <target> [--port <port>] [--lun <lun>] [--encodedlun <lun>] [--username <username>] [--password <password>] [--type normal|writethrough|immutable] [--intnet] VBoxManage getextradata global|<uuid>|<name> <key>|enumerate VBoxManage setextradata global|<uuid>|<name> <key> [<value>] (no value deletes key) VBoxManage setproperty hdfolder default|<folder> | machinefolder default|<folder> | vrdpauthlibrary default|<library> | websrvauthlibrary default|null|<library> | loghistorycount <value> VBoxManage usbfilter add <index,0-N> --target <uuid>|<name>|global --name <string> --action ignore|hold (global filters only) [--active yes|no] (yes) [--vendorid <XXXX>] (null) [--productid <XXXX>] (null) [--revision <IIFF>] (null) [--manufacturer <string>] (null) [--product <string>] (null) [--remote yes|no] (null, VM filters only) [--serialnumber <string>] (null) [--maskedinterfaces <XXXXXXXX>] VBoxManage usbfilter modify <index,0-N> --target <uuid>|<name>|global [--name <string>] [--action ignore|hold] (global filters only) [--active yes|no] [--vendorid <XXXX>|""] [--productid <XXXX>|""] [--revision <IIFF>|""] [--manufacturer <string>|""] [--product <string>|""] [--remote yes|no] (null, VM filters only) [--serialnumber <string>|""] [--maskedinterfaces <XXXXXXXX>] VBoxManage usbfilter remove <index,0-N> --target <uuid>|<name>|global VBoxManage sharedfolder add <vmname>|<uuid> --name <name> --hostpath <hostpath> [--transient] [--readonly] VBoxManage sharedfolder remove <vmname>|<uuid> --name <name> [--transient] VBoxManage vmstatistics <vmname>|<uuid> [--reset] [--pattern <pattern>] [--descriptions] VBoxManage guestproperty get <vmname>|<uuid> <property> [--verbose] VBoxManage guestproperty set <vmname>|<uuid> <property> [<value> [--flags <flags>]] VBoxManage guestproperty enumerate <vmname>|<uuid> [--patterns <patterns>] VBoxManage guestproperty wait <vmname>|<uuid> <patterns> [--timeout <msec>] [--fail-on-timeout] VBoxManage guestcontrol execute <vmname>|<uuid> <path to program> --username <name> --password <password> [--arguments "<arguments>"] [--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"] [--flags <flags>] [--timeout <msec>] [--verbose] [--wait-for exit,stdout,stderr||] VBoxManage metrics list [*|host|<vmname> [<metric_list>]] (comma-separated) VBoxManage metrics setup [--period <seconds>] (default: 1) [--samples <count>] (default: 1) [--list] [*|host|<vmname> [<metric_list>]] VBoxManage metrics query [*|host|<vmname> [<metric_list>]] VBoxManage metrics enable [--list] [*|host|<vmname> [<metric_list>]] VBoxManage metrics disable [--list] [*|host|<vmname> [<metric_list>]] VBoxManage metrics collect [--period <seconds>] (default: 1) [--samples <count>] (default: 1) [--list] [--detach] [*|host|<vmname> [<metric_list>]] VBoxManage hostonlyif ipconfig <name> [--dhcp | --ip<ipv4> [--netmask<ipv4> (def: 255.255.255.0)] | --ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]] VBoxManage dhcpserver add|modify --netname <network_name> | --ifname <hostonly_if_name> [--ip <ip_address> --netmask <network_mask> --lowerip <lower_ip> --upperip <upper_ip>] [--enable | --disable] VBoxManage dhcpserver remove --netname <network_name> | --ifname <hostonly_if_name>
Conclusion
Des fonctionnalités de plus en plus nombreuses viennent enrichir VirtualBox au fur et à mesure des versions, comme l'option teleport de controlvm, qui permet la migration à chaud d'un serveur vers un autre d'une machine virtuelle.