Content Cleanup Required: This article should be cleaned-up to follow the content standards in the Wiki Guide. More info... |
Conteúdos
|
This document provides information on using the Virtual Box system emulator under Ubuntu. This works under 6.06, 6.10, 7.04, 7.10, 8.04.
Installation
There are two versions of VirtualBox available, the Open Source Edition and the free, but proprietary, Personal Use / Evaluation License version.
Open Source Edition on Ubuntu 8.04 (Hardy)
Installing VirtualBox OSE on Hardy is even easier. From a terminal session run the following commands to install Virtualbox OSE.
sudo apt-get install virtualbox-ose virtualbox-ose-modules-`uname -r`
Add yourself to the vboxusers group. You can add more usernames after "whoami" if you wish.
sudo gpasswd -a `whoami` vboxusers
or
sudo usermod -Gvboxusers -a `whoami`
or
sudo adduser $USER vboxusers
You will now have to log out of your desktop session and log back in order to update your group membership. Congratulations, you can now skip down to "Using Virtual Box" (which might be out of date?)
If you have a multi-core CPU and experience high CPU usage even when the guest OS is almost no using CPU, you can force Virtual Box to execute in just one of your cores by launching it through taskset.
sudo apt-get install util-linux
taskset -c 1 virtualbox
See http://www.virtualbox.org/ticket/1233 and http://ubuntuforums.org/showthread.php?t=775503 for further info on this issue.
NOTE: If you are using SCIM, you may run into a problem where VirtualBox does not respond to the Host Key and you get stuck. The solution is to install a package:
sudo apt-get install scim-bridge-client-qt
Open Source Edition on Ubuntu 7.10 (Gutsy Gibbon)
Installing VirtualBox OSE on Gutsy Gibbon is much easier. From a terminal session run the following commands to install Virtualbox OSE and build and install the kernel modules.
sudo apt-get install virtualbox-ose virtualbox-ose-source
sudo module-assistant prepare
sudo module-assistant update
sudo module-assistant unpack virtualbox-ose
sudo module-assistant auto-install virtualbox-ose
Now you can verify that the kernel module is installed, but if you didn't receive any errors on the previous steps you're probably fine.
From a terminal:
$ ls -l /dev/vboxdrv
crw-rw---- 1 root vboxusers 10, 62 2007-10-08 13:27 /dev/vboxdrv
If the group is not set to vboxusers, reload the kernel module:
sudo rmmod vboxdrv
sudo modprobe vboxdrv
Add yourself to the vboxusers group. You can add more usernames after "whoami" if you wish.
sudo gpasswd -a `whoami` vboxusers
To automatically load the kernel module (driver) at boot time you need to run the following to append vboxdrv to /etc/modules
echo "vboxdrv" | sudo tee -a /etc/modules
You will now have to log out of your desktop session and log back in order to update your group membership. Congratulations, you can now skip down to "Using Virtual Box"
Dependency problems
In some cases when you execute "sudo module-assistant auto-install virtualbox-ose" dependecy problems appears because virtualbox-ose-modules-2.6.22-14-generic conflicts with virtualbox-ose-modules. You can fix this with the following commands:
sudo apt-get remove virtualbox-ose-modules-2.6.22-14-generic
sudo dpkg -i /usr/src/virtualbox-ose-modules-2.6.22-15-386_1.5.0-dfsg2-1ubuntu3+2.6.22-15.58_i386.deb (filename can change)
sudo apt-get install virtualbox-ose
Perhaps it is not needed but I repeated previous step:
sudo module-assistant prepare
sudo module-assistant update
sudo module-assistant unpack virtualbox-ose
sudo module-assistant auto-install virtualbox-ose
If you are lucky the problem is gone
Open Source Edition on Ubuntu 7.04 (Feisty Fawn) and earlier
Currently the best way to install the GPL version of Virtual Box is to compile from scratch. The following page details how to compile Virtual Box (follow instructions for use under Debian).
After you compile and install VirtualBox, you may need to load the module before the program will run.
sudo modprobe vboxdrv
PUEL (Personal Use & Evaluation License) Version
For both Edgy and Feisty, install the edgy .deb from http://virtualbox.org/wiki/Downloads
For Dapper, install the Dapper .deb from same adress.
While this is non-free and only for personal use, it adds USB support and virtual Remote Desktop support. Without this, your USB devices can't be used in the guest OS and you cannot use Windows Remote Desktop as a server in the guest OS.
Using Virtual Box
Menu item
The VirtualBox can be run from the menu Applications > System Tools >
First Run
Creating a new Virtual Machine
Click New to start the "Create New Virtual Machine" Wizard.
Specify a virtual machine name and operating system type.
Specify an amount of RAM to dedicate to this virtual machine when it is running.
Either choose an existing image, go and find one with the Existing button, or press "New" to start the "Create New Virtual Disk" Wizard.
Creating a new disk image
Assign the image to the virtual machine
Back in the "Create New Virtual Machine" Wizard.
Summary page is then shown.
Details page shows the settings for this Virtual Machine.
Attaching a CDROM image
Click on CD/DVD-ROM in the Details tab.
Tick "Mount CD/DVD Drive" and tick ISO Image file then go find it with the select button.
Virtual Disk Manager starts. Click Add.
Explorer style dialog appears, go find the ISO image.
Added to the Virtual Disk Manager as a CD/DVD Image, choose it then click Select.
Back in the CD/DVD-ROM selection dialog.
Starting the emulator
Boot up the VM using the "Start" button.
The VM booted.
Un-Grabbing the mouse & keyboard
In the bottom right hand corner of the emulated machine window is the name of the key required to make Virtual Box un-grab the mouse and keyboard. By default this is Control_R which actually means the right hand Control key, not control and the letter R.
Networking
To start, NAT is by far the easiest way to get your guests connected to the interweb, but you may want to use the guests as servers. For this you need Host Networking.
Install Necessary Software
You will need to install bridge-utils and uml-utilities so that you can make a tap device and add it to a bridge.
sudo apt-get install bridge-utils uml-utilities
8.04 Hardy
To configure bridging, you basically go through three steps on the host machine. First you need to create a bridge. Next you create virtual interface(s). Then you add a real interface and virtual interface(s) to the bridge. Because of the scripts available on the distribution which take care of all the details, all of this sums up to two steps:
- declare bridge and real network interface you add to it
- declare virtual interfaces
Create a permanent bridge by editing /etc/network/interfaces
On the host machine:
$ sudo gedit /etc/network/interfaces
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet dhcp
bridge_ports eth0
# The loopback network interface
auto lo
iface lo inet loopback
"br0" is an arbitrary name. To take the modifications into account, restart the network:
$sudo /etc/init.d/networking restart
From now on, your system will always set up the bridge on boot. Note that this could slow down the boot time a little bit, because of the bridge coming up.
Declare virtual interfaces which will be used by VirtualBox by editing /etc/vbox/interfaces
On the host machine:
$ sudo gedit /etc/vbox/interfaces
# Each line should be of the format :
#[ ]
vbox0br0
vbox1br0
...
"vbox#" is an arbitrary name. You may declare here as many virtual interfaces as you wish, and add it to a bridge.
Later when you will configure the network of your virtual machine you will use the virtual adapter name "vbox#" for host networking. For example if you use the VirtualBox Qt graphical interface, enter "vbox#" in the "Interface Name" field, when choosing "Host interface".
To take the modifications into account, restart the VirtualBox host networking script:
$sudo /etc/init.d/virtualbox-ose restart
The virtual interfaces are now created and added to the bridge.
That's it! Now the different scripts will take care of cleanly create/configure/remove bridges and virtual interfaces when you boot and shut your system down.
Configure networking in VirtualBox
Once you have everything ready, you can start the VirtualBox management interface on the host machine, configure the network of your virtual machine, and by selecting "host networking", enter the name of one of the virtual adapter you have configured. Start your virtual machine, it gets a network card presented, that you can set up as you wish (static IP address, DHCP) using the network configuration tools inside the virtual machine.
Edit One System File On The Host Machine
Edit the host machine's /etc/network/interfaces to let your system know what the tap device is. Note: This step will be saved permanently to your host machine's settings so that even if you reboot the machine, you won't need to repeat it.
Back Up The System File
Before you begin, back up the current interfaces file with a copy that has the current date in its name:
sudo cp /etc/network/interfaces /etc/network/interfaces.`date +~%b-%d-%Y~%T`
Edit The System File
To edit the file in GNOME, type:
gksudo gedit /etc/network/interfaces
To edit the file in KDE, type:
kdesu kate /etc/network/interfaces
Go to the bottom of the file and add this section, making sure to leave a blank line between the existing contents of the file and the new section you're adding:
auto tap1
iface tap1 inet manual
up ifconfig $iface 0.0.0.0 up
down ifconfig $iface down
tunctl_user USERNAME
Replace USERNAME with your username and save the file.
Create A Bridge
Now make a bridge and put your current interface into it:
sudo tunctl -t tap1 -u USERNAME
sudo chown root.vboxusers /dev/net/tun
sudo chmod g+rw /dev/net/tun
Replace USERNAME with the username you use on your host computer.
Set the permission to persist across reboots, by editing as root /etc/udev/rules.d/20-names.rules and changing:
KERNEL=="tun", NAME="net/%k"
to
KERNEL=="tun", NAME="net/%k", GROUP="vboxusers", MODE="0660"
Make a new bridge called br0:
sudo brctl addbr br0
Put your current interface (in this case eth0) into promiscuous mode, then add it to the bridge and give the bridge a DHCP address. Note after running the following ifconfig command via ssh you may/will lose connectivity to the box. I'm thinking that using the auto script instead, which is later on in this document, will be required for creating the tunnels.
sudo ifconfig eth0 0.0.0.0 promisc
sudo brctl addif br0 eth0
If you are using DHCP to automatically get an IP address, set the bridge to use DHCP.
sudo dhclient br0
If you are using a static IP, specify the host machine's IP address and netmask, and add the default gateway route:
#Where 192.168.1.105 is your host machine's static IP and 255.255.0.0 is your netmask
sudo ifconfig br0 192.168.1.105 netmask 255.255.0.0
#Where 192.168.1.1 is your default gateway
sudo route add default gw 192.168.1.1 br0
Add the new tap1 device to the bridge and activate tap1 (the second line appears to be necessary according to http://ubuntuforums.org/showthread.php?t=561461#3)
sudo brctl addif br0 tap1
sudo ifconfig tap1 up
You should now be able to use host networking in VirtualBox. Just change "Attached to" from "Nat" to "Host interface" and type "tap1" (without the quotes) into the Interface Name box in your virtual machine's Networking settings. Read the manual as well. There are some other nifty ways to do this. Do not forget to use the root account when doing this. Also, reboot your computer afterwards.
Automate The Process
Since the steps in the "Create A Bridge" section are not permanent, if you reboot the machine, you'll have to repeat them (with the exception of the part where you can edit /etc/udev/rules.d/20-names.rules). Rather than re-entering all this information manually, you can automate it by saving the commands into text files and executing them either via a shortcut or from the command line.
Below are four scripts. You'll need either the two static IP scripts or the two dynamic IP scripts, depending on whether your host computer uses a static or dynamic IP. Paste the contents of each into a text editor and save the file. I recommend naming them BridgeUp and BridgeDown or something similar so that you'll know at a glance what each one does.
If you want to make them executable, open the properties of each file and change the executable setting. Then you can either click the files to launch them or make shortcuts to them and click the shortcuts.
If you'd rather run them from the command line, don't make the files executable. Open a terminal and change to the directory the scripts are in and type:
bash SCRIPTNAME
Be sure to substitute BridgeUp or BridgeDown (or whatever you named the files) for SCRIPTNAME in the command.
Script To Bring The Bridge Up If Your Host Computer Uses A Static IP
sudo tunctl -t tap1 -u USERNAME
sudo chown root.vboxusers /dev/net/tun
sudo chmod g+rw /dev/net/tun
sudo brctl addbr br0
sudo ifconfig eth0 0.0.0.0 promisc
sudo brctl addif br0 eth0
sudo ifconfig br0 HOST_IP netmask NETMASK
sudo route add default gw GATEWAY br0
sudo brctl addif br0 tap1
sudo ifconfig tap1 up
Replace USERNAME with the username you use on your host machine. Replace NETMASK with your router's netmask number. Replace GATEWAY with your router's gateway number.
Script To Bring The Bridge Up If Your Host Computer Uses A Dynamic IP (DHCP)
sudo tunctl -t tap1 -u USERNAME
sudo chown root.vboxusers /dev/net/tun
sudo chmod g+rw /dev/net/tun
sudo brctl addbr br0
sudo ifconfig eth0 0.0.0.0 promisc
sudo brctl addif br0 eth0
sudo dhclient br0
sudo brctl addif br0 tap1
sudo ifconfig tap1 up
Replace USERNAME with the username you use on your host machine.
Script To Bring The Bridge Down If Your Host Computer Uses A Static IP
sudo ifconfig tap1 down
sudo ifconfig br0 down
sudo brctl delbr br0
sudo ifconfig eth0 HOST_IP netmask NETMASK up
sudo route add default gw GATEWAY eth0
Replace NETMASK with your router's netmask number. Replace GATEWAY with your router's gateway number.
Script To Bring The Bridge Down If Your Host Computer Uses A Dynamic IP (DHCP)
sudo ifconfig tap1 down
sudo ifconfig br0 down
sudo brctl delbr br0
sudo dhclient eth0
Now you can put the bridge up or take it down at the drop of a hat!
Additional Tunnels for more Clients
- nano -w /etc/network/interfaces
auto tap2
iface tap2 inet manual
up ifconfig $iface 0.0.0.0 up
down ifconfig $iface down
tunctl_user USERNAME
Replace USERNAME with your username and save the file.
Increment tap# to as many as needed
Modify the BridgeUp.sh and BridgeDown.sh script adding for each new tunnel client, matching all the new tap#
Wireless Networking
Setting up a normal bridged network generally doesn't work if you're bridging from a wireless card to VirtualBox. A simple script that utilises the parprouted tool will allow your VM full access to the wireless network.
You will require parprouted to do this:
sudo apt-get install parprouted
Next, using your favourite text editor, create and edit the script, for example:
sudo nano /etc/network/if-up.d/vbox_network
Then, enter the script (replacing $USER with your username (or whoever you intend to run virtualbox as)). Replace wlan0 with the name of your wireless interface. Use an available IP address on your network for tap0 (I have used 192.168.1.100 in this case):
sysctl net.ipv4.ip_forward=1
VBoxTunctl -b -u $USER
ip link set tap0 up
ip addr add 192.168.1.100/24 dev tap0
parprouted wlan0 tap0
Finally, make sure the new file is executable by root:
sudo chmod 700 /etc/network/if-up.d/vbox_network
Now your networking script is installed, the virtual interface tap0 will be available on boot for VirtualBox. Rather than reboot, let's just run the script now:
sudo /etc/network/if-up.d/vbox_network
The final thing to do is tell VirtualBox to use the new virtual device tap0. Open VirtualBox, highlight a VM and click settings. Now choose the network option and select Host Interface on the 'attached to' drop down menu. In the Interface Name text box, enter: tap0
Click ok and start your VM. The VM should now behave as though it was another physical machine on your network!!
For more information on the process up to this point, please visit Bridged Networking with VirtualBox on Linux Hosts
Using DHCP in the Guest VM
It was possible to get DHCP to work on the guest virtual machine. Instructions were taken from here. Because parprouted does not relay multicast, we need to use an additional helper daemon to manage this. I tried dhcp-helper and bcrelay, and had the most success with bcrelay.
Use it as follows:
sudo apt-get install bcrelay
sudo bcrelay -i tap0 -o wlan0
At this point, my /etc/network/if-up.d/vbox_network is as follows:
sysctl net.ipv4.ip_forward=1
VBoxTunctl -b -u jacob
ip link set tap0 up
ip addr add 192.168.1.200/32 dev tap0
parprouted tap0 wlan0 &
route add -net 192.168.1.0 netmask 255.255.255.0 tap0
bcrelay -i tap0 -o wlan0 &
It seems that I have to start the script by hand after boot. Other than that, host networking now seems to work fine.
USB
To get USB support, you need the PUEL version. Via the GUI, there is an option to enable USB.
Furthermore, your user must be able to access /proc/bus/usb/*
Since Gutsy, /proc/bus/usb is not mounted by default. You need to edit /etc/init.d/mountdevsubfs.sh and uncomment the following lines:
#
# Magic to make /proc/bus/usb work
#
mkdir -p /dev/bus/usb/.usbfs
domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
ln -s .usbfs/devices /dev/bus/usb/devices
mount --rbind /dev/bus/usb /proc/bus/usb
In order to give users in the vboxusers group write permissions to the devices in /proc/bus/usb, you'll need to edit some rules in /etc/udev/rules.d.
Under gutsy, edit /etc/udev/rules.d/40-permissions.rules to say the following:
# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", MODE="0664", GROUP="vboxusers"
Under hardy, edit /etc/udev/rules.d/40-basic-permissions.rules to say the following:
# USB devices (usbfs replacement)
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664", GROUP="vboxusers"
SUBSYSTEM=="usb_device", MODE="0664", GROUP="vboxusers"
Then, restart the udev service:
sudo /etc/init.d/udev restart
Now, if you haven't done it already, make sure your user is part of the group vboxusers using the following command:
sudo adduser $USER vboxusers
http://www.virtualbox.org/ticket/747
Sharing Folders Between Host and Guest
Note: Before trying to mount/map shared folder you must install Guest Additions (run machine and choose "Install Guest Additions" form Device menu of machine window.
Note: The client OS can not be open when adding share.
On the host (ubuntu) computer, run
mkdir ~/VirtualBoxShare
VBoxManage sharedfolder add "XP" -name "share" -hostpath /home/your/shared/folder/VirtualBoxShare/
Where "XP" is the name of the virtual machine in VirtualBox, and "share" is the name of the share as the guest machine will see it. The hostpath must be a fully-qualified path.
On the Windows client, run
net use x: \\vboxsvr\share
If the client is Linux, run
mount -t vboxsf share mountpoint
For the above command if you get error as
mount: unknown filesystem type 'vboxfs'
Then just change the vboxfs to vboxsf means the command will be
mount -t vboxfs share mountpoint
For the above command if you get error as
mount: unknown filesystem type 'vboxfs'
Then just change the vboxfs to vboxsf means the command will be
mount -t vboxsf share mountpoint
See Section 4.4 Folder Sharing in the VirtualBox documentation.
Using VirtualRDP (VRDP) to View Guest VMs
VirtualBox has builtin RDP support, much like VMware's Remote View (VNC), however it does take some tinkering to get working on Ubuntu Desktop / Server.
The main issue is when trying to use PAM authentication, on the host system, to authenticate remote users who wish to RDP into a Virtual Machine. PAM needs to be configured to allow the VRDPAuth.so library access to PAM services. This can be done by
1. Creating a new PAM configuration file
sudo gedit /etc/pam.d/vrdpauth
and adding the following lines
auth required pam_unix.so
account required pam_unix.so broken_shadow
Save the file
2. You now need to set an environment variable so that VRDPAuth.so uses the correct PAM Service instead of the /etc/pam.d/login service:
export VRDP_AUTH_PAM_SERVICE="vrdpauth"
- You can alternately set this as part of your .bashrc to save retyping at each login.
Support
For help with virtualbox beyond the scope of this documentation, see the VirtualBox Community Page or for live assistance try #vbox on irc.freenode.net in an IRC client.
VirtualBox (editada pela última vez em 2008-10-15 11:05:10 por enekonieto)
Nenhum comentário:
Postar um comentário