Sunday, January 5, 2014

Raspberry Pi as TimeMachine

Install the 2013-12-20 Wheezy Rasbpian disk image on an SD card. This will probably work fine on later versions, but I'm being overly specific.

You'll probably want to install a new user instead of the usual pi/raspberry user so follow the guide I wrote here: Change the Default Pi User.

Install vim because great Caesar's Ghost I can never get vi to work right.
sudo aptitude install vim
 Change your hostname because you don't need any extra devices on your network called "raspberrypi"
sudo vim /etc/hostname
sudo vim /etc/hosts
I called mine "BackupPi" because I'm so clever and interesting.
Install enough tools to allow your Macs to find your Pi.
sudo aptitude install avahi-daemon netatalk
Restart your Pi so that you know nothing went crazy.
sudo shutdown -r now
Connect a hard drive to the USB port formatted as EXT4. I don't care how it is done, just do it. Mine shows up as /dev/sda1 but yours might be different.
Now mount your drive.
sudo mkdir /media/external
sudo chmod 775 /media/external
sudo chgrp pi /media/external
mount /dev/sda1 /media/external
Test it to make sure you have proper access to it.
touch /media/external/test_touch
Okay, good work. Now make sure it mounts on boot.
sudo vim /etc/fstab
Add an additional line to the configurations.
/dev/sda1      /media/external      ext4      defaults,rw      0      0
Restart your Pi so that you know nothing went crazy and your disk will auto mount.
sudo shutdown -r now
After it comes back hopefully you can see what is in your drive.
ls /media/external
If you don't see what you are hoping for something went wrong. Crap. Sorry.
If you get to see the test_touch file you created before, congratulations. You did it!
Now you need to get your Mac to know that what you created is a good spot to put your backups. Make a copy of the original settings and create a new file.
sudo mv /etc/netatalk/AppleVolumes.default /etc/netatalk/AppleVolumes.original
sudo vim /etc/netatalk/AppleVolumes.default
Put the following in the new file:
:DEFAULT: options:upriv,usedots
/media/external "External Storage" options:tm allow:@pi
Save it and restart. Cross your fingers.
sudo shutdown -r now
Once it restarts You should be able to easily see that there is a machine with shares available on my network with the name you chose previously. Mine is "BackupPi" and it has a shared folder of "External Storage" so now just tell Time Machine to backup to that folder.

Saturday, January 4, 2014

Create Your User on Raspberry Pi and Remove the Default

Since Raspbian comes with a standard user/password for all installs it makes some sense to create your own user/password combination in an attempt at some security.

I'm going to be creating the user "spoon" and deleting the user "pi" today.
sudo adduser spoon
This command will prompt you for a lot of information. Fill in as much as you want. The password bit is the only real important part.

You want to make sure the user "spoon" has the same groups as the user "pi" so checkout the groups that pi is in.
groups pi
Now set those same groups to the user spoon. I like to see they are exactly the same so using these commands sets them in the exact same order
sudo usermod -g pi spoon
sudo usermod -G gpio,spi,input,netdev,users,games,plugdev,video,audio,sudo,cdrom,dialout,adm,pi spoon
Now compare them to make sure they are the same. These two commands should look identical.
groups pi
groups spoon
Lastly, log out, login as your new user, verify you have sudo power, and nuke the user "pi" out of the sky.
sudo deluser -remove-home pi