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.
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.
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.
[LinuxHost] 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.
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, 10.0.2.2 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.