KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

Tip: How you can share files on your Linux Host with a Windows Guest using Samba

Here’s a quick and simple way to share files on your linux host with a windows guest using samba. This can useful for many reasons as you’ll probably find yourself needing to access files on your host from your guest at some point.  For this example, I’ll be using a linux Fedora 9 host and Windows XP guest. The only requirement is that samba is installed on your host. This procedure is also specifically for running guest using the default mode of networking which is user mode networking.


Install Samba on your host

 First thing you’ll need to do is ensure that samba is installed on your host. In this example we can check on a fedora 9 host with the following command.

[root@localhost ~]# yum list installed | grep samba

samba.x86_64                             3.2.0-2.17.fc9         installed       
samba-client.x86_64                      3.2.0-2.17.fc9         installed       
samba-common.x86_64                      3.2.0-2.17.fc9         installed       
samba-winbind.x86_64                     3.2.0-2.17.fc9         installed       

You’ll have to check on how to install samba on your linux distribution as this will be different for every distribution.  If you’re using a Fedora host and need to install samba, simply type in the following command.

 yum -y install samba

 Once you have verified that samba is installed you can begin configuring samba for sharing directories.


Configure samba share on your host

 All of samba can be configured in one file called smb.conf.  On my Fedora host, this was located in /etc/samba/smb.conf but you’ll have to find where that file is located on your distribution.  My smb.conf file is configured as shown below.

        comment = Host Share
        path = /home/hsolomon
        valid users = hsolomon
        public = no
        writable = yes
        printable = no


The name “LinuxHost” is the name of the share. I’ve also added the system users that will have access to the share, in this case hsolomon.   The other important variable, path,  specifies the directory that you’ll be sharing, in this case it is /home/hsolomon, my home directory.  I’ve also made the share writeable so that I can save files to my host from within my Virtual Machine Guest.  The comment , public and printable variables are not critical to getting this working.  Once you’ve configured your smb.conf file, restart samba service. On Fedora or any Redhat variation you can use the following command to restart the samba service.

service samba restart

Now you’ve finished configuring your host for sharing files with samba.



Access Host Shared Files from Guest

From a windows guest, there’s no special option that is needed to access a samba share on your linux host and starting your kvm guest requires no special options for user mode networking.  All you need to do is open the following location from within your windows guest.  With user mode networking, represents your host machine.



You’ll then be prompted for user authorization for access to the share.



Once you’ve logged in you’ll see your share.




This procedure is a quick and simple solution for sharing files on kvm linux host with a windows guest and may be a common use case especially for home users.  Sharing files between your host and guest is something that most people will probably need at some point. The current GUI tools don’t provide for this right now but this shouldn’t stop you in case you need to share files. Give it a try if you haven’t already done so and see how much easier it can make your life.


See Also


Or you can just use RDP...

If you access the Windows system with remote desktop, you can use the integrated mounting-function within the RDP-protocol. Say you have the virtual machine running on the same machine with NAT-networking like the example above. Setup qemu-kvm to redirect port 3389 so it is accessible from the host machine. You can now mount your home directory within the virtual machine with:
rdesktop '-rdisk 'home'=/home/testuser' localhost

The share will of course only exist while the RDP-session is alive, but it's sufficient in most cases.

That's interesting..

That's certainly an interesting way of doing it with rdesktop.

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.