Raspberry PI as NAS

A friend of mine was wondering about using a Raspberry PI as a NAS, the question being: how fast is the PI at file transfers from/to an external hard disk connected via a USB rack.

So I booted up my PI, mounted some random 3.5 inch Samsung 160GB SATA hard drive inside another random Spire USB-SATA external (powered) rack and gave it a go at some testing.

Mounting the USB rack / hard disk in PI

The first thing I noticed was my rack – although connected to the PI – would not show up in the lsusb output. So I tested the rack by connecting it to the computer and it was detected just fine.

I did have an ASUS wireless card connected to the PI, and after unplugging that, another lsusb finally saw my usb rack:

pi@raspberrypi /mnt/hdd $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 14cd:6116 Super Top M6116 SATA Bridge

The issue here could be there was not enough power left on the USB ports with the wireless LAN connected. The rack is indeed powered (as the drive requires a lot of +5 and +12V power), but the SATA/USB interface in it is actually USB bus-powered.

Since my PI has no fdisk installed, I used the output of dmesg to find out the drive designation:

pi@raspberrypi / $ dmesg
[    2.362224] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    2.371848] Indeed it is in host mode hprt0 = 00001101
[    2.582510] usb 1-1: New USB device found, idVendor=0424, idProduct=9512
[    2.592401] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    2.602396] hub 1-1:1.0: USB hub found
[    2.611248] hub 1-1:1.0: 3 ports detected
[    2.892320] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[    3.012587] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00
[    3.021468] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.038744] smsc95xx v1.0.4
[    3.106779] smsc95xx 1-1.1:1.0: eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:9e:54:88
[    3.202356] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[    3.323798] usb 1-1.2: New USB device found, idVendor=14cd, idProduct=6116
[    3.332930] usb 1-1.2: New USB device strings: Mfr=1, Product=3, SerialNumber=2
[    3.342368] usb 1-1.2: Product: USB 2.0  SATA BRIDGE
[    3.349603] usb 1-1.2: Manufacturer: Super Top
[    3.356280] usb 1-1.2: SerialNumber: M6116018VE15
...
[    8.441661] scsi0 : usb-storage 1-1.2:1.0
[    8.540758] usbcore: registered new interface driver ums-cypress
[    9.533493] scsi 0:0:0:0: Direct-Access     SAMSUNG  HD161HJ               PQ: 0 ANSI: 0
[    9.562897] sd 0:0:0:0: [sda] 312581808 512-byte logical blocks: (160 GB/149 GiB)
[    9.602902] sd 0:0:0:0: [sda] Write Protect is off
[    9.609934] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
[    9.626005] sd 0:0:0:0: [sda] No Caching mode page present
[    9.652324] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.671398] sd 0:0:0:0: [sda] No Caching mode page present
[    9.699578] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.728749]  sda: sda1
[    9.750782] sd 0:0:0:0: [sda] No Caching mode page present
[    9.770537] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.792464] sd 0:0:0:0: [sda] Attached SCSI disk

This told me the drive is seen as sda, the partition on it being sda1.

Mounting it was easy

sudo mkdir /mnt/hdd
sudo mount /dev/sda1 /mnt/hdd

Unfortunately, after doing this I noticed I cannot write any data on the mounted partition (in /mnt/hdd/). All I got was “access denied”.

Checking it out showed the partition should have been mounted read/write so this shouldn’t happen:

pi@raspberrypi /mnt/hdd $ mount
/dev/sda1 on /mnt/hdd type ntfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

After several minutes tinkering with permissions and browsing around, I remembered about ntfs-3g.

So I quicky installed it:
sudo apt-get install ntfs-3g

then unmounted the drive and remounted it
sudo mount -t ntfs-3g /dev/sda1 /mnt/hdd

and the partition became writable. Hooray.

Setting up Samba

Moving on, no NAS is complete without samba (not the dance). I wanted to just copy some big files on the hard drive, so this required a public (I did not want to tinker with permissions and logins) and writeable share.

After installing samba
sudo apt-get install samba

I edited /etc/samba/smb.conf and set it up to create a \\pi-ip\storage share for the whole /mnt folder:

[global]
log file = /var/log/samba/log.%m
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
obey pam restrictions = yes
null passwords = yes
map to guest = bad user
encrypt passwords = yes
public = yes
passdb backend = tdbsam
passwd program = /usr/bin/passwd %u
dns proxy = no
writeable = yes
server string = %h server
unix password sync = yes
workgroup = MYNET
os level = 20
syslog = 0
panic action = /usr/share/samba/panic-action %d
usershare allow guests = yes
max log size = 1000
pam password change = yes
guest account = nobody
[storage]
directory mask = 0777
writeable = yes
public = yes
read only = no
path = /mnt
create mask = 0777
write list = nobody
guest ok = yes

Initial results

All being set up, I copied the biggest file I had lying around, a bluray image of a Nightwish concert. Here is the result with an NTFS formatted drive:

raspberry-hdd

The speed is rather disappointing, a mere 2.8 MB/s.

I know the network isn’t the bottleneck (a test with iperf showed me an average 60-70 MB/s Mbps or 7.5-10 MB/s) nor the drive/rack (which both can do about 25MB/s connected to my computer).

I would have wished for a value closer to 10MB/s (the 100Mbps network speed), nonetheless this speed is almost acceptable for very small file transfers, or remote/online file transfers which are actually limited by the internet connection bandwidth.

More testing (updated)

I must re-state I was using NTFS as the filesystem for the initial test.

After receiving suggestions on using different filesystems, I re-did the test with EXT3 and FAT32. The results surprised me.

Filesystem: ext3
Filesystem: ext3

Filesystem: FAT32
Filesystem: FAT32

That’s 7.8 MB/s (or about 62 Mbps) when using ext3 and 8.5 MB/s (or about 68 Mbps) when using FAT32. That is indeed a lot of overhead when using NTFS.

So the PI is actually usable as a very low-power NAS device when using an USB hard disk formatted to ext3 (as FAT32 proved its low reliability time and time again)

6 Comments

    1. Zed

      ExFAT is a proprietary filesystem, requiring a licence from Microsoft for implementation. It is only available under Linux via FUSE (no direct kernel support yet).

  1. Pingback: Raspberry Pi NAS | Ray Writes Code

  2. unknown

    it is probably the format of the hdd with fat32 on a usb flashdrive i get 9mb per sec so try and format your drive to fat 32 i hear ext4 works better but i have not tryed.

Leave a Reply