Simon The Pi Man bookstore
Mmmm Raspberry Pi
Simon the Pi Man
To Infinity (probably) and beyond
(A beginners Resource for the Raspberry Pi computer using the Debian distro)
since June 2012

If you are looking for info on the Raspberry Pi computer stay on this site
however
If you are looking for a good cafe in Rye in East Sussex try "Simon the Pie man" near the church.

How2SetUp a Raspberry Pi Windows NAS storage server on WHEEZY

One of a set of simple easy to use guides for beginners to set up a Raspberry Pi computer.


Ok this instruction sheet will allow you to setup a Raspberry Pi computer to act as a (NAS)Network Addressed Storage server so it will be possible for you to access files from any/all your windows PC's in your house using the Raspberry Pi to share the files on a disk drive attached to one of the usb ports on the Raspberry Pi.

1. Firstly I need remote access to my pi so firstly carry out the How2SetUp Remote Access from the menu on the left.

Lets connect to the Pi remotely using putty so we get the following screen.

Login using the default user pi and the default password raspberry.

2. Now lets make sure all the system updates from Debian have been applied
pi@raspberrypi~$ sudo apt-get update
lots of stuff will fly up the screen so wait until finished, then repeat until nothing else updates - agree y to any y/n questions.

Probably a reboot is a good idea at this time so
pi@raspberrypi~$ sudo reboot

NOTE:- The disk drives that I will be attaching will be formatted in windows format - either FAT32 or NTFS, I suggest you do this with a Windows PC and check the drives are readable by the PC before attaching to the Pi, and also add a test file so that you can see this while testing. You can use unix formatted drives but the FAT/NTFS file systems will make the drives portable in case of a Pi failure.

3. Attach the disk drive or drives to the Raspberry Pi then type
pi@raspberrypi~$ sudo fdisk -l
This will show all the details of the attached disks even if you are not yet using or are able to access them.

I have attached a 4Gb usb card to my Pi for my file server bits from the command is shown below - i have left out stuff not relevent for this How2SetUp.

-----------------------------------------------------
Disk /dev/mmcblk0: 7964 MB, 7964983296 bytes
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    15556607     7716864   83  Linux

Disk /dev/sda: 4005 MB, 4005560320 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63     7807589     3903763+   b  W95 FAT32
-----------------------------------------------------

From the above listing you can see that I have a disk /dev/mmcblk0 (the SD Card) which contains 2 partitions - so this is the operating system disk.

I also have a disk /dev/sd1 that is a 4Gb usb card with 1 partition but this time its been formatted in a windows FAT32 format - old style formatted.

All the disk drives and partitions attached to the Pi are shown, they are all given a device address such as /dev/sda with a partiton 1 so /dev/sda1 is the card in the first Pi usb port and is partition 1.

4. Now we need to make the disks available to the operating system so we need to create a point in the filesystem to mount the disks on.

To do this we need to find a directory that the disk can be attached to, so in the example below we will use the default media folder on the Pi /media then use /media/usb1 for the 1st Disk and /media/usb2 for the second.
pi@raspberrypi~$ sudo mkdir /media/usb1
pi@raspberrypi~$ sudo mkdir /media/usb2
The above commands have made 2 new directories for us to use.

To test they exist type
pi@raspberrypi~$ ls /media
it should show the following if all is ok

-----------------------------------------------------
usb1
usb2
-----------------------------------------------------


5. Now we need to attach the disks to these folders so we have to edit the /etc/fstab file that is used my the operating system on bootup to connect the physical disks to the filesystem.
pi@raspberrypi~$ sudo vi /etc/fstab
This will show the following

-----------------------------------------------------
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, so no using swapon|off from here on, use
dphys-swapfile swap[on|off]  for that
-----------------------------------------------------

We need to add the bottom 2 lines for the 2 disk drives, please note that the entry vfat or ntfs-3g is dependant on your disk type and should be modified accordingly.
An easy way to add lines to a file is as follows, in my case for a fat formatted drive
pi@raspberrypi~$ sudo bash -c 'echo "/dev/sda1 /media/usb1 vfat defaults,dmask=0000,fmask=0000 0 0" >> /etc/fstab'
This will add the device mount point to /etc/fstab that can be seen by either editing the file
or by typing
pi@raspberrypi~$ sudo cat /etc/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, so no using swapon|off from here on, use
dphys-swapfile swap[on|off]  for that
/dev/sda1       /media/usb1           vfat    defaults,dmask=0000,fmask=0000        0       0
-----------------------------------------------------

Please make sure for Wheezy to set the dmask(Directory mask) and fmask(File mask) entries to 0
or you will find the usb is mounted read only

To make the files visible to the filesystem type
pi@raspberrypi~$ sudo mount -a
This will try to mount the new devices into /mnt/disk1 and /mnt/disk2 - so to test if it has worked type
pi@raspberrypi~$ ls /media/usb1
This should now list any files on the disk that you have put there. If this is not the case then check that the disk types are correct in /etc/fstab

