19

For a project I'm working on I'd like to create a "stock" image based on Raspbian that I can install on many Pis.

Ideally I'd like to be able to (on my computer) take the Raspbian image, apt-get some packages, edit some config and then create and SD card image from that to put on my Pis.

Is there a simple or recommended way to do this? Any pitfalls I may encounter?

I am keen to avoid manually tinkering with a pi and then cloning that image. Presumably Raspbian is made in some way that isn't someone manually clicking buttons on a Pi. I'd like to do it that way, if I can.

Ideally I want to create something that can be automatically built on an continuous integration server - I don't want a build process that involves "write an SD card, put it in a Pi" because I want to be ale to create images without any physical access to a Raspberry Pi.

  • 3
    May come in handy: How can I mount a Raspberry Pi Linux distro image? -- note the emphasized line in the accepted answer, "If you do change anything, those changes will be included in the .img file." Unfortunately, this doesn't provide the opportunity to apply apt-get; the easiest way to do that would be to use a VM and rsync with a mounted image identical to the one used to start the VM (since VM images themselves aren't good for this) but I think the only VM option here is QEMU, which AFAICT is a PITA. – goldilocks May 26 '16 at 11:39
  • Another approach would be net-booting. – lexu Jul 18 '16 at 7:03
  • The Win32DiskImager have a Read function, have you tried that? – Kong Chun Ho Jul 18 '16 at 17:38
6
+200

The Raspberry Pi foundation uses a set of bash scripts automating QEMU to generate their images. You should still look into the "industry standards" buildroot and Yocto too.

https://github.com/RPi-Distro/pi-gen

http://cellux.github.io/articles/diy-linux-with-buildroot-part-1/

  • If the OP is looking to create an industry standard release image.. yes thats the way to go but its a massive learning curve and I wish no hobbyist down that route. – Piotr Kula Jul 19 '16 at 14:36
  • 1
    This sounds like what I'm looking for! Are there any guides about for using this? build.sh seems to assume a bunch of environment variables are set. – Andy Smith Jul 19 '16 at 17:44
  • Probably covered by #4 under TODO ;) Hasn't been touched in a few months so either the people involved are busy with other things or have lost interest in it. – goldilocks Jul 21 '16 at 15:06
  • @goldilocks so this isn't where the base rasbian image comes from? – Andy Smith Jul 21 '16 at 18:21
  • 3
    I'll be honest and say that my impression is you are pursuing the Y side of an XY problem with too much vigour -- it's implied you think the simpler method (just set up an image on a pi, which can be done from a computer via remote login, and the image itself tweaked by mounting, which can be done on a PC, and all of this can be automated with scripting) is too much hassle, and so you have put your hopes in a method that is actually much more hassle. – goldilocks Jul 21 '16 at 18:33
5

My project Nard SDK has many of the features you want. It's not Raspbian but it has Raspbian binary emulation and are thus very close. With Nard you build everything on a PC and the process is very fast and reproducible. Everything is scriptable and can be done by e.g. a nightly continuous integration.
http://www.arbetsmyra.dyndns.org/nard/

0

In my opinion, doing it in the way you suggested (mounting, doing workarounds for updating and configuring, etc.) presents more challenges than actual solutions. Sure, it may be fun to do it your way if you're interested, but the best and easiest way may be the one you're avoiding.

I recommend you get a Pi and do what you have to do on it, then make an image of its SD card. Then, use that image on your other Pis since that image is already configured.

Note: I'll assume you'll use Raspbian. I'll also assume you're just an average person and not some person who prepares images on a frequent basis (e.g. Raspberry Pi Foundation).


Steps if you do tinker with your Pi:

  1. Download and install fresh OS image of your choice
  2. Plug in Ethernet cable/connect to WiFi
    • Possibly do a LAN scan if you don't know your Pi's IP addres
  3. Do stuff via SSH
    • apt-get update -y && apt-get upgrade to update packages
    • Your personal configuration needs
  4. Make an image, then use that image for other Pis.

Steps if you don't tinker with your Pi (see note above):

  1. Download fresh OS image
  2. Mount image using instructions from https://raspberrypi.stackexchange.com/a/13138/24224 (you also have to consider what OS/image you have since some have different FS layouts)
    • Have a calculator ready.
  3. Find the deb file for each and every package you want to update, plus their dependencies, plus those dependencies' dependencies, plus those dependencies' dependencies' dependencies. apt-offline is a hassle. Refer to this link
    • Then find a way to install all of those packages without using/tinkering with your Pi. apt-get won't work offline. deb file details here. Good luck.
  4. Update the Pi kernels and low-level stuff using Hexxeh's tool
  5. Configure to your requirements
  6. Write modified image to your Pis' SD cards.

I don't see any benefit in not tinkering with your Pi.

Cut yourself some slack and tinker with your Pi. You only have to do it once.

  • Its almost impposible to get programs manually by getting, dependencies, and there dependencies, and there dependencies, etc. But if you use apt-get and say you want VLC you would do, apt-get install vlc --yes --print-uris. That will give a list of links; once downloaded, put them in /var/cache/apt/archives/partial and run dpkg -i partial/*.deb to install. Even better, if you get Synaptics, it has a option to generate package download script. Run that script on a Linux Computer and you got your packages. Then you can install them with synaptics again. – NULL Jul 19 '16 at 13:32
  • @NULL Then find a way to install all of those packages without using/tinkering with your Pi. – Gene Dela Rosa Jul 19 '16 at 13:45
  • @NULL As far as I know, you can only use dpkg on the system itself, not on a mounted image. Also, OP is planning on using his/her PC, so the *.deb files you have is for a wrong architecture in the first place (PC is x86/x64, Pi is ARMv6/v7) – Gene Dela Rosa Jul 19 '16 at 13:47
  • As I specify in my question, I don't want to do 1. As for 2, that sounds nuts :). What makes you think @flakeshakes suggestion is any more difficult from 2? – Andy Smith Jul 21 '16 at 18:19
  • @AndySmith I'll quote goldilock's comment: I'll be honest and say that my impression is you are pursuing the Y side of an XY problem with too much vigour -- it's implied you think the simpler method (just set up an image on a pi, which can be done from a computer via remote login, and the image itself tweaked by mounting, which can be done on a PC, and all of this can be automated with scripting) is too much hassle, and so you have put your hopes in a method that is actually much more hassle. – Gene Dela Rosa Jul 22 '16 at 9:55
0

I think what you are looking for is some kind of (software) configuration management. With this you would be able to boot up a stock raspbian image and then push over your own configuration (including new packages and the like). There are plenty of SCM systems out there. The downside is that most of these systems are aimed to support large scale networks and so are maybe a bit overkill for your purpose. You also need some kind of provisioning server. Most popular SCM's seem to be Puppet, Chef, Ansible. Articles to get you started:

This is kind of a generic answer but SCM is a wide field. Maybe this is worth digging into depending on what your plans are.

  • Ansible seems promising because it's agentless and you don't need a full blown server to run it. – duenni Jul 21 '16 at 6:26
  • 1
    Not really, I want the image to be already built, not something that I tack stuff on to. This suggestion doesn't work if my Pi doesn't have a network connection. – Andy Smith Jul 21 '16 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.