Run Windows and Linux simultaneously in a single computer, share files between using Samba and vboxsf

In this demo,  we will setup Windows 7 to host a Debian server as guest operating system using VirtualBox 4.2.4,  the latest version as of blog time.   This virtualization setup may be useful for learning Linux without having to have a separate PC.   The setup may also be useful for testing Linux application before they are deployed to a live server.

We use Samba to move files between operating systems as well as demonstrate how to share files using VirtualBox's "Shared Folders", the vboxsf filesystem.

It is our assumption that you have a PC capable of virtualization.   To check if your computer's processor supports virtualization download "Microsoft® Hardware-Assisted Virtualization" detection tool here http://www.microsoft.com/en-us/download/details.aspx?id=592. When downloaded simply run it to get the summary of your processor's features.

For better performance it is best to use a 64bit version of Windows 7, although not required by VirtualBox.  From this point, it is assumed that you have a 64bit Windows on a 64bit physical machine with enough memory (RAM) and sufficient disk space.  For memory requirements, we cannot say exactly how much you need but consider this, my main Windows 7 development machine has 4GB of RAM running Netbeans and VS2010 at the same time and I can still run 2 VirtualBox Debian guests with 512MB each of RAM without problems.

VirtualBox

Download VirtualBox here https://www.virtualbox.org/wiki/Downloads, it is free.   Pick the latest download for Windows.  Install them to your Windows machine.   This should be straightforward, just follow the prompts.  This is no different than installing a regular Windows application.   When installed, your Windows machine is ready to host a VirtualBox guest.

Additionally, to enable USB support in your Guest, also install "VirtualBox 4.2.4 Oracle VM VirtualBox Extension Pack" which can be downloaded in the same location of the main VirtualBox software. Install them when the main VirtualBox software completes installation.

Debian

Download Debian here http://www.debian.org/distrib/netinst and take note the location of the downloaded file. The download should be an ISO image file. Pick the 64bit version of "Small CDs" that matches your system achitechture, that is, if you have AMD64 download the one for AMD64, etc.

Create the Guest

Run VirtualBox and look for "New" at the toolbar or in the menu of the main VirtualBox frame.  It will lunch a series of Windows following your replies.   They are reproduced below:





(1)  Enter any desired name in the edit box.  This is the name of your Guest, you can make up for any name you want.

Select the type and version of the operating system you are planning to install.  In our case, they are Linux and Debian 64 bit version respectively.

Click next.
    Install VirtualBox Step 1





(2)  Use the slider to setup the desired amount of memory (RAM) to assign to the guest machine.  For this demo, we use 512 MB of RAM.  Note that if you are planning to use this as a test machine for a live server, it would be best to match the RAM of the live server.

Click next.
    Configure RAM,  Step 2





(3)  Select "Create a virtual hard drive now".

click create.
    Create virtual hard drive,  Step 3





(4)  Select VDI (Virtual disk image) for hard drive type.

Hit next.
    Virtual Hard drive type,  Step 4





(5)  Select fixed size as the type of storate.

Click next.
    Storage on virtual hard drive, step 5





(6)  Create the disk image.  You may accept the default location or browse to where you want the image created.

Adjust the size of the disk image through the slider.  As mentioned in the memory setup, if you are using this setup as a test machine, you may want the same disk size as your live server.  In our example here, we create a 20 GB storage.

Hit create when ready.

The create process may take time depending on the size of the disk image you provided.
    Determin the size of harddrive,  Step 6





(7)  Complete.  Our Guest Virtual machine has just been created. At this point it is like a computer with no operating system in it yet.

Note that since we just created a guest, you should have only one entry in the list and should only be the circled item.
    Install VirtualBox Step 7



Install Debian into our Guest Virtual Machine.

This step requires the Debian ISO image file downloaded earlier.  From step 7, above, double click on the newly create guest.  You should see a window similar to the graphic that follows.





Browse to the downloaded Debian ISO image file and select that file.

Hit start.
    Debian as guest OS Step 1





This is start of Debian installation process.  This is the same as you would install Debian in a "real" computer.
    Install VirtualBox Step 1

