A Hot Serving Of Pi – P3

Step 2: Mounting Drives

[Introduction] [Step 1]

Before we install Samba, it is a good idea to make sure that the USB drives you want to plug-in are actually mounting in a useable way. Before we even get that far, though, we first need to make sure that the drives are formatted correctly. Being a Mac user, all my hard drives and USB sticks are formatted in HFS+ (or, Mac OS Extended (Journaled)). This is fine for me, as up until I bought my Pi, I only ever used Macs. Raspbian didn’t like any of my HFS drives though, so I needed to reformat one of them in FAT32 format. Which I don’t like (It doesn’t deal with large files very well). FAT does have its advantages though, it’s a good format for small USB sticks that need to transfer data between Macs and PCs (and Linux machines) so it’s a good happy-medium.

Using ‘Disk Utility’, in [Macintosh HD > Applications > Utilities], you can can reformat your USB drive quite easily.

WARNING

Reformatting a drive will erase its content. Make a backup first.

As you can see in the lower left corner of the image below, the ‘partition’ “GREEN”, on my 16GB JetFlash drive is already formatted for FAT32.

Screen Shot 2013-06-17 at 23.21.30

If your drive says anything other than FAT32 or NTFS, then you will need to reformat it. To do that, select the Drive icon, such as in the image below. Navigate to ‘Partition’, select ‘1 Partition’ from the dropdown menu on the left. Name your partition and choose ‘MS-DOS (FAT) from the dropdown menu on the right and STOP! DO NOT CLICK APPLY.

Screen Shot 2013-06-17 at 23.32.26

STOP

Take some time now to make sure that you are not about to reformat your computer’s hard drive.

I would imagine that OS X has a failsafe built-in that will stop you from reformatting your boot drive, but I am not going to be the one to test that theory.

You have been warned.

When you’re happy everything is correct, click ‘Apply’. The process won’t take very long, even on the 500GB drive I did this on the other day. Once it is done, you can eject it from your Mac.

Depending on how you like to access your Pi, you either want to SSH into it, or load up LXTerminal in the GUI and run this command. (Before you plug-in your USB drive.)

tail -f /var/log/messages

Give this a moment to settle, and then plug-in your USB drive.

What you want to see is a block of lines appear that identify your USB device. If this appears then your Pi can see your drive and all is bon. If your drive doesn’t appear, it is possible that your device is drawing too much power from your Pi, and your Pi doesn’t like it. Try using a powered USB hub. When your happy, press ctrl-c to cancel out.

We’re nearly there

Now we want to give the drive a place to mount. We do this by creating a directory:

sudo mkdir /media/ORANGE
NOTE

Note that the ‘ORANGE’ is simply the name I gave to my drive. This is primarily because I find that colour coding my drives makes them much easier to deal with in general. You can change ‘ORANGE’ to whatever you like, just keep it one word.

The next step is to mount the drive.

sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/ORANGE/
IMPORTANT NOTE

If your drive is using the NTFS format, change ‘vfat’ in the command to ‘ntfs-3g’ (without the quotes).

You may find that NTFS is not supported, you can get around this by simply installing it via ‘apt-get’ with the command:

sudo apt-get install ntfs-3g

Once that is done your drive is mounted. Yay!

Now that’s fine, but we want to run it as a media server, and we want to run it headless, so we don’t want to have to SSH into it every time we boot it up and mount the drive manually. If only we could get the Pi to mount it at login. Oh wait! We can!

I don’t know why, but I had issues making my drive mount every time at login, but I did eventually find a way round it. First, because we are going to make some changes to an important system file, and we’re going to be the superuser, we need to make a backup copy of the ‘fstab’ file we are going to be editing. We do this by running this command:

sudo cp /etc/fstab /etc/fstab.copy

Now most walkthroughs will tell you to go straight ahead and edit the fstab file, but after doing this I still had issues, so first we are going to find out what the UUID of our drive is. We do this by running:

sudo blkid

What we’re looking for is the UUID (Universally Unique Identifier) of the drive we want to mount. The reason we do this is because ‘sda2’, in my case, isn’t necessarily going to be the same place that drive ends up in each time we boot up, especially if I start adding more drives, which I have been doing. By putting the UUID in the fstab file, we can be sure that the right drive is always mounted. sudo blkid will output something like this:

Screen Shot 2013-06-18 at 00.44.17

You want to look for the UUID that is next to a very familiar looking label. Copy the UUID to your clipboard, as we need to put it in the fstab file.

Open fstab in a text editor like so:

sudo nano /etc/fstab

Place this line at the bottom of the file:

UUID=YOUR-UUID /media/ORANGE    vfat    auto,user,rw,exec 0       0

It should look like this:

Screen Shot 2013-06-18 at 00.52.24

NOTE

If you simply copied and pasted your UUID from your blkid output, remember to delete the quote marks.

Exit out of the file, making sure to save the changes.

While we’re here, probably best to make sure we give ourselves write permissions. To do this, we run:

sudo chmod 775 /media/ORANGE

Okay. Shutdown the machine, using:

sudo halt

Unplug your drive and take it to your normal, everyday computer and copy a file onto it. Take it back to your Pi, plug it in and boot it up.

If you’re at the command line you’ll need to log in and then either type ‘startx’ to load the GUI and check that the drive has mounted and that the file is there, or you can ‘cd’ into it with:

cd /media/ORANGE

and then ‘ls’ to look in the drive and see the file. If you see something like the image below, then everything is working perfectly.

Screen Shot 2013-06-18 at 01.12.34

To get back to the home folder in the command line use:

cd ~

And that’s it!

Wait! Wait, wait, wait.

As it stands, the Pi won’t mount the drive unless we log in. We want to run the Pi headless and unattended, having to log it in every time we switch it on is only going to be tedious, and doesn’t let us hide the Pi away somewhere out of the way. Before we finish for the night, we need to make the Pi log itself in automagically.

Make sure you’re back at the home folder by typing ‘cd ~’, once there run:

sudo cp /etc/inittab /etc/inittab.copy

This makes a copy of this important system file incase we ruin it. Now run:

sudo nano /etc/inittab

This is a long file, and what we’re looking for is quite near the bottom. Look for the line:

1:2345:respawn:/sbin/getty --noclear 38400 tty1

Navigate to that line and place a # symbol in front of it to ‘comment it out’. Hash on a Mac is easy to get to by typing alt-3.

Now, below the line we just commented out, add this line:

1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Exit and save the changes made and reboot your Pi. If all has gone well, not only has your Pi logged itself in, it has also mounted the drive as well.

That’s it for this evening, next time, installing Samba and miniDLNA, and getting them both working harmoniously.

Jump to Step 3

Author: Dan

Share This Post On