Andrino Moro
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Raspberry Pi Compile Farm ========================= [TOC] ## operating system - Ubuntu Core 64bit Server preinstalled for Raspberry Pi -- https://ubuntu.com/download/raspberry-pi - Replug the FTDI adapter if Serial Communication seems buggy - the image allows serial connection by default ## hardware - Pi4B 4GB 60.- - pw supply 2A 10.- - 5W -> 76kW a 17Rp/kWh -> per Pi per year ca. 15.- - Samsung SSD T5 80.-/ 30 bis 40.- - MicroSD card: 10.- für 32GB from Ultra SanDisk - Totaling Cost for 3 years: 195.- -> 65.- per year and pi - with network boot: total of 105 resulting in 35.- per pi and year - server in france: 8\*4\*12 EURO per year # overlay file system ## documentation, concepts and helpfull links > For documentation of the **overlayfs** (built into kernel) **see man page of mount** (search for overlay). The **overlayroot** packet commes preeinstalled with ubuntu with the cloud-initramfs-tools bundle <https://packages.ubuntu.com/source/bionic/cloud-initramfs-tools>. Overlayroot is a high end wrapper for overlayfs and consists of initramfs scripts to automatically mount the rootfs. - use `dpkg --listfiles overlayroot`. Avoid writing a custom initramfs script. > Concider using a **memory based overlay file system** with an swap partition - might be beneficial as kenel is probably smarter in deciding what to outsource and what to keep in memory (as files get chached by memory anywas) - aditional links - **basics of overlay** <https://windsock.io/the-overlay-filesystem/> - <https://openwrt.org/docs/guide-user/additional-software/extroot_configuration> - <https://spin.atomicobject.com/2015/03/10/protecting-ubuntu-root-filesystem/> ## Setup - In **/media/root-ro/** is the underlying filesystem mounted. - In **/media/root-rw/overlay/** the overlay changes are stored. ```bash root@raspi4-1:~ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 110G 0 part /media/root-ro ├─sda2 8:2 0 20G 0 part /media/root-rw ├─sda3 8:3 0 3.6G 0 part └─sda4 8:4 0 90G 0 part /root/bamboo-agent-home ``` - the home dir of the bamboo agent is persistent. ## Step-by-step 1) `e2label /dev/sda2 overlay` mark overlay partition for later use 2) `e2label /dev/sda4 persistent` mark partition for bambo-agent-home that is not included in the overlay 3) make the bamboo-agent homedir persistent across reboots `echo 'LABEL=persistent /root/bamboo-agent-home/ ext4 defaults,rw 0 0' >> /etc/fstab` 4) ` echo 'overlayroot=device:dev=LABEL=overlay,timeout=180,debug=1,recursive=0' > /etc/overlayroot.local.conf` make the the overlaydevice, recursive=0 excludes on rootfs mounted file systems from the overlay 5) `reboot` 6) chekc motd on logging: output should be (due to debug=1 in config): ```bash root@raspi4-1:~ bash /etc/update-motd.d/97-overlayroot overlayroot / overlay rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_ 0 0 /dev/sda1 /media/root-ro ext4 ro,relatime 0 0 /dev/disk/by-label/overlay /media/root-rw ext4 rw,relatime 0 0 ``` 7) Make Script to controll the overlay. ```bash cat > /usr/local/bin/overlay-control < EOF #!/usr/bin/env bash # This script controls the behavier of the overlay file system. # Edits # Licence GNU GLPv3 (or whatever you want if you ask) # 04.04.2020: Andrino Meli # # TODO: make absolute paths DEBUG= [[ ! -z DEBUG ]] && set +x USSAGE="$0 [ help | status | chroot | overlay | no-overlay | reset ]" reboot_prompt () { LOOP="loop" while [ $LOOP == "loop" ] do read -e -p "You should reboot, reboot now? [Y,n]: " RES case $RES in "y"|"Y"|"") reboot ;; "n") LOOP="quit" ;; *) ;; esac done } function isoverlay { [[ -d /media/root-ro/ ]] && return 0 return 1 } # Print Help [[ -z $1 ]] && echo "$USSAGE" && exit 1 [[ $1 == "help" ]] && echo "$USSAGE" && exit 0 # print status if [[ $1 == "status" ]] then if isoverlay; then echo "Running in overlay mode." else echo "No overlay active." fi exit 0 fi # check permissions [[ $USER != "root" ]] && echo "run as root! " && exit 5 # reboot with overlay if [[ $1 == "overlay" ]] then # only chroot if overlay is enabled if isoverlay; then overlayroot-chroot sed 's/^# overlayroot=/overlayroot=/' -i /etc/overlayroot.local.conf else sed 's/^# overlayroot=/overlayroot=/' -i /etc/overlayroot.local.conf fi [[ ! -z $DEBUG ]] && cat /etc/overlayroot.local.conf reboot_prompt exit 0 fi # reboot with no overlay if [[ $1 == "no-overlay" ]] then if isoverlay; then overlayroot-chroot sed 's/^overlayroot=/# overlayroot=/' -i /etc/overlayroot.local.conf else sed 's/^overlayroot=/# overlayroot=/' -i /etc/overlayroot.local.conf fi [[ ! -z $DEBUG ]] && cat /etc/overlayroot.local.conf reboot_prompt exit 0 fi # reset overlay (delete changes) - consider rebooting if [[ $1 == "reset" ]] then if isoverlay; then overlayroot-chroot rm -rf /media/root-rw/overlay/* else echo "TODO: implement this feature - reformat the overlay partition" fi reboot_prompt exit 0 fi # reset overlay (delete changes) if [[ $1 == "chroot" ]] then if isoverlay; then overlayroot-chroot && reboot_prompt else echo "Chroot failed: no overlay active" fi exit 0 fi # none of the arguments match - print help echo "$USSAGE" && exit 1 EOF ``` 9) Make the script for shell autocompletion. ```bash cat > /usr/local/bin/overlay-control-completion.bash < EOF #/usr/bin/env bash complete -W "help status chroot overlay no-overlay reset " overlay-control EOF ``` 10) `echo 'source /usr/local/bin/overlay-control-completion.bash' >> /root/.bashrc` 11) `chmod +x /usr/local/bin/overlay-control-completion.bash` 11) `chmod 744 /usr/local/bin/overlay-control` ## use cases - simplest is to just use the script - `rm -rf /media/root-rw/overlay/` resets the file system - use **overlayroot=disabled** as a kernel boot argument to bypass the overlay or edit the config file - use the ``overlayroot-chroot`` command to make changes (updates) on the underlying fs. As the kernel does not like to remount an in-use rootfs read-only other proagramms could potentially use /media/root-ro/ to write to the rootfs directly. If one is really concered about that, consider rebooting. # Network Boot ## documentation and links - https://kiljan.org/2019/11/16/arch-linux-arm-network-boot-on-raspberry-pi-4/ 1) the raspberry boots from a a SoC which runs some closed source binary blob in the GPU. The GPU then loads the CPU. This process is controlled by bootconf.txt 2) the EEPROM Boot Code executed in the GPU loads start4.elf (for 4B Model i think not anymore) 3) There is basically no such thing as a BIOS and the raspi is only bootable from SD-Card. 4) There is a beta EEPROM boot code since 23 September 2019. It allows to boot the Pi4B to load the necessary files from an TFTP server using the embedded Ethernet controller. -> EEPROM reprogramming <https://github.com/raspberrypi/rpi-eeprom> - Boot Configuration in EEPROM (bootconf.txt) or altern. via DHCP - **DHCP Server** or **SLAAC** - The Mac Adress and Serial Number determine which Directory from the **TFTP Server** the Pi Boots from, if start.elf not found: the Pi boots from / - start4.elf proprietary - provided by rootfs - Loaded Files: start.elf, config.txt, kernel.img, **initramfs-linux.img**, cmdline.txt (nobtcmd.txt) - initramfs must be prepared to boot with network rootfs - The kernel can boot with the initramfs but now requires the rootfs iSCSI/NBD or **NFS**/SMB ## server setup 1) **install**, sshd, ufw, hostname, network(netplan), update, upgrade, gen. sshkey to copy to nodes 2) create partition table on ssd(rootfs 50G, vmdisks) and mkfs.ext4 3) move / to the ssd - create partition table on /dev/sda and make file systems, `mount /dev/sda1 /mnt` - **rsync** rootfs to ssd `sudo rsync / -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt` - Empty the folder /mnt/boot/firmware. The Ubuntu Core OS uses U-Boot. - U-Boot mounts the boot partition /dev/mmcblk0p1 on /boot/firmware - U-Boot:<https://github.com/umiddelb/armhf/wiki/Get-more-out-of-%22Das-U-Boot%22> - official doc: <http://www.denx.de/wiki/view/DULG/Manual> - For U-Boot config file structure consult /boot/firmware/README. - change device label of the mounted partition: `gdisk /dev/sda1` and label sda1 *rootfs* `e2label /dev/sda1 rootfs` - add/replace rootfs label in /etc/fstab ("/" is mount point of the ssd) - change the LABEL to rootfs in /boot/firmware/nobtcmd.txt (the no bluetooth cmdlne kernel arguments (Alternativelly do the same with UUID) - reboot check if `lsblk` that /dev/sda1 is mounted on / - on problems work with u-boot cli interface (press any key to interrupt kernel startup). Use *u-boot-tools* to change environment variables directly from linux 4) Create a Base Image - create /nfs/base - get fresh "Ubuntu Core" base image in */nfs/* - `partprobe $(losetup --find --show /vm/baseimage.img)` - mount the two partitions of the image on /mnt and /mnt/boot/firmware - `sudo rsync /mnt/ -aAXv /nfs/base/` - configure files if necessary (network, ssh, ...) 5) Setup TFTP - create /tftp - `echo "/nfs/base/boot/firmware /tftp/ none defaults,bind 0 0" | sudo tee -a /etc/fstab` - `sudo mount /tftp; sudo chown -R tftp:tftp /tftp` - install tftp server package *tftpd-ha* - change config in /etc/default/tftpd-hpa to: - TFTP_USERNAME="tftp" - TFTP_DIRECTORY="/tftp" - TFTP_ADDRESS="192.168.1.2" #nfs server address - TFTP_OPTIONS="--map-file /etc/tftpd.mapfile --secure -v -R 50000:50000" # use port 50000 (for firewall) - TODO: create mapfile in */etc/tftpd.mapfile* - restart *tftp-hpa.service* - power raspberry, REQUEST CYCLE should be (for future reference) `journalctl _SYTEMD_UNIT=tftp-hpa.service -f`: RRQ dde3fc98/start4.elf RRQ dde3fc98/config.txt RRQ dde3fc98/start4.elf RRQ dde3fc98/fixup4.dat RRQ dde3fc98/recovery.elf RRQ dde3fc98/config.txt RRQ dde3fc98/syscfg.txt RRQ dde3fc98/nobtcfg.txt RRQ dde3fc98/usercfg.txt RRQ dde3fc98/dt-blob.bin RRQ dde3fc98/config.txt RRQ dde3fc98/syscfg.txt RRQ dde3fc98/nobtcfg.txt RRQ dde3fc98/usercfg.txt RRQ dde3fc98/bcm2711-rpi-4-b.dtb RRQ dde3fc98/config.txt RRQ dde3fc98/syscfg.txt RRQ dde3fc98/nobtcfg.txt RRQ dde3fc98/usercfg.txt RRQ dde3fc98/nobtcmd.txt RRQ dde3fc98/uboot_rpi_4.bin RRQ dde3fc98/armstub8-gic.bin RRQ dde3fc98/uboot_rpi_4.bin 6) Setup NFS - bind mount /nfs/base to /nfs/node0 (add entry in file system table) - install *nfs-kernel-server* package - add "/nfs/node0 192.168.1.3(crossmnt,insecure,rw,fsid=0,no_root_squash,no_subtree_check)" int /etc/exports or use 192.168.1.0/24 for the entire subnet instead of a single host, alternativelly use a dns hostname - test mounting with mount 192.168.1.2:/ /mnt/ -v #### whiteboard Basic Setup, sshd, ufw, hostname, network(netplan), update, upgrade, setup Plan: - setup bootable disk - reprogramm firmware - tftp service - nfs service - prepare initramfs and kernel cmd to boot via nfs x. Setup cloud init on vm disk a Server with: rootfs, TFTP, NFS, DHCP (preferably in its own network) ## client setup ### firmware updae - some help: <https://github.com/raspberrypi/rpi-eeprom/blob/master/firmware/raspberry_pi4_network_boot_beta.md> 1) read all the step by step instructions (ESPECIALLY 8.5 as this might cut down the work to two commands) 2) dedicate a microSD Card to update the EEPROM: reusable of course, so only one is needed 3) Flash Raspian Buster Lite onto the SSD Card and mount both partitions. Put an empty file */ssh* on the root partition or add *enable_uart=1* to /config.txt in the boot partition. 4) Install Raspian Buster Lite, upgrade, update. 5) `apt install rpi-eeprom` Download latest firmware `rpi-update` - not sure if this is needed. For Network Boot you need a firmware newer than 10.Sept 2019. Check with `rpi-eeprom-update`. If the firware is still to old you might need to switch to the Beta-Channel. `sed -i /etc/default/rpi-eeprom-update -e 's/^FIRMWARE_RELEASE_STATUS.*$/FIRMWARE_RELEASE_STATUS="beta"'` 6) Update Firmware with `rpi-eepromt-update -a` and confirm, yeah its that simple. Reboot to install firmware. TODO: Note this allways auto updates to the newest Beta Firmware when booting from SD-Card. This might not be what we want as the Version from 10.9.2019 is sufficient and might be more stable. Beta firmware (and recovery firmware) resides in /lib/firmware/raspberrypi/bootloader/beta/. Check if Firmware is Bricked; unplugg all the devices an power on the board. If the Green LED flashes and eventually starts to cycle (per cycle 4 flashes) Firmware is ok. If the Green LED is off create a recovery SD. 7) If further updates are not wanted `systemctl mask rpi-eeprom-update` 8) Enable Network Boot. (FIRMWARE) 1) Jump to point 5 and see if you can skip the Firmware Building Step 2) `cp /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2020-01-09.bin pieeprom.bin` (use required version) 3) Change Config: 4) BOOT_ORDER=0x21 (first try to boot from SD-Card, then from Network) 5) BOOT_UART=1 6) NET_BOOT_MAX_RETRIES=-1 7) TFTP_IP=192.168.x.x -> this setting can also be retrived with dhcp 8) Rebuild Firware file `rpi-eeprom-config --out newpieeprom.bin --config bootconf.txt pieeprom.bin` 9) Create new binary. `rpi-eeprom-update -d -f ./newpieeprom.bin` **This file resides in the home dir of the flash SSD and can be reused (Firmware 2020-01-09)** 10} EDIT EEPROM file newpieeprom.bin now called **custom-netboot-firmware2020-01-09.bin** 11) Flash: `sudo rpi-eeprom-update -d -f ./newpieeprom.bin` Reboot. 12) Check with `rpi-eeprom-update`. 9) Enable Network Boot. (SOFTWARE - requires U-Boot and a permament SD-Card) - TODO

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully