At home, I’ve installed a Netatalk Apple Filing Protocol (AFP) file server on a machine running Ubuntu so that I can easily share files between my Macs and the Ubuntu machine (see this post for details). Using an open source network service discovery protocol similar to Apple’s Bonjour called Avahi (see this post for a setup guide), this file server is advertised to Macs on my local area network (LAN). The Netatalk file server works great, but I wanted to configure Netatalk to share an external USB hard drive connected to my Ubuntu file server. I wanted to use the USB hard drive to backup the data on my Macs so that in the event of an emergency I could easily grab my data. Here is the steps I took to do this.
Step 1: Find the USB Hard Drive’s Device Name
Before formating and partitioning your USB hard drive, you must first determine its device name. To do this, plug in the USB storage and let it auto mount. After it mounts, the following command will list details about all of the drives connected to your machine.
sudo fdisk -l
Scan the output. If you know the size of your USB hard drive you should be able to identify its details. Somewhere in the output corresponding to the USB drive there is a path that looks like
/dev/XXX: where the
XXX in this path is the USB drive’s device name (write this down). My USB hard drive has the device name
sdc, which I use throughout the rest of this guide.
Step 2: Partition the USB Hard Drive
You have many options to partition your USB hard drive. I used a GUI based program
gparted that can be installed and run using the following commands.
sudo apt-get update
sudo apt-get install gparted
The program is very user friendly. There is a dialog box in the upper right corner where you can select the path to the device you want to partition. Referring to the device name you determined in Step 1, select the path to your USB hard drive. Make sure any existing partitions that appear in the partition list are unmounted by right clicking on each and selecting “Unmount”. After everything is unmounted, you can select, delete, resize, or format partitions at will. I created two partitions, one for each of the user that I wanted to grant access to the USB hard drive. I formated both partitions using the ext3 protocol. I recommend the same. After formating, write down the device name for each of the new partitions you created. These will be prefaced by the USB hard drive’s device name but will have trailing numbers. For example my partitions are named
Step 3: Set Mount Points and Configure Auto Mounting of the USB Storage in fstab
Next create a directory or directories where you want the partition(s) you just created to mount. Below I am creating two directories as mount points for each of the partitions I created above, one for
user1 and one for
user2 (or course feel free to modify the directory names).
sudo mkdir /media/user1backup
sudo mkdir /media/user2backup
These directories are placed in the media directory, which is where you may have noticed external storage dynamically auto mounts by default. This step is important because in order to share the USB hard drive partitions on the network we need them to have static mount points. Next, make sure that the permission on the new directory or directories are set correctly so that
user2 can access the USB storage. The commands to do this will be similar to those shown below with the substitution of your user and directory name(s).
sudo chown -R user1 /media/user1backup
sudo chgrp -R user1 /media/user1backup
sudo chown -R user2 /media/user2backup
sudo chgrp -R user2 /media/user2backup
Next, we must open the
fstab list and add a few lines to specify how the USB drive partitions will auto mount at system startup. Open
sudo gedit /etc/fstab
You will add a line for each partition on the USB hard drive to the end of this file. They will be similar to what is shown below with the substitution of your device and directory name(s).
/dev/sdc1 /media/user1backup ext3 defaults 0 0
/dev/sdc2 /media/user1backup ext3 defaults 0 0
The first column is the path to each partition on the USB storage. Replace the device name(s) with the device name(s) for the partition(s) determined in Step 2. The second column specifies the directory or directories of the mount point(s) as created above. The third column specifies each partition’s format protocol. The final three columns set the default behavior for each partition;
default 0 0 will be sufficient for most applications.
Step 4: Configure Netatalk
The final step is to configure Netatalk to share the new external USB storage partitions. Open the Netatalk volumes configuration file.
sudo gedit AppleVolumes.default
At the end of this file you will add lines similar to those shown below with the substitution of your directory and user name(s).
/media/user1backup "User1's Backup" allow:user1
/media/user2backup "User2's Backup" allow:user2
The first column specifies the path to each partition’s mount point as specified above. The second column is the name of the shared drive that will appear in Finder on the Macs connected to your LAN. the third column defines that only the specified user can access the partition listed in the first column. That’s it, after a system reboot your USB storage should be shared with the Macs on your LAN. After connecting to your Ubuntu machine in Finder, the shared directories should appear. For more tips on getting your Ubuntu machines to integrate with your Macs, check out the Ubuntu section.