masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Raspberry Pi NAS/Plex/Torrent Headless Setup

Sun Oct 23, 2016 6:59 pm

Well, first of all I'm a noob when comes to Linux. Although I use a Mac and I should be able to know one or two bash commands, I'm far from familiar with its command lines also. Just to give more fun to this guide, English is not my primary language… having said that, sorry for any grammar assassination.
As I mentioned, I'm new to Linux, don't expect to have full description about what this or that command does. I might have a clue, but better not say something that I don't fully understand.

Short story why I decide to create this guide

I bought a RPi 3 first time I've ever looked at one to stop using my MacBook Pro as Plex + Torrent server. After tons of tutorials and how-to guides I managed to get it working-ish. Performance wasn’t that good, definitely acceptable though. My thumbnails were not loading properly, well not all of them.
Basically I had the feeling of being halfway there.
After reading some good tutorials on how to spare your SD and boot from HD instead and few other things that would give me some performance and a more solid structure, I decide to start over again.
As I can't count on my memory I thought would be safer to write every step down in case I need to set everything up again.

HOW-TO
Outcome

After finishing this guide you might have a running Plex Media Server, Transmission torrent and the ability to share some folder over your network.
All of this will be running from an USB External HD sparing your SD and avoid killing it with I/Os.
I will explain only using Ethernet connection and accessing RPi through SSH. So, you don't need monitor, TV nor keyboard.

Pre-requisites
- Raspberry Pi (Model B)
- SD Card
- USB External HD

1. Download Raspbian

I rather download using torrent cause is way faster, but you can try your luck by using direct link.

Torrent: https://downloads.raspberrypi.org/raspb ... st.torrent
Direct link: https://downloads.raspberrypi.org/raspbian_latest

2. Install Raspbian

After having your SD card into your Mac device open terminal and run below command:

Code: Select all

diskutil list
With this you should be able to identify you SD disk, not partition.

Code: Select all

disk2   -- disk
disk2s1 -- partition # (you DON'T want this)
Let's pick disk2 as our SD (change to whatever you have in your system) and mount Raspbian image onto it. Run below in the terminal:

Code: Select all

sudo dd bs=1m if=<path_to_raspbian_img>/raspbian-jessie.img of=/dev/rdisk2
Sit back and relaxe, this command has no verbose mode, and it can take sometime to run depending on your machine.
This will flash the image onto your SD.

3. Welcome to Raspb… not quit yet.

Once your SD card is ready you are good to give life to your RPi. Just put your SD into RPi and turn it on. Don't forget plugging in an Ethernet cable as well.

Back to your Mac, from terminal let's access your RPi: Type your password when asked (raspberry) and voila. Welcome to Raspbian!
BUT we will not update or upgrade yet. Let's fix few things and move everything to the spinning disk and then really start using RPi.

Export your locale:

Code: Select all

export LANGUAGE=en_GB.UTF-8
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
sudo locale-gen
Change en_GB to whatever is your lang.
Fix your time zone by executing:

Code: Select all

sudo dpkg-reconfigure tzdata
After all these, I think worth rebooting:

Code: Select all

sudo reboot
EXTRA

You might want to change your password at this point, totally up to you.

1. root's password change

Code: Select all

sudo passwd
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
2. pi's password change

Code: Select all

passwd pi
Changing password for pi.
(current) UNIX password: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
4. Preparing your HD

Let's prepare the HD to accommodate Raspbian. Make sure you don't have anything important onto your HD, it will be wiped out.
The HD is configured with one 10GB ext partition and one ext4 with the remaining space. I can go with a single or even more partitions and diferente filesystems. But I'll not focus on this.

First unmount your sda:

Code: Select all

 sudo umount /dev/sda1
then prepare the disk:

Code: Select all

