VMWare and Virtual Box How To

From KnowWiki
Jump to: navigation, search

Contents

[edit] How to change VirtualBox guest resolution via RDP

Assuming you are using VirtualBox's built-in RDP you have to submit the video mode change "hint" manually to the guest VM:

VBoxManage controlvm "Machinename" setvideomodehint 1280 800 16

[edit] How to improve VirtualBox guest performance

Use SATA disks, not IDE. For XP guest you might need to install the Intel Matrix Drivers for SATA. For others it is out of the box.

[edit] How to increase VirtualBox VDI disk size

First, make sure it is not a static disk

VBoxManage showhdinfo <disk.vdi>

Look for "format variant". If it says 'static' then convert it to a dynamic disk first, by cloning it:

VBoxManage clonehd <disk.vdi> <diskclone.vdi>

Verify the new format by running VBoxManage showhdinfo again and reconnect your cloned to the VM:

VBoxManage storageattach <vmname> --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium <diskclone.vdi>

Now expand it:

VBoxManage modifyhd <disk.vdi> --resize 40960

Get partedmagic in an iso format and mount it to the VM

VBoxManage storageattach <vmname> --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium pmagic_2011_12_30.iso 

Now start the VM, press F12 and choose CD-ROM to boot from the iso, start gparted and resize your partition to fill the drive.

[edit] How to configure VirtualBox VM RDP authentication

Here is how to authenticate against credentials stored in inside the VM's own XML definition file vm_name/vm_name.vbox:

VBoxManage setproperty vrdeauthlibrary "VBoxAuthSimple"

Make sure your VM is down, then

VBoxManage modifyvm <vm_name> --vrdeauthtype external

Generate a password hash

VBoxManage internalcommands passwordhash "<password>"

Set the user and the password

VBoxManage setextradata <vm_name> "VBoxAuthSimple/users/alex" <password_hash>

Then use the -u and -p options for rdesktop to connect (you can put password in quotes and it should still work)

[edit] How to configure VirtualBox VM RDP encryption

Do the following while in the folder where your VM located. This forces the TLS encryption, be wary of potential performance impacts. Create a self signed CA for your vm:

openssl req -new -x509 -days 3650 -extensions v3_ca -keyout vm_ca_key_private.pem -out vm_ca_cert.pem

When asked, create a passphrase for the CA. Create the VM server private key:

openssl genrsa -out vm_server_key_private.pem

Create a request to the CA for signing the VM server key:

openssl req -new -key vm_server_key_private.pem -out vm_server_req.pem

Sign the request and issue the server public key:

openssl x509 -req -days 3650 -in vm_server_req.pem -CA vm_ca_cert.pem -CAkey vm_ca_key_private.pem -set_serial 01 -out vm_server_cert.pem

Make sure that your VM is stopped and configure it for TLS

VBoxManage modifyvm <vm_name> --vrdeproperty "Security/Method=TLS"
VBoxManage modifyvm <vm_name> --vrdeproperty "Security/CACertificate=vm_ca_cert.pem"
VBoxManage modifyvm <vm_name> --vrdeproperty "Security/ServerCertificate=vm_server_cert.pem"
VBoxManage modifyvm <vm_name> --vrdeproperty "Security/ServerPrivateKey=vm_server_key_private.pem"

Try connecting. No changes are required on the client.

[edit] How to connect USB remotely to a VirtualBox VM on Ubuntu

For some reason the tool to connect USB over RDP (rdesktop-vrdp) is not included in the VirtualBox distros from the PPA. If you had installed it this way you'd need to do the following to get rdesktop-vrdp:

Download a debian pack from https://www.virtualbox.org/wiki/Linux_Downloads. extract it somewhere with 7zip or dpkg. Now do the following as root:

