Saturday, October 18, 2008

Shared Folders and Seamless Windows in Virtual Box

In this final installment of running Ubuntu Linux in Windows Vista with Virtual Box, I'll look at using shared folders and seamless windows. A directory in the Vista filesystem can be used to share files between the Vista host and Ubuntu guest operating systems. Seamless windows allows Ubuntu application windows to be used side-by-side with Vista application windows.

Shared Folders

First the folder to be shared must be created on the Vista host. Open a command prompt by clicking on Start -> All Programs -> Accessories -> Command Prompt. A directory can be created in the resulting location or at the top level of the C:\ drive with the following commands:

C:\users\kleyba> md \virtshare
C:\users\kleyba> exit


Now the folder needs to be accessible to the guest Ubuntu. In the running instance of Ubuntu, from the Virtual Box menu select Devices -> Shared Folders... In the resulting Shared Folders dialog box, select Machine Folders, then click on the folder icon with the plus sign in the upper right. In the Folder Path: drop down box select Other... and navigate to the folder created in the Vista host. The Folder Name: text box will be filled automatically, it can be left as the default. Add a check to the Make Permanent check box, the shared folder will be always available to the Ubuntu guest. Click OK in the Add Share and then Shared Folders dialog boxes to complete this step.

To test the shared folder the share will be mounted manually. Open a terminal window in Ubuntu by selecting from the menu Applications -> Accessories -> Terminal. Using the mount and umount commands test the share:

$ sudo mount -t vboxsf virtshare /mnt
$ mount
$ touch /mnt/virtshare/testfile.txt
$ ls /mnt/virtshare
$ sudo umount /mnt

The first command mounts the the share virtshare, with the vboxsf filesystem type, on the directory /mnt. The /mnt directory in Linux is used for temporarily mounting filesystems. The vboxsf filesystem type, selected by using the -t option to the mount command, is unique to Virtual Box with the Virtual Box Additions. The mount command by itself displays the mounted filesystems, the shared filesystem will be listed last as:

virtshare on /mnt type vboxsf (rw)

The next two commands create a test file with touch and displays the file with ls. Finally, the share is umounted with the umount command. After successful testing the share, it will become permanent by creating a mount point and editing the file with the filesystem static information, /etc/fstab, with the nano editor.

$ mkdir ~/vistashare
$ cp /etc/fstab ~/fstab.backup
$ sudo nano /etc/fstab

The mount point, which is just an empty directory, is created with the mkdir command. The cp command is used to make a backup copy of the fstab file; just a little insurance. The nano editor now displays the content of the /etc/fstab file. Add the follwing line to the end.

virtshare /home/{USER}/vistashare vboxsf rw 0 2

Replace {USER} with the name of your home folder, which is normally your username. To save the file press CTRL+O, then , then CTRL+X.


After the changes are made to /etc/fstab, the shared folder will be automagically mounted whenever the Ubuntu guest is booted. The share can also be mounted with the mount command and -a switch as follows:

$ sudo mount -a

The shared folder can now be used, view the folder by selecting Places -> Home Folder in Ubuntu.


Seamless Windows

The seamless windows feature allows you to display host and guest application windows. The desktop of the guest operating system is suppressed, but the application menu is available. To enable seamless windows press the Host+L keys. A dialog box will display with information on seamless windows, put a check in the Do not show this message again check box and click on the Switch button.


Ubuntu application windows and Vista application windows now are displayed on the Vista desktop. Seamless windows can be disabled by pressing the Host+L keys.

3 comments:

Anonymous said...

Very nice article.

I mentioned your blog up on the DC Coder forums:

http://www.donationcoder.com/Forums/bb/index.php?topic=15473.new#new

Come visit when you get a chance. There's a small but vocal community of Linux advocates to be found there.

Look forward to reading your posts in the future and hope you're able to continue posting.

Best luck,

-40hz

Anonymous said...

Very well written and descriptive article! I had been able to set up the shared folders with ubuntu as a guest on vista, but had to mount them everytime I booted ubuntu. Very clear cut instructions. Thank you!

Unknown said...

Hi SBA,

Thanks for the incredibly clear tutorial you put forward, it is the clearest so far. unfortunately, I am very slow... In the linux terminal after the mount step, the testfile seemed to fail, here is the text displayed.
fabien@fabien-laptop:~$ sudo mount -t vboxsf virtshare /mnt
[sudo] password for fabien:
fabien@fabien-laptop:~$ mount
/dev/sda1 on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.24-23-generic/volatile type tmpfs (rw)
securityfs on /sys/kernel/security type securityfs (rw)
gvfs-fuse-daemon on /home/fabien/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=fabien)
/dev/scd0 on /media/cdrom0 type iso9660 (ro,nosuid,nodev,utf8,user=fabien)
virtshare on /mnt type vboxsf (rw)
fabien@fabien-laptop:~$ touch /mnt/virtshare/testfile.txt
touch: cannot touch `/mnt/virtshare/testfile.txt': No such file or directory
fabien@fabien-laptop:~$

It cannot touch!! Any help would be appreciated. Thanks again for the great effort with this explanation.

Fabien