Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

How To Connect to a Local Directory on a Windows Host with a Linux Guest in VirtualBox

Recently I felt the need to retrieve files from my Windows host on my Linux guest in VirtualBox 4.2.6. This is an easy task with the VBoxAdditions installed on the guest OS and a simple change in the shared folders in VirtualBox.

If VBoxAdditions are not installed on the guest host you must first get them installed. If you are running Fedora 17 or 18 look here for the instructions.

Next make sure to power off the guest VM and once powered off open the Settings for the VM and click on Shared folders.

shared1

Click on the add folder icon on the right side and a dialog box will open asking for the folder to add, you can type in the path ex: c:\Download or browse for it by selecting the drop down and select Other.

shared2

Insert a Folder Name and select Auto-mount. Click OK to accept the changes and restart the guest VM.

shared3

Once you have logged into your Linux VM you are ready to create a directory to mount and then mount the shared folder. In this example I have created the /mnt/share folder. Now all that is needed is to execute.

$ sudo mount -t vboxsf Download /mnt/share

Now we can get to the files but this command will have to be run every time, so why not create a shell script called mntshare.sh and just populate it with the exact command you ran. Now each time you start the VM you just run ./mntshare.sh.

Note that with this, the default mount options are used and all files are owned by root. This can be changed by adding some mount options. Options are passed on with the -o parameter. You can use multiple options with one parameter, separate the values with a comma.

$ sudo mount -t vboxsf -o uid=1000,gid=1000 Download /mnt/share

And that is all there is to creating and accessing a shared folder in VirtualBox.

How To Install VBoxAdditions on Fedora 18

With the latest Fedora release now out it is time to get it installed as a VM in VirtualBox and get the VBoxAdditions installed. First make sure you have VirtualBox 4.2.6 installed and then install Fedora as a VM as you usually do. Once you have all the latest updates installed and a few added programs, you are ready to install the VBoxAdditions.

First you will need to install gcc kernel-devel kernel-headers dkms make bzip2

$ sudo yum -y install gcc kernel-devel kernel-headers dkms make bzip2

Now lets mount the VBoxAdditions, click Devices > Install Guest Additions.

vbox-guest-additions

VirtualBox will mount it to /run/media/<userid>/VBOXADDITIONS_4.2.6_82870. Open a terminal and change to the directory. Substitute <userid> with your login id.

