Monday, December 3, 2012

Initial Setup

This blog is more for me to take notes and remember what I did than anything else.  Hopefully, you can follow along.

I purchased a Raspberry Pi a while ago, but never got around to setting it up for multiple reasons, one mostly (because I'm cheap) and didn't want to buy a monitor.  Almost a year later, I got a 55" HD TV with an HDMI input.  So now is a good time to start playing with my RPi.

The first thing to know sf the Raspberry Pi is a full computer on a chip.  CPU, Memory, etc, etc.  Its running an ARM processor.  It has no harddrive, keyboard, mouse, monitor, etc, etc.  You need to provide all that.  It doesn't even come with a power supply.   It provides jacks to a couple of things:  2 USB ports, 1 HDMI video, Ethernet, and Composite Video/Sound (which I won't use because I have HDMI).  The beauty is you can install whatever OS you want on the OS, and the RPi will boot off the SD Card.  Linux is the preferred OS (of course), so here goes...

I bought an 8 GB Sandisk SD Card to use to hold the OS, an HDMI cable to connect the RPi to my TV, a USB Keyboard, USB Mouse, and I'm using the microUSB adapter from my old Blackberry.

The first thing I wanted to do was just get a basic linux distro running on it.  Raspian Wheezy is the supported distro as of this writing.   I downloaded the .IMG file and burned it to the SD Card using 'dd'.    Next, I plugged the Rpi into the TV, connected the USB keyboard/mouse, inserted the SD Card, and powered it up.  It booted up beautifully.

Resize SD Card

The SD Card is 8GB, but the image I burned to it is only 2 GB, so the OS doesn't see the rest of the space.  To resize the SD card WHILE running Debian on RPi, run the following commands:

df -h


sudo fdisk /dev/mmcblk0

# p to see current start of the main partition
# d, 3 to delete the swap partition (I don't have a swap partition)
# d, 2 to delete the main partition
# n p 2 to create a new primary partition.  Enter the start of the old main
# partition and then the size (enter for complete SD card).
# w to write the new partition table

sudo shutdown -r now

sudo resize2fs /dev/mmcblk0p2

df -h

Networking 

I really want it to act as a DHCP server for my home network, among other things, so I need to get a DHCP server configured.  I plugged in the RPi into a network switch, and connected my Mac to the same switch.  Nothing else is plugged in to the switch, so its a simple 2 computer network.  I couldn't figure out the network aspect at first since its not like Redhat/CentOS, but I did find this:  In /etc/network interfaces, change the line that reads

iface eth0 inet dhcp

to


iface eth0 inet static
address 192.168.2.3
netmask 255.255.255.0
gateway 192.168.2.1

and reboot.  The RPi should now have the IP address 192.168.2.3.  

I'm using 192.168.2.0 as my network because the Wireless LAN I'm running my Mac on uses 192.168.1.0.

Set up Internet Sharing on the Mac.  It will take on the address of 192.168.2.1.  So RPi should see the Mac as the gateway to the rest of the world.  

At this point I can ssh to the RPi from my Mac.  And my RPi can see the rest of the world.  Yeah!

Next thing to do is run 'sudo raspi-config' and update 'raspi-config'.  This will update the installed packages to the latest versions, then set the correct timezone.


DHCP Server

The next step is to get a DHCP server installed and running so my RPi can manage all the devices on my local LAN.  My old DSL router used to handle this for me.  This also gives me a lot more control on how everything is set up.  Run:

sudo apt-get install dhcpd

Edit /etc/default/udhcpd and set:
DHCPD_ENABLED="yes"

This installs and enables the DHCP server daemon.

Edit /etc/udhcpd.conf:
1.  Set the start of the IP lease block to whatever you want.  I'm using the addresses 100-254 as my lease addresses.  Everything below 100 will be for static addresses of my specific devices aka RAID Storage drive, Wireless Access Point, Blu-Ray player, TV, etc:


start           192.168.2.100   #default: 192.168.0.20
end            192.168.2.254   #default: 192.168.0.254

2.  Set the network specific options (at the bottom of the file):

opt     dns     8.8.8.8 8.8.4.4 # Google Public DNS Servers
option  subnet  255.255.255.0
opt     router  192.168.2.1

3.  Then run:

sudo /etc/init.d/udhcpd restart

4.  I then plugged in another laptop configured to acquire a network address via dhcp, and viola! It worked!

TV / Blu-Ray

Both the TV and Blu-Ray player have NIC cards so I plugged them both into the hub.  They automatically acquired DHCP addresses and could connect to the Internet.

TB Drive

This was previously configured using a static IP address.  I update the network settings and can connect to it.  I gave it a new static IP address but also set up the RPi to give it a static lease.  The static lease is more of a place holder so it never gets used for anything else.

No comments:

Post a Comment