This is Part 1 of the setup walk-through. It is continued with Part 2 (Wireless and Adafruit IO Python library coming soon),
Ubuntu on a BeagleBone Black (BBB) is a glorious thing. Since I use Ubuntu as my primary workstation, I am very comfortable with this OS. Having it on my BBB is like an old friend in a new box.
This series of posts will serve as documentation as to how I was able to install and configure my BBB with Ubuntu 13 – Raring. I hope that others may find it useful as well. A couple of notes before we get started. I used several blogs and sites to build this document and all the links can be found below. Some are modifications for setting up Angstrom on BBB, others for configuring Ubuntu in general. It’s really an aggregation of information for me to have a single source for setting up my BBB.
DISCLOSURE: As the subtitle of this blog says, “I HAVE NO IDEA WHAT I’M DOING.” Use this information for what you will but don’t take my word for it. Be careful and don’t brick your BBB (can such a thing be done?). I do not get paid for writing this. I am not endorsing any site, blog or manufacturer (though I do shop from many of them). I openly state that this work is a derivative of the hard work of others and that I am merely standing on the shoulders of giants. Be cool, give me your hand and you can stand on mine.
Here’s the list of things I had at my disposal when doing this:
- BeagleBone Black
- USB wireless dongle from Adafruit.com
- Ethernet connection and cable
- 5v, 1A wall wart power supply
- Wireless network
- 8GB SD-Card
You might not need all this stuff but I assume that you do.
First Things First – Get Ubuntu Image on an SD Card
I’m not going to go into the ugly details of how this is done. However, here is what I did:
- Downloaded the image file
- Booted into Windows and used Win32DiskImager to build out the image onto my SDCard – I was never able to get ‘dd’ on Linux to work on Ubuntu. It wouldn’t recognize my card. Most likely, it’s a driver issue.
- Wait 10 minutes
- Image is baked onto card.
I have opted not to burn the image to the BBB because of the Network Tango that might take place. I will use the Angstrom image as a “Get out of network hell FREE” card. Later on, when I have things tightened down, I might burn the image to BBB.
The details on how to do everything up to this point can be found on the Adafruit.com site. Have a look around while you’re there because there is so much electronical coolness to be seen there.
The Networking Tango
Since I do not have a monitor/keyboard/mouse connected to my BBB, this part get’s a little tricky. While on a home network, it’s pretty straightforward b/c you should be able to find the IP address that DHCP has assigned to your BBB. If you are on a network where you don’t have access to the DHCP tables, then there is a magical trick that works most of the time (60% of the time, it works every time).
Connect an Ethernet cable to the BBB, put the sd-card in the BBB and reboot. The wait isn’t terrible. Next, head over to the admin web site of your router and find the IP address allocated to the BBB. If the address doesn’t show up, just wait a minute for the boot process to finish. While you’re waiting, check the connector on the BBB and verify that you see green blinky lights (it’s an industry term). If you don’t, you need to troubleshoot your cable/connection. If you have the ability to do so, create a reservation for your IP in DHCP or create a static entry.
Next, take that IP address and create an entry in your host file. I am only discussing how to do this on a Ubuntu workstations but if you don’t know how for your OS flavor, then google, “create host entry for <insert OS name here>”
For me, I go to the terminal on my workstation and put in, “sudo vi /etc/hosts” and the editor will load up my host file. I use the following:
192.168.7.2 bbb.local #stock USB ip… not always but nice to have
192.168.X.X beaglebone.local #IP assigned by my router.
So, this allows me to not have to memorize my IP address (though I often do anyway) and it’s easier for me to type. Finally, it’s consistent with my systems. If your not familiar, the host file is like a poor man’s DNS server. It maps IP address to human-friendly names. You can put most anything in here but a word of caution. The Network service checks here first before looking outside of the system. So if you map cnn.com to your local system (127.0.0.1), the networking service will always redirect requests for this domain to your local system and you will never get cnn.com again (well, at least until you take the entry out of the hosts file).
But I digress…
Now that the IP is mapped to a friendlier name, I can SSH (Secure SHell) into my fresh version of BBB-Ubuntu. Here we go…
ssh email@example.com firstname.lastname@example.org's password: ****** Welcome to Ubuntu 13.04 (GNU/Linux 3.8.13-bone20 armv7l) * Documentation: https://help.ubuntu.com/ ubuntu@ubuntu-armhf:~$
(the default password is ‘ubuntu’… don’t worry, we’ll fix this shortly).
and it worked.
The Hard Way
Let’s say you are visiting someone and have permission to use there hard-wired ethernet network connection but you have no access to find out what the IP might be when you boot your BBB. You can fall back to the standard install of Angstrom to help you here. Plug in the USB and ethernet cable to the BBB then, with the sd-card our of the BBB, power it up. After a minute or so, the BBB will be started and you can navigate either the internal web server or SSH. I use SSH
ssh email@example.com (or 192.168.7.2)
This is the USB interface and when you login to BBB, you can type in:
This will return you a bunch of stuff. In that stuff, you should see
inet addr: <ethernet address>
This is the DHCP address currently assigned to your BBB (in most cases). Copy or write it down. Then power off the BBB, unplug the USB, put the sd-card back in and plug in the power to boot.
You should be able to proceed as I discussed in “The Easy Way.” You may also have to do this a couple times if the IP shifts on you. It’s not a perfect process but it worked for me.
The next thing we need to do is to get our IP address emailed to us in case the assigned one ever gets changed. Let’s do that now before anything else:
So, I pried this python script up from the interwebs. You don’t have to do too much to actually get it to work but this script assumes that you have a gmail account.
Using your favorite terminal editor, create a file called, ‘getIP.py’
#!/usr/bin/python #http://elinux.org/RPi_Email_IP_On_Boot_Debian import subprocess import smtplib import socket from email.mime.text import MIMEText import datetime # Change to your own account information to = 'firstname.lastname@example.org' gmail_user = 'email@example.com' gmail_password = 'yourpassword' smtpserver = smtplib.SMTP('smtp.gmail.com', 587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(gmail_user, gmail_password) today = datetime.date.today() # Very Linux Specific arg='ip route list' p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE) data = p.communicate() split_data = data.split() ipaddr = split_data[split_data.index('src')+1] my_ip = 'Your ip is %s' % ipaddr msg = MIMEText(my_ip) msg['Subject'] = 'IP from BBB on %s' % today.strftime('%b %d %Y') msg['From'] = gmail_user msg['To'] = to smtpserver.sendmail(gmail_user, [to], msg.as_string()) smtpserver.quit()
You will only have to change the ‘to’, ‘gmail_user’, and ‘gmail_password’ account. You can create a gmail account specifically for this purpose so that if your bbb is stolen or compromised, you don’t have the plain-text password to your personal stuff in your scripts. This is what I did.
Next, let’s make the script executable by running:
chmod +x getIP.py
That’s it. All that’s left with this is to test it:
if you just get a prompt after running the script, that means it probably ran without an issue. Let’s go check:
Yup. There it is:
Your ip is 192.168.1.27
So now your saying to yourself, “Well, this is just great Dave, but how do I get it to trigger the email? Magic?”
Well, almost… Ubuntu has a really cool feature I haven’t seen in other distros with regards to ‘crontab’ and thats the ‘@reboot’ feature. Where is might seem that this would only fire at reboot, it fires anytime the system is started (cold or warm boot). To be sure that I had this in place right up front, I put it under the ‘ubuntu’ user. I will move this later but for now, this will work in case the system reboots or we goof something up.
sudo crontab -user ubuntu -e
You should be prompted to select your favorite editor. For the initiated, VI is an option. For ease of use, Nano is also available. Next put add this line and save:
I make the assumption that the script was created in the home directory of the ubuntu user.
If your test was successful, then the next time we reboot (coming soon), you should receive an email with your IP Address.
Ok, so this post is getting pretty long so I am going to wrap it up here. I’ll put up part 2 shortly with:
- Setting the Date (since BBB doesn’t have a a real-time clock)
- Creating a user, group and giving that user SUDO access
- Updating/Upgrading the OS
- My favorite alias list.
- …and lots more
If you have any questions, comments, or suggestions, please feel free to leave a comment. Please be advised that I warmly welcome input but trolls will be ejected from the conversation.
Some Links to sites that I referred to for this blog entry: