External USB crashed Raspberry Pi

Talk about excitement… I was setting up the Pi for a backup server and connected one USB drive, no problem. Everything seemed to work and I was in great shape. Then I decided to add the second drive. Upon doing so, BAM! CRASH! BOOM! etc. Raspberry Pi was down for the count and was not getting up. Want to take a guess what happened?…

Well, the main piece of information I left out was that the two drives were USB powered drives and relied on the Pi for their power. WHOOPS! A raspberry pi doesn’t have enough power to provide the power to maintain two USB drives. Hence, drives attached = Pi no more…


You didn’t honestly think I gave up there right?!?

So I needed the drives connected to the Pi but an external power source for the drives to work and the Pi not to crash.

You get where this is going yet…

All you need is a powered USB hub. I picked mine up at a local best buy since I wanted it that day. If you plan ahead you can probably get a better price online if you want.

At any rate, if you have USB drives that need power from the USB they connect to and you are trying to attach them to a Pi. I highly recommend a powered USB hub.

Creating a home backup server with Raspberry Pi

So, how many of us remember to have redundancy in files and other data that we trust a computer to store for us? Have you ever lost data to a faulty drive? Well I certainly have and it sucks trying to retrieve it after the drive fails. For the most past I have been able to recover the data but I don’t want my luck to run out. Hence, I wanted and needed a backup solution. I have thought long and hard about getting some kind of a RAID solution but in the meantime decided it was worth the money to use a Raspberry Pi and a couple USB drives. This post will explain as simple as possible the steps to getting it setup.

Note: This article assumes you have a Raspberry Pi, 2 identical USB drives and the Raspberry Pi already has an OS installed.

One link I recommend reviewing is Here. This link for “How to Geek” was really helpful and provided a great guide. I will summarize the steps within and add where I ran into problems.

1. Mounting the drives

This is typically done using the a combination of a couple commands.

sudo apt-get install ntfs-3g

to install the proper file system format.

sudo fdisk -l

will then list out the connected drives allowing you to find the connected USB drives. When the list returns you are looking specifically at the sda and sdb entries. These are the ones that represent the USB drives. Now this is also where I ran into my first issue. The issue was actually with the next step is to mount the drives. As it turned out the drives mounted themselves. How dare they, right?

Well because the already mounted themselves I ended up editing the fstab file manually and create the directories I wanted the drives to mount to specific directories so that I could control the mounting directory for future steps. Therefore I used the following steps for the mounting:

sudo mkdir /media/USBHDD1
sudo mkdir /media/USBHDD2

creating the directories I wanted and then

sudo nano /etc/fstab

to open the fstab file to make the change to have the drives mount to the directories I wanted by adding the following to the end of the file:

/dev/sda1 /media/USBHDD1 auto noatime 0 0
/dev/sda2 /media/USBHDD2 auto noatime 0 0

save the file and the mounting is complete… reboot and the drives should not mount to the designated directories.

2. Create share directories and install Samba to enable Windows shares

sudo mkdir /media/USBHDD1/shares
sudo mkdir /media/USBHDD2/shares

will create directories on both of the drives. Since we want the drives to be identical it is important to keep them in sync with the same directories. Once you have the share directories let’s install Samba:

sudo apt-get install samba samba-common-bin

The install will prompt for continuing at which point ‘Y’ is a good response if you want the install to complete successfully. Once it does complete you can now take a backup of the config file (for safe keeping) and modify the file using the following commands:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
sudo nano /etc/samba/smb.conf

Once inside of the file modify the workgroup if one is being used. After that we can modify the authentication to prevent just anyone from getting to the files. This is generally a good idea as you don’t want just anyone connected to your wireless to have access. To do this scroll down in the file and remove the ‘#’ from the ‘security = user’ line. This will enable the security to use a usernamepassword authentication mechanism. I realize we haven’t created a user yet, no worries, we also haven’t stored anything in the share we didn’t create yet either…

Speaking of the share we didn’t create, before closing the config file let’s add the information about our share. Add this to the end of the file:

comment = Backup Folder
path = /media/USBHDD1/shares
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Hey we have a share… Can you guess the name? The name is actually what you put inside of the [], or in our example above Backup.

Note, you only need one share as the second drive is truly a disaster recovery drive in this case. Once you finish that you can save the config file and restart.

sudo /etc/init.d/samba restart

This will restart Samba so we have a share all ready to go. How about we create a user to access that share.

sudo useradd backups -m -G users
sudo passwd backups