6. Now we need to install a software package called samba which will allow a unix box to share windows files.
pi@raspberrypi~$ sudo apt-get install samba
Wait while stuff flies up the screen and type y at any yes/no prompts
Now you will need to install these utility packages.
pi@raspberrypi~$ sudo apt-get install samba-common-bin
pi@raspberrypi~$ sudo apt-get install smbclient

7. When all is complete then the samba package has been installed so will need configuring for your setup, so you will need to edit the /etc/samba/smb.conf file.

pi@raspberrypi~$ sudo vi /etc/samba/smb.conf
The things that possibly need changing are the workgroup entry set to WORKGROUP for XP and previous operating systems and HOME for Windows 7 and above (not sure what is the default for Vista). Then i would comment out the following lines by adding a ; to the front of the item as this makes initial setup and testing easier.

------------------------------------------------------
;[homes]
; comment = Home Directories
; browseable = no
;[printers]
; comment = All Printers
; browseable = no
; path = /var/spool/samba
; printable = yes
; guest ok = no
; read only = yes
; create mask = 0700
;[print$]
; comment = Printer Drivers
; path = /var/lib/samba/printers
; browseable = yes
; read only = yes
; guest ok = no
;[cdrom]
; comment = Samba server's CD-ROM
; read only = yes
; locking = no
; path = /cdrom
; guest ok = yes
; preexec = /bin/mount /cdrom
; postexec = /bin/umount /cdrom
------------------------------------------------------

Now remove the comment Then finally at the end add your windows share name - i will use a share name of usb and will share out the content of /media/usb1 - to share the other disk, add another entry as below with the share name within the [ ] and the path to the other disk drive.

------------------------------------------------------
[usb]
   comment = USB Share
   path = /media/usb1
   writeable = Yes
   create mask = 0777
   directory mask = 0777
   browseable = Yes
   public = yes
   guest ok = no
   valid users = pi
------------------------------------------------------
# NOTE: If you want to make the shares open access then 
# replace the last 2 entries "guest ok" and "valid users" with
# Then there is no need to connect with username/password
#        guest only = Yes
#        guest ok = Yes
------------------------------------------------------


8. At last we can restart samba and test the configuration so to restart samba.
pi@raspberrypi~$ sudo service samba restart
and to check the shares and configuration run
pi@raspberrypi~$ sudo testparm -s
this should show something similar to that below

------------------------------------------------------
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[usb]"
Loaded services file OK.
Server role: ROLE_STANDALONE
[global]
        server string = %h server
        map to guest = Bad User
        obey pam restrictions = Yes
        pam password change = Yes
        passwd program = /usr/bin/passwd %u
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        unix password sync = Yes
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000
        dns proxy = No
        usershare allow guests = Yes
        panic action = /usr/share/samba/panic-action %d
        idmap config * : backend = tdb

[usb]
        comment = USB Share
        path = /mnt/disk1
        read only = No
        create mask = 0777
        directory mask = 0777
        valid users = pi
------------------------------------------------------


If you get the above info then you need to add the pi user to the samba user database
which is not the same as the pi username/password but can be so
pi@raspberrypi~$ sudo smbpasswd -a pi
This will add a pi user with the password you typed in for windows to connect with.

Now try connecting to the server using windows map network drive. On Windows XP you will see the following. So type \\raspberrypi\usb in the Folder field.
Connecting to a <a href='#raspberrypi'>Raspberry Pi</a> NAS server
Now click on the [Connect using a different user name] link and enter raspberrypi\pi in the user name field and raspberry in the password field.
NOTE: windows will always by default try your username and password from your PC to make the connection (in my case my PC is called VNET and my username is simon so you see VNET\simon in the window), and as we only have the one user on the Raspberry Pi, we have to specify that the user connecting is one that exists on the Pi. We also have to also specify the machine that the user is on before the user name therefore the username is raspberrypi\pi.
Connecting to a <a href='#raspberrypi'>Raspberry Pi</a> NAS server
Then click [OK] which will close the pop-up and [Finish], this should now map your drive to the Raspberry Pi NAS server.


If you are having issues with the samba server try looking at the samba logs which are
in /var/log/samba
pi@raspberrypi~$ sudo ls -l /var/log/samba
This will list the files that samba is recording, there are 2 master files nmbd.log and
smbd.conf which can be looked at if you cant get samba to start, and the others are each of the
windows pc's that are in the LAN.
to view the logs just type - as an example
pi@raspberrypi~$ sudo cat /var/log/samba/smbd.conf


Now you can reboot and the server will keep on working and sharing your windows files on boot

If you dont want your server called raspberrypi then change its name by reading "How2Setup Rename my Pi".

© simonthepiman.com 2012->2024
email:
simon@villagenet.co.uk

hosted by VillageNetThe Raspberry Pi Foundation is a UK registered charity which exists to promote the study of computer science and related topics, especially at school level, and to put the fun back into learning computing.

Please Note:- any mention of the Raspberry Pi computer on these pages refers to the Raspberry Pi Foundation's product, who also have trademark rights to the term 'Raspberry Pi'.