Raspberry Pi Recipe

Being a Computer Scientist sure has its perks. Take for instance one occasion where I decided to take part in a company’s programming challenge just for the heck of it. The result was a brand new Raspberry Pi B 2! Yet another perk.

For the uninitiated, the Raspberry Pi is a credit card sized computer. Yes, when I say computer I don’t mean an embedded device that you program with some kind of esoteric language or a weird mutation of your preferred language (yes Processing, I’m talking about you), but a computer much akin to the one you use at work or at home to get through your day. Of course, being that small a computer means that it’s not as powerful as your Intel machines or Macbooks, but you’d be surprised by what you can accomplish.

Alas, to get started is the trickiest bit on the Pi! It’s small and cheap, but it lacks a lot of things such as secondary memory, wifi support, bluetooth connectivity and other things. So if you’re interested in working with a Pi, you’ll be interested in getting these items as well, but the choices are pretty overwhelming (and in some cases, exorbitant). That’s where this post comes in. If you follow the guidelines here, you’ll at least be up and running in no time.

First things first, the Pi is a computer and computers need operating systems to do a lot of the heavy lifting for you. You can head over to the Raspberry Pi Foundation page and get the images for the various compatible OSes. I personally prefer Raspbian (Jessie over Wheezy, since it is newer) and Windows IoT Core, since the Arch Linux image reportedly has problems and I outgrew Ubuntu. However, we have a small problem: we need a memory card to save the image on! Amazon to the rescue. I was able to order a 32GB card for approximately $10. You can get any card you like, just make sure it is a Class 10 Micro SDHC card. You can’t really go wrong with the memory card if you just buy the right type.

Installing the image is super easy and I wholly recommend following the procedure given by the distribution of your choice. I myself just needed 5 clicks to get the memory card ready. Next, you’ll want to actually see the device in action, so you need a screen since the Pi, sadly, doesn’t have one built-in. The Pi supports HDMI which is absolutely great since digital signal trumps anything else in terms of video communication. Either get an old TV monitor with HDMI ports or borrow one from your friend, though I recommend getting your own. You can get a good HDMI cable for super cheap off Amazon (~ $5).  Insert the memory card, hook up the Pi to the screen with the HDMI cable, and use your standard phone charger to power the Pi up. You should see it boot up in the coolest way possible.

Finally, what’s the point of having a portable mini-computer if it doesn’t connect to the internet? Pick up a Wi-Fi USB adapter (I used Edimax), and ensure it is Pi compatible. It should mention on the label if it supports the Raspberry Pi or not. Plug that in, let the drivers do their thing, and you should be good to go. Optionally you can also get a Bluetooth USB module that lets you connect wireless headphones and stuff, but that depends on your choice.

And there you go! Your Pi is all baked and ready for awesomeness. You now have all the power you need to run some crazy Internet of Things experiments and show off your Tony Stark to the world!

Arch-ing In

Alright, so I had an interesting day yesterday:

  • Opened my newly won laptop.
  • Booted Arch Linux from a USB Flash drive.
  • Setup wi-fi connectivity via terminal.
  • Installed the whole damn thing from a terminal (no GUI whatsoever!).
  • Did something dumb.
  • Erased the Window EFI System partition and hence the entry from the bootloader as a consequence of doing something dumb.
  • Managed to install an intermediate bootloader – Gummiboot (nice name).
  • Couldn’t boot into Windows at all.
  • Did a network boot to recover the Windows bootloader. May have to reinstall Gummiboot now.

So yeah, overall, a day of epic hacking around with some pretty cool learnings, such as how to manually set up mount points, create partition layouts, how the EFI bootloader works and why is it better than MBR and loads of other things.

Eviva!

PintOS on Ubuntu

Note: This process is currently broken and seems to throw up unexpected errors. I am trying to look for a solution but the internet is just not helping me at the time of writing this. Until I figure out a way to fix this, I recommend trying out NachOS or xv6 for your OS cravings.

