Installing Windows 7 into a virtual machine on FreeBSD using VirtualBox
My job at LANDesk requires that I write code in C# for an application that only runs on Windows Server. I also have to test a lot of code on Windows 7. Like me, so many people are forced to run a version of Windows because they have special windows applications at work or because that is the platform we are developing for in our jobs.
If running windows is a must for you, as it is for me, then moving to FreeBSD exclusively is just not an option. I want to run an FreeBSD, but running Windows 7 is a must too.
At first VMWare Workstation looked like it was going to solve this problem. But while its early versions worked on FreeBSD, they failed to port newer versions over. Quemu just never could get to level of usability needed. Well, along comes VirtualBox from Sun. Sun, now Oracle, released an open source edition cleverly named VirtualBox Open Source Edition (OSE). Like many of Sun’s code, it is duel licensed.
Prerequisites
- A FreeBSD desktop – Hopefully you are here because you already have this. If you don’t have a FreeBSD desktop, you can follow my guide to build one.
How to install and configure a FreeBSD 8 Desktop with Xorg and KDE?
Or you can install and use PC-BSD which is a nice desktop version of FreeBSD. - A Windows 7 DVD or ISO and a product key. Please do not pirate!
Step 1 – Installing VirtualBox OSE on FreeBSD 8.1
Installing VirtualBox is not complex. It involves only a few steps.
- Go to the directory for virtualbox-ose in your ports tree.
# cd /usr/ports/emulators/virtualbox-ose - Configure your installation.
# make config - Select Guest Additions, as it is not selected by default.
Note: The defaults are Qt4, DBUS, X11, NLS and they should remain checked. - You may also want to select VNC.
- Install virtualbox-ose
# make install
Step 2 – Configuring FreeBD for Virtual Box
There are few things we need to configure on the FreeBSD system to make VirtualBox work.
- Add users to the vboxusers.
- Configure CD/DVD drive access.
- Configure VirtualBox kernel modules to load.
Step 2.1 – Adding use to the vboxusers group
- To add users to the group, use this command:
FBSD# pw groupmod vboxusers -m SomeUserName Step 2.2 – Configure CD/DVD drive access
Note: This is a copy of what is in my document for building a FreeBSD Desktop.
FreeBSD is more secure by default, so something as simple as accessing a CD or DVD or USB drive is not actually allowed by default. You have enable this.
These steps assume that your user is a member of the operator group. Remember above during the installation, I mentioned to make your user a member of both the wheel and operator groups.
- Access a shell and su to root.
Note: The easiest shell to access now that you are in KDE is Konsole. To access Konsole, click the K and go to Applications | System | Terminal. Also you can add the shell icon to your panel by right-clicking on the icon and choosing Add to Panel. - Enable vfs.usermount.
FBSD# sysctl -w vfs.usermount=1 - Configure vfs.usermount to be enabled on boot.
FBSD# echo vfs.usermount=1 >> /etc/sysctl.conf - Open the following file with an editor: /etc/devfs.conf
FBSD# ee /etc/devfs.conf - Add the following lines:
# Allow all users to access CD’s
perm /dev/acd0 0666
perm /dev/acd1 0666
perm /dev/cd0 0666
perm /dev/cd1 0666# Allow all USB Devices to be mounted
perm /dev/da0 0666
perm /dev/da1 0666
perm /dev/da2 0666
perm /dev/da3 0666
perm /dev/da4 0666# Misc other devices
perm /dev/pass0 0666
perm /dev/xpt0 0666
perm /dev/agpart 0666
perm /dev/uscanner0 0666Note: Yes, I copied these from a PC-BSD install’s version of this file.
Note: Change to 0660 to only allow users in the operator group to mount drives.
- Edit the /etc/devfs.rules file.
FBSD# /etc/devfs.rules - Edit the following file: /usr/local/etc/PolicyKit/PolicyKit.conf
FBSD# ee /usr/local/etc/PolicyKit/PolicyKit.conf - Change the xml’s config section from this…
<config version="0.1"> <match user="root"> <return result="yes"/> </match> <define_admin_auth group="wheel"/> </config>
…to this:
<config version="0.1"> <define_admin_auth group="operator"/> <match action="org.freedesktop.hal.storage.mount-removable"> <return result="yes"/> </match> <match action="org.freedesktop.hal.storage.mount-fixed"> <return result="yes"/> </match> <match action="org.freedesktop.hal.storage.eject"> <return result="yes"/> </match> </config>
- Edit the following file with ee: ee /etc/fstab
FBSD# ee /etc/fstab - See if there is a line in the fstab for your CD/DVD-Rom. Comment out or remove the line for your /cdrom. I usually just comment it out by adding a # sign as shown:
#/dev/acd0 /cdrom cd9660 ro,noauto 0 0
- Restart the computer.
You should now be able to mount CD, DVD, and USB drives. You also should be able to both read and write to them, burn disks, write and format USB drives, etc…
Step 2.3 – Configure VirtualBox kernel modules to load
- As root, edit the /boot/loader.conf file.
# ee /boot/loader.conf - Add the following text:
# VirtualBox
vboxdrv_load=”YES” - Save and close the file.
- Edit the /etc/rc.conf file.
- Add the following text.
# VirtualBox
vboxnet_enable - Save and close the file.
Step 3 – Creating your Windows 7 VirtualBox
- Launch Virtual Box.
Note: VirtualBox registers itself with the KDE menu. On my installation, it was in Lost & Found, but on PC-BSD it was under System. Either way you can type VirtualBox in the KDE menu search and find it. Also, VirtualBox is the command and it should in $PATH so you should be able to open any shell from your desktop environment and run VirtualBox and have it open. - Click New. This brings up a Wizard.
- Follow the wizard.
Ok, if you need help with the wizard, here are my steps. - Read and click Next.
- Choose an easy name. I used “W7”.
- Make sure the Operating System is set to Microsoft Windows.
- Change the Version to Windows 7 (64-bit) or if you are on 32 bit hardware still use just Windows 7.
- Click Next.
- Allow at least 1536 MB (1.5 GB) for the base memory size. You can get away with less if you need to. You can do better with more if
- you want to.
- Click Next.
- The Virtual Hard Disk page is already configured correctly, Boot Hard Disk is checked and Create new hard disk is selected. So just click next.
- Read and click Next.
- For Hard Disk Storage Type, I left it set at Dynamically expanding storage.
Comment: This means that even if you use a 100 GB drive, it will only physically use as much space as Windows 7 has used in the Virtual Drive. So if Windows 7 is using 10 GB, even if you have 100 GB drive, the physical size on disk is only 10 GB. This is important information for the next screen. - Click Next.
- I change the drive size to 50 or 100 GB.
Comment: It doesn’t really matter, but it is best to not run out of space either virtually or physically. Read my comment in the previous step. - Click Next.
- Read and click Finish.
You virtual Machine now shows in the list.
Lets move to the next step.
Step 4 – (Optional) Changing Settings on your Windows 7 VirtualBox
I make two changes to my Windows 7 virtual box. As noted above this is optional, but I like to do them.
- Click the settings.
- Click System.
- Change the boot order to be hard drive first.
Note: I make this change because it annoys me it when I install and then reboot the machine after the install and it boots right back to the install media. So I make this change and the press F12 during boot to the CD once. - Uncheck and get rid of the floppy. (Does anyone still use those?)
- Now click on Storage.
- Under the Storage Tree, select your optical drive.
- If you are using an ISO, change the CD/DVD Device to point to the ISO. If you are using a DVD, as I am, choose Host Drive. My host drive says: Host Drive Optiarc DVD RW AD-7910A (cd0). I assume everyone drive will show up slightly different, but should start with Host Drive.
- Click OK.
Your settings should be good to go.
Step 5 – Install Windows 7
Now it is time to install Windows 7.
Don’t pirate! Use a legal product key. Again, just because I like open source does not make me anti closed source. I am not a Microsoft hater and I would hope you aren’t either. Even if you are, that is no excuse for pirating.
- Insert the DVD into your DVD drive, unless you are using an ISO and have already connected it.
- Click the Start icon.
- A new installation window will popup.
Important! You may get a lot of popups telling you about important tips for using VirtualBox. Take time to read them. If you don’t read them or don’t already know what they are telling you, you will wish you had read them. - Click in the window and to have it take control of your mouse and keyboard.
- Press F12 to choose your boot option.
Note: If you miss this, that is OK, you can restart the VM and try to be quicker.
- Once you have pressed F12 in time, you will see the following screen. At this screen, press the letter next to DVD drive.
- Press a key when prompted to boot to the Windows 7 media.
Well, you are off to installing Windows 7. Hopefully you can get Windows 7 installed on your own, cause I am not here to walk you through doing that. Don’t worry, the install media for Windows 7 should be easy enough for you to follow if this is your first time.
Once finished, you will be running Windows 7 on FreeBSD.
Step 6 – Install VirtualBox Guest Additions
Even though all the devices are virtual, drivers are still needed. VirtualBox guest additions installs most of these drivers as well as other features of VirtualBox.
- Log in to your Windows 7 install.
- Select Device | Install Guest additions.
This will mount an ISO and start the installer for VirtualBox Guest Additions inside Windows 7.
- Click Run VBoxWindowsEditions.exe.
- Follow the wizard.
Note: I use the default install location and I check the option to Use Direct 3D support. - Reboot when prompted.
Step 7 – Install the sound card driver
The sound card driver must be installed. VirtualBox uses a virtual device representing the Realtek AC’97 sound card.
- Log back into Windows 7.
- Go to the following web site:
http://download.cnet.com/Realtek-AC-97-Driver-Windows-Vista-Windows-7/3000-2120_4-10962344.html - Download and install the Realtek AC’97 Driver.
- Reboot when prompted.
Your Finished
You now have Windows 7 running. Now you can have the great experience of using FreeBSD as your primary OS and load Windows 7 when you need something requires windows, like I do.
Sources:
http://wiki.freebsd.org/VirtualBox
http://forums.freebsd.org/showthread.php?t=18699
The virtualbox-ose port’s pkg-message - Access a shell and su to root.