Backup, Share and Sync – Part 2: Hard Drive Preparation and Server Configuration

 | January 25, 2009 12:08 am

On the way to file backup, sharing and sync nirvana, there are several important steps.  These include understanding the roadmap and how the individual components work together as well as the configuration of each of client and server programs.  In this article, I will explain how to set-up the USB drives and configure Samba for access to your shared files from any computer in the house.

Understanding Samba

Before delving into the step by step procedure, there are a few important things that you need to know about how Samba works.  If you encounter a problem in configuring your new server, it might prove useful in determining the cause of the difficulty.

Samba is s file and printer sharing service for Linux, BSD, and other ‘nixes.  It is an OpenSource implementation of the windows networking protocols.  Since it is OpenSource, it is also nearly universal and included in Mac OS X.  Samba works by giving authorized individuals access to a particular folder, also known as a share.  All of the settings and configuration information is kept in the /etc/samba/smb.conf file.  Once Samba is set up and running, you will be able to a number of things:

  • Windows and Mac Users will be able to access a dedicated folder, called the home directory, that is associated with their server account.
  • A public, shared directory for regular files as well as computer backups can be made available.
  • You can set up the server to act as a central printer manager.  Both Windows and Mac computers can send jobs to the server, rather than clogging the itself.  I will not, however, be covering this topic in any depth with this series.

While there are a number of graphical and web based options for configuring Samba, I find it easiest to directly edit the configuration files.  For this, I use a command line text editor called Vi.  Part 1 includes some information on basic navigation and editing of text files in Vi.

Because Samba runs as a service on Linux, we need to stop and restart the service after making any changes to the configuration file.  The upside is that the changes we made should instantly appear after the service is running again.

Setting Up Samba

Setting up a samba share is a three step process.  First, we will format the two USB hard drives in the NTFS file format using Windows.  Second, we will attach them to the server box and create mount points.  Last, we will edit the /etc/samba/smb.conf file so that we can access the drives over the network.

Step 1: Format and Prepare the USB Hard Drives

For my server, I will be setting up two USB hard drives.  One will be used as a public file store, which any user of the network will have access to.  The other is a dedicated backup drive which I will be using with Time Machine on my Mac and the built-in backup client on my Windows Vista machines.

While it is possible to format the drives using Linux, I would recommend using Windows.  Formatting disks in Windows is slightly easier than doing so in Linux.  Also, I have sometimes had difficulties in reading an NTFS drive formatted by a Linux machine whereas Linux machines seem to be able to read drives formatted by their Windows counterparts without difficulty.

image The easiest way to format a drive in Windows is to right click on its icon in the “My Computer/Computer” Dialog.    Select format from the context menu.

If you are using Windows Vista, you may have to enter your administrator credentials before the computer will load the “Format Disk” dialog.  Under File System select “NTFS.”  The other option, exFat, is a new drive format that was introduced with Windows Vista Service Pack 1 and Windows XP Service Pack 3.  It currently cannot be read by Linux machines.

If this is the first time that you have you used the drive, then you may wish to do a full format.  A full format will first remove the files and then scan the disk for bad sectors.  The scan is one of the reasons why the full format may take twice as long as the quick format.  The full format will truly scrub through the hard drive from scratch and rebuild the file structures.

An alternative to formatting the drive through “My Computer” is to use the “Computer Management” console.  You can access it through Control Panel or by typing “Computer


Management” in the Vista search box.  Once the computer management console has loaded, select “Disk Management” from the left hand pane and locate the USB drive.  Again, right click on the drive and select “Format Drive.” It may take between 10 and 30 minutes for the hard drive to format, or longer if you opted to do a full format.

Once the drive has finished formatting, right click on its icon in “My Computer/Computer” and then click on the “Safely Remove” Option.  It might also be a good time to give the drive a name.  Do this by clicking on the “Rename” option of the context menu.

Step 2: Connect the drives to the server and create mount points

After you have finished formatting your disks attach them to the server.  Like a Windows or Mac computer, the machine will recognize the attached disks.  Unlike Windows or Mac, however, we will need to manually create mount points and specify where in the file system we would like the drives to be mounted.

The next few steps will need to be run from the command line.  You will either need to be standing at the server or working through a secure shell (ssh).  For instructions on how to create a secure shell, see part 1. You will need root access for all of these steps.  Once you are connected to the server, you can gain root access by typing:

sudo bash


An alternative to formatting the disk through “My Computer” is to use the Computer Management Console.  You can access the computer management console through the Windows Control Panel.

2.1 : Working with fdisk

In Windows, disk drives are assigned an alphabet letter.  Typically, the main drive is C:\, the floppy drive was A:\, etc.  Linux machines use a different format.  Drives are typically listed under the /dev/ folder.  A convenient command to see all of the attached drives to computer is by typing:

fdisk –l

as the root user.  Once your drives are attached, you should see something similar to the output below.  While it may appear convoluted, there is a logic to it.  To make the console output slightly more readable, I have separated each of three hard drives on my server with a line.  This will be absent when working at a typical command line.

Disk /dev/sda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe441d40f

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4863      747022+   5  Extended
/dev/sda5            4771        4863      746991   82  Linux swap / Solaris

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe4793562

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001    7  HPFS/NTFS

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa4b57300

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      121601   976760001    7  HPFS/NTFS