cp unpacked/usr/bin/rdesktop-vrdp /usr/bin/
chmod 755 /usr/bin/rdesktop-vrdp
cp -R unpacked/usr/share/virtualbox/rdesktop-vrdp-keymaps /usr/share/virtualbox/
chmod 755 /usr/share/virtualbox/rdesktop-vrdp-keymaps
chmod 644 /usr/share/virtualbox/rdesktop-vrdp-keymaps/*

Now, configure your vm to accept remote USB. First make sure that your VM is down, then run

VBoxManage showvminfo VMNAME

To enable an existing USB device filter for remote use:

VBoxManage usbfilter modify 0 --target VMNAME --remote yes

or to catch all usbs

VBoxManage usbfilter add 0 --name "remoteUSB" --remote yes --target VMNAME

or to connect iPhone 4 remotely:

VBoxManage usbfilter add 0 --name "aiPhone" --vendorid 05ac --productid 1297 --revision 0001 -manufacturer "Apple Inc." --product iPhone --remote yes --target VMNAME

Note: --remote "any", for both local and remote connections does NOT work from the command line, but you can use GUI to set it up

Make sure you have a vboxusers group. Run

groups

If vboxusers is not listed run

sudo usermod -a -G vboxusers alex

And re-login

Start the VM and connect with the remote USB:

rdesktop-vrdp -5 -r usb -x l -k en-us -N server

[edit] How to mount a VirtualBox VDI disk image in Linux

This is not trivial and there are no tools that can do that, yet. Here is how to do it in a semi-manual approach.

gcc -fPIC -c -o vdiwrap.o  vdiwrap.c && gcc -nostdlib -shared -ldl -o vdiwrap.so vdiwrap.o
LD_PRELOAD="./vdiwrap.so" /sbin/sfdisk -qluS your_disk_goes_here.vdi
sudo mount -t ntfs -o loop,offset=[partition offset] your_disk_goes_here.vdi /media/temp

[edit] How to increase a VMDK disk size

Shutdown the vmware image (it could be just paused for expansion but Win2K will not notice the Physical disk increase untill reboot) Do the following for the 377byte file with the disk descriptor (not the actual disk)

"C:\Program Files\VMware\VMware Workstation\"vmware-vdiskmanager.exe -x 8Gb "Windows Server 2003 Enterprise Edition.vmdk"

Fire it back up

Download Knoppix live cd. Boot from it into the vmware. Start QTParted, perform disk expansion. Alternatively you could install Acronis Disk Director Suite on the vmware image do the disk expansion

[edit] How to map vmware disks directly to the host

To mount the disk download howtomapvmwaredisks directly to the host run

"C:\Program Files\VMware\VMware DiskMount Utility\"vmware-mount.exe /p "Windows Server 2003 Standard Edition.vmdk"

to get the list of partitions vmdk must be the small text file with a disk description. not the actual multigig disk file - however the text file might be inside of the disk file if not present in the folder. Look at the disk file - it should be at the beginning. in this case yo uneed to point the vmware-vdisk to the big disk file then mount them

"C:\Program Files\VMware\VMware DiskMount Utility\"vmware-mount.exe v: /v:1 "Windows Server 2003 Standard Edition.vmdk"

[edit] How to shrink a preallocated disk - convert to growable

"C:\Program Files\VMware\VMWare Workstation\"vmware-vdiskmanager.exe -r "Windows Server 2003 Standard Edition.vmdk" -t 0 growable.vmdk

after it is complete reconfigure the vmware image - delete old hdd and create a new one pointing to the growable.vmdk it might be already small so that you would not have to shrink it

[edit] How to shrink disk

Either power on the vmware and go to control panel -> vmware tools -> shrink or mount using

vmware-mount.ext v: /v:1 ....vmdk

then prepare for shrinking

vmware-vdiskmanager.exe -p V:

then shrink

vmware-vdiskmanager -k ....vmdk

[edit] How to virtualize windows partition

Directions for VMWARE:

apt-get install ntfsprogs
ntfsclone -o file /dev/sda1 (ntfs partition)

or use

dd if=/dev/sda1 of=file bs=1024

ntfs clone is just better feedback (percentage complete) and possibly speed you could then nuke the partition with gparted

  1. create a virtual disk
  2. create a new disk in a new vm or an existing, of the same size and preallocate it.
  3. boot the vm with a partedmagic or gparted ISO mounted to be able to partition the new vmdk
  4. create the partition table and the ntfs partition on the new vmdk. Mark it as bootable.
  5. shut down the vm
  6. copy the image to vmdk
  7. create a mounting-point for the vmdk
  8. mount vmdk with
vmdk-mount disk 1 mounting-point

where 1 is the number of the ntfs partition in vmdk

  1. now, we're gonna use the block device, not the mount point
  2. run "mount" to see what block device is in use for the mounting-point
  3. copy the image content
dd if=image of=/dev/vm-block-device bs=1024
  1. restart vmware. vmdk-mount gets its noodles screwed up by using dd so a simple unmount with
vmdk-mount -X 

may not work.

boot and enjoy and BTW if your boot record is screwed-up, boot with a Windows bootable floppy mounted or try to restore MBR and the boot sector using Windows recovery console (did not work for me)

[edit] How to zero out linux or cygwin disk

cat /dev/zero > /zero.dat; sync; sleep 1; sync; rm -f /zero.dat

or

dd if=/dev/zero of=/empty_file
rm /empty_file

then shrink -

vmware-vdiskmanager -k MyDisk.vmdk
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox