I'm following a tutorial from here for setting up Deluge on my Raspberry Pi. However, whenever I try to start up a torrent download to my external hard drive connected by USB, Deluge says that permission is denied for the directory. I tried to fix it with chmod
but that doesn't fix it. I looked here and here but I'm not quite sure what they are talking about. They talk about fstab file but I'm not sure what that is.
TL;DR:
What user are you logging in with and would like to run the deluge daemon at boot?
Once we know this, we can begin to assign proper settings for the user and the files and folders
- We need to setup /etc/fstab file to use the proper syntax and options and mount the external drive.
- Once the drive is mounted, we need to create the folders and setup permissions on those newly created files and folders with the right user and settings.
What user account are you using to login to the pi? The boot script and deluge auth file from howtogeek are setup for the user "pi." Is that the user account you are logging in with? If not, we need to find out who you are logging in with so we can get the right settings in place. I personally prefer to run deluged as my user I log in with because of all the permission problems I ran into. The command "whoami" will print to the terminal who is the currently logged in user.
cjohnson@dev:~$ whoami
cjohnson
Fstab can be a little tricky, especially with USB drives. We can setup the USB drives in fstab the right way once we get to that part of the problem. The proper way to mount devices in fstab would be by using the UUID of the device that will be mounted because sometimes the device names will change, but not the UUID; and then we can assign the right options. To get the UUID of all devices:
cjohnson@dev:~$ sudo blkid
/dev/sda1: UUID="59c8053f-53e2-45cf-ae1f-bf2804edd353" TYPE="ext4" PARTUUID="8e94f8d6-01"
/dev/sda5: UUID="6eb0352f-2592-440f-bc9a-7895ad91c340" TYPE="swap" PARTUUID="8e94f8d6-05"
Basically, we want to mount the USB drive on boot at the right mount point and with the right permissions, and skip mounting if it's taking too long or not physically connected so the pi can boot the machine just in case the USB is disconnected. I like to reference the Ubuntu Community Fstab document, since it's pretty good. The syntax of your file would need to look something like:
#Mount for External Drive
UUID="UUID from sudo blkid" /mount_point auto defaults,nofail 0 0
We need to make sure the USB is connected when we setup your sub directories, so we can assign permission to the folders on the USB. The funny thing about USBs in linux is that you can create the sub directories without the USB connected and the directories will really be created, but once the USB is connected, those directories will not show up until the USB is disconnected once again. So what is happening is the pi see's those directories as real directories, because they are, but when you mount a USB on top of those directories they no longer exist since the USB is now actively showing its directories. So, we need to make sure the sub directories are being created while the USB is connected so we can setup proper permissions on the directories.
There are several ways to determine if your USB is connected and working. The first and easiest is using "lsusb":
cjohnson@dev:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Fdisk is also a great tool and will show if you even have partitions setup for the drive:
cjohnson@dev:~$ sudo fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8e94f8d6
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 37748735 37746688 18G 83 Linux
/dev/sda2 37750782 41940991 4190210 2G 5 Extended
/dev/sda5 37750784 41940991 4190208 2G 82 Linux swap / Solaris
You will see a different list than me, and VirtualBox wouldn't display my connected USB, but you should see a short description of your connected devices by USB including you drive with "lsusb" and you will hopefully see your connected drive with all its partitions when you run fdisk. BE SURE TO USE fdisk -l SO YOU DON'T CAUSE CORRUPTION. Fdisk is a partitioning tool, so proceed with caution. Now, this can go down several different roads because your external drive may need the partitions created and formatted
The unfortunate thing about the howtogeek article you used to setup deluge, made a lot of assumptions about previous articles that should've been read to make sense of the current article, which is never a good idea in writing. The article was somewhat confusing, and very unorganized for the guys at howtogeek usually write. Deluge has a great support page for getting deluge up and running like it should be, which I'll link here. http://dev.deluge-torrent.org/wiki/UserGuide/Service
This article will create a user and group named "deluge" that will run the deluge daemon and would need permissions for the deluge user on the USB folders.
The way deluge works, is all controlled by a config file usually located at: "/home/$USER/.config/deluge/core.conf". If you use the linked article above, the config file would be at "/var/lib/deluge/.config/deluge/core.conf" So our goal is to make sure that we are using the right config file with the right user, so our scripts will work and so we can configure proper permissions.
I use systemd to manage my startup scripts, and I use my main user for deluge.
My /etc/systemd/system/ service file:
[Unit]
Description=Deluge Bittorrent Client Daemon
Documentation=man:deluged
After=network-online.target deluged.service
[Service]
Type=simple
User=cjohnson
Group=cjohnson
UMask=022
ExecStart=/usr/bin/deluged -d -l /home/cjohnson/.config/deluge/daemon.log -L warning --pidfile=/home/cjohnson/.config/deluge/deluge.pid --config=/home/cjohnson/.config/deluge
Restart=on-failure
# Time to wait before forcefully stopped.
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
Be sure that your Operating System uses systemd before writing a systemd service file. The howtogeek article uses init.d scripts instead of the newer systemd service. The delgue article I linked shows how to convert init.d scripts to systemd if your Operating System supports it.
The only changes I made in my config file,"/home/cjohnson/.config/deluge/core.conf", are location options where I want to store my data. In your case, these need to point to your External Drive once we are sure it's setup right:
torrentfiles_location
autoadd_location
download_location
move_completed_path
Once the drive is mounted, we need to create the sub directories that you would like, in the howtogeek article it's the folders under /media/USBHDD1/shares, and we should be able to use this command: (We will have different folder name rather than USBHDD1, I'm just using that as our example and our $USER will be whatever user we determined to run deluged at boot)
sudo chown -R $USER.$USER /media/USBHDD1/shares/
EDIT: I personally prefer to use ACLs for managing ownership and permissions, simply because it's dynamically applied to all the files and subfolders in a directory. ACLs are a bit more advanced, but much better to use, because I can add cjohnson with 755 permissions to a directory, and all the new files and folders that are added to that directory, will always be set with the user cjohnosn with rwx.r-x.r-x permissions to anything in that directory, even if I'm not the owner of said directory.
For Reference, one can try to:
chmod 755 -R yourdownloaddir
(as StarShire did)start deluge with
umask 000
(see google)manually restart deluge
If the last works for you, probably add these automated scripts to your system. ($user = yourusername)
sudo nano /etc/init.d/deluge-wra
#!/bin/sh
### BEGIN INIT INFO
# Provides: deluge-wra
# Required-Start: $local_fs $remote_fs $syslog $all
# Required-Stop: $local_fs $remote_fs $syslog $all
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: deluge startup workaround
# Description: script to reset deluge after autostart
### END INIT INFO
#Author: Hirsch
#http://raspberrypi.stackexchange.com/users/19600/hirsch
waittime=60
#(seconds)
case "$1" in
'start')
echo "starting background-process.."
sudo /home/$user/bin/deluge-wra-bin $waittime &
#nested script for background-waiting
;;
'stop')
#nothing to do
echo "don't poke me, please."
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
chmod 755 /etc/init.d/deluge-wra
update-rc.d deluge-wra enable
mkdir /home/$user/bin
(if not existent)
nano /home/$user/bin/deluge-wra-bin
#!/bin/sh
echo "restarting the daemon in $1 sec.."
sleep $1
sudo /etc/init.d/deluge-daemon restart
echo "done."
sudo chmod 755 /home/$user/bin/deluge-wra-bin
Now everything should be set up, you can test the service by typing
sudo service deluge-wra start
or
sudo /etc/init.d/deluge-wra start
(General Setup: deluge-daemon from here, to set up everything i primarly used this from howtogeek)
-
Those scripts are positively hideous! Please do elaborate on you
umask
solution, that's interesting, but find some other way to script the restart is necessary! ;) – Bex Aug 12 '14 at 8:47 -
@Bex: I'll probably look into it some time. Did you vote down because it isn't clean? – hirsch Aug 13 '14 at 9:25
-
Yes, I voted it down to signify that I don't recommend using that script. Edit it, and I will probably change my vote. ;) – Bex Aug 13 '14 at 19:01
-
-
fstab is the file /etc/fstab which is the File Systems TABle.
It contains the instructions of how to handle mounted file systems, think hard drives and USB pen drives.
if I look at my Raspberry Pi /etc/fstab I get
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
"proc" is special internal file system, so ignore that. The /dev/mmcblk0p[12] are the device files that the kernel added at boot time for each of the partitions on the SD card. The are mounted to /boot and / accordingly. When you add another device, like an external HDD you append(or the OS does it for you) a new line.
Along the lines of
/dev/sdc1 /mnt/sdc1 auto user,noatime 0 1
This is taken from I home Linux machine. When I plug a USB thumbdrive in the kernel assigns it /dev/sdc1(normal) and I have a folder /mnt/sdc1 which is where it will show up. The auto is the file system type, think DOS/APPLE etc.
The last bit is the options, user means any user account should have permissions and noatime means the access time attribute should not be updated, stops wear on the drive.
Once you have your drive connected run
cat /etc/fstab
to see the current settings.
You will need to run
nano /etc/fstab
to edit the file as root.
I was having the exact same problem as you, following the same guide.
In my case, my HDD is FAT formatted. I changed the part in the /etc/fstab
file where my HDD is mounted. This is how its configured for my HDD.
/dev/sda1 /media/USBHDD vfat umask=000 0 0
Rebooted and it's working now.
What filesystem are you using on the external drive? If you're not using a filesystem that supports unix permissions (VFAT, NTFS), then the drive will be mounted with uid=0, gid=0, which means only root will have full permissions. See the manpage for mount for full details.
You could modify the umask settings, but you may not want every user to have unrestricted rights. Those permissions are there for a reason! I recommend using the User ID and Group ID (-o uid= and gid=) mount options in /etc/fstab.
You can identify the current user's effective UID by typing the following at a shell prompt:
echo $EUID
Alternately, you could use:
grep <username> /etc/passwd
On my RPi, I get:
pi:x:1000:1000:,,,:/home/pi:/bin/bash
The fields are separated by colons (:). The 3rd field is the UID, the 4th the GID.
The value returned is what you need to type into your /etc/fstab line for that filesystem. (From memory), here's an example:
/dev/sdd1 /data vfat defaults,uid=1000,gid=1000 0 2
That way, the filesystem is mounted as owned by that user rather than allowing unrestricted read/write by any user.