Lazy Is Good
I am basically lazy. Lazy is good. It is also known as “efficient”.
I really don’t like to do the same thing three or four times if I can do it once and be done. Consequently, I tend to do things once and put it in a ‘script’ if I think I’m ever going to need it again.
I’ve sunk the better part of 2 or 3 days into figuring out what software I wanted on the R.Pi Model2 to make it a ‘core server'; find out the exact package names to build, and do all the “apt-get install” by hand. At that point, folks usually make a backup image of the product and call it done.
I like having a “build script”. It means your process is repeatable. Done “while doing the build” the first time, it means that if you have a catastrophic failure you don’t have to head scratch about what you did before and / or read notes off of soggy napkins or in cluttered notebooks.
It also means that you can “cooky cutter” another one any time you want.
So here’s my cookie cutter.
The SD Card Software Factory
While the script tells you to do it, this reminder is also a good idea:
You will be running the normal “NOOBS” set up. I’m not going to detail it, as there’s lots of documentation on that already.
Choose to install the Raspbian version of Debian and also check the box in front of the “add a 512 MB EXT file system” option. The script will be marking that partition for NFS export as a nice “scratchpad” you can share with other machines on your network.
When you have all that done, and are logged into the Pi, “become root” before you run the script if you want it to work. You can run it not-as-root, but nothing really gets done. (In fact, I added a bunch of “echo” comments to talk to you while it runs and to ‘syntax check’ it, ran as not-root. Found a few lines that needed close quotes ;-) Hopefully I got all of them…)
I have also taken the pristine “NOOBS download” and put it, along with this build script, onto a 1 GB SD card. I can now use that “portable archive” on darned near any machine to prep the micro-SD card for the Raspberry Pi. Just format the micro-SD to FAT (or FAT32) and copy over the NOOBS files. Then the micro-SD is ready to boot in the Pi as NOOBS install media. I don’t need to hit the ‘NOOBS Download’ every time I want to build a system.
After the basic NOOBS install, I put the 1 GB card into a small USB adapter and plug it into the Raspberry Pi and then copy over this build script. You could just as easily use a USB thumb drive or ‘whatever’.
So with my 1GB “build starter”, and the target micro-SD card, and any computer than can format SD cards and/or copy files, I’m good to run my Raspberry Pi SD card system factory…
I’m mostly just going to paste the script here. It ought to be more or less self documenting. Any questions, speak up.
I’m also hoping that the WordPress tendency to steal anything with angle brackets in it doesn’t screw things up too much. We’ll see how good my proof reading is ;-)
You will need to scroll the listing to the right to see all of it, but a ‘test mark and copy’ caught it all even off the edge. So a “copy and paste” ought to work fine.
Any line starting with “pi@RaPiM2″ is a command prompt from the computer and is followed by the directory in which I am working. In this case, that added 512 MB partition named /media/data/ (but any directory works fine for this.)
Any line starting with a “#” is a comment and does nothing.
It is advisory only.
Any line starting with “echo” gets printed to your screen when the script is run.
The line that says “cat ./BuildIt” is the Unix / Linux way of saying “print this file to the screen” where “cat” means “conCATenate and print” (yes you can list several files and have them all concatenated if desired). The actual script begins on the very next line with echo ” “.
pi@RaPiM2 /media/data $ pi@RaPiM2 /media/data $ pi@RaPiM2 /media/data $ cat ./BuildIt echo " " echo "Do the NOOBS install: " echo " " echo " https://www.raspberrypi.org/help/noobs-setup/ " echo " " echo "and choose the option of having a 512 MB EXT partition added to your SD card" echo "along with the Raspbian installation. Then copy this script from an external SD" echo "card or USB drive into your working directory (home directory or /media/data" echo "after all the usual and customary NOOBS setup questions are answered and done." echo " " # # In general, I'm encapsulating what all I did in these two postings as a script: # # https://chiefio.wordpress.com/2015/07/18/raspberry-pi-m2-unboxing-and-setup/ # # https://chiefio.wordpress.com/2015/07/22/raspberry-pi-software-setup/ # # If you didn't already change the password while running NOOBS, # When done, log in as 'pi' password 'raspberry'. Change the password. # passwd # and respond with the new one when prompted. echo "Also, to change the name of your machine, edit /etc/hostname and make it" echo "what you like. " echo "Here, I'm going to just set mine by brute force write to the file." echo " " echo "echo 'Ra2PiM2' > /etc/hostname " echo " " echo "Ra2PiM2"> /etc/hostname echo " " echo "Next, do the 'usual' update upgrade that brings you up to the present" echo "repository status (need a network connection from here on out)" echo " " echo "You can either put 'sudo' in front of each of these commands, or just " echo "'become root' which is what I usually do." echo " " echo "sudo bash" echo " " echo "then run this script with ./BuildIt (assuming you didn't change the name" echo "and that you are 'in' the directory where it is located.)" echo " " echo "apt-get update" echo "apt-get upgrade" echo " " apt-get update apt-get upgrade echo " " echo "Start doing useful operational 'packages'. " echo " " # This gets the useful tools like "nslookup" for looking at Domain Names echo " " echo apt-get install dnsutils echo " " apt-get install dnsutils echo " " echo " VNC is a nice way to get a remote desktop. It takes some configuring later." echo " " echo " " echo apt-get install tightvncserver echo " " apt-get install tightvncserver echo " " echo "I like wicd for an easier way to manage wireless devices and networks." echo " " echo " " echo apt-get install wicd echo " " apt-get install wicd echo " " echo "Scrot is a tool for taking screen shots by saying 'scrot' in a terminal" echo " " echo " " echo apt-get install scrot echo " " apt-get install scrot # Normally I would install "build-essential" to get things like C compiler # and some language tools, but they were already installed on the R.PiM2. # apt-get install build-essential echo " " echo "Some 'user land' useful things like browser options and Office / Mail tools." echo " " echo "Chromium is the 'chrome' browser from Google but in Linux land" echo " " echo " " echo apt-get install chromium echo " " apt-get install chromium # IceApe is a "more free" version of IceWeasel that is a "more free" version of # Firefox that is a rebranded Mozilla that is... IceDove is the matching # Thunderbird replacement minus the trademarks, non-free bits, etc. echo " " echo "Doing IceApe browser and IceDove mail reader" echo " " echo " " echo apt-get install iceape echo apt-get install icedove echo " " apt-get install iceape apt-get install icedove echo " " echo "GIMP is the photo editor ( 'photoshop Free'...) " echo " " echo " " echo apt-get install gimp echo " " apt-get install gimp echo " " echo "Don't forget Libreoffice - Microsoft? We don't need no steenking MicroSoft..." echo " " echo " " echo apt-get install libreoffice echo " " apt-get install libreoffice # I tried "arora" and got error messages and "xbmc" was not working for sound # so I'm not installing those again until it's clear they work. Arora is a # browser (so who needs "yet another browser" with Epiphany in by default and # with both IceApe and Chromium installed?...) and I'll likely make a dedicated # SD card for the media center option as there are 2 Pi Model 2 version up # and I won't need to screw around with Debian issues... #apt-get install arora #apt-get install xbmc # As I also wanted one of these to be a bittorrent server, I sometimes add # the "transmission" bittorent code. echo " " echo "Adding the 'transmission' bit torrent server" echo " " echo " " echo apt-get install transmission echo " " apt-get install transmission echo " " echo "To get NTFS disks (like USB or an NTSB formatted SD card in adapter) to " echo "work 'read write' instead of just 'read only', you need ntfs-3g" echo " " echo " " echo apt-get install ntfs-3g echo " " apt-get install ntfs-3g # In Theory, this installed 2 VNC "viewers" so the R.Pi could use VNC to # get to other machines. In practice, I found that one of them locked up # my console when launched against my own machine as target (might be a # PIBKAC problem - Problem Is Between Keyboard And Chair - as the R.Pi # isn't really expecting to drive 2 video sessions at once (the real one # and the VNC one inside the real one...) so maybe all is fine and I just # need to RTFM (Read The, er, "Friendly" Manual) before using software... echo " " echo "Some VNC Viewers for being the client instead of the server" echo "I've not used either of these yet so have no clue about them in practice" echo " " echo " " echo apt-get install xtightvncviewer echo apt-get install ssvnc echo " " apt-get install xtightvncviewer apt-get install ssvnc echo " " echo "Want an NFS (Network File System) server so you can share disks with" echo "your internal network? This will install the code, then you get to" echo "configure things like /etc/exports" echo " " echo " " echo apt-get install nfs-kernel-server echo " " apt-get install nfs-kernel-server # prior to first use. Or reboot. # In your /etc/exports file, put something like: # /etc/exports: the access control list for filesystems which may be exported # to NFS clients. See exports(5). # # Example for NFSv2 and NFSv3: # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) # # Example for NFSv4: # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) # # /YourFileSystem *(rw,sync,fsid=0,no_root_squash) # But without the # in front of YourFileSystem... and with your file system... echo " " echo "IF you chose that 'add a 512 MB partition option' at build time" echo "This adds it to the /etc/exports file so it is NFS mountable elsewhere" echo " " echo "echo '/media/data *(rw,sync,fsid=0,no_root_squash,no_subtree_check)' >> /etc/exports" echo " " echo "/media/data *(rw,sync,fsid=0,no_root_squash,no_subtree_check)" >> /etc/exports # Remember to do a echo " " echo "Restarting the appropriate services so NFS will work" echo " " echo " " echo service rpcbind restart echo service nfs-kernel-server restart echo " " service rpcbind restart service nfs-kernel-server restart # I also made my box a static IP number as it's a server. You will need to # make this your own server name and IP numbers. # # Here's my /etc/network/interfaces file with leading # to make it comments. # # I will make this a "dump these lines in to replace" in my running version. # echo " " echo "Remember to make your /etc/network/interfaces file have a static IP#" echo "If you are going to be using PXE boot and such" echo "My examples are below, but use your own values for your equipment." echo " " #auto lo #iface lo inet loopback #auto eth0 #allow-hotplug eth0 #iface eth0 inet static #address 172.22.22.253 #netmask 255.255.255.0 #gateway 172.22.22.254 #dns-domain chiefio.home #dns-nameservers 172.22.22.254 192.168.1.254 192.168.1.1 # #auto wlan0 #allow-hotplug wlan0 #iface wlan0 inet manual #wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf # #auto wlan1 #allow-hotplug wlan1 #iface wlan1 inet manual #wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf # Don't forget to do a # ifdown eth0 # wait a minute for it to quiet down # ifup eth0 # As I want this to be a DNS server, DHCP server, and PXE server (uses a # tftp or "Trivial File Transfer Protocol" server, all of those can come in # one package with dnsmasq. echo " " echo "Installing a light weight but effective DNS, DHCP and TFTP service" echo " " echo " " echo apt-get install dnsmasq echo " " apt-get install dnsmasq echo " " echo "Yes, it takes configuring. See the file at" echo " /etc/dnsmasq.conf" echo " " # Then I installed the Apache web server : # http://www.raspipress.com/2012/09/tutorial-install-apache-php-and-mysql-on-raspberry-pi/ echo " " echo "Instlling the Apache Web Servier and related stuff" echo " " echo " " echo apt-get install apache2 apache2-utils apache2-doc echo " " apt-get install apache2 apache2-utils apache2-doc # and yes, it takes some configuring and even web page building. # See files in places like /etc/apache2/sites-available and more. echo " " echo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache echo " " apt-get install libapache2-mod-php5 php5 php-pear php5-xcache echo " " echo apt-get install php5-mysql echo " " apt-get install php5-mysql echo " " echo apt-get install mysql-server mysql-client echo " " apt-get install mysql-server mysql-client # echo " " echo "And that's the end of my present install build process." echo " " # # There are several files to edit and configure. Eventually I'll add a # "here script" to dump them from this script to where they belong, or # I'll just save a copy and have a 'save / restore' copy process. # # Once I get everything configured ;-) pi@RaPiM2 /media/data $
With a fresh 64 GB micro-SD card, it took me about 30 minutes to do the basic NOOBS install and copy files. Then it was another hour to run this script (almost to the minute). That will vary with your network speed and how diligent you are about hitting “Y” when prompted. ;-)
I’m posting this using that chip and the IceApe it installed, so things look to have worked reasonably well.
One quirk I ran into: The NOOBS install did NOT like being behind two layers of NAT (Network Address Translation). I had to move from that 172.x.x.x network out to the 198.162.x.x network to get it to work. I’ve run into that kind of issue before with other products, so it isn’t a Raspberry Pi issue. Just be aware that NAT screws around with network addresses and that some things don’t like them changing underfoot when in use. OTOH, it can sure confuse folks trying to break in ;-)
I generally avoid it, but the router I had available for fast use was already configured with it and for most things it has not been an issue.
After final configuration of those various config files (like for PXE and NFS and such) those config files will also be copied off to the 1 GB chip. I may eventually incorporate them into my ultimate “build script”, or may just leave them as files to drag over by hand if needed.
As the various services I’ve installed “go production”, I’ll post more specifics on how to set it up. But in many cases, the specifics will be specific to your own site and needs; so mine will be more exemplar than ‘copy paste’.
By making this script, at any time I’m about 1 to 2 hours away from a fully built system. Even if 6 months from now I forget some bits. Even if I’m on the other side of the country via plane stuck in a hotel room and want to make one. Never again will it take 2 or 3 days of my life to paw through the jungle figuring out what matters and what is hiding where. What is missing in the basic build. As my needs change, or new things are discovered, they can be added to the script. New versions made for other special uses. Each time it is used it is, effectively, regression tested, and over time any small errors get ironed out, never to return. That is the benefit of such a build script. The downside is that capricious upstream changes in packages will take some maintenance, but the script will be shouting error at you when that package is no longer available and you will know that something changed.
Hopefully this will be helpful to others in their: