https://github.com/gokrazy/gokrazy Skip to content Sign up * Why GitHub? + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} gokrazy / gokrazy Public * Notifications * Fork 77 * Star 2.2k * a native Go userland for your Raspberry Pi 3 or 4 appliances (or amd64 PCs!) gokrazy.org BSD-3-Clause License 2.2k stars 77 forks Star Notifications * Code * Issues 22 * Pull requests 1 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 2 branches 0 tags Code Latest commit @stapelberg stapelberg GitHub Actions: remove branch restriction ... 1fb631a Jan 13, 2022 GitHub Actions: remove branch restriction 1fb631a Git stats * 174 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github GitHub Actions: remove branch restriction Jan 13, 2022 cmd dhcp: allow builds on non-64-bit architectures (#99) Nov 28, 2021 docs re-generate website Jan 12, 2022 empty add empty package Mar 5, 2017 integration/uefiboot disable KVM: GitHub Actions does not support nested virtualization Aug 18, 2021 internal status: live tail logs (#100) Dec 13, 2021 website docs(website): add user guide about how to access permanent data Jan 12, 2022 LICENSE Initial commit Mar 4, 2017 README.md README: slight editing Jan 12, 2022 authenticated.go Initial commit Mar 4, 2017 doc.go Initial commit Mar 4, 2017 go.mod update: support device-specific update handlers (#102) Jan 11, 2022 go.sum update: support device-specific update handlers (#102) Jan 11, 2022 gokrazy.go supervise: added optional configuration to wait for clock (#105) Jan 13, 2022 httpsredirect.go Honor https-port when redirecting (#79) Jan 8, 2021 listeners.go add TODO for Go 1.17 May 30, 2021 mount.go tmpfs: remove explicit size limit (- 50% of RAM) Nov 21, 2021 netlink.go update listeners when netlink reports an address change Nov 1, 2018 proc.go supervise: wait for services to stop before reboot (#106) Jan 12, 2022 reboot.go use Go 1.17 in GitHub Actions Aug 18, 2021 reboot_amd64.go update to new rootdev API Apr 7, 2020 status.go transparently add service when diverting an unknown service Dec 18, 2021 status_test.go load templates at func init time to catch parse errors during test Nov 21, 2021 supervise.go supervise: added optional configuration to wait for clock (#105) Jan 13, 2022 update.go supervise: wait for services to stop before reboot (#106) Jan 12, 2022 xsrf.go implement XSRF/CSRF protection for /stop and /restart Jun 25, 2018 View code [ ] Overview Usage Installation Overwriting an SD card for the Raspberry Pi 3 or 4 Updating your installation SD card contents Customization Changing program behavior for gokrazy Changing init behavior Repository structure Documentation README.md Build Status Go Report Card Overview gokrazy packs your Go application(s) into an SD card image for the Raspberry Pi 3 or 4 which -- aside from the Linux kernel and proprietary Raspberry Pi bootloader -- only contains Go software. The motivation is that @stapelberg spends way more time on C software and their various issues than he would like. Hence, he is going Go-only where feasible. Usage Installation Install the latest Go version if you haven't already. Create a directory for this gokrazy instance and initialize a Go module: INSTANCE=gokrazy/hello mkdir -p ~/${INSTANCE?} cd ~/${INSTANCE?} go mod init hello Then, install gokr-packer: go get github.com/gokrazy/tools/cmd/gokr-packer@latest Overwriting an SD card for the Raspberry Pi 3 or 4 To re-partition and overwrite the SD card /dev/sdx, use: gokr-packer -overwrite=/dev/sdx github.com/gokrazy/hello Then, put the SD card into your Raspberry Pi 3 or 4 and power it up! Once the Raspberry Pi 3 or 4 has booted (takes about 10 seconds), you should be able to reach the gokrazy web interface at the URL which gokr-packer printed. Under the hood, gokr-packer... 1. ...packed the latest firmware and kernel binaries into the boot file system. 2. ...built the specified Go packages using go install and packed all their binaries into the /user directory of the root file system. 3. ...created a minimal gokrazy init program which supervises all binaries (i.e. restarts them when they exit). Updating your installation To update gokrazy, including the firmware and kernel binaries, use: go get -u github.com/gokrazy/tools/cmd/gokr-packer go get -u github.com/gokrazy/gokrazy go get -u github.com/gokrazy/kernel go get -u github.com/gokrazy/firmware go get -u github.com/gokrazy/rpi-eeprom To update your gokrazy installation (running on a Raspberry Pi 3 or 4), use: GOKRAZY_UPDATE=http://gokrazy:mysecretpassword@gokrazy/ gokr-packer github.com/gokrazy/hello SD card contents gokrazy uses the following partition table: num size purpose file system 1 100 MB boot (kernel+firmware) FAT16B 2 500 MB root2 (gokrazy+apps) SquashFS 3 500 MB root3 (gokrazy+apps) SquashFS 4 rest permanent data ext4 The two root partitions are used alternatingly (to avoid modifying the currently active file system) when updating. If you'd like to store permanent data (i.e. data which will not be overwritten on the next update), you'll need to create an ext4 file system on the last partition. If your SD card is /dev/sdx, use mkfs.ext4 /dev/sdx4. After you successfully created the new filesystem on the forth partition, gokrazy will automatically mount the filesystem under /perm during startup. Use this mount directory to store your permanent data. Customization Changing program behavior for gokrazy gokr-packer sets the "gokrazy" build tag for conditional compilation. You can find an example commit which implements a gokrazy-specific controller that triggers the main program logic every weekday at 10:00 at https://github.com/stapelberg/zkj-nas-tools/commit/ 6f90ace35981f78dcd66d611269f17f37ce4b4ef Changing init behavior Assuming the application you'd like to create on gokrazy lives in the repository github.com/stapelberg/mediaserver, this is how you can make gokrazy dump the generated init package's source: mkdir -p $(go env GOPATH)/src/github.com/stapelberg/mediaserver/cmd/init gokr-packer \ -overwrite_init=$(go env GOPATH)/src/github.com/stapelberg/mediaserver/cmd/init/init.go \ github.com/gokrazy/hello (Note that the package must result in a binary called "init".) Then, edit the github.com/stapelberg/mediaserver package to your liking. When done, pack an image with your own init package: gokr-packer \ -init_pkg=github.com/stapelberg/mediaserver/cmd/init \ -overwrite=/dev/sdx \ github.com/gokrazy/hello Repository structure * github.com/gokrazy/gokrazy: system code, main issue tracker, documentation * github.com/gokrazy/tools: SD card image creation code, pulling in: + github.com/gokrazy/firmware: Raspberry Pi 3 or 4 firmware files + github.com/gokrazy/rpi-eeprom: Raspberry Pi 4 EEPROM files + github.com/gokrazy/kernel: pre-built kernel image and bootloader config Documentation gokrazy.org uses hugo for creating and generating the website. You can find the hugo install instructions here: Install Hugo. With hugo you can write documentation in Markdown and generate a static website from it. The website subdirectory is hugo's root directory. In order to preview the documentation or to re-generate the website, switch the directory to website. To preview the website, run the hugo webserver: hugo serve Generate the website: hugo The updated website content will be stored in the ./docs directory. Do not update anything here manually. About a native Go userland for your Raspberry Pi 3 or 4 appliances (or amd64 PCs!) gokrazy.org Topics linux golang raspberry-pi raspberrypi Resources Readme License BSD-3-Clause License Stars 2.2k stars Watchers 55 watching Forks 77 forks Releases No releases published Used by 16 * @adrianroos * @fwiedmann * @anupcshan * @anupcshan * @stapelberg * @gokrazy * @PiterPentester * @gokrazy + 8 Contributors 10 * @stapelberg * @andig * @anupcshan * @mdlayher * @tklauser * @christian-heusel * @fwiedmann * @Moredread * @dtchanpura * @janisstreib Languages * Go 33.0% * HTML 28.1% * CSS 25.5% * JavaScript 13.3% * SCSS 0.1% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.