VirtualBox on Linux

Install VirtualBox


sudo apt install virtualbox
Install the extension package for VirtualBox if you need it to support USB devices, connect the host webcam, control a virtual machine remotely, and more features like this.

sudo apt install virtualbox-ext-pack -y
Once the extension pack has been installed, you can start using VirtualBox by searching for “VirtualBox” in the “Applications” menu and clicking on the VirtualBox icon.

2. Enable USB 3.0

With this feature enabled, you will be able to use devices connected to USB 3.0 and 2.0 ports on your guest operating system.

To enable this:

  • Open the Oracle VM VirtualBox Manager and select the virtual machine for which you would like to enable the USB support or Mouse, Keyboard.
  • At the top menu of the selected virtual machines, click on “Settings”.
  • Click on the item USB to select it.
  • Click on the USB 3.0 controller.

$ lsusb
Bus 001 Device 016: ID 0ca6:0010 Castles Technology Co., Ltd EZUSB PC/SC Smart Card Reader

Oracle® VM VirtualBox: User Manual for Release 6.0

3.11. USB Support

Oracle VM VirtualBox can enable virtual machines to access the USB devices on your host directly.

To achieve this, Oracle VM VirtualBox presents the guest OS with a virtual USB controller. As soon as the guest system starts using a USB device, it will appear as unavailable on the host.

The VirtualBox needs to be executed as the sudo priveledge or the user has been added to the group "vboxusers":

  
  $ sudo usermod -a -G vboxusers jerry
Then, reboot the host Linux to make it efective.

To list all the USB devices that are connected to your host machine with their respective vendor IDs and product IDs, use the following command:

  
...
UUID:               8544e7f5-d70d-4d3d-b345-f81737941911
VendorId:           0x0ca6 (0CA6)
ProductId:          0x0010 (0010)
Revision:           0.16 (0016)
Port:               3
USB version/speed:  1/Full
Manufacturer:       CASTLES
Product:            EZ100PU Smart Card Reader
...
UUID:               82634456-29f5-4b0c-8edf-bbc694ff17c2
VendorId:           0x047f (047F)
ProductId:          0xc009 (C009)
Revision:           1.50 (0150)
Port:               1
USB version/speed:  2/Full
Manufacturer:       Plantronics
Product:            Plantronics .Audio 400 DSP
...
To enable USB for a VM, select the Enable USB Controller check box.
The xHCI and EHCI controllers are shipped as an Oracle VM VirtualBox extension package, which must be installed separately.

Add support for USB 3.0 on Win 7

As you may know, Windows 7 doesn't support USB 3.0 by default.

In short, because Windows 7 supports USB 2.0 by default and not USB 3.0, VirtualBox defaults to an USB 2.0 controller when you create a virtual machine to install Windows 7.

To use an USB 3.0 controller in a VirtualBox virtual machine under Windows 7, you must first go to the USB section of your virtual machine's settings. Then, select : Controller 3.0 (xHCI).

In the Windows 7 guest operating system, you will see that Windows couldn't automatically install the driver for the used USB bus controller since it doesn't support it by default.

In the device manager, this "Universal Serial Bus (USB) Controller" will appear with a yellow icon as there is no driver for this device.

To solve this problem, you had to download and install the "USB 3.0 Driver: Intel® USB 3.0 eXtensible Host Controller Driver for Intel® 7 Series/C216 Chipset Family" provided by Intel.
The official website of Intel said that this "product" was at the end of life.
Fortunately, the "Archive.org" site had saved these pages, as well as the associated driver. So, you can download this official "Intel USB 3.0 eXtensible" driver via the archive.org cache.

Once installed, Windows 7 will recognize this new USB 3.0 controller.
Then, you enable the host's USB devices to attach to the guest Windows 7 system.

Install VirtualBox Guest Additions

VirtualBox Guest Additions is special software that can be installed inside Linux virtual machines to improve performance and make integration much more seamless. Among the features provided by these VirtualBox Guest Additions are mouse pointer integration and arbitrary screen solutions (e.g. by resizing the guest window).