We wish not to go into the details of installing Debian, instead we just refer you to an external article that will guide you through the installation process. Here is that article http://www.howtoforge.com/perfect-server-debian-squeeze-ispconfig-2. At the software installation sections of that article, just escape what you don't need.

We assume at this point that you have successfully installed Debian into our Guest machine.


Setup VirtualBox Guest

From VirtualBox main window, select the Vitual Guest just created, and for later convenience, create a short cut to this guest by right click on this item and click on "Create Shortcut on Desktop", you use this shortcut, in the future, to run the guest directly without going through the VirtualBox window each time.

Click on settings to get the following Window, to setup your network adapter.




Select Network from the left side of the Window and then adjust where the adapter is attached to what works best for you.

For some people the default, which is NAT, is fine. In our case, "Bridged adapter" always works, so we use it here.
    Install VirtualBox Step 1

Install "Guest Additions"

VirtualBox "Guest addition" is required if you want to use devices such as CD/DVD.  It is also required for sharing folders between host OS (Windows) and the guest Debian.  Guest Additions is installed from the menu bar of Guest frame.   So go ahead and run your virtualBox Guest.   It should look like the Window below.


Right after you login to the Debian OS, look for Devices at the menu and click on "Install Guest Additions" as shown in the graphic to your right side.  It will ask you to confirm to download the Guest Addition Image file, like the graphic shown below

Download VirtualBox Guest Addition

Simply respond "Yes".   Also respond "Mount" if prompted to mount Virtual CD/DVD drives.
    Install VirtualBox Step 1

Please note that, "Guest Additions", when installed, becomes available to the current VirtualBox guest and subsequest guests that you add or create.

Setup Shared Folders

"Shared Folders" (vboxsf) of VirtualBox is sharing host (Windows) folders to the Guest OS (Debian).   From the Devices menu shown in the previous graphic (right side) click on "Shared Folders" as shown circled in blue.  This is the same routine found in the Settings Window from the main frame of VirtualBox.

Browse to the folder you want shared from the right-most red-circled button (right graphic). Browse will give you the window below.

Configure VirtualBox shared folders Step 2

The "folder name" you specify is the name you use to mount the shared folder.
Configure VirtualBox shared folders Step 1

Mount Shared Folders

To access the "Shared Folders" described in the previous section, you have to mount it.   Login to VirtualGuest OS, (into Debian) and become root and enter the following:

mount -t vboxsf [window_shared_folder] [linux_shared_folder]

Make sure the "window_shared_folder" is the same as the name if specified when you created the shared folder.   In the screen capture above (left image), this should be lagrenee.    Also make sure "linux_shared_folder" is an existing folder in the Guest OS.  It is a protocol error if either or both do not exist.

Using Samba

This is the opposite of VirtualBox shared folders.  Samba shares Guest (Debian) folders to Host (windows) .   Install Samba using the following.   You must be root to install it.

apt-get update
apt-get install samba

The install scripts will prompt for workgroup name. This default is WORKGROUP. This should match with the workgroup defined in Windows.   To check the Windows workgroup name, get into Start/Computer.  From Computer window, right click and click on the Properties, the Worgroup name should be near the bottom of the Properties window.

Then update your samba configuration, smb.conf, which is located at /etc/samba. Look under "Authentication" section and uncomment (remove the # sign in front of the line) the security entry. It should set security = user. Go to the bottom of that file and add a shared folder entry.   A sample should look like below:

[Guest-OS Shared Folder]
	path = /home/user/Shared-Folder
	browsable = yes
	read only = no
	guest ok = no

Then add a samba user.  To enable a seamless integration between Guest and Host, it would be best if the samba user/password is identical to the Windows user/password.

smbpasswd -a user
# supply password

Restart Samba

/etc/init.d/samba restart

After a few moments, your Samba Shares, from the guest OS, should appear in the "Network" section when you open your Windows Explorer. If for some reasons it does not appear immediately, enter \\ip-address from the address bar of Windows Explorer.

That's it Good Luck.

If you like the article, please share.
(Site URL pattern has changed as a result social actions counter was reset.)



Comment icon   Comments (Newest first)