Raspberry Pi File Server

This site has been great fun, but it has run its course, and it is time to move on. Please get what you want from the site before January 1, 2020. Some pages will move to another site but most will go away.

A Raspberry Pi fileserver with an mSata SSD
Inside an mSata USB3 SSD

The Raspberry Pi file server is a means of providing network-based storage through mapped drives on Windows, OS X, and Linux. For the sake of performance, I used a 64GB mSata SSD in a little external enclosure. My need was simply to allow easy transfer of files from one workstation to another.

Having no moving parts, it is both quiet and energy efficient - a big deal for a device that will remain on 24 x 7. The drive in its enclosure is almost exactly the same size of the Raspberry Pi.

Boot Disk

I started with a full install of Raspian on a 16GB SD card.

Format the drive

The drive I picked up was a pull from a working system. The first thing I did was unmount the drive, which Rasbian automatically mounts. To do that I had to know some particulars of the drive.

df -h

That returns the device name and the mount point:

pi@rpi-:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  3.4G   11G  24% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           463M     0  463M   0% /dev/shm
tmpfs           463M  6.3M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1   63M   21M   43M  33% /boot
tmpfs            93M     0   93M   0% /run/user/1000
/dev/sda1        59G   52M   56G   1% /media/pi/7c770a7d-a41a-4dca-b259-cf5b1221e7fd

The /dev/sda1 is what is of interest. It is the device name for the volume. That is what needs to be unmounted.

sudo umount /dev/sda1

Then I ran 'fdisk' on it to wipe out the partitions and start over. I piped some canned answers into fdisk to partition the disk into a single partition that takes all of the disk. The commands are 'o' to clear the in-memory table, 'n' to create a new partition, and 'w' to write it to disk. Each linefeed is to take the default value for a prompt.

sudo echo -e "o\nn\n\n\n\n\nw" | fdisk /dev/sda

To format the drive, use 'ext2fs':

sudo mkfs.ext3 /dev/sda1

It takes a minute or less to format the drive.

Mount the volume

All drives mount on top of an existing directory, so I had to make the directory first:

sudo mkdir /xfer
sudo mount -t auto /dev/sda1 /xfer
sudo chmod 01777 /xfer

You have to edit /etc/fstab in order to have the newly created volume mount where you need it to be. fstab is the file system table. It defines where each drive mounts to make the whole file system. The Raspberry Pi has a simple fstab:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

Using nano, edit fstab:

sudo nano /etc/fstab

And add one line to make it look like this:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

/dev/sda1       /xfer           ext3    defaults          1       2

Install the Software

To allow access from Windows machines, I installed Samba.

sudo apt-get install samba samba-common-bin

The samba config file is noisy with comments. I cleaned it up by first renaming it, then copying it back through the grep filter:

sudo su
mv /etc/samba/smb.conf /etc/samba/smb.conf.org
grep -ve ^# -ve "^;" -ve ^$ /etc/samba/smb.conf.org > /etc/samba/smb.conf

The resulting file is easier to read and using nano, I added a section at the end:

nano /etc/samba/smb.conf
   comment = Data share
   path = /xfer
   browsable = yes
   read only = no

Then restart samba.

service smbd restart

Add Users

Anyone who uses the samba share must be a user on the Raspberry Pi. Add yourself as a user. There will be several prompts for the adduser command. You can take the defaults on all of them.

adduser mlamb
smbpasswd -a mlamb

Now from any PC (Windows, OS X or Linux) you should be able to attach to the share. In Windows and OS X the share just magically shows up. In linux you may need to connect to the server first.

Arduino Board Logo


Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support


Stay updated

Sign up if you would like to receive our once monthly newsletter.