After your VirtualBox is installed,
  • Click "Devices" -- "Install Guest Additions…"
  • Then start the Linux VM. The iso image can be mounted via /dev/cdrom.
  • Mount VirtualBox Guest Additions
  • On the started Linux VM,
    
    mkdir /media/VirtualBoxGuestAdditions
    mount -r /dev/cdrom /media/VirtualBoxGuestAdditions
    
    Or, you can mount the downloaded iso image,
    
    mount -o loop image.iso /media/VirtualBoxGuestAdditions
    
  • Install dependent packages
  • Install packages fro the started Linux VM,
    • epel
    • 
      ## CentOS 7 and Red Hat (RHEL) 7 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
      
      ## CentOS 6 and Red Hat (RHEL) 6 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
       
      ## CentOS 5 and Red Hat (RHEL) 5 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
      
    • Build packages
    • 
      ## Fedora 28/27/26/25/24/23/22 ##
      dnf install gcc kernel-devel kernel-headers dkms make bzip2 perl
      
      ## Fedora 21/20/19/18/17, CentOS/RHEL 7/6/5 ##
      yum install gcc kernel-devel kernel-headers dkms make bzip2 perl
      
    • Add KERN_DIR environment variable
    • Before building the package,
      
      ## Current running kernel on Fedora 28/27/26/25/24/23/22, CentOS 7/6 and Red Hat (RHEL) 7/6 ##
      KERN_DIR=/usr/src/kernels/`uname -r`/build
      
      ## Current running kernel on CentOS 5 and Red Hat (RHEL) 5 ##
      KERN_DIR=/usr/src/kernels/`uname -r`-`uname -m`/build
      
      ## Fedora example ##
      KERN_DIR=/usr/src/kernels/4.15.6-300.fc27.x86_64/build
      
      ## CentOS and Red Hat (RHEL) example ##
      KERN_DIR=/usr/src/kernels/3.10.0-693.17.1.el7-x86_64/build
      
      ## Export KERN_DIR ##
      export KERN_DIR
      
    • Install Guest Additions
    • 
      cd /media/VirtualBoxGuestAdditions
      
      # 32-bit and 64-bit systems run following
      ./VBoxLinuxAdditions.run
      

The VirtualBox Guest Additions image for MacOS


To locate VirtualBox in the Application folder,
  • right-click it and select show package contents
  • browse to Contents/MacOS/VBoxGuestAdditions.iso
  • copy it to a location that accessible when browsing for files
  • To mount the optical Drives: Choose disk image... and then choose your copied iso file


Installation of VirtualBox (RPM system)


This guide shows howto install VirtualBox 5.2 (currently 5.2.8) on RPM package systems: Fedora 27/26, CentOS 7.4/6.9, Red Hat (RHEL) 7.4/6.9.

This guide uses Virtual Box own yum repositories.

Prepare and update the packages

  • Install Fedora or RHEL Repo Files
  • 
    cd /etc/yum.repos.d/
    
    ## Fedora 27/26/25/24/23/22/21/20/19/18/17/16 users
    wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
    
    ## CentOS 7.4/6.9 and Red Hat (RHEL) 7.4/6.9 users
    wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
    
  • Update latest packages and check your kernel version
  • 
    ## Fedora 27/26/25/24/23/22 ##
    dnf update
    
    ## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
    yum update
    
    ## Output of following commands version numbers should match
    rpm -qa kernel |sort -V |tail -n 1
    uname -r
    
  • Install following dependency packages
    • epel
    • 
      ## CentOS 7 and RHEL 7 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
      
      ## CentOS 6 and RHEL 6 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
      
      ## CentOS 5 and RHEL 5 ##
      rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
      
    • binutils
    • 
      ## Fedora 27/26/25/24/23/22 ##
      dnf install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms
      
      ## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
      yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms
      
      ## PAE kernel users install ##
      ## Fedora 24/23/22 ##
      dnf install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-PAE-devel dkms
      
      ## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
      yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-PAE-devel dkms
      
  • Install VirtualBox Latest Version
  • 
    ## Fedora 27/26/25 ##
    dnf install VirtualBox-5.2
    
    ## Fedora 24/23/22 ##
    dnf install VirtualBox-5.1
    
    ## CentOS/RHEL 7/6 ##
    yum install VirtualBox-5.2
    
    This command create automatically vboxusers group and VirtualBox user must be member of that group. This command also build needed kernel modules for the host Linux system. Rebuild kernel modules with following command:
    
    ## Fedora 27/26/25/24/23/22/21/20/19 and CentOS/RHEL 7 ##
    /usr/lib/virtualbox/vboxdrv.sh setup
    
    ## CentOS/RHEL 6 ##
    /etc/init.d/vboxdrv setup
    ## OR ##
    service vboxdrv setup
    

System Administration

  • Add VirtualBox User(s) to vboxusers Group
  • Add some another real user account in the vboxusers group.
    
    usermod -a -G vboxusers user_name
    
  • Start VirtualBox
  • Use belongs to the vboxusers group can launcher it from menu or simply run:
    
    VirtualBox
    

Troubleshoting


If you have problems with KERN_DIR parameter or your kernel directory while installing dependency packages, using following method then do it again:

## Current running kernel on Fedora ##
KERN_DIR=/usr/src/kernels/`uname -r`
 
## Current running kernel on CentOS and Red Hat (RHEL) ##
KERN_DIR=/usr/src/kernels/`uname -r`-`uname -m`
 
## Fedora example ##
KERN_DIR=/usr/src/kernels/2.6.33.5-124.fc13.i686
 
## CentOS and Red Hat (RHEL) example ##
KERN_DIR=/usr/src/kernels/2.6.18-194.11.1.el5-x86_64
 
## Export KERN_DIR ##
export KERN_DIR

留言

熱門文章