A new version of this series has been published. Please refer to the new index for updated articles and ordering. This article is kept for historical reference, but should be considered out of date.
Note: This article is part of a series. See the Index for more information.
Self-promotion: I’ve recorded this series as a screencast for Pluralsight:
If you have a Pluralsight subscription, please consider watching it. Thanks!
Updates: Everything in this post works just fine under the Jessie release of Raspbian, so there are no changes to report at this time.
Now that the Raspberry Pi has the space to hold your stuff, it’s about time it started doing something useful around the house. Its first task will be to share files from the hard drive. In the previous post we added a hard drive with two partitions, one ext4 partition for the operating system, and one NTFS partition to hold data.
- A Raspberry Pi
- A mounted, USB hard drive
Mine is the second hard drive partition, mounted at /mnt/data
The “Samba” package creates network file shares in a way that Mac and Windows computers on the network will understand. Install Samba as follows:
sudo apt-get install samba samba-common-bin
Set up shares
Just for fun, we’ll use Webmin to do this part. Get to a browser on your primary computer (or the Pi, if you like waiting), and navigate to the Raspberry Pi’s IP address, port 10000 (e.g. https://192.168.1.123:10000).
Webmin has a Samba administration module, which should currently be listed under the “Un-used Modules” section because Samba wasn’t installed before. Since you’ve just installed Samba, it would be nice if this module weren’t hidden like this. Click “Refresh Modules” near the bottom of Webmin’s left-hand menu, and Webmin will go through its inventory, and figure out which modules can actually be used. This can take a little while, so be patient.
When it is finished, the “Samba Windows File Sharing” module should have moved to the “Servers” section at the top.
Click on the “Samba Windows File Sharing” module, and then on the “Windows Networking” icon under “Global Configuration”. Change “Workgroup” to match your home network if it is different (it’s probably just “WORKGROUP”, though, unless you specifically changed it). Select the “Be a WINS server” radio button on the second row.
Click “Save” to save the settings and return to the main Samba page.
Click on the “Create a new file share” link near the top of the page. Give the new share a name. I called mine “Data” to avoid confusion, and type “/mnt/data” (or whatever you called your mount point) in the “Directory to share” textbox. Your screen should look like this:
Click “Create” to create the share, and you will be taken back to the main Samba page. Your new share should now appear in the list. Click on it to go to the “Edit File Share” page. From here, click the “Security and Access Control” icon.
Set “Writeable” and “Guest Access” to “Yes”.
Click “Save” to save your settings and return to the “Edit File Share” form.
Click the “Return to share list” link at the bottom of the page to return to the main Samba page.
Click on the “Restart Samba Servers” button near the bottom of the page. You should now be able to view the share from other computers on your network.
This is a wide-open file share. Anyone on the local network can add, edit, or delete the files it contains. I am not a Linux security expert, and somewhere someone is screaming at me for doing it all wrong. I’m sorry, it’s nothing personal, but we’re talking about a home network, here. I’m more interested in having a place to put stuff than in controlling access to it.
You can certainly do that, of course, but the intricacies of Linux filesystem security are beyond the scope of this series.
Make some folders
Create some file folders in the Data share to hold your stuff, and copy it in. Music, Pictures, Videos, anything you want. For this server, I’ve created the following folder structure.
You don’t have to use the same structure as me, of course, but this is the one I’ll be using in future posts, so you’ll need to adjust accordingly if you do something else.
Load it up
When it comes to copying the files in, you can save some time, and skip the network bottleneck by moving the external hard drive to the computer that currently has the data. Because the data partition was formatted as NTFS in the previous post, when you plug it in to your Windows or Mac computer, you’ll just see a drive called “Data”, or whatever you named it.
Remember to shut down the Raspberry Pi before removing the hard drive, of course. Just put it back when you’re done copying files, and start up the Raspberry Pi as usual.
In the next post, we’ll get a media server up and running so that you can stream music and movies all over your house from the hard drive share.