Monday, November 15, 2010

How to hide VirtualBox menu and status bars

VirtualBox machine window is adorned with menu bar at the top and status bar at the bottom. You can hide both to save on valuable disk space.

For Windows XP Desktop (Host):
  • If not already, add VirtualBox executable path to your %PATH% environment variable in Windows:
    • Bring System Properties dialog with My Computer->Properties->Advanced
    • Click on Environment Variables
    • Edit Path system variable and add C:\Program Files\Oracle\VirtualBox path. 

  • Under Windows:
    • From Start button, run 'cmd' command to open command shell.
    • To modify global configuration settings of the VirtualBox, type in the command:

C:\> VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar

When you restart next time your Guest Virtual Machine, you should get optimized view.

To bring back the menu popup, press the Host key and Home key. My Host key is mapped to Right Ctrl, so the combination would be {Right Ctrl}-{Home}.

Thursday, November 11, 2010

Configure VirtualBox Host-to-Guest ssh port forwarding with NAT

My Host OS : WindowsXP
My Guest OS: is Linux Fedora Core.

By default, VirtualBox sets up new Guest with NAT (Network Address Translation) configuration.

NAT configuration forms a private network between Host and the Guest. The Host takes a role of a router that maps the incoming/outgoing traffic of a NAT Guest transparently.

The annoying fact, however, is that this private network is not visible even from the Host machine. With default settings I cannot ssh or sftp from WindowsXP Host to Linux Guest. None of the network services such as Apache web server, or ssh daemon, or my own services that I might want to run on the Guest are visible to the outside world, including the Host itself.

This is a major inconvenience that defeats the purpose of running various virtual Guests in a first place.

To overcome this obstacle, we need to enable NAT port forwarding.

Essentially, with port forwarding, we ask NAT engine to route external traffic that arrives on a certain port of a Host to a different port on Guest.

The ssh daemon that runs on my Linux Guest listens for incoming connection requests on port 22. We are going ask NAT to route external traffic that arrives on port 2222 to the Guest's 22.

The preparation steps:
  • Shut down Linux Guest
  • Exit VirtualBox application
  • Add VirtualBox path to %PATH% variable:
    • Bring System Properties dialog with My Computer->Properties->Advanced
    • Click on Environment Variables
    • Edit Path system variable and add C:\Program Files\Oracle\VirtualBox path.
To setup port forwarding: 

 c:\> VBoxManage modifyvm "salmon" --natpf1 "guestssh,tcp,,2222,,22"

Where:
  • 'tcp' is mandatory protocol type (could be 'udp' as well)
  • 'guestssh' is a description name that can be used to identify and remove the port forwarding
  • The first skipped generic parameter between commas of "tcp,,2222" is external interface IP. By default, all traffic that might arrive on port 2222 of every network interface (localhost, LAN, WiFi, etc.) is routed to port 22 of the Guest. However, you can be more restrictive, and say allow only local traffic from 127.0.0.1 to be routed to the Guest.
  • The second skipped generic parameter between commas of "2222,,22" is used to specify static IP address of the Guest if it is assigned one by VirtualBox in favor of dynamically-assigned DHCP address.
To remove port forwarding:

c:> VBoxManage modifyvm "salmon" --natpf1 delete "guestssh"

To test the connection:
  • Boot the Guest OS.
  • Login in to Linux and make sure the sshd daemon is running.
  • On Windows XP desktop,
    • Start WinSCP free scp/sftp client.
    • Connect to IP: 127.0.0.1 Port: 2222
You should be able to login now into your Guest and transfer files.

Source: VirtualBox Manual  

Tuesday, November 9, 2010

FedoraCore VirtualBox Guest setup

