Ubuntu Samba Share

Whether you have laptops loaded up with Windows XP or extra desktops around (like me), sometimes there is a need for a quick and painless file share with windows machines. Sure you could get a NAS or some other expensive external hard drive with networking capability, but why spend the money and resources when you can make your own with your current setup and an extra drive. The following is a quick howto for Ubuntu machines (specifically Hardy Heron 8.04) about how to turn an extra hard drive into a Windows share.

NTFS support for hard drives has historically been kind of flakey in Linux. Reading generally worked well enough, but writing has been spotty. With the advent of NTFS-3g libraries, these types of issues have all but gone away finally giving Linux users an easy and stable solution for formatting and writing to NTFS. NTFS is preferred over FAT32 due to 4GB file size limitations on FAT32. I have chosen to use the entire second hard drive as an NTFS swap space to keep things simple.

Installing Libraries and Programs

The system I use for my desktop is Ubuntu Hardy Heron 8.04. The steps below reflect an install on this particular flavor of linux and may not be identical to your own install. To be fair, there are only two required libraries ‘samba‘ and ‘ntfs-3g‘, everything else explained below can be done by modifying a few config files like /etc/fstab and /etc/samba/smb.conf.

sudo apt-get install samba smbfs ntfs-3g ntfs-config ntfsprogs

If you prefer not to use the silly guis, then you do not need ntfs-config, however I have found them helpful in my desktop environment. ntfs-config is a utility that turns on/off the NTFS write capability.

Installing the Hard Drive

After putting the second hard drive as slave or cable select onto the IDE or SATA connection, debian-based linux machines will see the device under /dev/sdX where X will be something like sdb if it is the second hard drive. You can verify this by typing:
sudo fdisk -l

Take careful note of the devices listed here and be very, VERY careful you select the right one because your actual hard drive will also be listed there usually as /dev/sda. There are two places that Ubuntu machines generally use to mount things /mnt and /media. Mounting onto /media will provide an additional icon of the drive on the desktop in addition to normal mounting. Different systems have different conventions. In reality, you can mount anything anywhere as long as you have permissions. In this example, I have chosen to mount the second hard drive into /mnt/share.

I repurposed an old external drive for this project, so I needed to repartition. fdisk is the perfect utility for this. After making careful note of the correct drive under /dev, I reconfigured my partition table by first removing old partitions:
sudo fdisk /dev/sdb

Once inside fdisk, use ‘d’ to delete all available partitions, then create a new one with ‘n’ setting it as the primary ‘p’ and using the entire disk (pressing ‘enter’ twice for the starting and ending heads). My drive already was marked as NTFS, but if you have a fresh drive you will also need to use ‘l’ and label it as HPFS/NTFS which is choice 7. ‘w’ writes the partition table out to disk.

In order to format the disk to NTFS, we use mkntfs from ntfsprogs:
sudo mkntfs /dev/sdb

If you want to give your drive a name you can use mlabel. After formatting, it is time to setup the mount point. If we want to put the drive onto /mnt, we need to create a folder for it:
sudo mkdir /mnt/share

Then we need to edit our fstab to get it to mount every time we boot. Change fstab to include an entry about our new drive by editing /etc/fstab. Add the line:
/dev/sdb1 /mnt/share ntfs-3g defaults,users,locale=en_US.UTF-8 0 0

To load your changes:
sudo mount -a

Do the Samba

Samba file sharing provides protocols and visibility to share files between windows machines. By enabling Samba and pointing to our new mounted drive, we will effectively turn our entire second hard drive into a windows-friendly swap space on the network. The easiest way of configuring Samba in the Ubuntu desktop is using ubuntu-config-samba. There were some issues with Samba in Hardy Heron when it was first released, but they have been fixed.

Once the config program has been installed, it will be available under Sytem->Administration. The setup is very straight-forward. Make a new share using our new drive under /mnt/share. Add any number of users you desire. You can even create and edit new Samba users and passwords right in the config tool. Alternatively you can make changes in the /etc/samba/smb.conf file if you know what you are doing. The GUI tool is simply editing this configuration file for you.

Finally, you can reload Samba with your new settings using:
sudo /etc/init.d/samba restart

Now other windows machines will be able to see the share as part of the local network and login in the method specified in the configuration gui. You can also Map network drives in Windows to this Samba share and use it as a local network swap space. This swap space can be easily by all devices Linux and Windows alike.

Tags: , , , , , , , , , ,

2 Responses

  1. ranjan says:

    I too followed his method for mounting an NTFS partition of on hard drive but i most often I am geting an error message “Failed to mount Windows share” wile trying to accessing my share file through nautilus … do you have any idea how to fix it and presently i am using Ubuntu 9.04 and i am trying to share my NTFS part with Windows based network Pc ….. if you have any solution then please help me…. thanks in advance …..:)

  2. BJ says:

    Sounds like it could be a permissions issue. Make sure the folders that you are sharing have proper permissions for both the files and the folder which you are attempting to mount.

Search

Websites

  • slide
  • slide
  • slide
  • slide