9. Thanks for the memories
For this chapter you’ll need a memory stick or a pre-formatted external hard drive with a USB connection.Â As we are going to be putting videos on it, the larger the better.Â Got one?Â Good.Â Stuff it up your Pi’s USB port.Â There should be whirrings and flashings (subject to lights or motors being present) as something happens. If we were using Windows, the external storage would appear as a drive letter.Â Linux, however, lets you choose where to make it appear. Â Linux has a single directory tree under which external storage and internal storage is placed, or “mounted” in Linux terminology.Â Remember when I said to change the “Download to: ” directory setting in Transmission to /mnt/downloads”?Â That’s where we will be mounting your external storage.Â You might have questions at this point, but let’s get your external storage mounted before we come to them. A while ago I was blethering on about how bad it was to be root and how it was a good idea that you couldn’t log in as root.Â Yes, well, I was probably slightly exaggerating to reinforce a point.Â Sometimes you have to do lots of stuff as root and all that sudoing starts getting boring.Â You can make yourself root until you exit, by doing sudo -s. Â Try it:
naich@raspberrypi ~ $ sudo -s root@raspberrypi:/home/naich#
Notice a few things here – the “$” has changed to “‘#” to indicate you are now root, the “~” has changed to “/home/your_name because it is no longer your home directory and you are now “root@raspberrypi”.Â You now have absolute power over the entire operating system.Â Let it go to your head for a while, cackle like Emperor Palpatine and let the hate flow through you. I like to do this occasionally when I become root and I find it best get it out of my system before I do anything else.Â Back to normal again?Â Good. First we need to create the directory to mount the external storage on.Â The mount location has to already exist in order to mount something on it.Â Type in the commands in bold:
root@raspberrypi:/home/naich# cd /mnt root@raspberrypi:/mnt# ls -l total 0 root@raspberrypi:/mnt# mkdir downloads root@raspberrypi:/mnt# ls -l total 4 drwxr-xr-x 2 root root 4096 Aug 21 13:24 downloads root@raspberrypi:/mnt#
You change your working directory to /mnt (this is traditionally where you mount things), see what is already there (nothing), create a directory called “downloads” with “mkdir” and then you list it. Quick aside here – see that “drwxr-xr-x” bit?Â That shows you what sort of file it is (“d” means directory) and the permissions for it, showing who is allowed to do what to it.Â Read the this page up to and including section 2.1.1to understand permissions or try and battle through my very short explanation here:
There are 3 lots of “rwx”s, the first for the owner of the file, the second for the specified group (it is the second “root” in the illustration above, shown here in italics) and the third is for “others”, i.e. everyone else who is not the owner or a member of the group.Â In each “rwx”, “r” means “read”, “w” means “write” and “x” means “execute” if it is a program or “enter” if it is a directory.Â A dash (“-“) means a lack of permission for that function, so in the above example, the first 3 letters after “d” (“rwx”) mean the owner (root) can “r”ead, “w”rite and “x”enter the directory.Â A member of the “root” group (the next 3 letters) can “r”ead and “x”enter the directory but not “w”rite any files to it, as the “w” is missing.Â The same “r-x” permissions apply to everyone else, as shown in the last 3 letters.
Now we need to find the external storage. Â The Linux kernal (the core of the operating system) will have interrogated your external storage to find out what it was when you plugged it in, and then set it up as a block device, making it available in the /dev directory as if it were a file.Â As it is, it is an interface that you can read and write to it but not in any way that is useful to you.Â It is now up to you to mount that block device on the filesystem so you can treat it as a branch on the directory tree.Â Have a look in /dev and you’ll see a whole load of files that are interfaces to devices.Â One of those files is your external storage, but which one?Â There are a few ways to find it, but the easiest is with the command fdisk -l:
root@raspberrypi:/mnt# fdisk -l Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes 4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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 Disk identifier: 0x000714e9 Â Â Â Â Â Â Â Device BootÂ Â Â Â Â StartÂ Â Â Â Â Â Â Â EndÂ Â Â Â Â BlocksÂ Â IdÂ System /dev/mmcblk0p1Â Â Â Â Â Â Â Â Â Â Â 8192Â Â Â Â Â 122879Â Â Â Â Â Â 57344Â Â Â cÂ W95 FAT32 (LBA) /dev/mmcblk0p2Â Â Â Â Â Â Â Â Â 122880Â Â Â Â 7744511Â Â Â Â 3810816Â Â 83Â Linux Disk /dev/sda: 8019 MB, 8019509248 bytes 20 heads, 16 sectors/track, 48947 cylinders, total 15663104 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 Disk identifier: 0x665e2cdf Â Â Device BootÂ Â Â Â Â StartÂ Â Â Â Â Â Â Â EndÂ Â Â Â Â BlocksÂ Â IdÂ System /dev/sda1Â Â *Â Â Â Â Â Â Â Â Â 80Â Â Â 15663103Â Â Â Â 7831512Â Â Â bÂ W95 FAT32 root@raspberrypi:/mnt#
There’s a lot of information there, but the important bits are where it says “Disk /dev/…”, showing the size of the hardware and the column under “Device” which shows the names of the block devices each partition has been assigned. “Disk /dev/mmcblk0” is the SD card – see how it is split into two partitions, one large (3810816 blocks, each block being 1K making it about 3.8GB) and one small (57344 blocks)?Â The other “Disk” (it will probably be “/dev/sda”) is your external storage, with its single partition appearing as “/dev/sda<number>”.Â In my case it’s “sda1 “and 8019 MB big – it’s an 8GB memory stick with its partition having 7831512 1K blocks.Â Yours might have a different number – “sda4”, for example, in which case use that rather than “sda1”.Â Now let’s mount the /dev/sda1 device to /mnt/downloads with mount /dev/sda1 /mnt/downloads:
root@raspberrypi:/mnt# mount /dev/sda1 /mnt/downloads root@raspberrypi:/mnt# ls -l downloads total 188 drwxr-xr-x 3 root rootÂ Â 4096 Jul 12 17:07 Acad Course -rwxr-xr-x 1 root root 181574 Jul 12 16:44 Chamber Assembly.wmv drwxr-xr-x 2 root rootÂ Â 4096 Aug 15 19:31 vids root@raspberrypi:/mnt#
The contents of the memory stick may vary.Â Note how the owner and group are “root”?Â That is because it was root who mounted the device.Â Now we know it works, we can make it so the drive is automatically mounted at boot time,Â writeableÂ by the user “debian-transmission”, who runs the transmission-daemon program. We need to find out his user ID and group ID though – type id -u debian-transmissionÂ and make a note of the user ID:
root@raspberrypi:/mnt# id -u debian-transmission 106 root@raspberrypi:/mnt#
It’s 106 for me. Â Then do the same for the group ID with id -g debian-transmission and make a note of that number – 109 for me. We need to unmount it before we remount it for real.Â This is the equivalent of safely removing it – unwritten data will be flushed and no more can be sent to it.Â The command is umount /mnt/downloads – that’s umount, not unmount. Â If you are doing this as a normal userÂ later on, remember to sudo the command.
root@raspberrypi:/mnt# umount /mnt/downloads/ root@raspberrypi:/mnt# ls -l downloads/ total 0 root@raspberrypi:/mnt#
Never remove a storage device without unmounting it first. Â If you do, a boxing glove on a spring will shoot out of the top of your Pi and punch you in the nose. Â Well, it should. Â You can lose data and corrupt the file system by yanking it out without unmounting. Â You might also be wondering what would happen to anything that was already in the /mnt/downloads directory when your device was mounted.Â The contents are preserved but are not accessible while the device is mounted over the top of them.
Now let’s automate the mounting of the external storage.Â At boot time the file /etc/fstab is read to see what needs to be mounted.Â Edit that file now with nano /etc/fstabÂ and you will see this:
procÂ Â Â Â Â Â Â Â Â Â Â /procÂ Â Â Â Â Â Â Â Â Â procÂ Â Â defaultsÂ Â Â Â Â Â Â Â Â 0Â Â Â Â Â Â 0 /dev/mmcblk0p1Â /bootÂ Â Â Â Â Â Â Â Â Â vfatÂ Â Â defaultsÂ Â Â Â Â Â Â Â Â 0Â Â Â Â Â Â 0 /dev/mmcblk0p2Â /Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext4Â Â Â defaults,noatimeÂ 0Â Â Â Â Â Â 0 # a swapfile is not a swap partition, so no using swapon|off from here on, use $
Any line starting with “#” is a comment for the benefit of humans and ignored by the computer.Â This goes for most configuration files.Â Have a guess at what the first two columns are.Â If you are really keen, try reading the man page for fstab with man fstab. The first is the block device name, the second is where it is mounted, the third is what sort of filesystem it is and the fourth is options.Â Â The other two are used for maintenance and can be left out or set to 0.Â You will want to add this line at the end in order to automatically mount your external storage:
/dev/sda1 /mnt/downloads auto defaults,uid=106,gid=109 0 0
Replace the “uid=106” and “gid=109” with the numbers you found earlier for user ID and group ID.Â Save and exit with CTRL-X and then answering “Y” and hit return to save it with the same file name. Now mount the drive with mount -a. This mounts all the devices in /etc/fstab in the same manner as if it was booting up. Finally, check everything is hunky-dory:
root@raspberrypi:/mnt#Â mount -a root@raspberrypi:/mnt# ls -l total 4 drwxr-xr-x 4 debian-transmission debian-transmission 4096 JanÂ 1Â 1970 downloads
Smashing.Â I should also point out that Linux distributions like Ubuntu do all this automatically, popping up a file manager window showing the contents of the memory stick as soon as it is plugged in.Â But we are operating at a lower level than that.
Now stop being root by tying exit:
root@raspberrypi:/mnt# exit exit naich@raspberrypi ~ $
Now we are back to normal.Â You can stop cackling.Â Your Pi is set up to mount the memory stick whenever it boots, so you don’t need to do anything else other than remember to sudo umount /mnt/downloads if you take the stick out and sudo mount -a when you put it back in.
10. Torrent something!
Now open up the Transmission web interface by pointing your browser at http://your_pi_ip_address:9091 and click on the “Open” icon. Â Put this URL for a perfectly legal video torent in it:
Put it in the “URL” box and click open.Â Magnet links also work in this box. If you have found a Magnet link from a perfectly respectable web site, right click and choose “copy link location” and paste it into the “URL” box in Transmission.Â If you have downloaded the .torrent file, upload it to Transmission.
You can check on the status of the torrent by clicking on it and then clicking the “i” icon for more info on it. Â I got a “unregistered torrent” error, but DHT found enough peers to get it all.
Sometimes, with a popular torrent with lots of fast peers, the poor little Pi can get a bit overwhelmed with all the traffic hammering its ports.Â It’s like a DOS attack and can bring down the Pi if it is bad enough.Â So I like to limit the number of connections by going to the web panel, opening up settings by clicking on the spanner, going to the “Peers” tab and setting a limit of 20 peers per torrent and 100 peers overall.Â I also set speed limits of 400kB/s for up and downloads in the “Speed” tab.
If you are having trouble connecting to any peers, make sure that “Use port forwarding from my router” is checked in “Network” tab of the settings.Â This page gives some more info about setting up your router.Â If your internet connection is fast you should have a high definition video file on your memory stick before you know it.Â I’ll leave you to find out more about how Transmission works by the age-old method of clicking things to see what happens.
Most tellies these days have USB ports on them which you can lob a stick into.Â If yours does, unmount and lob your stick.Â Our telly also has an ethernet port on it, for streaming video from a uPNP media server.Â Wouldn’t it be good to have a uPNP video server on the Pi?Â I think we could probably manage that in the next chapter.
12 Replies to “Memory sticks and torrents”
having trouble mounting USB stick.
When I type in ls -1. It says downloads underneath. Instead of total 0
That should be “ls -l” with the lower case letter “L” not the number “1”. Try copy and pasting the code in red. Is there anything on the memory stick already? If it’s empty you won’t see anything. Hope this helps.
Im having an issue mounting a 500gb external drive.
Error – mount: warning: /mnt/downloads seems to be mounted read-only
Im new to linux coding. It seems that im using ntfs format which might be causing the issue. I want to retain the file format but im lost and dont know how to change the permission.
Permission: dr-x—— 1 debian-trans….
Any solution on this? Thanks.
Linux should be able to mount ntfs filesystems. By the looks of this post you will have to install the ntfs drivers with “sudo apt-get install ntfs-3g”.
using sudo apt-get install ntfs-3g allowed me to mount my WB 1TB external hard drive with full permissions – thanks for the great tutorial
Very nice guide, congratulations! I’ve set up Transmission to download on a USB stick. My only problem is that (from Windows too) I can see shared USB folder but I can not write. I tried to change permissions (from raspberry) or add my account to debian-transmission group, but everything remains the same. Thanks.
I’m a little lost here. So, I’ve mounted my USB at /mnt/downloads and given access to debian-transmission.
I;m using Samba and have shared the same location of USM there but I’m unable to access it. I thought maybe it’s got something to do with this. please help me!
Samba eh? I’ve not actually used Samba on a Pi, as I’m using NFS because all my home PCs are Linux. I have used Samba on desktop PCs and found it a total pain to get working properly. The only thing I can suggest is to set the umask to enable anyone to access it – “defaults,uid=106,gid=109,umask=0000” in the options part of the line in fstab for /mnt/downloads.
When I mount my drive (WD MyBook 1TB) the permissions for the downloads folder change to dr-x—— even though when the device is umounted the permissions change back to
I am worried that down the track transmission will not be able to write to this folder because permissions are not granted on the mounted drive.
When I try to fix it with:
chmod u+w downloads
I get a return:
chmod: changing permissions of `downloads’: Read-only file system
even though I am in root user
Any help for this available?
If you set the “umask” for the directory to writeable when you mount it, that should fix things. Add “,umask=0000” to the options section of the line for /mnt/downloads in fstab, e.g.
/dev/sda1 /mnt/downloads auto defaults,uid=106,gid=109,umask=0000 0 0
This should make the permissions drwxrwxrwx when it gets mounted.
hey, thx a lot for the helpful infos, I was able to get me torrent up and running, using xbmc, a slight problem has now come up and maybe u know the short answer to handle it: i cannot simply remove the usb over the xmbc by clicking safe remove anymore…no clue how to get both the torrent and the easy remove button working 😀
If you are mounting it using fstab then you will have to unmount it as the user specified in /etc/fstab. i.e. if you are mounting it as user “transmission-daemon” you will not be able to unmount it as user “xbmc” (or whatever user the “safe remove” bit of xbmc runs under). The way to fix it would be to mount it in fstab with the uid the “safe remove” runs under and alter the umask (see two comments up) so that transmission can write to it.
Comments are closed.