$ cd /run/media/<userid>/VBOXADDITIONS_4.2.6_82870
$ sudo ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.2.6 Guest Additions for Linux.........
VirtualBox Guest Additions installer
Removing installed version 4.2.6 of VirtualBox Guest Additions...
Removing existing VirtualBox DKMS kernel modules           [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Building the OpenGL support module                         [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers
Installing X.Org Server 1.11 modules                       [  OK  ]
Setting up the Window System to use the Guest Additions    [  OK  ]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services component[  OK  ]

Now all that is left is to reboot.

 

How To Set Your VirtualBox 4.2 VM to Automatically Startup

Being system administrators and tweakers we always like to make things automatically take care of themselves, right? Well of course we do and that’s where any auto starts we find are likely to get put in place.

A new feature added in VirtualBox 4.2 is autostart, this feature is available in Linux, Solaris and MacOSX hosts only. Let’s say there is a VirtualBox VM you start everytime  you startup your system, why not make it startup as soon as you start VirtualBox. I am using Fedora 17 for this example.

First you need to create the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings. The file should look similar to this:

# vi /etc/default/virtualbox
# virtualbox defaults file
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/vbox.cfg

Update: It has been commented that the file named vbox.cfg didn’t work for some. They have been successful using autostart.cfg, if vbox.cfg doesn’t work for you, then trying naming the file autostart.cfg.

Now we need to create /etc/vbox/vbox.cfg file and add

# Default policy is to deny starting a VM, the other option is "allow".
default_policy = deny
# Create an entry for each user allowed to run autostart
myuserid = {
allow = true
}

If you are the only user you can just add the line default_policy = allow to the vbox.cfg file.

Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
# chgrp vboxusers /etc/vbox
# chmod 1775 /etc/vbox

Add each of the users to the vboxusers group. Make sure to check their group memberships so they do not loose any groups they currently have assigned to their id.

# groups myuserid
myuserid wheel

# usermod -G wheel, vboxusers myuserid

Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

$ VBoxManage setproperty autostartdbpath /etc/vbox

Now we are ready to set the VM’s we choose to start.

$ VBoxManage modifyvm --autostart-enabled on

This will create a myuserid.start  file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
# service vboxautostart-service restart

Reboot your system and your VM should start

VirtualBox 4.1.20 Released

VirtualBox 4.1.20 Released !!! make sure to update your installation to get the latest bugfixes,!
This is a maintenance release. The following items were fixed and/or added:

  • VMM: fixed a crash under rare circumstances for VMs running without hardware virtualization
  • VMM: fixed a code analysis bug for certain displacement instructions for VMs running without hardware virtualization
  • VMM: fixed an interpretion bug for TPR read instructions under rare conditions (AMD-V only)
  • Snapshots: fixed a crash when restoring an old snapshot when powering off a VM (bugs #9604, #10491)
  • VBoxSVC: be more tolerant against environment variables with strange encodings (bug #8780)
  • VGA: fixed wrong access check which might cause a crash under certain conditions
  • NAT: final fix for crashes under rare conditions (bug #10513)
  • Virtio-net: fixed the problem with receiving of GSO packets in Windows XP guests causing packet loss in host-to-VM transfers
  • HPET: several fixes (bugs #10170, #10306)
  • Clipboard: disable the clipboard by default for new VMs
  • BIOS: the PCI BIOS was not properly detected with the chipset type set to ICH9 (bugs #9301, #10327)
  • Mac OS X hosts: adaptions to Mountain Lion
  • Linux Installer: fixes for Gentoo Linux (bug #10642)
  • Linux guests: fixed mouse integration on Fedora 17 guests (bug #2306)
  • Linux Additions: compile fixes for RHEL/CentOS 6.3 (bug #10756)
  • Linux Additions: compile fixes for Linux 3.5-rc1 and Linux 3.6-rc1 (bug #10709)
  • Solaris host: fixed a guru meditation while allocating large pages (bug #10600)
  • Solaris host: fixed possible kernel panics while freeing memory
  • Solaris Installer: fixed missing icon for menu and desktop shortcuts

Download the latest here and don’t forget to download the latest extensions as well.

Create VM’s from the Command Line with VirtualBox 4

In an earlier post on creating screenshots using vboxmanage command in VirtualBox. Building on using vboxmanage command I discovered that I could create and modify a VM at the command line. This is an awesome feature if you are always building and deleting VM’s for testing an other purposes.

So in this post I want to cover how to create an modify a VM in VirtualBox from the command line. So let’s get typing.

cd C:\Program Files\Oracle\VirtualBox\
vboxmanage createvm --name winxp --ostype WindowsXP --register


Get a list of available ostypes use the vboxmanage list ostypes command. The output will scroll off the screen so add | more to the command so it is easy to move down by using the enter key.

VBoxManage list ostypes | more


Now we have a vm but it has no attached storage and has the defaults, so we need to make changes, this is where the createhd, storageattach, storagectl and modifyvm parameters come in to play.

First lets create a disk and attach it to the system.

There are many parameters that you can pass to modifyvm, for greater detail you should refer to the online user manual or execute vboxmanage modifyvm | more and page through the various options. Since we are modifying the VM we just created we will just need to modify parameters.

  • network (--nic<1-N> none|null|nat|bridged|intnet|hostonly|generic)
  • memory (–memory)
  • Video Ram (–vram)
  • boot1 (installation)

For our setting we want 512 MB ram, the nic to use NAT, video ram at 128 MB and set first boot to installation DVD. So our syntax is as below.

VBoxManage modifyvm "winxp" --memory 512 --boot1 dvd --nic1 nat --vram 128

Next we need to create a virtual hard disk for the VM and set it to 10 GB.

VBoxManage createhd --filename "winxp.vdi" --size 10000

Now lets add an IDE controller to the VM.

VBoxManage storagectl "winxp" --name "IDE Controller" --add ide --controller PIIX4

Next we will need to assign the vdi (HD) we create earlier to the IDE Controller we added.

VBoxManage storageattach "winxp" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "winxp.vdi"

Attach the ISO file that contains the operating system installation that you want to install later to the virtual machine, so the machine can boot from it.

VBoxManage storageattach "winxp" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /path_to/winxp.iso

Finally lets start the VM using the VBoxHeadless command to start the installation. If successful you will see a copyright notice.

VBoxHeadless --startvm "winxp"

Thats all there is to create a VM in VirtualBox from the command line. There are other settings that have to be set through the GUI that cannot be set from the command line. There are also more settings that can be done from the command line. Explore and see what else is possible by using vboxmanage!!

 

Creating Virtualbox Screenshots with VBoxManage

As a system admin by day I am always documenting how something was done so that others can do it themselves and also as a blogger as well. Text is wonderful but sometimes pictures are much better at explaining.

With Windows and Linux there are many point and click solutions like Snipping Tool (Windows 7), KSnapshot (KDE) and many others, but sometimes the command line is better and can be scripted.

One such documentation task I recently completed was relying heavily on Virtualbox and what I was needing was the whole screen and not a cropped image. Luckily the VBoxManage command includes a parameter controlvm (screenshotpng) to accomplish such a task.

The syntax is:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "" screenshotpng 

As an example mhlinux3 is the name of my vm and test1.png for the filename. So the command will look like

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "mhlinux3" screenshotpng c:\temp\test1.png

Pretty simple. So now lets automate it and create a command script that prompts for a filename. We can use the set command to define the variables and set /P to prompt for the filename.

For the variables we need to set the filename, the vboxmanage command, the output directory and the vm. For the output directory I have created a screenshots folder on the desktop. Below is the script which is saved as vmsnap.cmd on the desktop.

echo off
rem Create Virtualbox screenshots on windows
rem Prompt for filename
set /P ssname="Enter filename: " %=%
set vboxmanage="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"

rem Specify the output directory
set outputdir=%USERPROFILE%\Desktop\screenshots

rem Specify the name of the VM here of which you want to take a screenshot
set vm=mhlinux3

%vboxmanage% controlvm "%vm%" screenshotpng %outputdir%\%vm%_%ssname%.png

If we double-click on the saved script a command box will appear waiting for a filename.

Enter in the name and press enter and the snapshot will complete and the window will close and if we check in the folder we will see the finished product.

And if we open the screenshot we see the finished product.

Happy snapping !!

Installing FreeNAS 0.8 on Oracle VirtualBox 4.1

As part of creating a Windows 2008 R2 cluster there is a requirement to have iSCSI storage or block storage for the Quorum and other shared storage for the cluster. An easy and affordable way to achieve this is FreeNAS. To keep my development cluster all virtual I found the need to create a FreeNAS instance. In this post I will attempt to share how I was able to achieve the desired results.

The Environment

  • Host: Fedora 16 64 bit
  • 4 GB RAM
  • Oracle VirtualBox 4.1.8

First download the appropriate FreeNAS iso from FreeNAS Sourceforge.

Open VirtualBox and click on New. Give the VM a name and select Operating System > BSD and Version > FreeBSD or FreeBSD (64 bit)click next to continue.

Allocate memory size for the VM. Default value will show 128 MB, I would set it either for 256 MB or 512 MB. For this installation I have chosen 512 MB. Click next when you have made your change.

Now we create the virtual hard disk. The default will appear as 2 GB, this will work well for the OS installation. Click next to appect and move along.

The virtual disk wizard will start and you will be presented with several option. The defaul VDI (VirtualBox Disk Image) will work. Click next to accept.

Accept the default of Dynamically allocated storage and click next.

Accept the default for the name for the disk, this will typically be what you set the name of the VM to.

At last the Summary page will appear. Click finish to create the VM.

Once the wizard has completed we will be back at the VirtualBox Management screen and we can move on to installing FreeNAS.

Start the new VM and the first time wizard will appear, click next.

For  the installation media we will need to select the install ISO downloaded earlier. Once selected click next.

Click Start when ready to boot the new vm. elect the default to install FreeNAS.

Select the hard disk to install and press OK.

Press yes to start the installation.

After the installation has been completed you will be prompted to reboot and disconnect the CD-ROM media. Remove the iso file and reboot.

FreeNAS will start and you will be left at an option screen for further configuration.

At this point we need to add a network interface and configure a static ip to FreeNAS. Select option 1 (Configure Network Interface)

Eneter in the following responses:
Select and interface: 1
Delete existing config? (y/n): n
Configure interface for DHCP? (y/n): n
Configure IPV4? (y/n) y
Interface name: lan1  (note: Make this whatever you like)
IPV4 Address: Type in you ip and subnet mask here. I used a class C non routable address (192.168.1.10/24)
Configure IPV6?: n

Now, FreeNAS 0.8 is ready to connect via web browser, make sure your client PC can ping to virtual machine’s new IP. You may have to change the network adapter setting on your VM.

Open your browser of choice and type in the ip address of your running FreeNAS instance and you will be prompted for the admin id and password (freenas by default)

After successful login you will enter into the FreeNAS interface and ready to add storage and configure.

Look for future posts on adding storage and making available for clusters!!

 

Enable Virtualization on Dell Optiplex 755 to run Oracle VirtualBox 4

Recently I ran into an issue when working on creating a test cluster environment for Windows 2008 R2 with Oracle VirtualBox running on Fedora 16 64 bit on a Dell Optiplex 755.

The issue was VirtualBox would complain about VT-x/AMD-V not being enabled and would stop the VM from loading. After doing some digging around found that there is a specific setting in the BIOS to enable what is needed to enable the settings for 64 bit  VM’s to run. These changes will also work in enabling Hyper-V to run properly on Windows systems.

To fix this, boot the computer and press F2 to enter the BIOS.

In the BIOS you need to change the following settings

Security > Execute Disable (set to On)
Performance > Virtualization (set to On)
Performance > VT for Direct I/O Access (set to On)
Performance > Trusted Execution (set to Off)

Save and exit the BIOS, then power the computer down. it is important that the system be powered down.

After the system was powered up, the VM started properly with 64 bit support.

Install Virtualbox 4.1.8 Fedora 15

Recently I wanted to add a small network to test Windows 2008 clusters and to use for training for Windows 2008 R2 certification. To do this with minimal costs I looked to virtualization. To do that I had to install Virtualbox or VMWare Workstation. While VMWare workstation is great, it costs money., so Virtualbox is the way to go. This post describes how to install Virtualbox on Fedora 15. Look for future posts on how to build a virtual cluster using FreeNAS and Virtualbox.

Open a terminal session on your system.

Copy and import key

$ sudo wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | rpm --import -

 

Add Virtualbox repo to /etc/yum.repos.d.

$ cd /etc/yum.repos.d

$ sudo wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo

$ sudo yum update

 

Install kernel-devel kernel headesr gcc and dkms

$ sudo yum -y install kernel-devel kernel-headers dkms gcc gcc-c++

 Install Virtualbox

$ sudo yum install VirtualBox-4.1

 

Add Virtualbox, or your id, user to Virtualbox user group

$ sudo usermod -a -G vboxusers

 

Now you can open up Virtualbox and start adding VM’s

 

Switch to our mobile site