Mount a usb drive or hard disk on Raspbian

What’s the best way to auto mount a usb drive or hard disk? What if the filesystem is ntfs?

To get a list of connected usb disks you can:

sudo blkid

In the screenshot above you can see there are two usb devices:

  • /dev/sda1: UUID=”E89484EA9484BC96″ TYPE=”ntfs” PARTUUID=”008ffb75-01″
  • /dev/sdb1: LABEL=”Extern station” UUID=”92FA278AFA2769A5″ TYPE=”ntfs” PARTUUID=” 0009a8db-01″

To be able to use these devices, you have to mount them in a folder. Let’s create two folders:

sudo mkdir /mnt/usb1
sudo mkdir /mnt/hd1

The usb1 folder I’ve created for my usb stick. The hd1 folder for my external hard drive.

We need to take ownership of these folders:

sudo chown -R pi:pi /mnt/usb1
sudo chown -R pi:pi /mnt/hd1

If any of the usb devices is formatted in ntfs, you best install ntfs-3g:

sudo apt-get install ntfs-3g

Now let’s edit our file system table, so that the usb stick & external hard drive are mounted every time the system boots:

sudo nano /etc/fstab

As you can see in the screenshot above I’ve used the disk UUID as name to find it. This way, if you unplug your usb flash drive and put it in another usb port, it still works. As type, make sure to use ntfs-3g.

Now you just need to reboot and the disks are both mounted!

sudo reboot

For completeness, you could also mount the usb stick just once with this:

sudo mount -o uid=pi -o gid=pi -t ntfs-3g /dev/sda1 /mnt/usb1

Sources

 

Raspbmc: iptables

By default, all requests arriving at the pi, coming from the internet (WAN), are blocked. Only requests coming from your local LAN are allowed.

To do this, Raspbmc uses iptables. It’s like a firewall, and uses a set of rules to determine if a request has to be blocked or not.

Interested to see your current iptables rules? Use this command:

iptables -L -n

If you want to allow a port, to be not blocked, you have to add this to your iptables. The following bash command is an example that allows all tcp requests to the port 5050:

iptables -A INPUT -p tcp --dport 5050 -j ACCEPT

However, every time you restart your pi, this rules are flushed or emptied. That’s why we need to add them to a script, that gets executed on every boot. That script is: /etc/network/if-up.d/secure-rmc.

Use:

sudo nano /etc/network/if-up.d/secure-rmc

Change/add the ports you want open, to the script. I’ll add 5050, 9091 & 8888. That’s for couchpotato, transmission & BitTorrent Sync. You’ll find the block at the end of the script.

if [ "$IFACE" != "lo" ]; then
    NETMASK=$(get_subnet $IFACE)
    if [ ${#NETMASK} -eq 0 ]; then
        logger -t secure-rmc "netmask not found"
        exit 1
    fi
    iptables -A INPUT -s $NETMASK -i $IFACE -j ACCEPT
    iptables -A INPUT -p tcp --dport 5050 -j ACCEPT
    iptables -A INPUT -p tcp --dport 9091 -j ACCEPT
    iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
    iptables -A INPUT -i $IFACE -j DROP
fi

Resources

My raspberry pi

The raspberry pi is an awesome device. It’s affordable, it’s a media center, a web server, very slow and doesn’t use much electricity. It’s also a very good looking piece of hardware. Fits your living room!

pi-1

pi-2

This post is about how mine is configured!

The services

  • Xbmc (installed as raspbmc): a powerful media center, running on Debian.
  • Transmission: A minimalistic torrent client.
  • CouchPotato: Software that searches the movies you want and starts to download them as soon as they come available.
  • BitTorrent Sync: Dropbox like service, easy way to backup folders on multiple computers.
  • Samba: Share a hard disk to the local network.

The place

My pi lives next to my TV. It’s powered by a 5V 2A power supply. It has a 8 gb sd card and their is a 2 TB external usb hard drive attached.

Connected

I use Putty to modify raspbmc via ssh, Yatse android app to control Xbmc. When needed I can connect an external keyboard because I still have 1 usb port over.

Security

As you could possibly open up some ports to the internet, you will want to secure your raspberry pi.

Install

I won’t list the complete process but refer to guides I followed.

0. Static IP

http://choorucode.com/2012/08/14/how-to-assign-a-static-ip-address-to-raspbmc/

1. Raspbmc

First we need to install raspbmc on the pi: http://www.raspbmc.com/wiki/user/windows-installation/.

2. CouchPotato, Transmission

3. BitTorrent Sync

4. Enable samba

You can do this in the xbmc interface.

5. Dynamic Dns

http://www.techjawab.com/2013/06/setup-dynamic-dns-dyndns-for-free-on.html

XBMC tweaks

  1. By default, if there is no hdmi connected on boot, it won’t enable hdmi. That’s ridiculous!