The second command will ask that you type a password in and then confirm that password. Make sure you remember this to ensure you can use this user to access the share later. Note, this still didn’t add the user as a valid Samba user.

sudo smbpasswd -a backups

at this point you are ready to test the share from another computer and add some files. You must run the above in order to access the file, though…

3. install rsync

sudo apt-get install rsync

Will install a component known as rsync. Once installed you can test if you have files in the shared directory by running the following command.

sudo rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/

All this component does is the backup from drive 1 to drive 2. Notice that we had to run this manually. If we stop here we can have the backups occur but we would have to come back to the machine and manually run the rsync command each time we want to update the backup.

4. setup Cron

Cron, this sounds like the villain in some superhero comic… Well, although that would be a great name, it is actually the mechanism for running scheduled events. To open the file for entering the jobs use this command:

crontab -e

and then you can enter the following as an example scheduled job:

0 5 * * * rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/

Now this looks a lot like the test line we used in the previous step with a couple additions. Mainly 0 5 * * *. let’s examime:

0 – (day) 0 indicates to run every day
5 – (hour) 5 would be 5 am
* – (year) every year
* – (month) every month
* – (day) every day

with this setup you can add a couple new files to the share and wait overnight to see if the files are added to the backup location.

One issues I hit here is that I added GBs of data, roughly 90GB, to the drive and woke up the next morning and the Pi seemed unresponsive. I reviewed a few things and realized the Pi was actually still running rsync from that night. I used the task manager to see rsync running and monitored the size of the directories using the properties to show that the file size continued to grow. After hours of running and seemingly unresponsive it completed successfully. Key here is that the Pi isn’t high powered, it may take a while to copy things but if this is the purpose of the Pi, does it matter how long it runs?…

Getting Started with Raspberry Pi

In this case I am going to talk about the Raspberry Pi B+ and my process for getting started. Now, of course, there is more than one way to use the Pi, to get started with the Pi and for that matter more than one type of Pi. Use my process if you want, if it doesn’t work for you feel free to just refer to this as needed.

Getting Started:
Once you have bought the Pi you will also need a few other components. If you have them laying around feel free to use what you have but otherwise most can be purchased easily online or at a local electronics store. Those components are:

  • USB Wifi adapter
  • USB Keyboard
  • HDMI cable
  • Monitor or TV (temporarily depending on Pi’s use)
  • Micro USB power supply
  • MicroSD card
  • connector for MicroSD to laptop or desktop

With all of those in place it is assumed that another laptop or computer will be available for use during the process.

The End Goal
At the end of the steps you will have a Pi ready to roll… I typically install Raspian but any OS will work.

1. Format the microSD card

This step is accomplished easiest when your computer offers an adapter built in. In my case I have a MacBook and with the SD adapter I can plug the card directly into the machine. For other machines I have a USB adapter I purchased when I first got a digital camera that has also worked in other machines. In either case connect the card and get ready to format.

Now once connected you may be tempted to just download the image and copy directly to the card. DON’T! this doesn’t work. Use a formatter like SDFormatter. Once formatted you can drag and drop the image. For more detailed instructions I followed the steps on the raspberry pi site.


2. Hook up the Pi and boot

So, now you need to hook everything up to the Pi. I highly recommend making the microsd power supply the last thing you attach. This way everything is ready when pi powers up. Since this is the first time you are booting the Pi and haven’t installed the OS or more importantly SSH, you should have a monitor or TV that you can use for the first time. Once you install the OS you can install SSH and then access the machine remotely.

For now, attach the HDMI cable to the Pi and monitorTV.
Connect the USB Wifi adapter
Connect the USB Keyboard
Insert the microsd care into the Pi slot.
attach the power supply to the Pi and wall outlet.

Now we get to watch and configure…

3. Install the OS

Upon your first boot of the device you will be prompted to install one of the operating systems on the microSD. Raspian is always a good choice…

Note: up to this part is included in the previous link.

4. Configure remote access & a couple more things

You have the Pi installed and running now let’s free it from the restraints of a monitortv. To do this you need to get to the have the Raspberry Pi on and booted to the command prompt.

At a command prompt type the following:

sudo raspi-config

This is, yes that’s right you guessed it, the raspian Configuration. Here you can configure things such as the host name of the Pi, you can overlock the Pi and also enable SSH.

To enable SSH follow the following link:

SSH Configuration

While here I highly encourage you to take a look at various settings. One setting I have definitely changed is the hostname to ensure I don’t have duplicate names and also to provide a better description of the purpose of the Pi.

Once you have enabled SSH, you are free to play… Enjoy the Pi and explore all the cool things you can do with it…