mindwave
Posts: 36
Joined: Mon Aug 29, 2011 5:24 pm
Contact: Website

Creating a "special" RASPBI Image

Mon Apr 09, 2018 4:47 pm

Team,

1st time poster, long time Linux user. WAY back when Penguins first roamed the earth I was helping the Mandriva team with a project that was really gaining traction, then well, we all know what happened to them.....sigh.

Anyway, this was back when "roll your own images" was first really getting started. And the folks I was working with had adapted some tools from another project that REALLY worked well. As a matter of fact in an effort to make Linux more "user friendly" we were working on a sidebar that would allow any user to load a pc with mandriva, load up whatever desktop and a certain number of apps from a list we created, and then create a "bare metal" restore DVD.

This would allow you to take the DVD to ANY PC and run a LIVE Distro from the DVD, and it would appear as though it were YOUR installed system.

OR if you had primarily the same hardware (MB/BIOS etc) you could actually boot the live and then 10 minutes later have a completely new reinstalled system just like you wanted it!

At the time Mandriva was having an awful time with weird crashes whipping out the GUI and leaving folks uninitiated with a CLI with JUST a cli, so we were going to resolve that, Its also the same time that USB keys started to get cheaper, so we were working on those as well (2006 the year that MandivaFlash was released for $27)

Anyway I digress.
From where I sit RASPI's one weakness (in my home) is that I setup a media player, amp everything out, load up external drives, things are rocking,

and we get a thunderstorm. Power goes out w/o warning, SD Card is scrubbed.

Some of them we can recover most we cant.

So thinking back to my old days, is there a way or a tool set that would allow me to do the following:

Setup the raspbian image so that it will load and install completely unattended, AND when it boots the 1st time to activate SSH and or VNC, AND email or SMS me its NEW IP address?

I'm sure there is a script out there to read an ip address, and then paste it in an email and send it to a preset mailer, just not sure about the rest.

Its been a decade since Ive been in that world,

Any and all ideas appreciated.

Thanks

J

User avatar
HawaiianPi
Posts: 5968
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Creating a "special" RASPBI Image

Mon Apr 09, 2018 7:25 pm

You can pre-configure an SD card to boot with wireless networking and SSH enabled. VNC would have to be enabled using the raspi-config utility over SSH (if you are running headless) or with the GUI configuration utility. As far as automating installation of software goes, that could be done with a script, but you would have to write that script yourself.

For protection from power failures most normal computer precautions apply. Make regular backups, and use a UPS if power problems are common in your area. You could also run your Pi from a more robust boot device, like an SSD or hard drive (instead of an SD card). You can boot the Pi3B and Pi3B+ directly from a USB device, and both can do PXE network boot as well (perhaps another option for automated setup).


This is the procedure I use for setting up headless boot with SSH and wireless network. It works with Raspbian Jessie or Stretch, Desktop or Lite, and with the built-in WiFi on the Pi3B(+) & Pi Zero W, or a Raspbian compatible USB WiFi dongle on other models. Everything is done before you boot, and can be done on a Windows or Mac computer which only has access to the small FAT32 "boot" partition of a Raspbian imaged SD card.
  1. Grab the latest Raspbian image from https://www.raspberrypi.org/downloads/raspbian/
  2. Grab the Etcher software from https://etcher.io/
  3. Install Etcher and use it to write the Raspbian image to your SD card.
    • You don't need to extract the image or format the card prior to writing.
    • Just run Etcher, choose the Raspbian .zip you downloaded, pick your SD card and write.
    • If you have trouble, verify the SHA256 checksum of the download.
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the card (labelled "boot").
    • If you get a message telling you the card must be formatted, cancel it.
  5. On that small FAT32 partition, create a file with the name ssh (or ssh.txt). It can be empty, the contents don't matter.
  6. To connect to a wireless network, create another file on the card called wpa_supplicant.conf, which has the following inside:

    Code: Select all

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=US
    
    network={
         ssid="Your network name/SSID"
         psk="Your WPA/WPA2 security key"
         key_mgmt=WPA-PSK
    }
    • Edit country=, ssid= and psk= with your information and save the file.
    • Use the 2 letter country abbreviation in CAPS.
    • Use a pure text editor, not a word processor, to edit the wpa_supplicant.conf file.
  7. Make sure that both files are in the main directory of the small FAT32 partition, not in any folder.
  8. Safely eject the card from your PC and use it to boot the Pi.
If Raspbian finds an ssh file it will enable SSH and delete the file. If it finds a wpa_supplicant.conf file, it will move it to its correct location and connect to your wireless network. Give your Pi some time to boot and connect to your network (the first boot always takes a bit longer), then you should be able to SSH into the Pi and configure it how you like.

If you have attempted this and failed, then unplugged the power to turn off your Pi, you should start over with a freshly imaged card. Improperly powering down the Pi can cause SSH key generation to fail, which will prevent SSH logins.

If you have a Zeroconf network service installed (Apple's iTunes, Bonjour or Quicktime install Zeroconf), you can SSH into pi@raspberrypi.local (provided you don't have any other Pi computers on your network with the same default hostname). Otherwise you must SSH into your Pi's IP address, which you can find by logging into your router and checking the list of connected clients, or using a network scanner app (like Fing for smartphones) to find your Pi on your network.


You can also monitor the Pi's output using a serial console cable. I use cheap CP2102 USB-TTL adapters from ebay that cost less than $2 each. Raspbian does output its IP to the screen and serial console during boot, but depending on where in the boot process that happens, it may be hard to spot. Most of the time it's among the last messages output and will still be on the screen at the login prompt (but not always). I normally use Fing or my ASUS Router app if I need the IP.

EDIT:
With the current version of Raspbian Stretch 2018-03-13 some people are having trouble with WiFi not getting enabled. The reasons for that are still under investigation (a possible race condition between 2 startup scripts is suspected). If wired networking is an option, it might be best to use that, at least for the initial setup. So far I haven't had any trouble.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

Return to “Advanced users”