1

I'm currently exploring whether it is possible to create a piece of software which can (ideally) install and configure itself automatically - with no interaction from the user - the first time the Raspberry Pi is booted.

Inspired by how the Wi-Fi and SSH are automatically configured on Jessie, I'm wondering if this would be possible by storing a binary or a script on the boot partition of the SD card (boot partition so that it will also work for Windows users without third-party software). The user shouldn't have to do anything other than image the SD card, possibly drop some files into the boot partition, and then connect it to power/the internet.

My question is, then: what piece of code (in Raspbian? In the kernel?) currently handles the Wi-Fi and SSH setup? Additionally, are there any other facilities for doing what I'm trying to do - i.e., am I going down the wrong path with this?

0

1 Answer 1

1

I think that I have just learned an answer to your question, "Additionally, are there any other facilities for doing what I'm trying to do". On the Pi or Linux type of system, download the image (zip) file. Unzip it, if Raspbian there will be a 2017-04-10-raspbian-jessie.img file. Run sudo fdisk -l 2017-04-10-raspbian-jessie.img. The output should be like:

Disk jessie.img: 4 GiB, 4285005824 bytes, 8369152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x402e4a57

Device      Boot Start     End Sectors Size Id Type
jessie.img1       8192   92159   83968  41M  c W95 FAT32 (LBA)
jessie.img2      92160 8369151 8276992   4G 83 Linux

You can mount these images files, see 'Mounting an image on the host' https://en.wikibooks.org/wiki/QEMU/Images#Mounting_an_image_on_the_host as loopback with offset. Make mount points and use the offset of sector size times start sector.

sudo mkdir /mnt/d1 /mnt/d2
sudo mount -o loop,offset="$((512 * 8192))" 2017-04-10-raspbian-jessie.img /mnt/d1
sudo mount -o loop,offset="$((512 * 92160))" 2017-04-10-raspbian-jessie.img /mnt/d2

Now you have access to both the boot and root filesystem images to configure, script, and modify as you choose. If you put a script in the boot filesystem, you also have to setup how to execute it from the root filesystem, may be in cron or other means.

Unmount sudo umount /mnt/d[12] and copy the image sudo dd bs-4M if=2017-04-10-raspbian-jessie.img of=/dev/sda if sda is the sd card. Install the sd card in Pi and power/boot up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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