Initial Commit

Good morning! Yes, it is morning somewhere in the world.

Welcome to my journey advancing my understanding of a Linux environment through tinkering on various Raspberry Pi setups. I find that trying to explain or teach a concept to another person helps me understand it better myself. I am in no way an expert on Linux or Raspberry Pi, so you might take my instructions with some caution. In fact, my only official expertise is in Mathematics (with some training in secondary education). My process will try to break down each project all the way to the individual commands if necessary while attempting to explain what each of those commands are doing. I think that part is what I’ve missed in many of projects that I’ve done already, explaining why I have to use one command vs another. To do this, I’m going to be working through the project as I’m writing each blog post. If (more when) I run into an issue trying to get a project working, I’m going to keep my troubleshooting notes in the post along with the explanation of how it all eventually worked. I hope I learn a lot from this exercise, but I hope more that I’ll be able to help someone else learn something new.

Thank you for visiting, now lets have some fun.

Advertisements

Step 0 – Part 2

Now that you’ve booted up your Raspberry Pi for the first time, changing the password for your pi user should really be the absolute first thing you do. If you want, you can disable the pi account later on, but not changing the password just leaves you vulnerable.

Changing your password is super simple. Assuming you are logged in as pi since this is our first time booting, you just have to type “passwd” at the bash prompt ($), enter your current (default) password, and then type in your new (secure) password twice.

passwd

You can check out the man (manual) page for passwd to see how to change the password for a user other than the one you are currently logged in as. But let’s be honest, who are you going to let touch your hard work? I’ll get more in to man pages in another post.

man

man passwd

You’ll also want to expand your file system. Chances are the SD card you wrote the Raspbian image to, is larger than the image was so you have a chunk of space on your SD card that you don’t even have access to. Expanding the file system allows Raspbian to utilize your entire SD card. Would you rather have a corner, or a whole room to yourself?

This is also made to be pretty easy for us to do. At the $ prompt type in “sudo raspi-config”. You should see this main menu screen.

raspi-config

You are going to use the arrow, tab, and enter keys to navigate this utility. Arrow down to highlight “7 Advanced Options” and press enter.

Expand Filesystem

And then with “A1 Expand Filesystem” highlighted, press enter. Your screen will probably flash back to the bash prompt for a quick second and then show this screen. (That’s just the utility running the command(s) necessary to expand your file system.)

Expanded

Once you see this screen you can press enter to go back to the main menu on the raspi-config utility. From there, you can press tab to highlight the “Finish” option and press enter. You’ll then be asked if you want to reboot your Pi.

Reboot

Go ahead and press enter to accept the default and reboot your Pi. If you select no here you’ll end up back at the $ prompt. From there you can restart your Pi with this command “sudo shutdown -r now”. The “-r” flag for the shutdown command will cause the Pi to restart. If you use the “-h” flag it will power off the Pi. The “now” option just tells the shutdown command to execute now. It would be possible to tell the shutdown command to restart or halt at some time in the future. Reading through the man(manual) page for the shutdown command will tell you everything you can do. Yes, we have to read the directions.

man shutdown

Once your Pi is back up, the last bit for the initial setup is to make sure Raspbian and all its software is up-to-date. The Raspbian image available for download can be several months to years old, but some of the software included in it can see updates every couple of weeks or so. Not keeping up on the latest OS updates can also leave you open to security vulnerabilities.

This just requires two commands (less than the number of commands my wife gives me) and not much other input from you, as the user. This first run is “sudo apt-get update”. It may be a bit misleading, but this only updates the cache that the Raspbian package manager uses to keep track of what software is available and which version each of those software packages is on.

apt-get update

Once that command has finished, the second command run is “sudo apt-get upgrade”. This is the command that will actually go through and compare the version of each piece of software installed on your Pi to the version of that software available through the package manager. It will tell you which packages have newer versions available and how much space those new versions will take up. It will then ask you if you want to download and install those newer versions. Why can’t life be this easy?

apt-get upgrade

Go ahead and type “Y” then press enter. Apt-get will take care of the rest and drop you at the $ prompt when it’s done.

That’s pretty much it. You should have the basics ready for most projects you’ll want to build on a Pi. Good luck igniting your creativity! Come back and see if my projects will spark some curiosity or ideas for your own!

Now, for me, it’s time to go grocery shopping for the week. Wife said.

Step 0 – part 1

This will be the starting point for all of my projects, unless otherwise specified in that project. Instead of using the NOOBS installer, I like to use the Raspbian Lite image for a couple of reasons. For one, most of my projects are using the Pi as a mini low-power server, so I don’t need nor want all the extra stuff that comes with a desktop environment. Second, and probably more importantly, I prefer the image over NOOBS because I can do some configuration before even booting up the Pi for the first time.

If you don’t know how to write the image file to your SD card, check out the instructions here. For the most part, Windows and any Linux distribution I’ve used with a decent Desktop Environment will have a tool built in and will probably auto mount the SD card as soon as you plug it in.

Now, I suspect you are wondering about the configuration you can do before booting up the Pi. To do this, after you’ve created your SD card you can open it up in the File Explorer for you desktop (you might have two options with one called “boot”. Pick the other one for now).

Raspian Lite Image File

You should see a list of folders with names like “dev”, “etc”, “home”, and “mnt”. We are going to focus on the “etc” folder.

filesystem

That is where all the configuration files for everything that will be running on our Pi live. In just about every Linux disto “etc” is where all your configuration files and scripts will live, so when you’re searching for how to change the default behavior of something, that directory is probably a good starting point.

A quick, easy, and useful configuration change we can make is to change the hostname of our Pi. This is the name that your Pi would be know by on your network. The default that comes with Raspbian is “raspberrypi” (go figure).

hostname edit

We can use the hostname to easily SSH into our Pi without having to know its specific IP address (especially useful if you do not have a static IP). The problem comes in if you have multiple Pis on your network, all with the same hostname. It’s like calling role in class and three student have the same name. You’ve probably already guessed it, but the fix here is to just change the default hostname by changing what is in the /etc/hostname file. You might need to run your Text Editor as an administrator then open the /etc/hostname file, change the hostname to whatever you like, and save the file.

If you want to put your Pi on your wireless network instead of plugging in an ethernet cable, we can also set that up before ever booting up your Pi. To do this we are going in to the “/etc/network” directory and open up the “interfaces” file.

interfaces

Here we can see that the WPA configuration for both or our wireless interfaces (wlan0 being the on board wireless for the Pi and wlan1 being any wireless adapter you might plug in) are referencing another file. So if we go find and edit that file, we can set up the Pi for our wireless networks.

wpa_supplicant

For a network with a password, you would enter something like the following:

network={
  ssid="The_ESSID"
  psk="The_wifi_password"
  }

For a network without a password, you would enter something like the following:

network={
  ssid="The_ESSID"
  key_mgmt=NONE
  }
and you can enter multiple different networks into this file.
Whether you are going to use a wired or wireless network, if you want to be able to SSH into your Pi from the start, we need to make sure SSH is enabled. To do this, we are going to go into that boot partition of the Raspbian image and add an empty file called “ssh”
boot
With that, you should be ready to eject your SD card and boot up your Pi. Part two will cover a few things we should do on the initial boot of any project.