Close

Results 1 to 1 of 1
  1. #1
    DF Admin Teajunkie's Avatar
    Join Date
    Dec 2009
    Location
    Devon
    Posts
    4,228
    Thanks
    1,827
    Thanked:        1,826
    Karma Level
    569

    Hardware Make a low power nas with your pi.

    What you will need:


    We will assume you have Rasbian installed, and are fully up-to-date.

    1. So first thing to do is get all the hardware plugged in and powered up
      1. Plug the powered USB hub into the Raspberry Pi
      2. Plug each of the external hard drives into the powered USB hub
      3. Hook up a network cable
        1. hdmi cable, keyboard and mouse if you’re not going to SSH to the Pi

      4. Plug the power into the USB hub and Pi, and power it all on!

    2. With everything powered on its time to start configuring your pi. We will be doing this all via the command line, so either SSH to your Raspberry Pi, or open up a LXTerminal if you have booted to desktop on Rasbian.
    3. Before we can mount and use our external hard drives, we need to add support for our NTFS formatted hard drives, to do this execute this command:
      sudo apt-get install ntfs-3g
    4. Now we need to check to see if we can see the unmounted partitions from our external hard drives, we do this by running the following command:
      sudo fdisk -l
      If everything is working you should see something along these lines (looking for number 1,2,3,4 labelled in the image.)


      Number 1 – Shows us the first external hard drive
      Number 2 – Shows us the first partition on the first hard drive
      Number 3 – Shows us the second hard drive
      Number 4 – Shows us the first partition on the second hard drive

      If you have made multiple partitions on either of the hard drives, you should see extra lines on section 2 and/or 4
      Take note of the “device” path for each partition, so in this example we need to remember:
      /dev/sda1
      /dev/sdb1
    5. Before we can mount the partitions, we need to create a directory for each hard drive to mount them to, we are going to create two directories, one called “main” one called “backup” you can name them whatever you like.
      sudo mkdir /media/main
      sudo mkdir /media/backup
    6. Now we have our directories created, we can mount each of the hard drive partitions to these directories (if your “device” path is different remember to change it in the command, refer to your notes back on step 4):
      sudo mount -t auto /dev/sda1 /media/main
      sudo mount -t auto /dev/sdb1 /media/backup

      Now we have our hard drives mounted!
    7. It’s now time to install Samba (this is what we’ll be using to share the hard drives on the network) to do this, run the command:
      sudo apt-get install samba samba-common-bin
    8. Now we have Samba installed, we need to edit the configuration file. Before we do this, we will make a backup of it, just in case we need to revert back to a working state.
      sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
    9. With the configuration file backed up, we can now edit it
      sudo nano /etc/samba/smb.conf
    10. First thing to check is the workgroup. The default workgroup is set to “WORKGROUP” which will work if you haven’t changed your windows workgroup. If you have changed it, simply update it here

    11. Now we need to enable user authentication for our samba shares, otherwise, anyone that has access to the network will be able to view the shares. Simply uncomment (remove the #) from the line that reads “# security = user”

    12. Now we need to add our “main” partition as a share. To do this we need to add an entirely new block of code. So scroll to the very bottom of the config file, and add the following (if you named your directory different to “main” back in step 5, then you will need to update the line “path = “):
      [Main]
      comment = Main Folder
      path = /media/main/
      valid users = @users
      force group = users
      create mask = 0660
      directory mask = 0771
      read only = no

      Here’s a breakdown of each line in the above block of code:
      [Main] – Anything between the square brackets, in this case “Main”, is the name of the share displayed on the network.
      comment – This is just a description of the share
      path – This is the directory that is used for this share
      valid users – This specifies which users can access the share, in our case we have specified a group (by using the @ symbol followed by the group name)
      force group – This will make sure any files added via the samba share will have the specified group
      create mask – This sets the permission of any files added to the samba share
      directory mask – This sets the permission of any folders added to the samba share
      read only – This makes sure that the files are writable
    13. With the samba configuration done, we need to restart the samba server so that these new settings take effect.
      sudo /etc/init.d/samba restart
    14. Time to create a user that will have access to this share. The following commands will create a user and add it to the group “users” (as specified in our samba config) on your pi and allow you to set a password. We will create a user called “backup” and give it a password. You will be asked to enter the password twice.
      sudo useradd backup -m -G users
      sudo passwd backup
    15. Now we need to add the user “backup” as a Samba user, do this with the following command:
      sudo smbpasswd -a backup
      You should now have a working Samba share. To test this jump onto a Windows computer and browse the network, you should see a server called “RASPBERRYPI” If you double click the server, you should then see a folder called “Main” (as specified in step 12, between the square brackets [Main])



      If you double click on the “Main” folder, you should be prompted for a username and password. Simply enter the username “backup” and the password you used back on step 14.
      Viloa! You have successfully accessed the samba share. You should be able to add/remove files.
    16. Now, if our Pi were to restart, we would lose the samba share because the external hard drives won’t re-mount. To fix this we need to tell our Pi to mount the external hard drives on boot. To do this, edit the following file:
      sudo nano /etc/fstab
      And the add the following lines (notice that the /media/<folder name> are the same for each mount as previously stated on step 6):
      /dev/sda1 /media/main auto noatime 0 0
      /dev/sda2 /media/backup auto noatime 0 0
    17. Now if our Pi reboots, the external hard drives will be automatically mounted and our Samba share will continue to work!
    18. Now it’s time to setup some redundancy. We are going to use rsync to backup all our files on our “main” hard drive over to our “backup” hard drive. First we need to install the rsync package:
      sudo apt-get install rsync
    19. With rsync installed, we are going to setup a cron job to automatically do the backup for us. Start by entering the following command to open up the cron scheduling table:
      crontab –e
    20. Then at the very bottom of the document, add the following line:
      0 5 * * * rsync -av --delete /media/main /media/backup
      This will run the backup every day at 5am and deleting anything on the backup drive which is no longer on the main drive.
    21. That’s it! You now have a PiNAS setup that’ll mirror your files to a backup drive.

    Have you joined the DF discord server. https://discord.com/invite/YajVGQxDaw

    3 Thanks given to Teajunkie

    elephantsoup (2nd April 2015),  Mystical_2K (1st April 2015),  Squizza (31st March 2015)  


Similar Threads

  1. Make tef89 a mod!
    By BlackBeard in forum Forum Suggestions & Feedback
    Replies: 14
    Last Post: 12th December 2002, 01:47 AM
  2. ATX Power supply tester?
    By Billy2052 in forum PC Hardware
    Replies: 1
    Last Post: 9th September 2002, 12:27 AM
  3. Power Miss-Management
    By El Wappo in forum PC Problems
    Replies: 3
    Last Post: 6th September 2002, 01:44 PM
  4. Make money with your mobile phone
    By colinjohn1 in forum The Dog and Duck
    Replies: 12
    Last Post: 30th August 2002, 04:49 PM
  5. Power pack for HP external rewriter (again!)
    By Gizzard in forum PC Problems
    Replies: 0
    Last Post: 30th August 2002, 07:25 AM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •