Project 2: Add USB storage to your Raspberry Pi
The Raspberry Pi has limited storage so use
a USB hard disk to store photos, videos and music you want to access on it.
Hard disks are more reliable than flash or SD card memory, so they're a better
storage option. Remember, you’ll need a powered USB hub in order to use an
external USB drive with your Pi.
The Raspberry Pi works with all standard
USB drives but only once you’ve reformatted them using the efficient EXT4
system. Tum on your Raspberry Pi, wait for the Raspbian desktop to load and
plug in the USB drive. On a PC, Windows assigns the drive a letter such as E:
or F: but a Linux system such as the Raspberry Pi uses mount points. These use
full paths such as ‘/dev/sdal’ rather than letters to indicate where a file is
stored.
Double-click LXTerminal, type sudo blkid
and press Enter. You should now see a list of all attached drives. In most
instances, the path name for your drive should start with /dev/sdal. If it
starts with something else instead, note what it is. You’ll need to substitute
this path when typing the instructions below.
Storage
data on a USB hard disk
Before you can format the USB drive you
need to unmount it. Type sudo umount /dev/sdal (or your drive’s path name). To
format the card, type sudo mkfs.ext4 /dev/sdal-L usbflash.
This creates a new file system labeled
‘usbflash’. Create a location for it by typing: sudo mkdir/media/usbflash. Press
Enter and type sudo mount/dev/sdal/media/usbflash to mount the drive, now, to
give permission to all users to save to the disk, type sudo chmod 777
/media/usbflash.
Open File Manager and your USB disk should
be listed under ‘places’. From now on, it will always be visible whenever it's
plugged into your Pi computer and you'll be able to access the files stored on
it.
Project 3: Turn your Pi into a NAS drive
Once you’ve attached a USB stick or USB
hard disk to your Pi you can use it as a NAS (network-attached storage) drive.
The Raspberry Pi can then be used to store digital photo albums, videos and
music that everyone on the network can share, whether they’re using a Windows
computer, Mac, tablet, phone or another Raspberry Pi.
Program
your Raspberry Pi so you can use it as a network storage device
First you need to set up the Raspberry Pi
networking software Samba. As in the previous projects you need to use apt-get
and LXTerrninal. Type sudo apt-get installs samba samba-common-bin, press Enter
and allow up to 30 minutes for the installation to complete. Now type sudo
smbpasswd-annobody to create a user called ‘nobody’. You can now share the disk
with Windows PCs on the same network.
You now need to use the Nano text editor to
edit Samba’s configuration file. Type sudo nano /etc/samba/smb.conf, use the
arrow keys to move around the file. Scroll down to the Authentication section.
Delete the # symbol from the start of the line ‘security = user’, press Enter
and type guest account = nobody, then press Enter.
Scroll to the bottom of the file and add the
following lines at the end, changing the path name to match whatever you used
in project 2.
[rpi]
comment=Raspberry
Pi
browsable=yes
path=mnt/usbflash
public=yes
writeable=yes
guest ok=yes
Press Ctrl and O to save the file, then Ctrl
and X to exit Nano.
Finally, type sudo service samba start to
run the networking software. The Raspberry Pi will appear as a standard drive
you can connect to on your Windows XP, Vista, Me, 7 or 8 home network. Click
its icon under Networks in Windows Explorer then double-click the rpi folder to
see its contents. You can now use your Pi as a NAS (network-attached storage)
device.
Project 4: Control your raspberry Pi remotely
Because the Raspberry Pi is so small it’s
ideal for installing in other devices. In some cases you’re able to control the
Pi through the host device (such as a hacked games console). In most cases
you’ll need to control the Pi from another computer. To do this you need access
to the LXTerminal so you can enter commands. You can set up remote control
using a simple technology called SSH (Secure SHell).
Install
PuTTY on your Windows PC to control your Raspberry Pi from it
Double-click LXTerminal. Type sudo
raspi-config and click Advanced Options. You can now enable SSH. Use the arrow
keys to move down to the <finish> button and press Enter. Type ifconfig
onto LXTerminal and make note of the Pi’s IP address.
To use SSH on a PC, download the free PuTTY
software (www.snipca.com/9245) on your
PC. Double-click the .exe file, type the Pi’s IP address into the ‘Host Name
(or IP address)’ field and click Open. In the window that opens type pi at the
‘login as’ prompt and raspberry as the password. You’ll now see a command
prompt that you can use as though you were sitting at the Raspberry Pi.