How to setup FedoraCore Guest in VirtualBox inWindowXP host.
  • Download VirtualBox installer from Oracle web site and install Oracle VM VirtualBox.
  • Launch Oracle VM VirtualBox.
  • Change the default Folder location for HardDisk and Machine:
    • Go to File->Preferences->General
    • Change location of Default Hard Drive Folder.
      • c:\MyStuff\VirtualBox\HardDisks
    • Change location of Default Machine Folder.
      • c:\MyStuff\VirtualBox\Machines
  • Create new virtual machine:

    • Click on New icon.
    • On Welcome screen, click Next.
    • On VM Name and OS Type screen, enter
      • Name: salmon
      • OS Type:
        • Operating System: Linux
        • Version: Fedora
      • Click Next
    • On Memory screen, 
      • set the Base Memory Size to 1024 MB.
      • Click Next
    • On Virtual Hard Drive screen
      • Check Boot Hard Drive
      • Select Create new hard disk
      • Click Next
    •  On Hard Disk Storage Type screen
      • Select Dynamically allocated
      • Click Next
    • On Virtual Disk Location and Size screen
      • Make sure the location of salmon is under c:\MyStuff\VirtualBox\HardDisks
      • Set the initial size to 32 GB (10GB is the bare minimum).
      • Click Next
    • On Summary screen
      • Click Finish
  • Adjust Virtual Machine salmon settings
    • Click on Setting icon
    • In salmon - Settings screen 
      • Select System/Motherboard tab 
        • Under Boot Order section
          • Uncheck Floppy entry
        • Under Extended Features
          • Leave Enable IO APCI unchecked
      • Select System/Acceleration tab 
        • Make sure 
        • VT-x/AMD-V is enabled
        • Nested Pages is enabled

      • Select Display/Video tab
        • Enable 3D Acceleration
      • Select Display/Storage tab
        •  Under Storage Tree in IDE Controller, select Empty CD icon.
        • To install directly from physical Fedora i386 DVD, you need to connect a physical host device (such as DVD drive) to your virtual machine. For that, under Attributes:


          • Click on a little DVD icon to the right of the CD/DVD Drive selection. Click on "Host Drive D:".  The IDE Controller child entry will change to 'Host Drive D:' selection.
          • Select Passthrough option. 

      • Select Audio tab.

        • Check 'Enable Audio' box
        • Select 'Windows DirectSound' audio driver
        • Select 'ICH AC97' audio controller
  • Insert Fedora Core DVD disk in DVD drive.
  • Click on the Start button to begin installation
    • Set Hostname to your Host machine name (with full domain name)
    • Choose Customize now option and select
      • Choose GNOME Desktop Development
      • Under Applications select
        • Authoring and Publishing
        • Editors
        • Graphics Internet
        • Graphics
        • Office/Productivity
        • Sound and Video
        • Text-based Internet (for wget)
      • Under Development select
        • Development Libraries
        • Development Tools
        • Fedora Packager
        • GNOME Software Development
        • Web Development
        • X Software Development
      •  Under Servers select
        • MySQL Database
        • Network Servers
        • Printing Support
        • Server Configuration Tools
        • Web Server
        • Windows File Server
      • Under Base System in addition to defaults, select
        • Administration Tools
        • System Tools
      • Under Languages
        • add Russian Support
    • Continue with installation (grab a sandwich or something...). This will take a while.
  • Reboot after installation is complete and
    • Create user account
    • Setup Network Time Protocol server
    • Enable sudo access for your login account:
      • $ su -
      • Password: {your superuser password}
      • # /usr/sbin/visudo
      • {edit /etc/sudoers file and add} 
        • {username}  ALL=(ALL) ALL


  • Install Guess Additions
    • Guest Additions add very useful functionality:
      • X server driver with higher screen resolution
      • Seamless cut-n-past between Host and Guest OSes
      • Mouse driver that integrates host and virtual desktop spac
        To install Guest Additions:
    • Install development tools to be able to compile kernel drivers:
      • # yum groupinstall "Development Tools"
    • Check if running guest VM window has its menu bar at the top shown. If not, shutdown the VM machine and re-enable it for the guest.
    • In the Oracle VM VirtualBox menu, click on Devices->Install Guest Additions 
    •  
    • In the Guest Virtual Machine (VM), GNOME desktop will detect new media inserted, VBOXADDITIONS_3.2.10_66523.
    • Click Cancel to dismiss the dialog.
    • Open terminal with Applications->System Tools->Terminal

    • $ cd /media/VBOXADDITIONS_3.2.10_66523
    • $ sudo sh ./VBoxLinuxAdditions-amd64.run
    • When Guest Additions installation is complete, right click on CD icon on the desktop and Eject it.
    • Release the cursor and in the Oracle VM VirtualBox menu, click on Devices->CD/DVD Devices click on 'Host Drive D:' to unmount GuestAdditions.iso image.
    • In the Virtual Machine, edit /etc/X11/xorg.conf to add screen resolutions that matches your primary desktop/laptop screen.
      $ sudo vi /etc/X11/xorg.conf
      
      Section"Screen"
      SubSection "Display"
      Modes "1900x1200" "1280x1024" "1024x768" "800x600"
      Depth 24
      EndSection
      ...
      EndSection
      
    • Reboot the Virtual Machine. Now you should have the resizable desktop with fullscreen mode available as well. 
  • From you account in the VM, 
    • Disable Firewall.
    • Set SELinux mode to Permissive.
  • To setup USB pass-through support,
    • In the Linux guest VM, Create 'usb' group and add yourself as a user to that group.
    •  Shut down guest VM
    • In the VirtualBox window manager, select the virtual machine and open its Settings dialog.
    • Under USB settings,
      • Enable USB Controller
      • Enable USB 2.0 (EHCI) Controller
      • Add a USB Device Filter
      • Enable the filter
      • Edit filter details and set Remote to 'Any'

    • Restart the guest VM
    • When Linux desktop appears, have focus on the desktop
    • Insert the USB stick.
    • First time around, Windows XP would detect a new hardware profile. Go on with driver installation to install VirtualBox USB driver.
    • In the guest VM, under Devices tab, select the USB stick.
    • The USB device should appear on your Linux desktop as icon.

    • NOTE: For a while, I was getting this error from VirtualBox's guest VM:
      USB device SanDisk USB U3 Cruzer with 
      UUID [some id] is busy with a previous request. 
      Please try again later.
      
      Result code: E_INVALIDARG (0x80070057)
      Component:   HostUSBDevice
      Interface:   IHostUSBDevice {some id}
      Callee:      IConsole {some id} 
      In my case the error was ultimately resolved by creating the "usb" group under guest VM as outlined above. For further information, please, refer to VirtualBox bug #3033 (USB device not available to Guest)

Strip leading path with GNU tar

Sometimes, when I untar an archive file, I need to strip leading path from the archived files. For example, if my archive is stored on a DVD disk the following command would unpack it to my home directory and strip the leading path name:

shell> cd $HOME
shell> tar --extract --file /mount/Backups/home-bkp-11082010.tar.gz --strip-components=1 

Essentially, if my original backup had a  file vlg/foobar.txt, the vlg/ part of the path would be stripped out.

This comes very handy if the backup file was created with something like:

shell> cd /home
shell> sudo tar xvfz home-bkp-11082010.tar.gz vlg