The first line gives the disk /dev/sda (sdb, sdc, etc.) and the total size.  The second block of text gives information about where the disk will attach on boot-up of the computer and the file-system.  On most systems, /dev/sda will correspond to the primary internal drive and /sdb/sdb, sdc will be the USB drives or secondary internal hard drives.  The number corresponds to the partition number.  On /dev/sdb and /dev/sdc there is only a single partition.

2.2 : Create a Mount Point

The mount point is where the path will use to access the hard drive.  One of the most common directories for external drives to access is in the /media/ directory.  You can move to that folder by typing:

cd /media/

cd is the Unix command for “change directory.”  Once you are in the /media/ directory, we need to create a new directory for our external hard drive.  This is done by typing:

mkdir /media/store

If you are using two separate drives, you can create one mount point for the public file store (/media/store) and a second mount point for the backup drive (/media/backup).

After the mount point has been created, you will need to give the folder writeable permissions for all users.  Do this by typing:

chmod 777 /media/store

If you have a second drive for the backup disk, repeat this step for /media/backup.

After you have set the permissions for the mount point, we need to mount the disks.  If using two drives, note which drive (/dev/sda or /dev/sdb) you mount to which location.  The disk can be mounted by typing:

mount /dev/sdb1 /media/store

Repeat the process for the second disk but change the mount point from /media/store to /media/backup.

When you mount a disk from the command line (like we have done here), it is only temporary.  The disk will be unmounted if the server reboots.  To have the server automatically attach the disk to the correct mount point, we will need to edit the fstab configuration file.  This file is stored at /etc/fstab.  Type:

vi /etc/fstab

The text editor, Vi will load with the configuration file, which will look similar to that below.

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sda1
UUID=25f1be66-20bf-4813-b890-bec5755d17eb /               ext3    relatime,errors=remount-ro 0       1
# /dev/sda5
UUID=a795bad3-1609-42c8-bf8a-9e375ab41994 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/scd1       /media/cdrom1   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

To have your disk(s) mounted automatically, add the following to the fstab file.  If you have two disks, it is important to remember which disk will be mounted to what location:

/dev/sdb1 /media/store ntfs defaults 0 0

# If there is a second drive, add the following line without the # symbol
# /dev/sdc1 /media/backup ntfs defaults 0 0

To mount the drives according to the fstab configuration, type:

mount –a

Step 3: Configure Samba

Now that the drives have been attached and configured, the last step is to change the options in /etc/samba/smb.conf so that the new drives will be visible on the network.

3.1 : Ensure that the server can be accessed

Prior to configuring samba, now is a good time to ensure that your new server is visible to other computers.  Go to another computer on your home network and type the following into a browser: will be the computer’s ip number.  In my case, it is  If everything is set up correctly, Apache (the web server software) will display “It Works!” in the browser window.  This means that the server is successfully able to communicate with the clients.

Backup-Part2 Fig

You can check if the server was correctly setup by opening a browser and typing the ip address of the server.  If you see “It works!” then your apache and the network settings are running correctly.

3.2 : Edit the Samba Configuration File

Several changes need to be made to the samba configuration file.  First, you need to specify the correct workgroup (which is normally MSHOME).  You will also need to add an entry that points to the mounted drives.  You can edit the samba configuration file by typing:

vi /etc/samba/smb.conf

Find the line which says, workgroup = MSHOME and ensure that it is the same as the workgroup on your network.  Next, you can make the two hard drives visible and writeable for all users by adding the following lines to the bottom of the smb.conf file.

comment = Public Folder
path = media/store
public = yes
writable = yes
create mask = 0777
directory mask = 0777
force user = nobody
force group = nogroup
guest ok = yes

comment = PC Backup Folder
path = media/backup
public = yes
writable = yes
create mask = 0777
directory mask = 0777
force user = nobody
force group = nogroup
guest ok = yes

Save the file and then restart Samba:

/etc/init.d/samba force-reload

The service will reload and you should now have access to both your Public drive and to the separate Backup drive.  If only using a single drive, you can create separate folders for the file store and the backup.  The path part of the samba entry should point to the correct corresponding directory.

3.3 : Check Configuration

You can check the configuration by opening an explorer window and typing:


You should see something similar to the screenshot below.  On my server, I have added a separate entries for Mac-Backup as well as PC-Backup.


You can check the same thing Mac by opening “Go” menu under finder and clicking on the “Connect to Server” option.




where is the server ip number.  If everything is configured correctly, you should be able to access either the Public or Backup shares.


By now, you should have a fully functioning Samba configuration on your server.  The first major cornerstone of file sharing, backup, and sync perfection is in place.  Functional Samba means that you now have a dedicated computer for sharing files between the other machines in the house.  We will piggyback off the filing share to also use the server as the central backup location.  In the next article, though, we will start looking at ways to set up file synchronization using Subversion.

Similar Posts:

2 Responses to “Backup, Share and Sync – Part 2: Hard Drive Preparation and Server Configuration”

[...] the introduction of Samba, we have taken another step towards computer backup, sharing and sync bliss.

[...] the instructions here assume that you will be making your backup to a simple home server running Samba and Subversion, they will work with most network attached storage devices [...]