<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[onecolumn,letterpaper,11pt]{article}

%===================================================================
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_definitions}
\input{common_latex/common_latex_lab_format}
%===================================================================

\begin{document}

\begin{labcover}
\labtitle{Creating a New RasPi PABLO SD Card Image}
\vspace{0.1in}
\labdate{Oct 2023}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labsrc{project-pavlab/mtasc/mt\_pablo\_build} 
\labtoc{small}
\end{labcover}

\wikidoc{file=MT.RasPiBuild}
\wikidoc{bugz=mt_raspi_bld}
\wikidoc{auth=mikerb@mit.edu} 


%===================================================================
\section{Building a New RasPi Image Overview}
%===================================================================
\label{sec_mt_rbld}  

Modifications to the Raspberry PI computers in the PABLO boxes are
mostly handled by automated scripts that pull down software updates and
configuration changes upon reboot. For PABLOS in an MTASC cluster,
updates happen automatically upon reboot, and for PABLOS used in
Herons or other projects, the updates are initiated by the user logged
into the PABLO.

\vspace{0.1in}
\noindent
Occasionally changes need to be applied to the RasPi image that cannot
be carried out through automated scripts. Examples include (a) upgrading
the current Raspbian (a.k.a. PiOS) release, (b) updating packages, or
(c) mods to the system configuration in \var{/etc} for example.

\vspace{0.1in}
\noindent
In these circumstances, we either (1) identify one of the PABLO Pis as
master, apply the changes, or (2) create a new master image from
scratch, customized to the PavLab configuration. In either case, the
master is then cloned with a disk cloner and the SD cards on all the
other PABLOS are physically replaced. The former may happen once or
twice per year, the latter happens once every year or two. 

\vspace{0.1in}
\noindent
This document covers the creation of a new master image from scratch. 

%===================================================================
\subsection{Two Types of PABLOS - One SD Card Image}

PABLO boxes are used in one of two primary ways in our lab. As a backseat
computer in one of our Heron robots, or as a node in an MTASC cluster.
The SD card image is the same in both use cases.

%===================================================================
\subsection{PABLO Unique Identifiers}

It is worth restating that PABLOS in MTASC clusters have unique
identifier names. For example \var{mts01}, \var{mts02}, \var{mts50} in
a 50-node MTASC cluster. These names refer to both the label on the
outside of the box, and the machine name shown on the command-line
prompt when logged in. The unique identifier is tied to the Pi board
itself, namely the MAC address of the Ethernet card. Inside the
\var{pablo-common} tree, there is script \var{get\_vnames.sh} which
checks the MAC address and assigns the name.

\vspace{0.1in}
\noindent
We mention that here to be clear that it does not matter which SD card
goes in which machine. Initially they should all have exactly identical
SD card images. Even after operation for some period, any SD card can
be switched into any other PABLO. 

%===================================================================
\subsection{Getting the latest Rasbian OS on a new SD boot card}

\vspace{0.1in}
\begin{fileverb}
(1) Find a 32G MicroSD card and MicroSD card reader and insert into your computer
(2) Go to the Raspberry PI website and follow instructions for using
 the \var{"Raspberry Pi Imager"} tool.
(3) Use the tool. When prompted make student2680 user. 
(4) Unmount the SD card and plug it into the PI with a monitor/keyboard.
\end{fileverb}
\vspace{0.1in}

%===================================================================
\subsection{ Log onto Pi and Get initial packages}

Note: This is done initially with a monitor and keyboard. 

\vspace{0.1in}
\begin{fileverb}
$ apt-get --assume-yes install emacs wget members cmake \
                       subversion screen ncdu watch git

If will be using with a USB blinkstick (MIT yes for sure):
$ sudo apt-get install python3-pip    (probably already have)
$ sudo pip install blinkstick
$ sudo blinkstick --add-udev-rule

Further blinkstick note:

Running blinkstick the first time produced an error:
/usr/bin/env: 'python3\r' : No such file or directory
This apparently was due to the python script (/usr/local/bin/blinkstick is
actually a python script) having the wrong line endings. Described here.
https://forums.raspberrypi.com/viewtopic.php?t=180848

The fix:
$ cd /usr/local/bin
$ tr -d '\r' &lt;blinkstick &gt;new_blinkstick
$ mv blinkstick old_blinkstick
$ mv new_blinkstick blinkstick

May also need to change this file to be executable

\end{fileverb}
\vspace{0.1in}


%===================================================================
\subsection{Log onto Pi, Set up a new student2680 user}

\vspace{0.1in}
\begin{fileverb}
$ sudo groupadd student2680
$ sudo useradd -g users -G student2680 -s /bin/bash -d /home/student2680 student2680
$ cd /home; sudo mkdir student2680
$ cd /home; sudo chgrp -R student2680 student2680
$ cd /home; sudo chown -R student2680 student2680
$ sudo passwd student2680
$ sudo usermod -G dialout,sudo student2680
username=pi, passwd=pavlab2012
\end{fileverb}
\vspace{0.1in}

%===================================================================
\subsection{System config (MIT preferences)}

\vspace{0.1in}
\begin{fileverb}
(1) Security
    Edit /etc/hosts.deny and add the below lines:
    # MIT PABLO Setting
    ALL: PARANOID
(2) Security
    Edit /etc/hosts.allow and add the below lines:
    # MIT
    ALL: 128.30.*.*, 128.31.*.*, 18.38.*.*
    # Local subnet
    ALL: 192.168.*.*, 10.1.*.*, 10.42.*.*,
    # localhost
    ALL: 127.0.0.1
(3) Change host name from RasPi to PABLO
    In /etc/hosts add the following line (rm the raspberry pi line)
    127.0.1.1  PABLO
    In /etc/hostname, set the one line to:
    PABLO
(4) Allow ssh access
    In /etc/ssh/sshd_config, add the following line:
      AllowUsers student2680 near/at the bottom
    Then restart ssh:
    $ sudo /etc/init.d/ssh restart
\end{fileverb}
\vspace{0.1in}

\vspace{0.1in}
\begin{fileverb}
(5) SSH Keys
    Add ssh key to allow incoming connections
    Add ssh key to allow data dumps to oceanai
(6) Make sure ssh is started upon boot
    $ sudo systemctl enable ssh
(7) Make symlink from /sbin/ifconfig to /usr/bin/ifconfig
    Reason: when ipaddr_info.sh runs this within pHostInfoV2,
    it does not have permission to run things in /sbin/.
(8) Configure eth0 to have a fall-back IP address.
    Edit the file /etc/dhcpcd.conf
    Uncomment the below lines typically at the end of the file:
    --------------------------------------
    # It is possible to fall back to a static IP if DHCP fails:
    # define static profile
    profile static_eth0
    static ip_address=192.168.2.24/24
    static routers=192.168.2.1
    static domain_name_servers=192.168.2.1

    # fallback to static profile on eth0
    interface eth0
    fallback static_eth0
    --------------------------------------
\end{fileverb}
\vspace{0.1in}

\vspace{0.1in}
\begin{fileverb}
(9) Allow student2680 user to execute poweroff, reboot and shutdown without
    needing to provide credentials.
    Edit the /etc/sudoers file.
    $ sudo visudo /etc/sudoers
    Add the line:
    student2680 ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown

    Note: To execute say shutdown, the user student2680 still needs
          to type $ sudo shutdown -h now, but won't be prompted
          for password
    Note: Normally remote shutdown will come from within
          pablo_common/bin/pablo_halt.sh

https://askubuntu.com/questions/168879/shutdown-from-terminal-without-entering-password

\end{fileverb}
\vspace{0.1in}




\end{document}


</pre></body></html>