Outils pour utilisateurs

Outils du site


59:tuto_vboxmanage

It's a common problem: you run VirtualBox, create a virtual machine, probably with a dynamic disk, at your best guess at an adequate disk size, run it for a while, then find you're running out of space. You can easily expand the hard disk size in VirtualBox using the command: VBoxManage modifyhd –resize The –resize option allows you to change the capacity of an existing image; this adjusts the logical size of a virtual disk without affecting the physical size. It works only for expanding the capacity of VDI and VHD virtual disk formats, and only dynamically allocated, not fixed size disks. But this is a way to add more space to a virtual disk without needing to create a new image, attach and copy all the data across within a virtual machine. This is a command-line application, so you need to open a Terminal session in order to run the command, and change directory to the path where your virtual disk is stored.

C'est un problème courant : vous lancez VirtualBox, créez une machine virtuelle, sans doute avec un disque dynamique, à une taille disque suffisante selon votre meilleure estimation, vous l'exécutez pendant un certain temps, puis vous vous retrouvez à court d'espace.

Vous pouvez facilement agrandir la taille du disque dur dans VirtualBox en utilisant la commande :

VBoxManage modifyhd –resize

L'option –resize vous permet de modifier la capacité d'une image existante, ce qui ajuste la taille logique d'un disque virtuel sans affecter la taille physique. Cela ne fonctionne que pour augmenter la capacité des disques virtuels aux formats VDI et VHD, et seulement ceux alloués dynamiquement, et pas les disques de taille fixe. Mais c'est une façon d'ajouter plus d'espace à un disque virtuel sans avoir à créer une nouvelle image, attacher et copier toutes les données dans la machine virtuelle.

C'est une application en ligne de commande, donc vous devez ouvrir une session Terminal pour lancer la commande et changer de répertoire vers l'endroit où votre disque virtuel est stocké.

Two important notes: • Shutdown the running virtual machine before you mess with the disk! • Backup the existing disk image, or at least any volatile data, before you alter it! The command you need follows this pattern: VBoxManage modifyhd XP_newdisk.vdi –resize 10240 • VBoxManage is the utility suite that comes with VirtualBox: • modifyhd is the command to resize the virtualdisk • XP_new.vdi is my example disk name; you'll need to change it to match your disk name, and don't forget the .vdi suffix. Under Linux it's also case sensitive. • –resize 10240 Next is the desired new size for the virtual disk. That's two dashes before the word “resize” followed by a number in megabytes; 10240 being equivalent to 10GB. Also remember that you'll need to increase the size of your guest partition on the disk, or create an additional partition in the new space. In this respect, you'll need to do the work with disk utilities appropriate to your guest operating system just as if it were a real PC with real spinning rust (magnetic disks).

Deux remarques importantes :

• Arrêtez le fonctionnement de la machine virtuelle avant de mettre la pagaille sur le disque !

• Sauvegardez l'image disque existante, ou au moins toutes les données volatiles, avant de la modifier !

La commande dont vous avez besoin suit ce modèle :

VBoxManage modifyhd XP_newdisk.vdi –resize 10240

• VBoxManage est la suite utilitaire qui est livrée avec VirtualBox ; • modifyhd est la commande pour redimensionner le disque virtuel ; • XP_newdisk.vdi est mon nom de disque par exemple, vous devrez le changer pour correspondre à votre nom de disque, et n'oubliez pas le suffixe .vdi. Linux est aussi sensible à la casse ; • –resize 10240 est la nouvelle taille souhaitée pour le disque virtuel. Il y a deux tirets avant le mot « resize » suivi par un certain nombre de méga-octets ; 10240 étant équivalent à 10 Go ; Souvenez-vous également que vous aurez besoin d'augmenter la taille de votre partition invitée sur le disque, ou créer une partition supplémentaire dans le nouvel espace. À cet égard, vous devrez faire le travail avec les utilitaires de disque appropriés à votre système d'exploitation invité, comme s'il s'agissait d'un vrai PC avec un vrai disque ferromagnétique.

Note:.vmdk disks cannot be expanded by modifyhd commands. Try this command line and you'll get the error: VBoxManage: error: Resize hard disk operation for this format is not implemented yet! You can find the manual for Oracle VirtualBox, indexed by each topic, on the website. VBoxManage is in Chapter 8: http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi where the full syntax of the command looks like this: VBoxManage modifyhd <uuid>|<filename> [–type normal|writethrough|immutable|shareable| readonly|multiattach] [–autoreset on|off] [–compact] [–resize <megabytes>|–resizebyte <bytes>]

Remarque : les disques .vmdk ne peuvent pas être élargis par des commandes modifyhd. Essayez cette ligne de commande et vous obtiendrez le message d'erreur : VBoxManage: error: Resize hard disk operation for this format is not implemented yet! [ Ndt : le redimensionnement du disque dur pour ce format n'est pas encore implémenté !]

Vous pouvez trouver le manuel de VirtualBox d'Oracle, indexé par sujet, sur le site web. VBoxManage est dans le chapitre 8 : http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi où la syntaxe complète de la commande ressemble à ceci : VBoxManage modifyhd <uuid>|<filename>

                          [--type normal|writethrough|immutable|shareable|
                                  readonly|multiattach]
                          [--autoreset on|off]
                          [--compact]
                          [--resize <megabytes>|--resizebyte <bytes>]

The –compact option can be used to shrink disk images, that is, remove blocks of empty space (containing zeroes). This will shrink a dynamically allocated image by reducing the physical size of the image without affecting the logical size of the virtual disk. However, free space in the guest system must first be zeroed. For Windows guests, you can use the sdelete tool provided by Microsoft; running sdelete -c in the guest will zero the free disk space. Under Linux, the zerofree utility supports ext2/ext3 filesystems to do the same. You can then compact (compress) the virtual disk image. Note: instructions and links relate to the Oracle VirtualBox version and not to the VirtualBox OSE package contained in the official Ubuntu repositories.

L'option –compact peut être utilisée pour réduire des images de disque, ce qui signifie retirer les blocs de l'espace vide (contenant des zéros). Ça va diminuer une image allouée dynamiquement en réduisant la taille physique de l'image sans affecter la taille logique du disque virtuel.

Cependant, l'espace libre dans le système invité doit d'abord être mis à zéro. Pour les clients Windows, vous pouvez utiliser sdelete, l'outil fourni par Microsoft ; lancer sdelete -c dans le système invité mettra à zéro l'espace disque libre. Sous Linux, l'utilitaire zerofree prend en charge ext2/ext3 pour faire de même. Vous pouvez ensuite compacter (compress) l'image du disque virtuel.

Remarque : Les instructions et les liens se rapportent à la version VirtualBox d'Oracle et pas au paquet VirtualBox OSE contenu dans les dépôts Ubuntu officiels.

59/tuto_vboxmanage.txt · Dernière modification : 2012/04/29 10:19 de andre_domenech