#+title: Raspberry Pi & Storage Setup
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="_share/media/css/computer.css" />
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="_share/media/css/org-media-sass/content-overview.css" />
#+OPTIONS: H:6

* links
- [[./toc.org][TOC - Home Computer]]

* Raspberry Pi Information

** network
| Category   | Value        |
|------------+--------------|
| IP address | 192.168.0.63 |
| Hostname   | ronberrypi   |

*** To Be Able to Ping the Raspberry Pi
#+begin_src bash
ping ronberrypi.local
#+end_src

** users

| username  | password     | groups         | /mnt/storage            |
|-----------+--------------+----------------+-------------------------|
| ronny     | 2reishit2ara | sudo           |                         |
| website   | 2reishit2ara | www-data, sudo | /var/www, /home/website |
| ftpuser   | 2reishit2ara | www-data, sudo | /home/ftpuser           |
| librarian | 2reishit2ara |                | librarian               |

* connect with a vnc
- [[https://www.youtube.com/watch?v=9fEnvDgxwbI][Raspberry Pi Headless Setup]]

** install
using the video you should be able to connect directly without doing anything special

** connect tiger vnc
- hostname: ronberrypi.local
- then enter the username and password

** connect realvnc
even easier


* External Hard Drive Info
This table keeps track of the Raspberry Pi's external storage setup.

| category      | value                                |
|---------------+--------------------------------------|
| device        | /dev/sda2                            |
| filesystem    | ext4                                 |
| label         | storage                              |
| mount point   | /mnt/storage                         |
| mount options | defaults,relatime,commit=600         |
| UUID          | 5bb54030-2df7-4798-afb5-bd2878ae0def |


* Directory Bind-Mount Information
This table documents how key directories on the Raspberry Pi are linked to `/mnt/storage` and the commands used.

| Directory       | Mounted From           | Mounted To      |
|-----------------+------------------------+-----------------|
| /home/website   | /mnt/storage/website   | /home/website   |
| /home/librarian | /mnt/storage/librarian | /home/librarian |
| /var/www        | /mnt/storage/www       | /var/www        |
| /srv/n8n        | /mnt/storage/n8n       | /srv/n8n        |

** command used to bind target directory to mount point
#+begin_src sh
sudo mount --bind /mnt/storage/<target_mount> /<bind directory>
#+end_src

*** example
- *target mount:* /mnt/storage/www
- *bind directory:* /var/www

** making bind mounts persistent
To ensure the mounts persist after a reboot, add the following lines to `/etc/fstab`:

#+begin_src sh
/mnt/storage/website /home/website none bind 0 0
/mnt/storage/calibre /home/calibre none bind 0 0
/mnt/storage/www /var/www none bind 0 0
/mnt/storage/n8n /srv/n8n none bind 0 0
#+end_src

** Setup Commands
These commands ensure everything is correctly prepared before binding.

| Step                             | Command                                                                                |
|----------------------------------+----------------------------------------------------------------------------------------|
| Ensure storage directories exist | `sudo mkdir -p /mnt/storage/website /mnt/storage/calibre /mnt/storage/www`             |
| Move existing data (if needed)   | `sudo mv /home/website/* /mnt/storage/website/`                                        |
| Create bind directories          | `sudo mkdir -p /home/website /home/calibre /var/www`                                   |
| Bind-mount directories           | `sudo mount --bind /mnt/storage/website /home/website`                                 |
| Add to `/etc/fstab`              | `echo "/mnt/storage/website /home/website none bind 0 0" \vert sudo tee -a /etc/fstab` |
| Apply changes                    | `sudo mount -a`                                                                        |
| Verify mount status              | `df -h  \vert grep storage`                                                            |

* Hard Drive Commands
** generally useful hard drive commands
| Purpose                          | Command                            |
|----------------------------------+------------------------------------|
| Find the UUID                    | lsblk -f                           |
| Check filesystem type            | sudo blkid /dev/sda2               |
| Remount drive without rebooting  | sudo mount -o remount /mnt/storage |
| Check if new options are applied | mount \vert grep storage           |
| Verify changes                   | cat /etc/fstab \vert grep storage  |

** Mount Options Available
| Option            | Description                                                                  |
|-------------------+------------------------------------------------------------------------------|
| defaults          | Uses the default options: `rw, suid, dev, exec, auto, nouser, async`.        |
| rw                | Mounts the filesystem as **read/write** (default).                           |
| ro                | Mounts the filesystem as **read-only**.                                      |
| noexec            | Prevents execution of binaries on the mounted filesystem.                    |
| exec              | Allows execution of binaries (default).                                      |
| nosuid            | Blocks `setuid`/`setgid` binaries from running.                              |
| nodev             | Ignores device files (e.g., `/dev/null`) on this filesystem.                 |
| noatime           | **Disables access time updates** to improve performance.                     |
| nodiratime        | Disables directory access time updates (for performance).                    |
| relatime          | **Updates access time only if the file is modified**, balancing performance. |
| strictatime       | **Always updates access time** (not recommended for performance reasons).    |
| sync              | Writes changes to disk **immediately** instead of caching them.              |
| async             | Writes changes to disk **asynchronously** (default, better performance).     |
| commit=600        | Delays disk writes for **600 seconds (10 minutes)**, reducing wear.          |
| nofail            | Allows booting even if the mount fails (useful for external drives).         |
| errors=remount-ro | If an error occurs, remounts the filesystem as **read-only**.                |

** Performance Options
| Performance Status                    | Mount Options                             |
|---------------------------------------+-------------------------------------------|
| Maximum Performance                   | defaults, noatime, nodiratime, commit=600 |
| Accurate File Access Times            | defaults, relatime, commit=600            |
| Extra Safety in Case of Drive Failure | errors=remount-ro, nofail                 |
