> For the complete documentation index, see [llms.txt](https://tdiesler.gitbook.io/cardano/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tdiesler.gitbook.io/cardano/plain-docker/raspberrypi-4.md).

# RaspberryPi 4

First, we need to burn the [latest](https://downloads.raspberrypi.org/raspios_arm64/images) 64bit OS on the [microSD](https://www.amazon.de/gp/product/B06XWMQ81P) card. At the time of writing, this was [2020-08-20-raspios-buster-arm64](https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-08-24/2020-08-20-raspios-buster-arm64.zip). The microSD card is not where we'll be writing the Cardano block data to, so 32GB is quite enough for the [OS](https://www.raspberrypi.org/software) and Docker.

Once you've burned the OS on the card, you may want to enable SSH on boot before you power up your Pi for the first time. For this you need to put an empty file called `SSH` in the root directory of the microSD card.

```bash
$ touch /Volumes/boot/SSH
```

When the Pi is running, you should be able to SSH into it, like this ...

```bash
$ ssh pi@raspi4
password: raspberry
Linux raspberrypi 5.4.51-v8+ #1333 SMP PREEMPT Mon Aug 10 16:58:35 BST 2020 aarch64
...
Use raspi-config to set the country before use.

pi@raspberrypi:~ $
```

You can now use `raspi-config` to change the default password, set the hostname, enable Wi-Fi, etc. One of the first things I usually do, is to add my public SSH key to `~/.ssh/authorized_keys`

```bash
$ scp ~/.ssh/id_rsa.pub pi@raspi4:.ssh/authorized_keys
```

For added security, we can then disable password authentication like this ...

```bash
$ sudo sed -i "s/^#PasswordAuthentication yes$/PasswordAuthentication no/" /etc/ssh/sshd_config
$ sudo cat /etc/ssh/sshd_config | grep PasswordAuthentication
PasswordAuthentication no

$ sudo systemctl restart sshd
```

Make sure you can indeed login without password, before you disable that. For details on how to generate an SSH key, we kindly ask you to look [here](https://www.ssh.com/ssh/keygen) for example.

Now that our Pi is reasonable well secured, we can continue with the setup and update system packages.

```bash
$ sudo apt-get update
$ sudo apt-get full-upgrade -y
```

**System Time Synchronization**

Keeping the system time synchronized among peers is quite important when we want to engage in peer-to-peer communication. Lets check real quick, whether the system time is getting synchronized ...

```bash
$ timedatectl
               Local time: Mon 2021-01-18 22:02:59 GMT
           Universal time: Mon 2021-01-18 22:02:59 UTC
                 RTC time: n/a
                Time zone: Europe/London (GMT, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
```

If that should not be the case, have a look at over [here](https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-debian-10).

**Enable memory accounting**

Later, we'll be looking at how much memory the various docker containers consume while running. This is an important metric that we Stake Pool Operators (SPO) want to have an eye on. Lets check whether memory accounting is enabled at the kernel level.

```bash
$ cat /boot/cmdline.txt
console=serial0,115200 rootfstype=ext4 ... cgroup_memory=1 cgroup_enable=memory
```

Add these last two cgroup settings in case they are not there already. Re-boot afterwards ...

```bash
$ sudo shutdown -r now
```

**Swap File Setup**

The Pi comes with 8GB of RAM, which should be plenty to run a Cardano node. Still, lets setup a swap file in case the process has high memory spikes.

```bash
$ sudo dphys-swapfile swapoff
$ sudo sed -i "s/^CONF_SWAPSIZE=100$/CONF_SWAPSIZE=8192/" /etc/dphys-swapfile
$ sudo sed -i "s/^#CONF_MAXSWAP=2048$/CONF_MAXSWAP=8192/" /etc/dphys-swapfile
$ sudo cat /etc/dphys-swapfile | grep CONF
$ sudo dphys-swapfile setup
$ sudo dphys-swapfile swapon
$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.6Gi       104Mi       7.4Gi       8.0Mi       174Mi       7.4Gi
Swap:         8.0Gi          0B       8.0Gi
```

**Mount Data Disks**

We won't be writing the block data to the microSD card. Instead, we'll be using an external SSD drive connected to one of the USB-C ports. Initially, this can be a [SanDisk Ultra Fit USB 3.1 Flash Drive](https://www.amazon.de/gp/product/B07855LJ99).

Fist, lets list the connected block devices

```
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1 114.6G  0 disk
`-sda1        8:1    1 114.6G  0 part
mmcblk0     179:0    0  29.7G  0 disk
|-mmcblk0p1 179:1    0   256M  0 part /boot
`-mmcblk0p2 179:2    0  29.5G  0 part /
```

Now, lets initialize the filesystem on that external drive. The commands below will re-partition the drive and format the file system. All existing data on that drive will be lost.

```
# DISK00 ########################################################################

DISK00=/dev/sda
MOUNT00=/mnt/disks/data00

# Create new empty filesystem:
$ sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,discard $DISK00

# Mount block storage
$ sudo mkdir -p $MOUNT00; sudo mount -o discard,defaults $DISK00 $MOUNT00

# Append to /etc/fstab
$ echo "" | sudo tee --append /etc/fstab
$ echo "$DISK00  $MOUNT00  ext4   defaults,noatime,nofail 0 0" | sudo tee --append /etc/fstab
```

Make sure the mounted directory for the block data is empty and does not contain the `lost+found` folder. Otherwise the Cardano node will not accept this location.

```
$ sudo rm -rf /mnt/disks/data00/*
```

This concludes the RaspberryPi setup. We can now continue with [Installing Docker](/cardano/plain-docker/installing-docker.md).
