2017-02-08 02:33:22 +01:00
|
|
|
Building the image from scratch
|
|
|
|
===============================
|
|
|
|
|
|
|
|
There is always a prebuilt image available for download and installation as
|
2017-02-08 03:18:40 +01:00
|
|
|
described in the [README](../README.md). If you'd like to build the project yourself,
|
2017-02-08 02:33:22 +01:00
|
|
|
there are several steps involved:
|
|
|
|
|
2023-05-22 08:59:48 +02:00
|
|
|
* Downloading a generic RaspiOS Lite image
|
2017-02-08 02:33:22 +01:00
|
|
|
* Resizing the image and partition
|
|
|
|
* Downloading and building the dependencies
|
|
|
|
* Modifying the image configuration
|
|
|
|
* Copying the project filesystem into the image
|
|
|
|
|
|
|
|
This procedure will only work on Ubuntu or Debian Linux. If you use MacOS or
|
|
|
|
Windows, the best option is to install Linux in a virtual machine using
|
|
|
|
something like VirtualBox.
|
|
|
|
|
|
|
|
It is recommended that you make a copy of image_setup_checklist.md and √ items off
|
|
|
|
on the list as you go.
|
|
|
|
|
|
|
|
Preparation
|
|
|
|
===========
|
|
|
|
|
|
|
|
* Make sure your development environment is up to date:
|
|
|
|
```
|
|
|
|
apt-get update
|
|
|
|
apt-get dist-upgrade
|
|
|
|
```
|
|
|
|
* Install qemu, qemu-user-static, and proot if not already installed:
|
|
|
|
```
|
2023-05-22 08:59:48 +02:00
|
|
|
apt-get install qemu qemu-user-static qemu-user proot xz-utils
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Download the Raspbian image
|
|
|
|
==============================
|
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
* Get the most recent version of RaspiOS Lite from [here](https://downloads.raspberrypi.org/raspios_lite_armhf/images/):
|
2017-02-08 02:33:22 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
wget https://downloads.raspberrypi.org/raspbian_lite_latest
|
|
|
|
```
|
|
|
|
* Verify the hash of the downloaded file and compare it to the hash on the server:
|
|
|
|
```
|
2020-01-15 18:01:38 +01:00
|
|
|
shasum XXXX-XX-XX-raspbian-buster-lite.zip
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
* Unpack it:
|
|
|
|
```
|
2023-05-22 09:18:44 +02:00
|
|
|
unxz XXXX-XX-XX-raspios-bullseye-armhf-lite.img.xz
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Add space to the image
|
|
|
|
=========================
|
|
|
|
|
|
|
|
* Use dd to add 2GB (2048 blocks of 1024k each). Using /dev/zero as the input
|
|
|
|
file yields an unlimited number of "0x00" bytes.
|
|
|
|
```
|
2023-05-22 09:18:44 +02:00
|
|
|
dd if=/dev/zero bs=1024k count=2048 >> XXXX-XX-XX-raspios-bullseye-armhf-lite.img
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
|
2018-01-29 14:20:58 +01:00
|
|
|
* Expand the root (second) partition using sfdisk:
|
2023-05-22 09:18:44 +02:00
|
|
|
```
|
2023-05-22 09:19:21 +02:00
|
|
|
echo ", +" | sfdisk -N 2 XXXX-XX-XX-raspios-bullseye-armhf-lite.img
|
2023-05-22 09:18:44 +02:00
|
|
|
|
|
|
|
Checking that no-one is using this disk right now ... OK
|
|
|
|
|
|
|
|
Disk 2023-05-03-raspios-bullseye-armhf-lite.img: 3.83 GiB, 4114612224 bytes, 8036352 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: 0x4c4e106f
|
2017-02-08 02:33:22 +01:00
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
Old situation:
|
2017-02-08 02:33:22 +01:00
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
Device Boot Start End Sectors Size Id Type
|
|
|
|
2023-05-03-raspios-bullseye-armhf-lite.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
|
2023-05-22 09:19:41 +02:00
|
|
|
2023-05-03-raspios-bullseye-armhf-lite.img2 532480 8036351 7503872 1.6G 83 Linux
|
2017-02-08 02:33:22 +01:00
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
2023-05-03-raspios-bullseye-armhf-lite.img2:
|
|
|
|
New situation:
|
|
|
|
Disklabel type: dos
|
|
|
|
Disk identifier: 0x4c4e106f
|
2017-02-08 02:33:22 +01:00
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
Device Boot Start End Sectors Size Id Type
|
|
|
|
2023-05-03-raspios-bullseye-armhf-lite.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
|
|
|
|
2023-05-03-raspios-bullseye-armhf-lite.img2 532480 8036351 7503872 3.6G 83 Linux
|
2017-02-08 02:33:22 +01:00
|
|
|
|
2023-05-22 09:18:44 +02:00
|
|
|
The partition table has been altered.
|
|
|
|
Syncing disks.
|
2017-02-08 02:33:22 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2018-07-23 11:48:31 +02:00
|
|
|
* Edit `shell_utils/basic_mount_image.sh` to use the correct image path ($IMAGE)
|
|
|
|
* Run the script
|
|
|
|
```
|
2019-08-30 15:09:39 +02:00
|
|
|
sudo shell_utils/basic_mount_image.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
* Resize the filesystem
|
|
|
|
|
2020-01-15 18:01:38 +01:00
|
|
|
Find the loop device of the root filesystem by running `losetup`, and it is the biggest one related to the image you mounted
|
|
|
|
|
2019-08-30 15:09:39 +02:00
|
|
|
```
|
|
|
|
sudo resize2fs /dev/loop<ID of the loop FS mounted as /mnt/rpi-root>
|
2018-07-23 11:48:31 +02:00
|
|
|
```
|
|
|
|
|
2017-02-08 02:33:22 +01:00
|
|
|
|
|
|
|
Installing the dependencies
|
|
|
|
===========================
|
|
|
|
|
2017-08-09 22:02:53 +02:00
|
|
|
* Copy circlean_fs/root_partition/etc/systemd/system/rc-local.service into the equivalent location in the image.
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
2017-08-09 22:02:53 +02:00
|
|
|
sudo cp circlean_fs/root_partition/etc/systemd/system/rc-local.service /mnt/rpi-root/etc/systemd/system/rc-local.service
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
2019-08-30 15:09:39 +02:00
|
|
|
* Use [proot](https://proot-me.github.io/) to enter the equivalent of a chroot inside the mounted image.
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
2018-01-29 16:29:58 +01:00
|
|
|
sudo proot -q qemu-arm -0 -r /mnt/rpi-root -b /mnt/rpi-boot:/boot -b /etc/resolv.conf:/etc/resolv.conf \
|
2018-07-23 11:48:31 +02:00
|
|
|
-b /dev/:/dev/ -b /sys/:/sys/ -b /proc/:/proc/ -b /run/shm:/run/shm /bin/bash
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
2018-07-23 11:48:31 +02:00
|
|
|
|
|
|
|
**WARNING**: if you have a permission error, make sure the `/tmp` directory is mointed with the `exec` flag.
|
|
|
|
|
2017-02-08 02:33:22 +01:00
|
|
|
* Change your locales (remove "en_GB.UTF-8 UTF-8", add "en_US.UTF-8 UTF-8"). The
|
|
|
|
arrow keys move the cursor, spacebar selects/deselects a locale, tab moves the cursor
|
|
|
|
to a different context, and enter lets you select "ok". This step might take some time,
|
|
|
|
be patient:
|
|
|
|
```
|
2019-03-02 09:24:42 +01:00
|
|
|
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
|
|
|
sed -i -e 's/en_GB.UTF-8 UTF-8/# en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
|
|
|
locale-gen en_US.UTF-8
|
|
|
|
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
* In the image, make sure everything is up-to-date and remove old packages. You may have to
|
|
|
|
run dist-upgrade and autoremove several times for everything to be installed, and a few
|
|
|
|
raspbian-sys-mods related installs may fail - you can ignore them:
|
|
|
|
```
|
|
|
|
apt-get update
|
|
|
|
apt-get dist-upgrade
|
|
|
|
apt-get autoremove
|
|
|
|
```
|
2017-10-02 03:43:57 +02:00
|
|
|
* Install the linux dependencies (see CONTRIBUTING.md for more details). If you see warnings that
|
|
|
|
from qemu about "Unsupported syscall: 384", you can ignore them. `getrandom(2)` was implemented in
|
|
|
|
kernel 3.17 and apt will use /dev/urandom when it fails:
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
2020-01-15 18:01:38 +01:00
|
|
|
apt-get install timidity git p7zip-full python3 python3-pip ntfs-3g libjpeg-dev libtiff-dev \
|
2019-08-30 15:09:39 +02:00
|
|
|
libwebp-dev tk-dev python3-tk liblcms2-dev tcl-dev libopenjp2-7 libxml2-dev \
|
2020-01-15 18:01:38 +01:00
|
|
|
libssl-dev libffi-dev libxslt1-dev exfat-fuse exfat-utils udisks2
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
* Compile p7zip-rar from source. First, uncomment out the second line in /etc/apt/sources.list. Then:
|
|
|
|
```
|
|
|
|
cd /home/pi
|
|
|
|
mkdir rar && cd rar/
|
2017-08-09 22:02:53 +02:00
|
|
|
apt-get update
|
2017-02-08 02:33:22 +01:00
|
|
|
apt-get build-dep p7zip-rar
|
2017-08-09 22:02:53 +02:00
|
|
|
apt-get source -b p7zip-rar
|
2017-02-08 02:33:22 +01:00
|
|
|
dpkg -i ${path to p7zip-rar .deb file}
|
|
|
|
```
|
2019-08-30 15:09:39 +02:00
|
|
|
* Install the Python dependencies for `PyCIRCLean/filecheck.py`. PyCIRCLean is 3.6+
|
2018-07-23 11:48:31 +02:00
|
|
|
compatible, so use `pip -V` to make sure you're using the right version of pip. You might
|
2017-02-08 02:33:22 +01:00
|
|
|
have to edit your PATH variable or use pip3 to get the correct pip. You also might want to
|
|
|
|
verify that these dependencies are current by checking in the PyCIRCLean git repo.
|
|
|
|
```
|
2019-08-30 15:09:39 +02:00
|
|
|
cd /home/pi
|
|
|
|
git clone https://github.com/CIRCL/PyCIRCLean.git
|
|
|
|
cd PyCIRCLean
|
2020-01-15 18:01:38 +01:00
|
|
|
pip3 install -r requirements.txt
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
* Create a new user named "kitten":
|
|
|
|
```
|
|
|
|
useradd -m kitten
|
|
|
|
chown -R kitten:kitten /home/kitten
|
|
|
|
```
|
2018-07-23 11:48:31 +02:00
|
|
|
* Enable `rc.local`, which ensures that the code in `/etc/rc.local` is run on boot.
|
2017-02-08 02:33:22 +01:00
|
|
|
This is what triggers CIRCLean to run.
|
|
|
|
```
|
|
|
|
systemctl enable rc-local.service
|
|
|
|
```
|
2018-07-23 11:48:31 +02:00
|
|
|
* Turn off several networking related services. This speeds up boot and reduces the attack surface:
|
2017-10-25 21:28:59 +02:00
|
|
|
```
|
|
|
|
systemctl disable networking.service
|
|
|
|
systemctl disable bluetooth.service
|
|
|
|
systemctl disable dhcpcd.service
|
|
|
|
```
|
2017-02-08 02:33:22 +01:00
|
|
|
* Clean up:
|
|
|
|
```
|
|
|
|
apt-get clean
|
|
|
|
apt-get autoremove
|
|
|
|
apt-get autoclean
|
|
|
|
```
|
|
|
|
* Exit proot, and copy the files from your repository into the mounted
|
|
|
|
image. Adding a -n flag will make rsync do a dry run instead of copying. See the rsync
|
|
|
|
manpage for more details. Make sure to include the trailing slashes on the paths:
|
|
|
|
```
|
|
|
|
exit
|
|
|
|
sudo rsync -vri circlean_fs/boot/ /mnt/rpi-boot/
|
|
|
|
sudo rsync -vri circlean_fs/root_partition/ /mnt/rpi-root/
|
2017-10-02 03:43:57 +02:00
|
|
|
sudo cp -rf midi /mnt/rpi-root/opt/
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|
|
|
|
* If have an external hardware led and you're using the led functionality, copy
|
|
|
|
the led files from diode_controller/ as well.
|
|
|
|
|
2018-07-23 11:48:31 +02:00
|
|
|
* Unmount the image
|
|
|
|
```
|
|
|
|
sudo umount /mnt/rpi-boot /mnt/rpi-root
|
|
|
|
```
|
|
|
|
|
2017-02-08 02:33:22 +01:00
|
|
|
Write the image on a SD card
|
|
|
|
============================
|
|
|
|
|
|
|
|
* Plug your SD card into the computer. Then, find where it is mounted using lsblk or df:
|
|
|
|
```
|
|
|
|
lsblk
|
|
|
|
df -h
|
|
|
|
```
|
|
|
|
* If it has been automatically mounted, unmount the SD card (use the path you
|
|
|
|
found in the previous step):
|
|
|
|
```
|
|
|
|
umount $PATH_TO_YOUR_SD
|
|
|
|
```
|
|
|
|
* Write the image to the card. Newer versions of dd include a status option to monitor the
|
|
|
|
copying process:
|
|
|
|
```
|
|
|
|
sudo dd bs=4M if=$PATH_TO_YOUR_IMAGE of=$PATH_TO_YOUR_SD status=progress
|
|
|
|
```
|
|
|
|
* Use fsck to verify the root partition:
|
|
|
|
```
|
2018-07-23 11:48:31 +02:00
|
|
|
sudo fsck.vfat -f /dev/<partition>1
|
|
|
|
sudo e2fsck -f /dev/<partition>2
|
2017-02-08 02:33:22 +01:00
|
|
|
```
|