sudo parted /dev/sda
(parted) mktable msdos
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary ext4 0% 10000M
(parted) mkpart primary ext4 10000M 100%
(parted) print
Model: Samsung D3 Station (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
    
Number  Start   End     Size    Type     File system  Flags
1      1049kB  10.0GB  9999MB  primary  ext4         lba
2      10.0GB  2000GB  2000GB  primary  ext4         lba
You should have similar output of print (parted) print. To exit type quit and return.
Format boot and root file systems:

Code: Select all

sudo mkfs.ext4 /dev/sda1
sudo mkfs.ext4 /dev/sda2
Mount your sda1 into mnt:

Code: Select all

sudo mount /dev/sda1 /mnt
You can check whether everything is ok by executing df:

Code: Select all

df -h | grep sda1
/dev/sda1       9.1G   21M  8.6G   1% /mnt
Make sure you have rsync installed sudo apt-get install rsync and run:

Code: Select all

sudo rsync -axv / /mnt
Now get the list os UUIDs and PARIDS of your disk:

Code: Select all

sudo blkid | grep sda
/dev/sda1: UUID="7c68f3d8-1b3b-4d56-9143-e8d3c2e05f02" TYPE="ext4" PARTUUID="11022dc3-01"
/dev/sda2: UUID="4f9fa5ab-51b1-410e-a5de-0446b7aced6b" TYPE="ext4" PARTUUID="11022dc3-02"
According to our partitions sda1 is or main linux partition and sda2 will be our storage.
Create a backup of your cmdline.txt case anything goes wild.

Code: Select all

sudo cp /boot/cmdline.txt /boot/cmdline.txt_original
You need to add your sda1's PARTUUID to root and add rootdelay=5 at the end. Let's change the boot file from default SD to HD:

Code: Select all

sudo nano /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=11022dc3-01 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait rootdelay=5
Create the mount target to your sda2:

Code: Select all

sudo mkdir /mnt/mnt/storage
Now will need to change fstab on the HD to auto mount everything. DO NOT CHANGE ON THE SD.

Code: Select all

sudo nano /mnt/etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  none            ext4    ro,noauto         0       1
/dev/disk/by-uuid/7c68f3d8-1b3b-4d56-9143-e8d3c2e05f02 /            ext4 defaults,noatime 0 1
/dev/disk/by-uuid/4f9fa5ab-51b1-410e-a5de-0446b7aced6b /mnt/storage ext4 defaults,noatime 0 0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
At this point you can start praying and reboot:

Code: Select all

sudo cp /mnt/etc/fstab /boot/fstab_usb
sudo reboot
EXTRA
From now on if something goes wrong you can simply revert your cmdline.txt_original to cmdline.txt, reformat and use rsync again.

Code: Select all

sudo mv /boot/cmdline.txt /boot/cmdline.txt_usb
sudo cp /boot/cmdline.txt_original /boot/cmdline.txt
sudo reboot

Code: Select all

sudo mkfs.ext4 /dev/sda1
sudo mount /dev/sda1 /mnt
sudo rsync -axv / /mnt
sudo mv /boot/cmdline.txt_usb /boot/cmdline.txt
# make sure of the UUID
sudo cp /boot/fstab_usb /mnt/etc/fstab 
sudo reboot
With this you're free to proceed from step 5 onwards.

5. Welcome to Raspbian!

If everything went well you should be running from your spinning disk now.
To check:

Code: Select all

sudo mount|grep ' / '|cut -d' ' -f 1
/dev/sda1
Or:

Code: Select all

lsblk
sda           8:0    0  1.8T  0 disk 
|-sda1        8:1    0  9.3G  0 part /
`-sda2        8:2    0  1.8T  0 part /mnt/storage
You are officially running your Raspbian from your HD
Now let's start giving some life to your NAS

First, Update and upgrade your distro:

Code: Select all

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
6. Let's Bring Plex to Life

First we need to secure connection and download a key that will authenticate our downloads to ensure they are safe:

Code: Select all

sudo apt-get install apt-transport-https -y --force-yes 
wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key  | sudo apt-key add -  
then add the repository from Plex and install it lastly reboot it:

Code: Select all

echo "deb https://dev2day.de/pms/ jessie main" | sudo tee /etc/apt/sources.list.d/pms.list
sudo apt-get update
sudo apt-get install -t jessie plexmediaserver -y
Change Plex user to whatever you want:

Code: Select all

sudo nano /etc/default/plexmediaserver
PLEX_MEDIA_SERVER_USER=media

Code: Select all

sudo reboot
Test your server by accessing:
http://raspberrypi.local:32400/web

7. Time to SAMBA

Samba will give you the ability of sharing folders throughout your network.
First install samba:

Code: Select all

sudo apt-get install samba samba-common-bin
Create an users to access your shared folders:

Code: Select all

sudo addgroup media
sudo useradd -g media media
sudo usermod -G media plex
sudo passwd media
sudo smbpasswd -a media
Change the owner of /mnt/storage to media:

Code: Select all

sudo chown -R media:media /mnt/storage
Configure the software by opening the file /etc/samba/smb.conf using the command:

Code: Select all

sudo nano /etc/samba/smb.conf
On the file change wins support to yes wins support = yes and add below [homes] an option to hide home folder available = no
At the end of the file add below:

Code: Select all

[storage]
    comment = Storage share
    path = /mnt/storage
    browseable = yes
    writeable = yes
    public = no
    guest ok = no
    guest only = no
    create mask = 0775
    directory mask = 0775
    read only = no
Restart the service and you should have an working shared folder on your network.

Code: Select all

sudo service smbd restart
8. Transmission LIVE!

Last but not least, let's add a torrent client to our structure.

Code: Select all

sudo apt-get install transmission-daemon
For the sake of organization I will add separate directories for separate needs:

Code: Select all

sudo mkdir -p /mnt/storage/Torrent/inprogress
sudo mkdir -p /mnt/storage/Torrent/complete
sudo mkdir -p /mnt/storage/Torrent/watch
Now we gonna tell Transmission where it will work. change all below to the respective values.

Code: Select all

sudo nano /etc/transmission-daemon/settings.json
    "incomplete-dir": "/mnt/storage/Torrent/inprogress",
    "incomplete-dir-enabled": true,
    "download-dir": "/mnt/storage/Torrent/complete",
    "rpc-password": "media",
    "rpc-username": "Your_Username",
    "rpc-whitelist": "192.168.*.*",
    "trash-original-torrent-files": true, 
Add these two items. As they are new, add a comma to the end and then add them.

Code: Select all

   "watch-dir": "/mnt/storage/Torrent/watch",
    "watch-dir-enabled": true
Now let's fix the user that runs the service to avoid issues moving files later:
Stop Transmission

Code: Select all

sudo service transmission-daemon stop
Change the user to media in /etc/init.d/transmission-daemon:

Code: Select all

sudo nano /etc/init.d/transmission-daemon
Change the owner of below files:

Code: Select all

sudo chown -R media:media /etc/transmission-daemon
sudo chown -R media:media /etc/init.d/transmission-daemon
sudo chown -R media:media /var/lib/transmission-daemon
Change the user to media in /etc/systemd/system/multi-user.target.wants/transmission-daemon.service:

Code: Select all

sudo nano /etc/systemd/system/multi-user.target.wants/transmission-daemon.service
Reload systemctl service:

Code: Select all

sudo systemctl daemon-reload
Create a symbolic link to the settings we changed earlier and change the owner of the folders:

Code: Select all

sudo mkdir -p /home/media/.config/transmission-daemon/
sudo ln -s /etc/transmission-daemon/settings.json /home/media/.config/transmission-daemon/
sudo chown -R media:media /home/media/.config/transmission-daemon/
sudo chown -R media:media /mnt/storage/Torrent/
Start transmission-daemon service:

Code: Select all

sudo service transmission-daemon start
That’s All Folks!

If you are lucky enough everything should be working now.
By not being used to linux and stuff you can imagine how I suffered to put all this together.
I hope this helps you guys.

External Sources
Last edited by masterbeer on Thu Nov 02, 2017 9:17 am, edited 1 time in total.

nirvana47
Posts: 3
Joined: Thu Mar 30, 2017 3:21 am

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Mar 30, 2017 3:27 am

Awesome post... thanks for taking the time to write this. I was browsing the net to understand if my raspberry pi 2 can be setup for torrent + vpn + plex server and I also wanted the ability to have a shared folder to take out downloaded content. This tutorial makes it look like it is entirely possible.

I am curious though.... how's the performance? Do you need to pause the torrent download when playing 1080 video using the raspberry? Any other observations..?

Thanks again for putting this together!

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Mar 30, 2017 9:00 am

nirvana47 wrote:Awesome post... thanks for taking the time to write this. I was browsing the net to understand if my raspberry pi 2 can be setup for torrent + vpn + plex server and I also wanted the ability to have a shared folder to take out downloaded content. This tutorial makes it look like it is entirely possible.

I am curious though.... how's the performance? Do you need to pause the torrent download when playing 1080 video using the raspberry? Any other observations..?

Thanks again for putting this together!
Hey, great I have managed to make it useful :D.

About the performance, I had few performance issues when Plex was trying to transcode the files (usually when running mkv files).
Now that you have mention, I never consider the download speed a factor when I had those issues... anyways.
I don't know what are your devices to watch, but I'm using (mostly) Apple TV and Chromecast. To help with the performance I have converted all my files to mp4, by doing this I have 95% of the time direct play. A few still requires transcoding because of the audio codex.
After doing that I have full speed download (I never really change to be less) + Plex multi devices (sometimes 3 at the same time) running without any issues.

I hope this helps you.

nirvana47
Posts: 3
Joined: Thu Mar 30, 2017 3:21 am

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sun Apr 02, 2017 10:05 pm

I am stuck at the step after installing Plex Media server. I can see the installation worked perfectly, I can see that the service plexmediaserver is running, however if I go to http://raspberrypi.local:32400/web/ or http://<ip-address>:32400/web/ I get a 'Browser can't connect to the server'.

I did an nmap and I see that my 32400 port is closed. I don't have any firewalls running (not that I ran anyway). I've been going nuts trying to figure out what's wrong. :? :?

Tried re-installing everything (right from n00bs on SD card, transfer to HDD, install plex), tried uninstalling and reinstalling plex, tried rebooting, tried restarting the plexmediaserver service... no fish. Seems like I'm not the only one with this problem.

http://raspberrypi.stackexchange.com/qu ... er-on-pi-2
https://www.reddit.com/r/raspberry_pi/c ... ex_server/

Unfortunately, through all my googling, have been unable to find a solution. :cry: :cry: :cry:

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Mon Apr 03, 2017 3:33 am

nirvana47 wrote:I am stuck at the step after installing Plex Media server. I can see the installation worked perfectly, I can see that the service plexmediaserver is running, however if I go to http://raspberrypi.local:32400/web/ or http://<ip-address>:32400/web/ I get a 'Browser can't connect to the server'.

I did an nmap and I see that my 32400 port is closed. I don't have any firewalls running (not that I ran anyway). I've been going nuts trying to figure out what's wrong. :? :?

Tried re-installing everything (right from n00bs on SD card, transfer to HDD, install plex), tried uninstalling and reinstalling plex, tried rebooting, tried restarting the plexmediaserver service... no fish. Seems like I'm not the only one with this problem.

http://raspberrypi.stackexchange.com/qu ... er-on-pi-2
https://www.reddit.com/r/raspberry_pi/c ... ex_server/

Unfortunately, through all my googling, have been unable to find a solution. :cry: :cry: :cry:
Weird, maybe can be some permission issues. Try to change PLEX_MEDIA_SERVER_USER to PI

Code: Select all

sudo service plexmediaserver stop
sudo nano /etc/default/plexmediaserver
PLEX_MEDIA_SERVER_USER=pi
sudo service plexmediaserver start
nmap -p 32400 localhost
Your port should be open...

nirvana47
Posts: 3
Joined: Thu Mar 30, 2017 3:21 am

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Wed Apr 05, 2017 1:14 pm

I did change the user to 'pi' from 'plex'. Also messed with the conf file to see if I could use it on another port. Didn't work. So then I was like ok, screw that... Let's try and at least get torrent and samba setup. Samba worked... Torrent again ran in to some issues. Whole of last weekend was a big frustration... going to try again this weekend.

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 06, 2017 5:49 am

nirvana47 wrote:I did change the user to 'pi' from 'plex'. Also messed with the conf file to see if I could use it on another port. Didn't work. So then I was like ok, screw that... Let's try and at least get torrent and samba setup. Samba worked... Torrent again ran in to some issues. Whole of last weekend was a big frustration... going to try again this weekend.
What happened with transmission?
You probably did, but on transmission, did you configure rpc-whitelist parameter with the range of IPs on your router?

kawaltee
Posts: 3
Joined: Wed Apr 19, 2017 10:15 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Wed Apr 19, 2017 10:18 pm

Hi,

Did you manage to do some progress on this ?
I got the same problem: Plex is running but port 32400 is closed abd I've no idea what to do to open it to access the web UI..
I did some googling but can't find anything

Thanks

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 20, 2017 5:15 am

kawaltee wrote:Hi,

Did you manage to do some progress on this ?
I got the same problem: Plex is running but port 32400 is closed abd I've no idea what to do to open it to access the web UI..
I did some googling but can't find anything

Thanks
I'm still waiting for nirvana47's reply
did you try this?

Code: Select all

sudo service plexmediaserver stop
sudo nano /etc/default/plexmediaserver
PLEX_MEDIA_SERVER_USER=pi
sudo service plexmediaserver start
nmap -p 32400 localhost

kawaltee
Posts: 3
Joined: Wed Apr 19, 2017 10:15 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 20, 2017 9:54 am

masterbeer wrote: I'm still waiting for nirvana47's reply
did you try this?

Code: Select all

sudo service plexmediaserver stop
sudo nano /etc/default/plexmediaserver
PLEX_MEDIA_SERVER_USER=pi
sudo service plexmediaserver start
nmap -p 32400 localhost
Hi,

Yes, the user is set up as "pi"
If I do

Code: Select all

sudo service plexmediaserver status
it says that Plex is running correctly, but the output of

Code: Select all

nmap -p 32400 localhost
shows that port 32400 is closed, therefore I can't access the web gui..

Any idea?
I tried to restart the service and the Pi multiple times and nothing changes..

I've seen someone with the same problem comment on this thread : https://pimylifeup.com/raspberry-pi-plex-server/
Truman wrote: I figured out mine! Just needed to enable port forwarding to 32400 and point it to the static IP of my Pi 3 while it’s connected to Ethernet. Success!
But I have no idea how to do that..

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 20, 2017 10:12 am

Truman wrote: I figured out mine! Just needed to enable port forwarding to 32400 and point it to the static IP of my Pi 3 while it’s connected to Ethernet. Success!
But I have no idea how to do that..[/quote]

This sounds like a router configuration. Try to do some googling on your router model by "forwarding ports" might help.
I am not really into to this router advanced stuff :( :(

kawaltee
Posts: 3
Joined: Wed Apr 19, 2017 10:15 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 20, 2017 10:34 am

masterbeer wrote: This sounds like a router configuration. Try to do some googling on your router model by "forwarding ports" might help.
I am not really into to this router advanced stuff :( :(
I tried every settings on my router (French provider Orange, Livebox v4), restarted it, restarted the pi, Plex, still nothing :/

i think I'm just going to have to start over and install a distrib with a gui where i could access the server direclty from a browser

:(

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Apr 20, 2017 12:57 pm

If you are looking for an interface and have any HDMI monitor (tv) you can plug your raspberry to it and test plex from its browser...

paulohsms
Posts: 1
Joined: Sat Sep 23, 2017 11:26 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sat Sep 23, 2017 11:29 pm

I'm living this nightmare too. Everything is working fine i also did opened it early. But for some reason it is giving me the connection refused error too. Also opened the port on the router. But no success.

My nmap shows the 32400 port CLOSED. Already changed the username. I don't know what to do next.

=(

007Nightfire
Posts: 1
Joined: Wed Sep 27, 2017 8:15 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Wed Sep 27, 2017 8:42 pm

This guide was exactly what I needed to get a jump start, thank you sooo much!

At first I had some problems, I use a Windows machine and had no experience with anything else. Also it was my first Pi project, so you can imagine I was slightly confused.
However, I’ve made a discovery (big for me, probably known stuff for others) that might help other newbies to get things done. I couldn’t connect through SSH with my Pi. I first thought I did something wrong, then I messed with network settings on my pc and on my router. Then I Googled, a lot. So all by all, this is what made it easier for me (on Windows):

1. I used ‘Etcher’ to flash Raspbian on an SD. Easy and no need for brains to get it working.
[etcher.io]
2. For SSH connection I downloaded ‘putty’. Put in the IP address of your Pi and press open. This gave me an ‘access refused’ error though, see point 3. >>
[putty.org]
3. The Raspberry Pi 3 with the newest version of Raspbian does not allow to be accessed through SSH out of the box anymore. To enable this, add a file named ‘ssh’ without extension in the boot folder of your SD. The first time it is read by the Pi, it will delete the file and enable SSH connections. Creating files without extension is easy enough with notepad. Simply save the file as "ssh" and actually use the quotation marks while saving! Then you only have to put it on the SD card in the boot directory, put it in your Pi again and boot.
[https://www.raspberrypi.org/blog/a-secu ... ian-pixel/]

With your guide, I now have a working NAS/Plex setup (choose not to install the Torrent part).

Thanks again!

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Sep 28, 2017 5:25 am

paulohsms wrote:
Sat Sep 23, 2017 11:29 pm
I'm living this nightmare too. Everything is working fine i also did opened it early. But for some reason it is giving me the connection refused error too. Also opened the port on the router. But no success.

My nmap shows the 32400 port CLOSED. Already changed the username. I don't know what to do next.

=(
Someone here had the same issue, unfortunately, network is not something that I have real knowledge.
I'll keep an eye out to see if I can find some answers

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Thu Sep 28, 2017 5:27 am

007Nightfire wrote:
Wed Sep 27, 2017 8:42 pm
This guide was exactly what I needed to get a jump start, thank you sooo much!

At first I had some problems, I use a Windows machine and had no experience with anything else. Also it was my first Pi project, so you can imagine I was slightly confused.
However, I’ve made a discovery (big for me, probably known stuff for others) that might help other newbies to get things done. I couldn’t connect through SSH with my Pi. I first thought I did something wrong, then I messed with network settings on my pc and on my router. Then I Googled, a lot. So all by all, this is what made it easier for me (on Windows):

1. I used ‘Etcher’ to flash Raspbian on an SD. Easy and no need for brains to get it working.
[etcher.io]
2. For SSH connection I downloaded ‘putty’. Put in the IP address of your Pi and press open. This gave me an ‘access refused’ error though, see point 3. >>
[putty.org]
3. The Raspberry Pi 3 with the newest version of Raspbian does not allow to be accessed through SSH out of the box anymore. To enable this, add a file named ‘ssh’ without extension in the boot folder of your SD. The first time it is read by the Pi, it will delete the file and enable SSH connections. Creating files without extension is easy enough with notepad. Simply save the file as "ssh" and actually use the quotation marks while saving! Then you only have to put it on the SD card in the boot directory, put it in your Pi again and boot.
[https://www.raspberrypi.org/blog/a-secu ... ian-pixel/]

With your guide, I now have a working NAS/Plex setup (choose not to install the Torrent part).

Thanks again!
Good to know! =)

Thanks for bringing this point about the newer version of Raspbian.
BTW, I read once that when you get it running try to avoid rebooting and, more important, try to not upgrade/update it.

jon894
Posts: 1
Joined: Sun Nov 05, 2017 12:43 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sun Nov 05, 2017 12:46 pm

Hi
I can't do

Code: Select all

sudo chown -R pi:pi /mnt/library/torrent/
, i get the "chown: changing ownership of '/mnt/library/torrent/': Operation not permitted " I'm trying to give the permissions on a hard drive.

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sun Nov 05, 2017 3:04 pm

jon894 wrote: Hi
I can't do

Code: Select all

sudo chown -R pi:pi /mnt/library/torrent/
, i get the "chown: changing ownership of '/mnt/library/torrent/': Operation not permitted " I'm trying to give the permissions on a hard drive.
I only get this when running without SUDO. can you try to do on a dummy directory.
Like create a new one in /tmp and try to change it.

rowmanns
Posts: 1
Joined: Sat Nov 11, 2017 2:24 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sat Nov 11, 2017 2:27 pm

This is an awesome guide! Just finished setting it up with Raspbian Stretch, thanks for taking the time to create it!

masterbeer
Posts: 11
Joined: Sun Oct 23, 2016 6:03 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sat Nov 11, 2017 4:24 pm

rowmanns wrote:
Sat Nov 11, 2017 2:27 pm
This is an awesome guide! Just finished setting it up with Raspbian Stretch, thanks for taking the time to create it!
Great!
When I find some time I'll add a VPN setup to the mix.
This will allow torrent over VPN, best part is that if the VPN goes down the torrent stops... So full privacy

adamos79
Posts: 2
Joined: Sun Dec 17, 2017 8:21 am

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Sun Dec 17, 2017 8:23 am

Thx very much, i spend hole weekend without resultants, and the I find Your guide ! That works for me!

anil170
Posts: 1
Joined: Thu May 18, 2017 1:09 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Wed Dec 27, 2017 2:51 pm

Can Anybody Provide me The Torrent Box SD Card Image File ?

ssharkj
Posts: 1
Joined: Mon Jan 15, 2018 6:18 pm

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Mon Jan 15, 2018 6:34 pm

why create a partition on the USB harddrive to install linux to?
is the hard drive that much faster than the SD card?

edit: nevermind, it's to reduce IO wear to the SD card

Dan1jel
Posts: 4
Joined: Wed Aug 08, 2018 6:21 pm
Location: Sweden
Contact: Twitter

Re: Raspberry Pi NAS/Plex/Torrent Headless Setup

Fri Aug 10, 2018 10:37 pm

masterbeer wrote:
Sun Oct 23, 2016 6:59 pm
Well, first of all I'm a noob when comes to Linux. Although I use a Mac and I should be able to know one or two bash commands, I'm far from familiar with its command lines also. Just to give more fun to this guide, English is not my primary language… having said that, sorry for any grammar assassination.
As I mentioned, I'm new to Linux, don't expect to have full description about what this or that command does. I might have a clue, but better not say something that I don't fully understand.

Short story why I decide to create this guide

I bought a RPi 3 first time I've ever looked at one to stop using my MacBook Pro as Plex + Torrent server. After tons of tutorials and how-to guides I managed to get it working-ish. Performance wasn’t that good, definitely acceptable though. My thumbnails were not loading properly, well not all of them.
Basically I had the feeling of being halfway there.
After reading some good tutorials on how to spare your SD and boot from HD instead and few other things that would give me some performance and a more solid structure, I decide to start over again.
As I can't count on my memory I thought would be safer to write every step down in case I need to set everything up again.

HOW-TO
Outcome

After finishing this guide you might have a running Plex Media Server, Transmission torrent and the ability to share some folder over your network.
All of this will be running from an USB External HD sparing your SD and avoid killing it with I/Os.
I will explain only using Ethernet connection and accessing RPi through SSH. So, you don't need monitor, TV nor keyboard.

Pre-requisites
- Raspberry Pi (Model B)
- SD Card
- USB External HD

1. Download Raspbian

I rather download using torrent cause is way faster, but you can try your luck by using direct link.

Torrent: https://downloads.raspberrypi.org/raspb ... st.torrent
Direct link: https://downloads.raspberrypi.org/raspbian_latest

2. Install Raspbian

After having your SD card into your Mac device open terminal and run below command:

Code: Select all

diskutil list
With this you should be able to identify you SD disk, not partition.

Code: Select all

disk2   -- disk
disk2s1 -- partition # (you DON'T want this)
Let's pick disk2 as our SD (change to whatever you have in your system) and mount Raspbian image onto it. Run below in the terminal:

Code: Select all

sudo dd bs=1m if=<path_to_raspbian_img>/raspbian-jessie.img of=/dev/rdisk2
Sit back and relaxe, this command has no verbose mode, and it can take sometime to run depending on your machine.
This will flash the image onto your SD.

3. Welcome to Raspb… not quit yet.

Once your SD card is ready you are good to give life to your RPi. Just put your SD into RPi and turn it on. Don't forget plugging in an Ethernet cable as well.

Back to your Mac, from terminal let's access your RPi: Type your password when asked (raspberry) and voila. Welcome to Raspbian!
BUT we will not update or upgrade yet. Let's fix few things and move everything to the spinning disk and then really start using RPi.

Export your locale:

Code: Select all

export LANGUAGE=en_GB.UTF-8
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
sudo locale-gen
Change en_GB to whatever is your lang.
Fix your time zone by executing:

Code: Select all

sudo dpkg-reconfigure tzdata
After all these, I think worth rebooting:

Code: Select all

sudo reboot
EXTRA

You might want to change your password at this point, totally up to you.

1. root's password change

Code: Select all

sudo passwd
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
2. pi's password change

Code: Select all

passwd pi
Changing password for pi.
(current) UNIX password: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
4. Preparing your HD

Let's prepare the HD to accommodate Raspbian. Make sure you don't have anything important onto your HD, it will be wiped out.
The HD is configured with one 10GB ext partition and one ext4 with the remaining space. I can go with a single or even more partitions and diferente filesystems. But I'll not focus on this.

First unmount your sda:

Code: Select all

 sudo umount /dev/sda1
then prepare the disk:

Code: Select all

sudo parted /dev/sda
(parted) mktable msdos
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary ext4 0% 10000M
(parted) mkpart primary ext4 10000M 100%
(parted) print
Model: Samsung D3 Station (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
    
Number  Start   End     Size    Type     File system  Flags
1      1049kB  10.0GB  9999MB  primary  ext4         lba
2      10.0GB  2000GB  2000GB  primary  ext4         lba
You should have similar output of print (parted) print. To exit type quit and return.
Format boot and root file systems:

Code: Select all

sudo mkfs.ext4 /dev/sda1
sudo mkfs.ext4 /dev/sda2
Mount your sda1 into mnt:

Code: Select all

sudo mount /dev/sda1 /mnt
You can check whether everything is ok by executing df:

Code: Select all

df -h | grep sda1
/dev/sda1       9.1G   21M  8.6G   1% /mnt
Make sure you have rsync installed sudo apt-get install rsync and run:

Code: Select all

sudo rsync -axv / /mnt
Now get the list os UUIDs and PARIDS of your disk:

Code: Select all

sudo blkid | grep sda
/dev/sda1: UUID="7c68f3d8-1b3b-4d56-9143-e8d3c2e05f02" TYPE="ext4" PARTUUID="11022dc3-01"
/dev/sda2: UUID="4f9fa5ab-51b1-410e-a5de-0446b7aced6b" TYPE="ext4" PARTUUID="11022dc3-02"
According to our partitions sda1 is or main linux partition and sda2 will be our storage.
Create a backup of your cmdline.txt case anything goes wild.

Code: Select all

sudo cp /boot/cmdline.txt /boot/cmdline.txt_original
You need to add your sda1's PARTUUID to root and add rootdelay=5 at the end. Let's change the boot file from default SD to HD:

Code: Select all

sudo nano /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=11022dc3-01 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait rootdelay=5
Create the mount target to your sda2:

Code: Select all

sudo mkdir /mnt/mnt/storage
Now will need to change fstab on the HD to auto mount everything. DO NOT CHANGE ON THE SD.

Code: Select all

sudo nano /mnt/etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  none            ext4    ro,noauto         0       1
/dev/disk/by-uuid/7c68f3d8-1b3b-4d56-9143-e8d3c2e05f02 /            ext4 defaults,noatime 0 1
/dev/disk/by-uuid/4f9fa5ab-51b1-410e-a5de-0446b7aced6b /mnt/storage ext4 defaults,noatime 0 0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
At this point you can start praying and reboot:

Code: Select all

sudo cp /mnt/etc/fstab /boot/fstab_usb
sudo reboot
EXTRA
From now on if something goes wrong you can simply revert your cmdline.txt_original to cmdline.txt, reformat and use rsync again.

Code: Select all

sudo mv /boot/cmdline.txt /boot/cmdline.txt_usb
sudo cp /boot/cmdline.txt_original /boot/cmdline.txt
sudo reboot

Code: Select all

sudo mkfs.ext4 /dev/sda1
sudo mount /dev/sda1 /mnt
sudo rsync -axv / /mnt
sudo mv /boot/cmdline.txt_usb /boot/cmdline.txt
# make sure of the UUID
sudo cp /boot/fstab_usb /mnt/etc/fstab 
sudo reboot
With this you're free to proceed from step 5 onwards.

5. Welcome to Raspbian!

If everything went well you should be running from your spinning disk now.
To check:

Code: Select all

sudo mount|grep ' / '|cut -d' ' -f 1
/dev/sda1
Or:

Code: Select all

lsblk
sda           8:0    0  1.8T  0 disk 
|-sda1        8:1    0  9.3G  0 part /
`-sda2        8:2    0  1.8T  0 part /mnt/storage
You are officially running your Raspbian from your HD
Now let's start giving some life to your NAS

First, Update and upgrade your distro:

Code: Select all

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
6. Let's Bring Plex to Life

First we need to secure connection and download a key that will authenticate our downloads to ensure they are safe:

Code: Select all

sudo apt-get install apt-transport-https -y --force-yes 
wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key  | sudo apt-key add -  
then add the repository from Plex and install it lastly reboot it:

Code: Select all

echo "deb https://dev2day.de/pms/ jessie main" | sudo tee /etc/apt/sources.list.d/pms.list
sudo apt-get update
sudo apt-get install -t jessie plexmediaserver -y
Change Plex user to whatever you want:

Code: Select all

sudo nano /etc/default/plexmediaserver
PLEX_MEDIA_SERVER_USER=media

Code: Select all

sudo reboot
Test your server by accessing:
http://raspberrypi.local:32400/web

7. Time to SAMBA

Samba will give you the ability of sharing folders throughout your network.
First install samba:

Code: Select all

sudo apt-get install samba samba-common-bin
Create an users to access your shared folders:

Code: Select all

sudo addgroup media
sudo useradd -g media media
sudo usermod -G media plex
sudo passwd media
sudo smbpasswd -a media
Change the owner of /mnt/storage to media:

Code: Select all

sudo chown -R media:media /mnt/storage
Configure the software by opening the file /etc/samba/smb.conf using the command:

Code: Select all

sudo nano /etc/samba/smb.conf
On the file change wins support to yes wins support = yes and add below [homes] an option to hide home folder available = no
At the end of the file add below:

Code: Select all

[storage]
    comment = Storage share
    path = /mnt/storage
    browseable = yes
    writeable = yes
    public = no
    guest ok = no
    guest only = no
    create mask = 0775
    directory mask = 0775
    read only = no
Restart the service and you should have an working shared folder on your network.

Code: Select all

sudo service smbd restart
8. Transmission LIVE!

Last but not least, let's add a torrent client to our structure.

Code: Select all

sudo apt-get install transmission-daemon
For the sake of organization I will add separate directories for separate needs:

Code: Select all

sudo mkdir -p /mnt/storage/Torrent/inprogress
sudo mkdir -p /mnt/storage/Torrent/complete
sudo mkdir -p /mnt/storage/Torrent/watch
Now we gonna tell Transmission where it will work. change all below to the respective values.

Code: Select all

sudo nano /etc/transmission-daemon/settings.json
    "incomplete-dir": "/mnt/storage/Torrent/inprogress",
    "incomplete-dir-enabled": true,
    "download-dir": "/mnt/storage/Torrent/complete",
    "rpc-password": "media",
    "rpc-username": "Your_Username",
    "rpc-whitelist": "192.168.*.*",
    "trash-original-torrent-files": true, 
Add these two items. As they are new, add a comma to the end and then add them.

Code: Select all

   "watch-dir": "/mnt/storage/Torrent/watch",
    "watch-dir-enabled": true
Now let's fix the user that runs the service to avoid issues moving files later:
Stop Transmission

Code: Select all

sudo service transmission-daemon stop
Change the user to media in /etc/init.d/transmission-daemon:

Code: Select all

sudo nano /etc/init.d/transmission-daemon
Change the owner of below files:

Code: Select all

sudo chown -R media:media /etc/transmission-daemon
sudo chown -R media:media /etc/init.d/transmission-daemon
sudo chown -R media:media /var/lib/transmission-daemon
Change the user to media in /etc/systemd/system/multi-user.target.wants/transmission-daemon.service:

Code: Select all

sudo nano /etc/systemd/system/multi-user.target.wants/transmission-daemon.service
Reload systemctl service:

Code: Select all

sudo systemctl daemon-reload
Create a symbolic link to the settings we changed earlier and change the owner of the folders:

Code: Select all

sudo mkdir -p /home/media/.config/transmission-daemon/
sudo ln -s /etc/transmission-daemon/settings.json /home/media/.config/transmission-daemon/
sudo chown -R media:media /home/media/.config/transmission-daemon/
sudo chown -R media:media /mnt/storage/Torrent/
Start transmission-daemon service:

Code: Select all

sudo service transmission-daemon start
That’s All Folks!

If you are lucky enough everything should be working now.
By not being used to linux and stuff you can imagine how I suffered to put all this together.
I hope this helps you guys.

External Sources
Great tutorial! I'm having a trouble that my SD card is saving a copy of the torrent file so it becomes full all the time. When I delete from transmission I also clear up space from SD card. What have I done wrong? Please help me with this :/

Edit: typo and also - I have a harddrive with a folder "downloaded" and "incomplete" that work just fine with transmission, but like I said I have a copy of the torrent file somewhere on my SD that I can't find the reason to why it's happening.

Return to “Media centres”

Who is online

Users browsing this forum: No registered users and 5 guests