PintOS is one brilliant skeletal Operating System and, given the right time and effort, is a great way to consolidate your knowledge on the design of modern operating systems. However, its installation can be quite a pain especially since the instructions on Stanford’s official site can be a tad bit confusing at times. Here I will walk you through the installation instructions. If you would rather just install than spend time reading my post, feel free to download an install script I wrote to automate the installation process from here: pintosInstall.

If you are using the script, please remember to change the file extension as WordPress does not accept .sh files. After that just run “bash pintosInstall.sh”, without the quotes, from a terminal for a completely automatic process. Also, while I can guarantee you the script runs well on Ubuntu in a folder you have root access to, the script is simple and generic enough for you to hack and customize to your distribution if required.

  1. Install some pre-requisites: GCC, Perl, QEMU, Make, GDB. Just run:
    sudo apt-get install gcc binutils perl make qemu gdb
  2. Create and installation folder. The script makes a folder ‘co302’ (the course number for OS in my college).
  3. Download the PintOS tar from here and extract it in the installation folder. I used the totally awesome wget tool in Linux (just like Mark Zuckerberg in the Social Network 😛 ).
  4. We need a folder where the PATH variable can point to, as it will have some executables that we need to run when coding the OS. I made a folder ‘bin’ in the base installation directory i.e. co302/pintos/bin.
  5. Move all the perl scripts from the src/utils folder of PintOS to the bin/ folder. The important ones are ‘backtrace’, ‘pintos’, ‘pintos-gdb’ and ‘pintos-mkdisk’.
  6. Edit your .bashrc file to add the path for the above bin/ folder. At the end of the .bashrc file, simply add the line
    export PATH=$PATH:$HOME/co302/pintos/bin/

    Again for this, I have used the awk tool as it provides a convenient, independent way to edit files programmantically.

  7. Now we have to make a change to one of the PintOS files. Open up the ‘pintos-gdb’ file (in Emacs I hope)  and edit the GDBMACROS variable to point to the ‘gdb-macros’ file in misc directory of the src directory. At this point, you have officially installed PintOS, so give yourself a pat on the back.
  8. Time to compile the utilities. Head over to the pintos/src/utils directory and run
    $ make

    . If you get a “Undefined reference to ‘floor’ ” error, simply open the Makefile and substitute LDFLAGS for LDLIBS and run make again.

  9. Copy the ‘squish-pty’ file to the PATH pointed bin directory.
  10. Head over to the pintos/src/threads/ directory and edit the ‘Make.vars’ file. Change the SIMULATOR variable from bochs to qemu, which should mostly be the last line of the file.
  11. Run make on the threads folder.
  12. Now we need to edit the ‘pintos’ util file in the bin directory with 3 edits. Many other sites will give you  the line numbers, but I will not use that as it is too variable and you get a chance to experiment with the text processing features of your favorite editor:
    1. Change $sim = bochs to $sim = qemu to enforce qemu as the simulator.
    2. Comment out the line push (@cmd, ‘-no-kqemu’); by prepending it with #.
    3. Put in the absolute path wherever required as Perl doesn’t seem to be able to interpret the ~ shorthand. Do this especially for the kernel.bin location path.
  13. Finally, edit the ‘Pintos.pm’ file in the bin directory and put in the absolute path for the line having the location of the loader.bin file.
  14. Congrats, you now have PintOS set up on your machine. Try running pintos run alarm-multiple as a test.

There you have it. A pretty easy and straightforward way to install a great experimental skeletal OS from Stanford University. I bet it took more work for me to write this up that it will take you to install PintOS. The good part about this little adventure of mine is that I got a chance to dabble in sed and awk, 2 Unix tools that no hacker can afford to not know the basics of. Add to that some wget magic and Emacs power, and you can potentially become a hacking superstar. Infact, this hack has proven really useful as the Computer Engineering department of my college has used it to install PintOS on all the machines so that the students can do meaningful OS practicals. My small way of giving back, you could say. 🙂

As a final note, at the time of writing, this post is as comprehensive a set of instructions you can get. This may not hold true forever as tomorrow someone might make some script-breaking changes. So if you find some change that I need to include, please feel free to comment and let me know about it.

Eviva!