Headless Raspberry Pi Configuration

How to configure Debian/arm using Ubuntu/intel

Configuring a Raspberry Pi for headless operation without having to connect a keyboard and a screen, involves the following step

  • Download the latest Raspbian image
  • copy the Raspbian image to sdcard
  • setup Wifi
  • change pasword for pi
  • enable sshd
  • adduser for me,
  • modify group
  • add me to sudo
  • add athorized ssh keys for me on my laptop so i can login without password
  • set timezone
  • set hostname
  • set keyboard
  • run raspi-config to configure various other stuff

Dependent on what it will be used for,  there is still more to do, quite a few of the above steps needs to be done on the sdcard before you can access the Raspberry Pi remotely.

I have automated this proces by writing a small shell-script rpido

which takes care of the bulk of this.

To create a configured sdcard for a new RPI, I would typically do

  • install a sd card on my laptop
  • run: rpido -w -h newtoy -s
  • check things are fine, exit
  • move the sdcard to the RPI

This will download and install the latest raspbian to the sdcard, configure all the things mentioned above and set the hostname to newtoy, and finally drop you into a root-shell on the sdcard, where you could run raspi-config.

Yes I can execute arm-binaries on my ubuntu laptop, in a chroot environment on the filesystem on sdcard, check my shell-script below for how it is done.

The current content of template is:

You probably have to install some tools on your ubuntu first, I would suggest:

Features:

  • rpido always checks for the latest version of Raspian lite. It is much more effcient to download a new up-to-date version than to try to upgrade an earlier version at hand.
  • if there is no sd-card installed, rpido will use a file-based loop mounted filesystem, much faster for debugging and trying out stuff,
  • -k is a debugging option wich will leave the filesystem mounted, hence you can easily dive into it again with a simple chroot
  • Even though the script is not running as root, there is a lot of sudo which can really do a lot of harm, so be sure to do a backup before, for me it only takes one command

If you are still wondering how I manage to run arm-binaries on an intel laptop the secret-sauce is line 108-112 in the above script

And finally I would recommend that the bash prompt shows whether you are root by color, like this little example of rpido use demonstrates:

peter@t470:~> ./rpido -s
SUDO losetup -P /dev/loop14 sdcard
SUDO mount /dev/loop14p2 sdcard
SUDO mount /dev/loop14p1 sdcard/boot
SUDO rsync -a template/. adcard
SUDO rsync /usr/bin/qemu-arm-static sdcard/usr/bin/
SUDO mount –bind /proc sdcard/proc
SUDO mount –bind /dev sdcard/dev
SUDO mount –bind /sys sdcard/sys
SUDO chroot sdcard bash -i
root@raspberrypi:/# cat ~peter/.bashrc
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~peter/bin
RED=$(tput setaf 1)
BLUE=$(tput setaf 4)
NORMAL=$(tput sgr0)
HOSTNAME=$(cat /etc/hostname)
if [ $(id -u) -eq 0 ]; then # you are root, make the prompt red
+++ PS1=”\[${RED}\]\u@${HOSTNAME}:\W#\[${NORMAL}\] ”
else
+++ PS1=”\[${BLUE}\]\u@${HOSTNAME}:\W>\[${NORMAL}\] ”
fi
root@raspberrypi:/# exit
SUDO umount sdcard/sys
SUDO umount adcard/proc
SUDO umount adcard/dev
SUDO umount sdcard/boot
SUDO umount sdcard
SUDO losetup -d /dev/loop14
peter@t470:~>

Print Friendly, PDF & Email
This entry was posted in Linux, Raspberry Pi. Bookmark the permalink.